Initial commit

This commit is contained in:
Michael J. Seiferling
2015-11-08 16:06:31 -06:00
parent 10be205da1
commit 2fd1aecfc9
87 changed files with 19755 additions and 1 deletions
+230
View File
@@ -0,0 +1,230 @@
Imports System.IO
Public Class mgrBackup
Private oSettings As mgrSettings
Private bCancelOperation As Boolean
Property Settings As mgrSettings
Get
Return oSettings
End Get
Set(value As mgrSettings)
oSettings = value
End Set
End Property
Property CancelOperation As Boolean
Get
Return bCancelOperation
End Get
Set(value As Boolean)
bCancelOperation = value
End Set
End Property
Public Event UpdateLog(sLogUpdate As String, bTrayUpdate As Boolean, objIcon As System.Windows.Forms.ToolTipIcon, bTimeStamp As Boolean)
Public Event UpdateBackupInfo(oGame As clsGame)
Public Event SetLastAction(sMessage As String)
Public Function CheckForUtilities(ByVal strPath As String) As Boolean
If File.Exists(strPath) Then
Return True
Else
Return False
End If
End Function
Private Function DoManifestUpdate(ByVal oGameInfo As clsGame, ByVal sBackupFile As String, ByVal dTimeStamp As DateTime, ByVal sCheckSum As String) As Boolean
Dim oItem As New clsBackup
'Create manifest item
oItem.Name = oGameInfo.Name
'Keep the path relative to the manifest location
oItem.FileName = sBackupFile.Replace(Path.GetDirectoryName(mgrPath.RemoteDatabaseLocation) & "\", "")
oItem.RestorePath = oGameInfo.TruePath
oItem.AbsolutePath = oGameInfo.AbsolutePath
oItem.DateUpdated = dTimeStamp
oItem.UpdatedBy = My.Computer.Name
oItem.CheckSum = sCheckSum
'Save Remote Manifest
If mgrManifest.DoManifestCheck(oItem.Name, mgrSQLite.Database.Remote) Then
mgrManifest.DoManifestUpdate(oItem, mgrSQLite.Database.Remote)
Else
mgrManifest.DoManifestAdd(oItem, mgrSQLite.Database.Remote)
End If
'Save Local Manifest
If mgrManifest.DoManifestCheck(oItem.Name, mgrSQLite.Database.Local) Then
mgrManifest.DoManifestUpdate(oItem, mgrSQLite.Database.Local)
Else
mgrManifest.DoManifestAdd(oItem, mgrSQLite.Database.Local)
End If
Return True
End Function
Private Sub BuildFileList(ByVal sBackupPath As String, ByVal sList As String, ByVal sPath As String)
Dim oStream As StreamWriter
Try
If File.Exists(sPath) Then File.Delete(sPath)
oStream = New StreamWriter(sPath)
Using oStream
If sList <> String.Empty Then
For Each sTypeItem As String In sList.Split(":")
oStream.WriteLine("""" & sBackupPath & "\" & sTypeItem & """")
Next
End If
oStream.Flush()
End Using
Catch ex As Exception
RaiseEvent UpdateLog("An error occured creating a file list: " & ex.Message, False, ToolTipIcon.Error, True)
End Try
End Sub
Public Sub DoBackup(ByVal oBackupList As List(Of clsGame))
Dim oGame As clsGame
Dim bDoBackup As Boolean
Dim bBackupCompleted As Boolean
Dim prs7z As Process
Dim sBackupFile As String
Dim sSavePath As String
Dim dTimeStamp As DateTime
Dim sTimeStamp As String
Dim sHash As String
For Each oGame In oBackupList
'Init
prs7z = New Process
sBackupFile = oSettings.BackupFolder
sSavePath = String.Empty
dTimeStamp = Date.Now
sTimeStamp = " " & dTimeStamp.Month & "-" & dTimeStamp.Day & "-" & dTimeStamp.Year & "-" & dTimeStamp.Hour & "-" & dTimeStamp.Minute & "-" & dTimeStamp.Second
sHash = String.Empty
bDoBackup = True
bBackupCompleted = False
CancelOperation = False
RaiseEvent UpdateBackupInfo(oGame)
If mgrRestore.CheckManifest(oGame.Name) Then
If MsgBox("The manifest shows the backup folder contains a backup for " & oGame.Name & " that has not been restored on this computer." & vbCrLf & vbCrLf & "Do you want to overwrite this file anyway?", MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.No Then
RaiseEvent UpdateLog("Backup aborted by user due to manifest conflict.", False, ToolTipIcon.Error, True)
bDoBackup = False
End If
End If
If oSettings.CreateSubFolder Then
sBackupFile = sBackupFile & "\" & oGame.Name
Try
If Not Directory.Exists(sBackupFile) Then
Directory.CreateDirectory(sBackupFile)
End If
Catch ex As Exception
RaiseEvent UpdateLog("Backup Aborted. A failure occured while creating backup sub-folder for " & oGame.Name & vbCrLf & ex.Message, False, ToolTipIcon.Error, True)
bDoBackup = False
End Try
End If
If oGame.AppendTimeStamp Then
sBackupFile = sBackupFile & "\" & oGame.Name & sTimeStamp & ".7z"
Else
sBackupFile = sBackupFile & "\" & oGame.Name & ".7z"
End If
If oSettings.ShowOverwriteWarning And File.Exists(sBackupFile) Then
If MsgBox("A file with the same name already exists in the backup folder." & vbCrLf & vbCrLf & "Do you want to overwrite this file?", MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.No Then
RaiseEvent UpdateLog(oGame.Name & " backup aborted by user due to overwrite.", False, ToolTipIcon.Error, True)
bDoBackup = False
End If
End If
If bDoBackup Then
If oGame.AbsolutePath = False Then
If oGame.Path <> String.Empty Then
sSavePath = oGame.ProcessPath & "\" & oGame.Path
Else
sSavePath = oGame.ProcessPath
End If
Else
sSavePath = oGame.Path
End If
If oGame.FolderSave = True Then
BuildFileList(sSavePath, "*.*", mgrPath.IncludeFileLocation)
Else
BuildFileList(sSavePath, oGame.FileType, mgrPath.IncludeFileLocation)
End If
BuildFileList(sSavePath, oGame.ExcludeList, mgrPath.ExcludeFileLocation)
Try
'Need to delete any prior archive if it exists, the 7za utility does not support overwriting or deleting existing archives.
'If we let 7za update existing archives it will lead to excessive bloat with games that routinely add and remove files with many different file names.
If File.Exists(sBackupFile) Then
File.Delete(sBackupFile)
End If
If Directory.Exists(sSavePath) Then
prs7z.StartInfo.Arguments = "a -t7z " & "-i@""" & mgrPath.IncludeFileLocation & """ -x@""" & mgrPath.ExcludeFileLocation & """ """ & sBackupFile & """ -r"
prs7z.StartInfo.FileName = mgrPath.Utility7zLocation
prs7z.StartInfo.UseShellExecute = False
prs7z.StartInfo.RedirectStandardOutput = True
prs7z.StartInfo.CreateNoWindow = True
prs7z.Start()
RaiseEvent UpdateLog("Backup of " & sSavePath & " in progress...", True, ToolTipIcon.Info, True)
While Not prs7z.StandardOutput.EndOfStream
If CancelOperation Then
prs7z.Kill()
RaiseEvent UpdateLog("Backup Aborted by user. The backup file for " & oGame.Name & " will be unusable.", False, ToolTipIcon.Error, True)
Exit While
End If
RaiseEvent UpdateLog(prs7z.StandardOutput.ReadLine, False, ToolTipIcon.Info, False)
End While
prs7z.WaitForExit()
If Not CancelOperation Then
If prs7z.ExitCode = 0 Then
RaiseEvent UpdateLog(oGame.Name & " backup completed.", False, ToolTipIcon.Info, True)
bBackupCompleted = True
Else
RaiseEvent UpdateLog(oGame.Name & " backup operation finished with warnings or errors.", False, ToolTipIcon.Error, True)
bBackupCompleted = False
End If
End If
prs7z.Dispose()
Else
RaiseEvent UpdateLog("Backup Aborted. The path " & sSavePath & " for " & oGame.Name & " does not exist.", False, ToolTipIcon.Error, True)
bBackupCompleted = False
End If
'Write Main Manifest
If bBackupCompleted Then
If oSettings.CheckSum Then
RaiseEvent UpdateLog("Generating SHA-256 hash for " & oGame.Name & " backup file.", False, ToolTipIcon.Info, True)
sHash = mgrHash.Generate_SHA256_Hash(sBackupFile)
End If
If Not DoManifestUpdate(oGame, sBackupFile, dTimeStamp, sHash) Then
RaiseEvent UpdateLog("The manifest update for " & oGame.Name & " failed.", False, ToolTipIcon.Error, True)
End If
'Write the process path if we have it
If oGame.AbsolutePath = False Then
mgrMonitorList.DoListUpdate(oGame)
End If
End If
Catch ex As Exception
RaiseEvent UpdateLog("An unexpected error occured during the backup process of " & oGame.Name & vbCrLf & ex.Message, False, ToolTipIcon.Error, True)
End Try
End If
If bBackupCompleted Then
RaiseEvent SetLastAction(oGame.CroppedName & " backup completed")
Else
RaiseEvent SetLastAction(oGame.CroppedName & " backup failed")
End If
Next
End Sub
End Class
+113
View File
@@ -0,0 +1,113 @@
Imports System.Net
Public Class mgrCommon
Public Shared ReadOnly Property BuildVersion As Integer
Get
Return My.Application.Info.Version.Build
End Get
End Property
Public Shared ReadOnly Property AppVersion As Integer
Get
Return (My.Application.Info.Version.Major * 100) + My.Application.Info.Version.Minor
End Get
End Property
Public Shared Function CheckAddress(ByVal URL As String) As Boolean
Try
Dim request As WebRequest = WebRequest.Create(URL)
Dim response As WebResponse = request.GetResponse()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Shared Function DateToUnix(ByVal dDate As DateTime) As Int64
Return DateDiff(DateInterval.Second, #1/1/1970#, dDate)
End Function
Public Shared Function UnixToDate(ByVal iDate As Int64) As DateTime
Return DateAdd(DateInterval.Second, iDate, #1/1/1970#)
End Function
Public Shared Function BooleanYesNo(ByVal bBool As Boolean) As String
If bBool Then
Return "Yes"
Else
Return "No"
End If
End Function
Public Shared Function SaveFileBrowser(ByVal sTitle As String, ByVal sExtension As String, ByVal sFileType As String, ByVal sDefaultFolder As String, ByVal sDefaultFile As String) As String
Dim fbBrowser As New SaveFileDialog
fbBrowser.Title = sTitle
fbBrowser.DefaultExt = sExtension
fbBrowser.Filter = sFileType & " files (*." & sExtension & ")|*." & sExtension
fbBrowser.InitialDirectory = sDefaultFolder
fbBrowser.FileName = sDefaultFile
If fbBrowser.ShowDialog() = Windows.Forms.DialogResult.OK Then
Return fbBrowser.FileName
End If
Return String.Empty
End Function
Public Shared Function OpenFileBrowser(ByVal sTitle As String, ByVal sExtension As String, ByVal sFileType As String, ByVal sDefaultFolder As String, ByVal bMulti As Boolean) As String
Dim fbBrowser As New OpenFileDialog
fbBrowser.Title = sTitle
fbBrowser.DefaultExt = sExtension
fbBrowser.Filter = sFileType & " files (*." & sExtension & ")|*." & sExtension
fbBrowser.InitialDirectory = sDefaultFolder
fbBrowser.Multiselect = bMulti
If fbBrowser.ShowDialog() = Windows.Forms.DialogResult.OK Then
If bMulti Then
Dim sFileNames As String = String.Empty
For Each sFileName As String In fbBrowser.FileNames
sFileNames &= sFileName & "|"
Next
sFileNames = sFileNames.TrimEnd("|")
Return sFileNames
Else
Return fbBrowser.FileName
End If
End If
Return String.Empty
End Function
Public Shared Function OpenFolderBrowser(ByVal sTitle As String, ByVal sDefaultFolder As String, ByVal bEnableNewFolder As Boolean) As String
Dim fbBrowser As New FolderBrowserDialog
fbBrowser.Description = sTitle
fbBrowser.SelectedPath = sDefaultFolder
fbBrowser.ShowNewFolderButton = bEnableNewFolder
If fbBrowser.ShowDialog() = Windows.Forms.DialogResult.OK Then
Return fbBrowser.SelectedPath
End If
Return String.Empty
End Function
Public Shared Function IsElevated() As Boolean
If My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
Return True
Else
Return False
End If
End Function
Public Shared Sub RestartAsAdmin()
Dim oProcess As New Process
oProcess.StartInfo.FileName = Application.ExecutablePath
oProcess.StartInfo.UseShellExecute = True
oProcess.StartInfo.CreateNoWindow = True
oProcess.StartInfo.Verb = "runas"
oProcess.Start()
End Sub
End Class
+4
View File
@@ -0,0 +1,4 @@
Public Class mgrGlobals
Public Shared LocalDatabaseHash As String = String.Empty
Public Shared RemoteDatabaseHash As String = String.Empty
End Class
+43
View File
@@ -0,0 +1,43 @@
Imports System.IO
Imports System.Security
Imports System.Security.Cryptography
Public Class mgrHash
'Generate SHA256 Hash
Public Shared Function Generate_SHA256_Hash(ByVal sPath As String)
Dim bHashValue() As Byte
Dim oSHA As SHA256 = SHA256.Create()
Dim sHash As String
If File.Exists(sPath) Then
Dim fileStream As FileStream = File.OpenRead(sPath)
fileStream.Position = 0
bHashValue = oSHA.ComputeHash(fileStream)
sHash = PrintByteArray(bHashValue)
fileStream.Close()
Else
sHash = String.Empty
End If
Return sHash
End Function
' Print the byte array in a readable format.
Public Shared Function PrintByteArray(ByVal bArray() As Byte) As String
Dim sHex As String = String.Empty
Dim i As Integer
For i = 0 To bArray.Length - 1
sHex &= String.Format("{0:X2}", bArray(i))
Next i
Return sHex
End Function
End Class
+168
View File
@@ -0,0 +1,168 @@
Imports System.IO
Public Class mgrManifest
Public Shared Function ReadManifest(ByVal iSelectDB As mgrSQLite.Database) As SortedList
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim oData As DataSet
Dim sSQL As String
Dim oBackupItem As clsBackup
Dim slList As New SortedList
sSQL = "SELECT * from manifest ORDER BY Name Asc"
oData = oDatabase.ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
oBackupItem = New clsBackup
oBackupItem.ID = CStr(dr(0))
oBackupItem.Name = CStr(dr(1))
oBackupItem.FileName = CStr(dr(2))
oBackupItem.RestorePath = CStr(dr(3))
oBackupItem.AbsolutePath = CBool(dr(4))
oBackupItem.DateUpdated = mgrCommon.UnixToDate(dr(5))
oBackupItem.UpdatedBy = CStr(dr(6))
If Not IsDBNull(dr(7)) Then oBackupItem.CheckSum = CStr(dr(7))
slList.Add(oBackupItem.Name, oBackupItem)
Next
Return slList
End Function
Public Shared Function DoManifestCheck(ByVal sName As String, ByVal iSelectDB As mgrSQLite.Database) As Boolean
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim oData As DataSet
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "SELECT * from manifest "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", sName)
oData = oDatabase.ReadParamData(sSQL, hshParams)
If oData.Tables(0).Rows.Count > 0 Then
Return True
Else
Return False
End If
End Function
Public Shared Function DoManifestGetByName(ByVal sName As String, ByVal iSelectDB As mgrSQLite.Database) As clsBackup
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim oData As DataSet
Dim sSQL As String
Dim hshParams As New Hashtable
Dim oBackupItem As New clsBackup
sSQL = "SELECT * from manifest "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", sName)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oBackupItem = New clsBackup
oBackupItem.ID = CStr(dr(0))
oBackupItem.Name = CStr(dr(1))
oBackupItem.FileName = CStr(dr(2))
oBackupItem.RestorePath = CStr(dr(3))
oBackupItem.AbsolutePath = CBool(dr(4))
oBackupItem.DateUpdated = mgrCommon.UnixToDate(dr(5))
oBackupItem.UpdatedBy = CStr(dr(6))
If Not IsDBNull(dr(7)) Then oBackupItem.CheckSum = CStr(dr(7))
Next
Return oBackupItem
End Function
Public Shared Sub DoManifestAdd(ByVal oBackupItem As clsBackup, ByVal iSelectDB As mgrSQLite.Database)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "INSERT INTO manifest VALUES (@ID, @Name, @FileName, @Path, @AbsolutePath, @DateUpdated, @UpdatedBy, @CheckSum)"
hshParams.Add("ID", oBackupItem.ID)
hshParams.Add("Name", oBackupItem.Name)
hshParams.Add("FileName", oBackupItem.FileName)
hshParams.Add("Path", oBackupItem.TruePath)
hshParams.Add("AbsolutePath", oBackupItem.AbsolutePath)
hshParams.Add("DateUpdated", oBackupItem.DateUpdatedUnix)
hshParams.Add("UpdatedBy", oBackupItem.UpdatedBy)
hshParams.Add("CheckSum", oBackupItem.CheckSum)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoManifestUpdate(ByVal oBackupItem As clsBackup, ByVal iSelectDB As mgrSQLite.Database)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE manifest SET Name = @Name, FileName = @FileName, RestorePath = @Path, AbsolutePath = @AbsolutePath, "
sSQL &= "DateUpdated = @DateUpdated, UpdatedBy = @UpdatedBy, CheckSum = @CheckSum WHERE Name = @QueryName"
hshParams.Add("Name", oBackupItem.Name)
hshParams.Add("FileName", oBackupItem.FileName)
hshParams.Add("Path", oBackupItem.TruePath)
hshParams.Add("AbsolutePath", oBackupItem.AbsolutePath)
hshParams.Add("DateUpdated", oBackupItem.DateUpdatedUnix)
hshParams.Add("UpdatedBy", oBackupItem.UpdatedBy)
hshParams.Add("CheckSum", oBackupItem.CheckSum)
hshParams.Add("QueryName", oBackupItem.Name)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoManifestNameUpdate(ByVal sOriginalName As String, ByVal oBackupItem As clsBackup, ByVal iSelectDB As mgrSQLite.Database)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE manifest SET Name = @Name, FileName = @FileName, RestorePath = @Path, AbsolutePath = @AbsolutePath, "
sSQL &= "DateUpdated = @DateUpdated, UpdatedBy = @UpdatedBy, CheckSum = @CheckSum WHERE Name = @QueryName"
hshParams.Add("Name", oBackupItem.Name)
hshParams.Add("FileName", oBackupItem.FileName)
hshParams.Add("Path", oBackupItem.TruePath)
hshParams.Add("AbsolutePath", oBackupItem.AbsolutePath)
hshParams.Add("DateUpdated", oBackupItem.DateUpdatedUnix)
hshParams.Add("UpdatedBy", oBackupItem.UpdatedBy)
hshParams.Add("CheckSum", oBackupItem.CheckSum)
hshParams.Add("QueryName", sOriginalName)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoManifestDelete(ByVal oBackupItem As clsBackup, ByVal iSelectDB As mgrSQLite.Database)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM manifest "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", oBackupItem.Name)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoManifestHashWipe()
Dim oLocalDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim oRemoteDatabase As New mgrSQLite(mgrSQLite.Database.Remote)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE manifest SET CheckSum = @CheckSum"
hshParams.Add("CheckSum", String.Empty)
oLocalDatabase.RunParamQuery(sSQL, hshParams)
oRemoteDatabase.RunParamQuery(sSQL, hshParams)
End Sub
End Class
+539
View File
@@ -0,0 +1,539 @@
Imports System.IO
Public Class mgrMonitorList
Public Enum eListTypes As Integer
FullList = 1
ScanList = 2
ListByKey = 3
End Enum
Public Shared Event UpdateLog(sLogUpdate As String, bTrayUpdate As Boolean, objIcon As System.Windows.Forms.ToolTipIcon, bTimeStamp As Boolean)
Public Shared Sub HandleBackupLocationChange()
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Remote)
Dim iGameCount As Integer
'Check if a remote database already exists in the new backup location
If oDatabase.CheckDB() Then
'Make sure database is the latest version
oDatabase.DatabaseUpgrade()
'See if the remote database is empty
iGameCount = mgrMonitorList.ReadList(eListTypes.FullList, mgrSQLite.Database.Remote).Count
'If the remote database actually contains a list, then ask what to do
If iGameCount > 0 Then
If MsgBox("GBM data already exists in the backup folder." & vbCrLf & vbCrLf & _
"Do you want to make your local game list the new master game list in this folder? (Recommended)" & vbCrLf & vbCrLf & _
"Choosing No will sync your local game list to the current master game list in this folder.", MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.Yes Then
mgrMonitorList.SyncMonitorLists()
Else
mgrMonitorList.SyncMonitorLists(False)
End If
Else
mgrMonitorList.SyncMonitorLists()
End If
Else
mgrMonitorList.SyncMonitorLists()
End If
End Sub
Private Shared Sub ImportMonitorList(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False)
Dim hshCompareFrom As Hashtable
Dim hshCompareTo As Hashtable
Dim hshSyncItems As Hashtable
Dim oFromItem As clsGame
Dim oToItem As clsGame
Dim iItems As Integer = 0
Cursor.Current = Cursors.WaitCursor
'Add / Update Sync
hshCompareFrom = mgrXML.ReadMonitorList(sLocation, bWebRead)
hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
hshSyncItems = hshCompareFrom.Clone
For Each oFromItem In hshCompareFrom.Values
If hshCompareTo.Contains(oFromItem.ProcessName) Then
oToItem = DirectCast(hshCompareTo(oFromItem.ProcessName), clsGame)
If oFromItem.CoreEquals(oToItem) Then
hshSyncItems.Remove(oFromItem.ProcessName)
End If
End If
Next
Cursor.Current = Cursors.Default
If hshSyncItems.Count > 0 Then
Dim frm As New frmAdvancedImport
frm.ImportData = hshSyncItems
If frm.ShowDialog() = DialogResult.OK Then
Cursor.Current = Cursors.WaitCursor
For Each oGame As clsGame In frm.ImportData.Values
If Not DoDuplicateListCheck(oGame.Name, oGame.TrueProcess) Then
DoListAdd(oGame, mgrSQLite.Database.Local)
iItems += 1
End If
Next
Cursor.Current = Cursors.Default
MsgBox("Import Complete. " & iItems & " entries have been imported.", MsgBoxStyle.Information, "Game Backup Monitor")
End If
Else
MsgBox("This list does not contain any new games to import.", MsgBoxStyle.Information, "Game Backup Monitor")
End If
Application.DoEvents()
End Sub
Public Shared Sub ExportMonitorList(ByVal sLocation As String)
Dim hshList As Hashtable = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
Dim bSuccess As Boolean
bSuccess = mgrXML.ExportMonitorList(hshList, sLocation)
If bSuccess Then
MsgBox("Export Complete. " & hshList.Count & " entries have been exported.", MsgBoxStyle.Information, "Game Backup Monitor")
End If
End Sub
Public Shared Sub SyncMonitorLists(Optional ByVal bToRemote As Boolean = True)
Dim hshCompareFrom As Hashtable
Dim hshCompareTo As Hashtable
Dim hshSyncItems As Hashtable
Dim hshDeleteItems As Hashtable
Dim oFromItem As clsGame
Dim oToItem As clsGame
Cursor.Current = Cursors.WaitCursor
If bToRemote Then
RaiseEvent UpdateLog("A sync to the master game list has been triggered.", False, ToolTipIcon.Info, True)
Else
RaiseEvent UpdateLog("A sync from the master game list has been triggered.", False, ToolTipIcon.Info, True)
End If
'Delete Sync
If bToRemote Then
hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote)
Else
hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote)
hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
End If
hshDeleteItems = hshCompareTo.Clone
For Each oToItem In hshCompareTo.Values
If hshCompareFrom.Contains(oToItem.ProcessName) Then
oFromItem = DirectCast(hshCompareFrom(oToItem.ProcessName), clsGame)
If oToItem.CoreEquals(oFromItem) Then
hshDeleteItems.Remove(oToItem.ProcessName)
End If
End If
Next
For Each oGame As clsGame In hshDeleteItems.Values
If bToRemote Then
DoListDeleteSync(oGame, mgrSQLite.Database.Remote)
Else
DoListDeleteSync(oGame, mgrSQLite.Database.Local)
End If
Next
'Add / Update Sync
If bToRemote Then
hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote)
Else
hshCompareFrom = ReadList(eListTypes.FullList, mgrSQLite.Database.Remote)
hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
End If
hshSyncItems = hshCompareFrom.Clone
For Each oFromItem In hshCompareFrom.Values
If hshCompareTo.Contains(oFromItem.ProcessName) Then
oToItem = DirectCast(hshCompareTo(oFromItem.ProcessName), clsGame)
If oFromItem.SyncEquals(oToItem) Then
hshSyncItems.Remove(oFromItem.ProcessName)
End If
End If
Next
For Each oGame As clsGame In hshSyncItems.Values
'Clear Extra Data
oGame.Version = String.Empty
oGame.Company = String.Empty
oGame.ProcessPath = String.Empty
oGame.Icon = String.Empty
If bToRemote Then
If DoDuplicateListCheck(oGame.Name, oGame.TrueProcess, mgrSQLite.Database.Remote) Then
DoListUpdateSync(oGame, mgrSQLite.Database.Remote)
Else
DoListAdd(oGame, mgrSQLite.Database.Remote)
End If
Else
If DoDuplicateListCheck(oGame.Name, oGame.TrueProcess, mgrSQLite.Database.Local) Then
DoListUpdateSync(oGame, mgrSQLite.Database.Local)
Else
DoListAdd(oGame, mgrSQLite.Database.Local)
End If
End If
Next
RaiseEvent UpdateLog(hshDeleteItems.Count + hshSyncItems.Count & " change(s) synced.", False, ToolTipIcon.Info, True)
Cursor.Current = Cursors.Default
Application.DoEvents()
End Sub
Public Shared Function DoImport(ByVal sPath As String) As Boolean
If (sPath.IndexOf("http://", 0, StringComparison.CurrentCultureIgnoreCase) > -1) Or _
(sPath.IndexOf("https://", 0, StringComparison.CurrentCultureIgnoreCase) > -1) Then
If mgrCommon.CheckAddress(sPath) Then
ImportMonitorList(sPath, True)
Return True
Else
MsgBox("There's no response from:" & vbCrLf & vbCrLf & sPath & vbCrLf & vbCrLf & "Either the server is not responding or the URL is invalid.")
Return False
End If
Else
If File.Exists(sPath) Then
ImportMonitorList(sPath)
Return True
Else
MsgBox("The file:" & vbCrLf & sPath & vbCrLf & "cannot be found.")
Return False
End If
End If
End Function
Public Shared Function ReadList(ByVal eListType As eListTypes, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As Hashtable
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim oData As DataSet
Dim sSQL As String
Dim hshList As New Hashtable
Dim hshDupeList As New Hashtable
Dim oGame As clsGame
Dim oDupeGame As clsGame
sSQL = "SELECT * from monitorlist ORDER BY Name Asc"
oData = oDatabase.ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
oGame = New clsGame
oGame.ID = CStr(dr(0))
oGame.Name = CStr(dr(1))
oGame.ProcessName = CStr(dr(2))
If Not IsDBNull(dr(3)) Then oGame.Path = CStr(dr(3))
oGame.AbsolutePath = CBool(dr(4))
oGame.FolderSave = CBool(dr(5))
If Not IsDBNull(dr(6)) Then oGame.FileType = CStr(dr(6))
oGame.AppendTimeStamp = CBool(dr(7))
If Not IsDBNull(dr(8)) Then oGame.ExcludeList = CStr(dr(8))
If Not IsDBNull(dr(9)) Then oGame.ProcessPath = CStr(dr(9))
If Not IsDBNull(dr(10)) Then oGame.Icon = CStr(dr(10))
oGame.Hours = CDbl(dr(11))
If Not IsDBNull(dr(12)) Then oGame.Version = CStr(dr(12))
If Not IsDBNull(dr(13)) Then oGame.Company = CStr(dr(13))
oGame.Enabled = CBool(dr(14))
oGame.MonitorOnly = CBool(dr(15))
Select Case eListType
Case eListTypes.FullList
If hshList.Contains(oGame.ProcessName) Or hshDupeList.Contains(oGame.ProcessName) Then
oDupeGame = DirectCast(hshList.Item(oGame.ProcessName), clsGame)
If Not hshDupeList.Contains(oGame.ProcessName) Then
hshDupeList.Add(oGame.ProcessName, oDupeGame)
hshList.Remove(oDupeGame.ProcessName)
oDupeGame.Duplicate = True
oDupeGame.ProcessName = oDupeGame.ProcessName & ":" & oDupeGame.Name
hshList.Add(oDupeGame.ProcessName, oDupeGame)
End If
oGame.ProcessName = oGame.ProcessName & ":" & oGame.Name
oGame.Duplicate = True
End If
hshList.Add(oGame.ProcessName, oGame)
Case eListTypes.ScanList
If hshList.Contains(oGame.ProcessName) Then
DirectCast(hshList.Item(oGame.ProcessName), clsGame).Duplicate = True
oGame.ProcessName = oGame.ProcessName & ":" & oGame.Name
oGame.Duplicate = True
End If
If oGame.Enabled Then hshList.Add(oGame.ProcessName, oGame)
Case eListTypes.ListByKey
hshList.Add(oGame.ID, oGame)
End Select
Next
Return hshList
End Function
Public Shared Sub DoListAdd(ByVal oGame As clsGame, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "INSERT INTO monitorlist VALUES (@ID, @Name, @Process, @Path, @AbsolutePath, @FolderSave, @FileType, @TimeStamp, "
sSQL &= "@ExcludeList, @ProcessPath, @Icon, @Hours, @Version, @Company, @Enabled, @MonitorOnly)"
'Parameters
hshParams.Add("ID", oGame.ID)
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
hshParams.Add("Path", oGame.TruePath)
hshParams.Add("AbsolutePath", oGame.AbsolutePath)
hshParams.Add("FolderSave", oGame.FolderSave)
hshParams.Add("FileType", oGame.FileType)
hshParams.Add("TimeStamp", oGame.AppendTimeStamp)
hshParams.Add("ExcludeList", oGame.ExcludeList)
hshParams.Add("ProcessPath", oGame.ProcessPath)
hshParams.Add("Icon", oGame.Icon)
hshParams.Add("Hours", oGame.Hours)
hshParams.Add("Version", oGame.Version)
hshParams.Add("Company", oGame.Company)
hshParams.Add("Enabled", oGame.Enabled)
hshParams.Add("MonitorOnly", oGame.MonitorOnly)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListUpdate(ByVal oGame As clsGame, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE monitorlist SET Name=@Name, Process=@Process, Path=@Path, AbsolutePath=@AbsolutePath, FolderSave=@FolderSave, "
sSQL &= "FileType=@FileType, TimeStamp=@TimeStamp, ExcludeList=@ExcludeList, ProcessPath=@ProcessPath, Icon=@Icon, "
sSQL &= "Hours=@Hours, Version=@Version, Company=@Company, Enabled=@Enabled, MonitorOnly=@MonitorOnly WHERE MonitorID=@ID"
'Parameters
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
hshParams.Add("Path", oGame.TruePath)
hshParams.Add("AbsolutePath", oGame.AbsolutePath)
hshParams.Add("FolderSave", oGame.FolderSave)
hshParams.Add("FileType", oGame.FileType)
hshParams.Add("TimeStamp", oGame.AppendTimeStamp)
hshParams.Add("ExcludeList", oGame.ExcludeList)
hshParams.Add("ProcessPath", oGame.ProcessPath)
hshParams.Add("Icon", oGame.Icon)
hshParams.Add("Hours", oGame.Hours)
hshParams.Add("Version", oGame.Version)
hshParams.Add("Company", oGame.Company)
hshParams.Add("Enabled", oGame.Enabled)
hshParams.Add("MonitorOnly", oGame.MonitorOnly)
hshParams.Add("ID", oGame.ID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListUpdateMulti(ByVal sMonitorIDs As List(Of String), ByVal oGame As clsGame, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
Dim iCounter As Integer
sSQL = "UPDATE monitorlist SET Enabled=@Enabled, MonitorOnly=@MonitorOnly WHERE MonitorID IN ("
'Parameters
hshParams.Add("Enabled", oGame.Enabled)
hshParams.Add("MonitorOnly", oGame.MonitorOnly)
For Each s As String In sMonitorIDs
sSQL &= "@MonitorID" & iCounter & ","
hshParams.Add("MonitorID" & iCounter, s)
iCounter += 1
Next
sSQL = sSQL.TrimEnd(",")
sSQL &= ")"
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListUpdateSync(ByVal oGame As clsGame, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE monitorlist SET Name=@Name, Process=@Process, Path=@Path, AbsolutePath=@AbsolutePath, FolderSave=@FolderSave, "
sSQL &= "FileType=@FileType, TimeStamp=@TimeStamp, ExcludeList=@ExcludeList, Hours=@Hours "
sSQL &= "WHERE Name=@QueryName AND Process=@QueryProcess"
'Parameters
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
hshParams.Add("Path", oGame.TruePath)
hshParams.Add("AbsolutePath", oGame.AbsolutePath)
hshParams.Add("FolderSave", oGame.FolderSave)
hshParams.Add("FileType", oGame.FileType)
hshParams.Add("TimeStamp", oGame.AppendTimeStamp)
hshParams.Add("ExcludeList", oGame.ExcludeList)
hshParams.Add("Hours", oGame.Hours)
hshParams.Add("QueryName", oGame.Name)
hshParams.Add("QueryProcess", oGame.TrueProcess)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListDeleteSync(ByVal oGame As clsGame, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM monitorlist "
sSQL &= "WHERE Name = @Name AND Process= @Process"
hshParams.Add("Name", oGame.Name)
hshParams.Add("Process", oGame.TrueProcess)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListDelete(ByVal sMonitorID As String, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM monitorlist "
sSQL &= "WHERE MonitorID = @MonitorID"
hshParams.Add("MonitorID", sMonitorID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoListDeleteMulti(ByVal sMonitorIDs As List(Of String), Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local)
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim hshParams As New Hashtable
Dim iCounter As Integer
sSQL = "DELETE FROM monitorlist "
sSQL &= "WHERE MonitorID IN ("
For Each s As String In sMonitorIDs
sSQL &= "@MonitorID" & iCounter & ","
hshParams.Add("MonitorID" & iCounter, s)
iCounter += 1
Next
sSQL = sSQL.TrimEnd(",")
sSQL &= ")"
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Function DoListGetbyID(ByVal iMonitorID As Integer, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As clsGame
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim oData As DataSet
Dim oGame As New clsGame
Dim hshParams As New Hashtable
sSQL = "SELECT * from monitorlist "
sSQL &= "WHERE MonitorID = @MonitorID"
hshParams.Add("MonitorID", iMonitorID)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oGame = New clsGame
oGame.ID = CStr(dr(0))
oGame.Name = CStr(dr(1))
oGame.ProcessName = CStr(dr(2))
If Not IsDBNull(dr(3)) Then oGame.Path = CStr(dr(3))
oGame.AbsolutePath = CBool(dr(4))
oGame.FolderSave = CBool(dr(5))
If Not IsDBNull(dr(6)) Then oGame.FileType = CStr(dr(6))
oGame.AppendTimeStamp = CBool(dr(7))
If Not IsDBNull(dr(8)) Then oGame.ExcludeList = CStr(dr(8))
If Not IsDBNull(dr(9)) Then oGame.ProcessPath = CStr(dr(9))
If Not IsDBNull(dr(10)) Then oGame.Icon = CStr(dr(10))
oGame.Hours = CDbl(dr(11))
If Not IsDBNull(dr(12)) Then oGame.Version = CStr(dr(12))
If Not IsDBNull(dr(13)) Then oGame.Company = CStr(dr(13))
oGame.Enabled = CBool(dr(14))
oGame.MonitorOnly = CBool(dr(15))
Next
Return oGame
End Function
Public Shared Function DoListGetbyName(ByVal sName As String, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As Hashtable
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim oData As DataSet
Dim oGame As New clsGame
Dim hshGames As New Hashtable
Dim hshParams As New Hashtable
Dim iCounter As Integer = 0
sSQL = "SELECT * from monitorlist "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", sName)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oGame = New clsGame
oGame.ID = CStr(dr(0))
oGame.Name = CStr(dr(1))
oGame.ProcessName = CStr(dr(2))
If Not IsDBNull(dr(3)) Then oGame.Path = CStr(dr(3))
oGame.AbsolutePath = CBool(dr(4))
oGame.FolderSave = CBool(dr(5))
If Not IsDBNull(dr(6)) Then oGame.FileType = CStr(dr(6))
oGame.AppendTimeStamp = CBool(dr(7))
If Not IsDBNull(dr(8)) Then oGame.ExcludeList = CStr(dr(8))
If Not IsDBNull(dr(9)) Then oGame.ProcessPath = CStr(dr(9))
If Not IsDBNull(dr(10)) Then oGame.Icon = CStr(dr(10))
oGame.Hours = CDbl(dr(11))
If Not IsDBNull(dr(12)) Then oGame.Version = CStr(dr(12))
If Not IsDBNull(dr(13)) Then oGame.Company = CStr(dr(13))
oGame.Enabled = CBool(dr(14))
oGame.MonitorOnly = CBool(dr(15))
hshGames.Add(iCounter, oGame)
iCounter += 1
Next
Return hshGames
End Function
Public Shared Function DoDuplicateListCheck(ByVal sName As String, ByVal sProcess As String, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local, Optional ByVal sExcludeID As String = "") As Boolean
Dim oDatabase As New mgrSQLite(iSelectDB)
Dim sSQL As String
Dim oData As DataSet
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM monitorlist WHERE Name = @Name AND Process= @Process"
hshParams.Add("Name", sName)
hshParams.Add("Process", sProcess)
If sExcludeID <> String.Empty Then
sSQL &= " AND MonitorID <> @MonitorID"
hshParams.Add("MonitorID", sExcludeID)
End If
oData = oDatabase.ReadParamData(sSQL, hshParams)
If oData.Tables(0).Rows.Count > 0 Then
Return True
Else
Return False
End If
End Function
End Class
+406
View File
@@ -0,0 +1,406 @@
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Reflection
Public Class mgrPath
'Important Note: Any changes to sSettingsRoot & sDBLocation need to be mirrored in frmMain.vb -> VerifyGameDataPath
Private Shared sSettingsRoot As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\gbm"
Private Shared sDBLocation As String = sSettingsRoot & "\gbm.s3db"
Private Shared sIncludeFile As String = sSettingsRoot & "\gbm_include.txt"
Private Shared sExcludeFile As String = sSettingsRoot & "\gbm_exclude.txt"
Private Shared sOfficialImportURL As String = "http://backupmonitor.sourceforge.net/GBM_Official.xml"
Private Shared sOfficialManualURL As String = "http://backupmonitor.sourceforge.net/manual.php"
Private Shared sOfficialUpdatesURL As String = "http://backupmonitor.sourceforge.net/"
Private Shared sRemoteDatabaseLocation As String
Private Shared hshCustomVariables As Hashtable
Private Shared oReleaseType As ProcessorArchitecture = AssemblyName.GetAssemblyName(Application.ExecutablePath()).ProcessorArchitecture
Shared Sub New()
hshCustomVariables = mgrVariables.ReadVariables
End Sub
Shared ReadOnly Property ReleaseType As Integer
Get
Select Case oReleaseType
Case ProcessorArchitecture.Amd64
Return 64
Case ProcessorArchitecture.IA64
Return 64
Case ProcessorArchitecture.MSIL
Return 32
Case ProcessorArchitecture.X86
Return 32
Case ProcessorArchitecture.None
Return 32
End Select
Return 32
End Get
End Property
Shared ReadOnly Property Utility7zLocation As String
Get
Select Case oReleaseType
Case ProcessorArchitecture.Amd64
Return Application.StartupPath & "\Utilities\x64\7za.exe"
Case ProcessorArchitecture.IA64
Return Application.StartupPath & "\Utilities\x64\7za.exe"
Case ProcessorArchitecture.MSIL
Return Application.StartupPath & "\Utilities\x86\7za.exe"
Case ProcessorArchitecture.X86
Return Application.StartupPath & "\Utilities\x86\7za.exe"
Case ProcessorArchitecture.None
Return Application.StartupPath & "\Utilities\x86\7za.exe"
End Select
Return Application.StartupPath & "\Utilities\x86\7za.exe"
End Get
End Property
Shared ReadOnly Property DatabaseLocation As String
Get
Return sDBLocation
End Get
End Property
Shared ReadOnly Property IncludeFileLocation As String
Get
Return sIncludeFile
End Get
End Property
Shared ReadOnly Property ExcludeFileLocation As String
Get
Return sExcludeFile
End Get
End Property
Shared ReadOnly Property OfficialManualURL As String
Get
Return sOfficialManualURL
End Get
End Property
Shared ReadOnly Property OfficialUpdatesURL As String
Get
Return sOfficialUpdatesURL
End Get
End Property
Shared ReadOnly Property OfficialImportURL As String
Get
Return sOfficialImportURL
End Get
End Property
Shared ReadOnly Property SettingsRoot As String
Get
Return sSettingsRoot
End Get
End Property
Shared Property RemoteDatabaseLocation As String
Get
Return sRemoteDatabaseLocation
End Get
Set(value As String)
sRemoteDatabaseLocation = value & "\gbm.s3db"
End Set
End Property
Public Shared Function ValidateForFileSystem(ByVal sCheckString As String) As String
Dim cInvalidCharacters As Char() = {"\", "/", ":", "*", "?", """", "<", ">", "|"}
For Each c As Char In cInvalidCharacters
sCheckString = sCheckString.Replace(c, "")
Next
If sCheckString.Length > 257 Then
sCheckString = sCheckString.Substring(0, 257)
End If
Return sCheckString
End Function
Public Shared Function DetermineRelativePath(ByVal sProcessPath As String, ByVal sSavePath As String) As String
Dim sPath1Array As String()
Dim sPath2Array As String()
Dim sPath1 As String
Dim sPath2 As String
Dim sResult As String = String.Empty
Dim i As Integer = 0
Dim iRemove As Integer = 0
Dim iBackFolders As Integer = 0
Dim bDeep As Boolean
'We are working with a case insenstive file system, ensure a uniform case
sProcessPath = sProcessPath.ToLower
sSavePath = sSavePath.ToLower
'We need to ensure we have a single trailing slash on the parameters
sProcessPath = sProcessPath.TrimEnd("\")
sSavePath = sSavePath.TrimEnd("\")
sProcessPath &= "\"
sSavePath &= "\"
'Determines the direction we need to go, we always want to be relative to the process location
If sSavePath.Split("\").Length > sProcessPath.Split("\").Length Then
sPath1 = sProcessPath
sPath2 = sSavePath
bDeep = True
Else
sPath1 = sSavePath
sPath2 = sProcessPath
bDeep = False
End If
'Build an array of folders to work with from each path
sPath1Array = sPath1.Split("\")
sPath2Array = sPath2.Split("\")
'Take the shortest path and remove the common folders from both
For Each s As String In sPath1Array
If s = sPath2Array(i) And s <> String.Empty Then
sPath1 = sPath1.Remove(sPath1.IndexOf(s), s.Length + 1)
sPath2 = sPath2.Remove(sPath2.IndexOf(s), s.Length + 1)
End If
i = i + 1
Next
'Remove the trailing slashes
sPath1 = sPath1.TrimEnd("\")
sPath2 = sPath2.TrimEnd("\")
'Determine which way we go
If bDeep Then
If sPath1.Length > 0 Then
iBackFolders = sPath1.Split("\").Length
End If
sResult = sPath2
Else
If sPath2.Length > 0 Then
iBackFolders = sPath2.Split("\").Length
End If
sResult = sPath1
End If
'Insert direction modifiers based on how many folders are left
For i = 1 To iBackFolders
sResult = "..\" & sResult
Next i
'Done
Return sResult
End Function
Public Shared Function ReplaceSpecialPaths(sValue As String) As String
Dim sMyDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sPublicDocs As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)
Dim sAppDataRoaming As String = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
Dim sAppDataLocal As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
Dim sCurrentUser As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
Dim oCustomVariable As clsPathVariable
If sValue.Contains("*mydocs*") Then
Return sValue.Replace("*mydocs*", sMyDocs)
End If
If sValue.Contains("*publicdocs*") Then
Return sValue.Replace("*publicdocs*", sPublicDocs)
End If
If sValue.Contains("*appdatalocal*") Then
Return sValue.Replace("*appdatalocal*", sAppDataLocal)
End If
If sValue.Contains("*appdataroaming*") Then
Return sValue.Replace("*appdataroaming*", sAppDataRoaming)
End If
If sValue.Contains("*currentuser*") Then
Return sValue.Replace("*currentuser*", sCurrentUser)
End If
For Each oCustomVariable In hshCustomVariables.Values
If sValue.Contains(oCustomVariable.FormattedName) Then
Return sValue.Replace(oCustomVariable.FormattedName, oCustomVariable.Path)
End If
Next
Return sValue
End Function
Public Shared Function ReverseSpecialPaths(sValue As String) As String
Dim sMyDocs As String = "*mydocs*"
Dim sPublicDocs As String = "*publicdocs*"
Dim sAppDataRoaming As String = "*appdatalocal*"
Dim sAppDataLocal As String = "*appdataroaming*"
Dim sCurrentUser As String = "*currentuser*"
Dim oCustomVariable As clsPathVariable
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), sMyDocs)
End If
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments), sPublicDocs)
End If
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), sAppDataLocal)
End If
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), sAppDataRoaming)
End If
If sValue.Contains(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)) Then
Return sValue.Replace(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), sCurrentUser)
End If
For Each oCustomVariable In hshCustomVariables.Values
If sValue.Contains(oCustomVariable.Path) Then
Return sValue.Replace(oCustomVariable.Path, oCustomVariable.FormattedName)
End If
Next
Return sValue
End Function
Public Shared Function IsAbsolute(sValue As String) As Boolean
Dim hshFolders As New Hashtable
Dim hshCustomVariables As Hashtable = mgrVariables.ReadVariables
Dim oCustomVariable As clsPathVariable
hshFolders.Add(Guid.NewGuid.ToString, Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments))
hshFolders.Add(Guid.NewGuid.ToString, Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments))
hshFolders.Add(Guid.NewGuid.ToString, Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
hshFolders.Add(Guid.NewGuid.ToString, Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))
hshFolders.Add(Guid.NewGuid.ToString, Environment.GetFolderPath(Environment.SpecialFolder.UserProfile))
'Load Custom Variables
For Each oCustomVariable In hshCustomVariables.Values
hshFolders.Add(Guid.NewGuid.ToString, oCustomVariable.Path)
Next
For Each de As DictionaryEntry In hshFolders
If sValue.Contains(de.Value) Then
Return True
End If
Next
Return False
End Function
Public Shared Function VerifyCustomVariables(ByVal hshScanlist As Hashtable, ByRef sGames As String) As Boolean
Dim hshCustomVariables As Hashtable = mgrVariables.ReadVariables
Dim sVariableCheck As String
Dim sPattern As String = "\*(.*)\*"
Dim oGame As clsGame
Dim oMatch As Match
Dim bClean As Boolean = True
For Each oGame In hshScanlist.Values
oMatch = Regex.Match(oGame.Path, sPattern)
If oMatch.Success Then
sVariableCheck = oMatch.Value.Replace("*", String.Empty)
If Not hshCustomVariables.ContainsKey(sVariableCheck) Then
sGames &= vbCrLf & oGame.Name & " (" & sVariableCheck & ")"
bClean = False
End If
End If
Next
Return bClean
End Function
Public Shared Sub CustomVariablesReload()
hshCustomVariables = mgrVariables.ReadVariables
End Sub
Public Shared Function SetManualgamePath() As String
Dim sDefaultFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Dim sNewPath As String
sNewPath = mgrCommon.OpenFolderBrowser("Choose the game folder containing the executable.", sDefaultFolder, False)
Return sNewPath
End Function
Public Shared Function ProcessPathSearch(ByVal sGameName As String, ByVal sProcess As String, ByVal sSearchReason As String, Optional ByVal bNoAuto As Boolean = False) As String
Dim frmFind As New frmFileFolderSearch
Dim sMessage As String
Dim sFolder As String = String.Empty
Dim bSearchFailed As Boolean = False
frmFind.SearchItem = sProcess & ".*"
frmFind.FolderSearch = False
'We can't automatically search for certain game types
If bNoAuto Then
sMessage = sSearchReason & vbCrLf & vbCrLf & "Do you wish to manually set the game path? (Path will be saved)"
If MsgBox(sMessage, MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.Yes Then
sFolder = SetManualgamePath()
End If
Return sFolder
End If
sMessage = sSearchReason & vbCrLf & vbCrLf & "Do you wish to automatically search for the game path? (Path will be saved)"
If MsgBox(sMessage, MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.Yes Then
frmFind.ShowDialog()
If frmFind.FoundItem <> String.Empty Then
sFolder = IO.Path.GetDirectoryName(frmFind.FoundItem)
sMessage = sGameName & " was located in the following folder:" & vbCrLf & vbCrLf & _
sFolder & vbCrLf & vbCrLf & "Is this correct?"
If MsgBox(sMessage, MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.Yes Then
Return sFolder
Else
sFolder = String.Empty
End If
Else
bSearchFailed = True
End If
If bSearchFailed Then
sMessage = "The search failed to locate the path for " & sGameName & "." & vbCrLf & vbCrLf & _
"Do you wish to manually set the game path? (Path will be saved)"
Else
sMessage = "Do you wish to manually set the game path? (Path will be saved)"
End If
If MsgBox(sMessage, MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.Yes Then
sFolder = SetManualgamePath()
End If
End If
Return sFolder
End Function
Public Shared Function VerifyBackupPath(ByRef sBackupPath As String) As Boolean
Dim dBrowser As FolderBrowserDialog
If Not Directory.Exists(sBackupPath) Then
If MsgBox("The backup location " & sBackupPath & " is not available." & vbCrLf & _
"It may be on an external or network drive that isn't connected." & vbCrLf & vbCrLf & _
"Do you want to select another backup location and continue?", MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.Yes Then
dBrowser = New FolderBrowserDialog
dBrowser.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
If dBrowser.ShowDialog = DialogResult.OK Then
sBackupPath = dBrowser.SelectedPath
Return True
Else
Return False
End If
Else
Return False
End If
End If
Return True
End Function
End Class
+164
View File
@@ -0,0 +1,164 @@
Imports System.Diagnostics
Imports System.IO
Imports System.Threading
Public Class mgrProcesses
Private prsFoundProcess As Process
Private dStartTime As DateTime = Now, dEndTime As DateTime = Now
Private lTimeSpent As Long = 0
Private oGame As clsGame
Private oDuplicateGames As New ArrayList
Private bDuplicates As Boolean
Private bVerified As Boolean = False
Property FoundProcess As Process
Get
Return prsFoundProcess
End Get
Set(value As Process)
prsFoundProcess = value
End Set
End Property
Property StartTime As DateTime
Get
Return dStartTime
End Get
Set(value As DateTime)
dStartTime = value
End Set
End Property
Property EndTime As DateTime
Get
Return dEndTime
End Get
Set(value As DateTime)
dEndTime = value
End Set
End Property
ReadOnly Property TimeSpent As TimeSpan
Get
Return dEndTime.Subtract(dStartTime)
End Get
End Property
Property GameInfo As clsGame
Get
Return oGame
End Get
Set(value As clsGame)
oGame = value
End Set
End Property
Property Duplicate As Boolean
Get
Return bDuplicates
End Get
Set(value As Boolean)
bDuplicates = value
End Set
End Property
Property DuplicateList As ArrayList
Get
Return oDuplicateGames
End Get
Set(value As ArrayList)
oDuplicateGames = value
End Set
End Property
Private Sub VerifyDuplicate(oGame As clsGame, hshScanList As Hashtable)
Dim sProcess As String
bDuplicates = True
oDuplicateGames.Clear()
For Each o As clsGame In hshScanList.Values
If o.ProcessName.Contains("dosbox") Then
If o.ProcessName.Split(":").Length = 3 Then
sProcess = o.ProcessName.Remove(o.ProcessName.LastIndexOf(":"))
Else
sProcess = o.ProcessName
End If
Else
sProcess = o.ProcessName.Split(":")(0)
End If
If o.Duplicate = True And sProcess = oGame.TrueProcess Then
oDuplicateGames.Add(o.ShallowCopy)
End If
Next
End Sub
Public Function SearchRunningProcesses(ByVal hshScanList As Hashtable, ByRef bNeedsPath As Boolean, ByRef iErrorCode As Integer) As Boolean
Dim prsList() As Process = Process.GetProcesses
Dim sDBoxProcess As String()
Dim sProcessCheck As String = String.Empty
For Each prsCurrent As Process In prsList
'Handle DOSBox Processes
If prsCurrent.ProcessName.ToLower = "dosbox" Then
sDBoxProcess = prsCurrent.MainWindowTitle.Split(":")
'If the dosbox process title doesn't have 3 elements it's not ready yet.
If sDBoxProcess.Length = 3 Then
sProcessCheck = "dosbox:" & sDBoxProcess(2).Trim
Else
'Drop out for now
Return False
End If
Else
sProcessCheck = prsCurrent.ProcessName
End If
If hshScanList.ContainsKey(sProcessCheck) Then
prsFoundProcess = prsCurrent
oGame = DirectCast(hshScanList.Item(sProcessCheck), clsGame).ShallowCopy
If oGame.Duplicate = True Then
VerifyDuplicate(oGame, hshScanList)
Else
bDuplicates = False
oDuplicateGames.Clear()
End If
If Not oGame.AbsolutePath Or oGame.Duplicate Then
Try
oGame.ProcessPath = Path.GetDirectoryName(prsCurrent.MainModule.FileName)
Catch exWin32 As System.ComponentModel.Win32Exception
'If an exception occurs the process is:
'Running as administrator and the app isn't.
'The process is 64-bit and the process folder is required, shouldn't happen often.
If exWin32.NativeErrorCode = 5 Then
bNeedsPath = True
iErrorCode = 5
ElseIf exWin32.NativeErrorCode = 299 Then
bNeedsPath = True
iErrorCode = 299
Else
'A different failure occured, drop out and continue to scan.
Return False
End If
Catch exAll As Exception
'A different failure occured, drop out and continue to scan.
Return False
End Try
End If
'This will force two cycles for detection to try and prevent issues with UAC prompt
If Not bVerified Then
bVerified = True
Return False
Else
bVerified = False
Return True
End If
End If
Next
Return False
End Function
End Class
+256
View File
@@ -0,0 +1,256 @@
Imports System.IO
Public Class mgrRestore
Private oSettings As mgrSettings
Private bCancelOperation As Boolean
Property Settings As mgrSettings
Get
Return oSettings
End Get
Set(value As mgrSettings)
oSettings = value
End Set
End Property
Property CancelOperation As Boolean
Get
Return bCancelOperation
End Get
Set(value As Boolean)
bCancelOperation = value
End Set
End Property
Public Event UpdateLog(sLogUpdate As String, bTrayUpdate As Boolean, objIcon As System.Windows.Forms.ToolTipIcon, bTimeStamp As Boolean)
Public Event UpdateRestoreInfo(oRestoreInfo As clsBackup)
Public Event SetLastAction(sMessage As String)
Public Shared Function CheckPath(ByRef oRestoreInfo As clsBackup, ByVal oGame As clsGame) As Boolean
Dim sProcess As String
Dim sRestorePath As String
Dim bNoAuto As Boolean
If Not oRestoreInfo.AbsolutePath Then
If oGame.ProcessPath <> String.Empty Then
oRestoreInfo.RelativeRestorePath = oGame.ProcessPath & "\" & oRestoreInfo.RestorePath
Else
sProcess = oGame.TrueProcess
If oGame.Duplicate = True Or oGame.ProcessName.Contains("dosbox") Then bNoAuto = True
sRestorePath = mgrPath.ProcessPathSearch(oRestoreInfo.Name, sProcess, oRestoreInfo.Name & " uses a relative path and has never been detected on this computer.", bNoAuto)
If sRestorePath <> String.Empty Then
oRestoreInfo.RelativeRestorePath = sRestorePath & "\" & oRestoreInfo.RestorePath
Else
Return False
End If
End If
End If
Return True
End Function
Public Shared Function CheckManifest(ByVal sAppName As String) As Boolean
Dim slLocalManifest As SortedList
Dim slRemoteManifest As SortedList
Dim oLocalItem As New clsBackup
Dim oRemoteItem As New clsBackup
Dim bLocal As Boolean = False
Dim bRemote As Boolean = False
slLocalManifest = mgrManifest.ReadManifest(mgrSQLite.Database.Local)
slRemoteManifest = mgrManifest.ReadManifest(mgrSQLite.Database.Remote)
If slLocalManifest.Contains(sAppName) Then
oLocalItem = DirectCast(slLocalManifest(sAppName), clsBackup)
bLocal = True
End If
If slRemoteManifest.Contains(sAppName) Then
oRemoteItem = DirectCast(slRemoteManifest(sAppName), clsBackup)
bRemote = True
End If
If bLocal And bRemote Then
'Compare
If oRemoteItem.DateUpdated > oLocalItem.DateUpdated Then
oRemoteItem.LastDateUpdated = oLocalItem.DateUpdated
oRemoteItem.LastUpdatedBy = oLocalItem.UpdatedBy
Return True
End If
End If
If bRemote And Not bLocal Then
Return True
End If
Return False
End Function
Public Shared Function CompareManifests() As SortedList
Dim slLocalManifest As SortedList
Dim slRemoteManifest As SortedList
Dim oLocalItem As clsBackup
Dim slRestoreItems As New SortedList
Dim bLocal As Boolean = False
Dim bRemote As Boolean = False
slLocalManifest = mgrManifest.ReadManifest(mgrSQLite.Database.Local)
slRemoteManifest = mgrManifest.ReadManifest(mgrSQLite.Database.Remote)
For Each oItem As clsBackup In slRemoteManifest.Values
If slLocalManifest.Contains(oItem.Name) Then
oLocalItem = DirectCast(slLocalManifest(oItem.Name), clsBackup)
If oItem.DateUpdated > oLocalItem.DateUpdated Then
oLocalItem.FileName = oItem.FileName
oLocalItem.LastDateUpdated = oItem.DateUpdated
oLocalItem.LastUpdatedBy = oItem.UpdatedBy
slRestoreItems.Add(oLocalItem.Name, oLocalItem)
End If
Else
oLocalItem = oItem
oLocalItem.LastDateUpdated = oItem.DateUpdated
oLocalItem.LastUpdatedBy = oItem.UpdatedBy
oLocalItem.DateUpdated = Nothing
oLocalItem.UpdatedBy = Nothing
slRestoreItems.Add(oLocalItem.Name, oLocalItem)
End If
Next
Return slRestoreItems
End Function
Public Shared Function SyncLocalManifest() As SortedList
Dim slLocalManifest As SortedList
Dim slRemoteManifest As SortedList
Dim slRemovedItems As New SortedList
slLocalManifest = mgrManifest.ReadManifest(mgrSQLite.Database.Local)
slRemoteManifest = mgrManifest.ReadManifest(mgrSQLite.Database.Remote)
For Each oItem As clsBackup In slLocalManifest.Values
If Not slRemoteManifest.Contains(oItem.Name) Then
slRemovedItems.Add(oItem.Name, oItem)
mgrManifest.DoManifestDelete(oItem, mgrSQLite.Database.Local)
End If
Next
Return slRemovedItems
End Function
Public Sub DoRestore(ByVal oRestoreList As List(Of clsBackup))
Dim prs7z As Process
Dim sBackupFile As String
Dim sExtractPath As String
Dim bDoRestore As Boolean
Dim bRestoreCompleted As Boolean
Dim sHash As String
For Each oBackupInfo In oRestoreList
'Init
prs7z = New Process
sBackupFile = oSettings.BackupFolder & "\" & oBackupInfo.FileName
sExtractPath = String.Empty
bDoRestore = True
bRestoreCompleted = False
CancelOperation = False
RaiseEvent UpdateRestoreInfo(oBackupInfo)
If oBackupInfo.AbsolutePath Then
sExtractPath = oBackupInfo.RestorePath
Else
sExtractPath = oBackupInfo.RelativeRestorePath
End If
'Check if restore location exists, prompt to create if it doesn't.
If Not Directory.Exists(sExtractPath) Then
If MsgBox("The restore path " & sExtractPath & " does not exist." & vbCrLf & vbCrLf & _
"Do you want to create the folder and continue?", MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.Yes Then
Try
Directory.CreateDirectory(sExtractPath)
Catch ex As Exception
RaiseEvent UpdateLog("The restore path could not be created due to an unexpected error." & vbCrLf & ex.Message, False, ToolTipIcon.Error, True)
bDoRestore = False
End Try
Else
RaiseEvent UpdateLog("Restored Aborted. The path " & sExtractPath & " does not exist.", False, ToolTipIcon.Error, True)
bDoRestore = False
End If
End If
'Check file integrity
If oSettings.CheckSum Then
If oBackupInfo.CheckSum <> String.Empty Then
sHash = mgrHash.Generate_SHA256_Hash(sBackupFile)
If sHash <> oBackupInfo.CheckSum Then
RaiseEvent UpdateLog("The backup file for " & oBackupInfo.Name & " has failed the file integrity check.", False, ToolTipIcon.Info, True)
If MsgBox("The backup file for " & oBackupInfo.Name & " has failed the file intergity check. It may be corrupted, not exist or been modified by another application." & vbCrLf & vbCrLf & _
"Do you still want to restore this backup? (Not Recommended)", MsgBoxStyle.YesNo, "Game Backup Monitor") = MsgBoxResult.No Then
RaiseEvent UpdateLog("Restored Aborted by user due to a failed file integrity check.", False, ToolTipIcon.Info, True)
bDoRestore = False
End If
Else
RaiseEvent UpdateLog(oBackupInfo.Name & " backup has been verified.", False, ToolTipIcon.Info, True)
End If
Else
RaiseEvent UpdateLog(oBackupInfo.Name & " has no stored checksum, verification has been skipped.", False, ToolTipIcon.Info, True)
End If
End If
If bDoRestore Then
Try
If File.Exists(sBackupFile) Then
prs7z.StartInfo.Arguments = "x """ & sBackupFile & """ -o""" & sExtractPath & "\"" -aoa -r"
prs7z.StartInfo.FileName = mgrPath.Utility7zLocation
prs7z.StartInfo.UseShellExecute = False
prs7z.StartInfo.RedirectStandardOutput = True
prs7z.StartInfo.CreateNoWindow = True
prs7z.Start()
RaiseEvent UpdateLog("Restore to " & sExtractPath & " in progress...", True, ToolTipIcon.Info, True)
While Not prs7z.StandardOutput.EndOfStream
If CancelOperation Then
prs7z.Kill()
RaiseEvent UpdateLog("Restored Aborted by user. The save games for " & oBackupInfo.Name & " will be damaged or invalid.", False, ToolTipIcon.Error, True)
Exit While
End If
RaiseEvent UpdateLog(prs7z.StandardOutput.ReadLine, False, ToolTipIcon.Info, False)
End While
prs7z.WaitForExit()
If Not CancelOperation Then
If prs7z.ExitCode = 0 Then
RaiseEvent UpdateLog(oBackupInfo.Name & " backup restored.", True, ToolTipIcon.Info, True)
bRestoreCompleted = True
Else
RaiseEvent UpdateLog(oBackupInfo.Name & " restore operation finished with warnings or errors.", False, ToolTipIcon.Info, True)
bRestoreCompleted = False
End If
End If
prs7z.Dispose()
Else
RaiseEvent UpdateLog("Restore Aborted. The backup file could not be found. Ensure the backup location is available.", False, ToolTipIcon.Error, True)
End If
If bRestoreCompleted Then
'Save Local Manifest
If mgrManifest.DoManifestCheck(oBackupInfo.Name, mgrSQLite.Database.Local) Then
mgrManifest.DoManifestUpdate(oBackupInfo, mgrSQLite.Database.Local)
Else
mgrManifest.DoManifestAdd(oBackupInfo, mgrSQLite.Database.Local)
End If
End If
Catch ex As Exception
RaiseEvent UpdateLog("An unexpected error occured during the restore process." & vbCrLf & ex.Message, False, ToolTipIcon.Error, True)
End Try
If bRestoreCompleted Then
RaiseEvent SetLastAction(oBackupInfo.CroppedName & " backup restored")
Else
RaiseEvent SetLastAction(oBackupInfo.CroppedName & " restore failed")
End If
End If
Next
End Sub
End Class
+440
View File
@@ -0,0 +1,440 @@
Imports System.IO
Imports System.Data.SQLite
Public Class mgrSQLite
Public Enum Database As Integer
Local = 1
Remote = 2
End Enum
Private sDatabaseLocation As String
Private sConnectString As String
Private eDatabase As Database
Private db As SQLiteConnection
Public Sub New(ByVal eSelectDB As Database)
Select Case eSelectDB
Case Database.Local
eDatabase = Database.Local
sDatabaseLocation = mgrPath.DatabaseLocation
sConnectString = "Data Source=" & mgrPath.DatabaseLocation & ";Version=3;"
Case Database.Remote
eDatabase = Database.Remote
sDatabaseLocation = mgrPath.RemoteDatabaseLocation
sConnectString = "Data Source=" & mgrPath.RemoteDatabaseLocation & ";Version=3;"
End Select
End Sub
Private Sub BackupDB(ByVal sLastVer As String)
Dim sNewFile As String = String.Empty
Try
Select Case eDatabase
Case Database.Local
sNewFile = mgrPath.DatabaseLocation & "." & sLastVer & ".bak"
File.Copy(mgrPath.DatabaseLocation, sNewFile, False)
Case Database.Remote
sNewFile = mgrPath.RemoteDatabaseLocation & "." & sLastVer & ".bak"
File.Copy(mgrPath.RemoteDatabaseLocation, sNewFile, False)
End Select
Catch ex As Exception
MsgBox("An error occured creating a backup of the database file at " & sNewFile & vbCrLf & vbCrLf & ex.Message)
End Try
End Sub
Public Function CheckDBVer(Optional ByRef iDBVer As Integer = 0) As Boolean
iDBVer = GetDatabaseVersion()
If iDBVer > mgrCommon.AppVersion Then
Return False
End If
Return True
End Function
Public Function CheckDB() As Boolean
If File.Exists(sDatabaseLocation) Then
Return True
End If
Return False
End Function
Private Function CreateLocalDatabase() As Boolean
Dim sSql As String
Try
'Create the DB
SQLiteConnection.CreateFile(sDatabaseLocation)
'Add Tables (Settings)
sSql = "CREATE TABLE settings (SettingsID INTEGER NOT NULL PRIMARY KEY, MonitorOnStartup BOOLEAN NOT NULL, StartToTray BOOLEAN NOT NULL, ShowDetectionToolTips BOOLEAN NOT NULL, " & _
"DisableConfirmation BOOLEAN NOT NULL, CreateSubFolder BOOLEAN NOT NULL, ShowOverwriteWarning BOOLEAN NOT NULL, RestoreOnLaunch BOOLEAN NOT NULL, " & _
"BackupFolder TEXT NOT NULL, Sync BOOLEAN NOT NULL, CheckSum BOOLEAN NOT NULL, StartWithWindows BOOLEAN NOT NULL);"
'Add Tables (Monitor List)
sSql &= "CREATE TABLE monitorlist (MonitorID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL, Process TEXT NOT NULL, Path TEXT, " & _
"AbsolutePath BOOLEAN NOT NULL, FolderSave BOOLEAN NOT NULL, FileType TEXT, TimeStamp BOOLEAN NOT NULL, ExcludeList TEXT NOT NULL, " & _
"ProcessPath TEXT, Icon TEXT, Hours REAL, Version TEXT, Company TEXT, Enabled BOOLEAN NOT NULL, MonitorOnly BOOLEAN NOT NULL, " & _
"PRIMARY KEY(Name, Process));"
'Add Tables (Variables)
sSql &= "CREATE TABLE variables (VariableID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, Path TEXT NOT NULL);"
'Add Tables (Local Manifest)
sSql &= "CREATE TABLE manifest (ManifestID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, FileName TEXT NOT NULL, RestorePath TEXT NOT NULL, " & _
"AbsolutePath BOOLEAN NOT NULL, DateUpdated TEXT NOT NULL, UpdatedBy TEXT NOT NULL, CheckSum TEXT);"
'Set Version
sSql &= "PRAGMA user_version=" & mgrCommon.AppVersion
RunParamQuery(sSql, New Hashtable)
Return True
Catch e As Exception
MsgBox("An error has occured attempting to create the local application database: " & vbCrLf & vbCrLf & e.Message)
Return False
End Try
End Function
Private Function CreateRemoteDatabase() As Boolean
Dim sSql As String
Try
'Create the DB
SQLiteConnection.CreateFile(sDatabaseLocation)
'Add Tables (Remote Monitor List)
sSql = "CREATE TABLE monitorlist (MonitorID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL, Process TEXT NOT NULL, Path TEXT, " & _
"AbsolutePath BOOLEAN NOT NULL, FolderSave BOOLEAN NOT NULL, FileType TEXT, TimeStamp BOOLEAN NOT NULL, ExcludeList TEXT NOT NULL, " & _
"ProcessPath TEXT, Icon TEXT, Hours REAL, Version TEXT, Company TEXT, Enabled BOOLEAN NOT NULL, MonitorOnly BOOLEAN NOT NULL, " & _
"PRIMARY KEY(Name, Process));"
'Add Tables (Remote Manifest)
sSql &= "CREATE TABLE manifest (ManifestID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, FileName TEXT NOT NULL, RestorePath TEXT NOT NULL, " & _
"AbsolutePath BOOLEAN NOT NULL, DateUpdated TEXT NOT NULL, UpdatedBy TEXT NOT NULL, CheckSum TEXT);"
'Set Version
sSql &= "PRAGMA user_version=" & mgrCommon.AppVersion
RunParamQuery(sSql, New Hashtable)
Return True
Catch e As Exception
MsgBox("An error has occured attempting to create the remote application database: " & vbCrLf & vbCrLf & e.Message)
Return False
End Try
End Function
Private Function CreateDB() As Boolean
Dim bSuccess As Boolean
Select Case eDatabase
Case Database.Local
bSuccess = CreateLocalDatabase()
Case Database.Remote
bSuccess = CreateRemoteDatabase()
End Select
Return bSuccess
End Function
Public Sub Connect()
If CheckDB() Then
db = New SQLiteConnection(sConnectString)
db.Open()
Else
CreateDB()
db.Open()
End If
End Sub
Public Sub Disconnect()
db.Close()
End Sub
Private Sub BuildParams(ByRef command As SQLiteCommand, ByRef hshParams As Hashtable)
For Each de As DictionaryEntry In hshParams
command.Parameters.AddWithValue(de.Key, de.Value)
Next
End Sub
Public Function RunParamQuery(ByVal sSQL As String, ByVal hshParams As Hashtable) As Boolean
Dim trans As SQLiteTransaction
Dim command As SQLiteCommand
Connect()
command = New SQLiteCommand(sSQL, db)
BuildParams(command, hshParams)
trans = db.BeginTransaction()
Try
command.ExecuteNonQuery()
trans.Commit()
Catch e As Exception
trans.Rollback()
MsgBox("An error has occured attempting run the query." & vbCrLf & vbCrLf & sSQL & vbCrLf & vbCrLf & e.Message)
Return False
Finally
command.Dispose()
Disconnect()
End Try
Return True
End Function
Public Function ReadParamData(ByVal sSQL As String, ByVal hshParams As Hashtable) As DataSet
Dim adapter As SQLiteDataAdapter
Dim command As SQLiteCommand
Dim oData As New DataSet
Connect()
command = New SQLiteCommand(sSQL, db)
BuildParams(command, hshParams)
Try
adapter = New SQLiteDataAdapter(command)
adapter.Fill(oData)
Catch e As Exception
MsgBox("An error has occured attempting run the query." & vbCrLf & vbCrLf & sSQL & vbCrLf & vbCrLf & e.Message)
Finally
command.Dispose()
Disconnect()
End Try
Return oData
End Function
Private Function GetDatabaseVersion() As Integer
Dim sSQL As String
Dim iVer As Integer
Dim oData As DataSet
sSQL = "PRAGMA user_version"
oData = ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
iVer = CInt(dr(0))
Next
Return iVer
End Function
Private Function FieldExists(ByVal sField As String, ByVal sTable As String) As Boolean
Dim sSQL As String
Dim sCurrentField As String
Dim oData As DataSet
sSQL = "PRAGMA table_info(" & sTable & ")"
oData = ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
sCurrentField = CStr(dr(1))
If sCurrentField = sField Then
Return True
End If
Next
Return False
End Function
Public Sub UpgradeToUnixTime(ByVal sTable As String, ByVal sField As String, ByVal sKeyField As String)
Dim sSQL As String
Dim oData As DataSet
Dim sID As String
Dim dDate As DateTime
Dim iDate As Int64
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM " & sTable
oData = ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
hshParams.Clear()
sID = CStr(dr(sKeyField))
Try
'We need to fallback if the date string cannot be converted
dDate = CDate(dr(sField))
Catch
'Use the current date as a fallback
dDate = Now
End Try
iDate = mgrCommon.DateToUnix(dDate)
sSQL = "UPDATE " & sTable & " SET " & sField & "= @NewDate WHERE " & sKeyField & "= @OldID;"
hshParams.Add("OldID", sID)
hshParams.Add("NewDate", iDate)
RunParamQuery(sSQL, hshParams)
Next
End Sub
Public Sub UpgradeToGUID(ByVal sTable As String, ByVal sField As String)
Dim sSQL As String
Dim iCurrentID As Integer
Dim oData As DataSet
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM " & sTable
oData = ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
hshParams.Clear()
iCurrentID = CInt(dr(sField))
sSQL = "UPDATE " & sTable & " SET " & sField & "= @NewID WHERE " & sField & "= @OldID;"
hshParams.Add("OldID", iCurrentID)
hshParams.Add("NewID", Guid.NewGuid.ToString)
RunParamQuery(sSQL, hshParams)
Next
End Sub
Public Sub DatabaseUpgrade()
Dim sSQL As String
'0.9 Upgrade
If GetDatabaseVersion() < 90 Then
BackupDB("v8")
sSQL = "ALTER TABLE monitorlist ADD COLUMN MonitorOnly BOOLEAN NOT NULL DEFAULT 0;"
sSQL &= "PRAGMA user_version=90"
RunParamQuery(sSQL, New Hashtable)
End If
'0.91 Upgrade
If GetDatabaseVersion() < 91 Then
If eDatabase = Database.Local Then
'Backup DB before starting
BackupDB("v84")
'Overhaul Monitor List Table
sSQL = "CREATE TABLE monitorlist_new (MonitorID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL, Process TEXT NOT NULL, Path TEXT, AbsolutePath BOOLEAN NOT NULL, FolderSave BOOLEAN NOT NULL, FileType TEXT, TimeStamp BOOLEAN NOT NULL, ExcludeList TEXT NOT NULL, ProcessPath TEXT, Icon TEXT, Hours REAL, Version TEXT, Company TEXT, Enabled BOOLEAN NOT NULL, MonitorOnly BOOLEAN NOT NULL, PRIMARY KEY(Name, Process));"
sSQL &= "INSERT INTO monitorlist_new (MonitorID, Name, Process, Path, AbsolutePath, FolderSave, FileType, TimeStamp, ExcludeList, ProcessPath, Icon, Hours, Version, Company, Enabled, MonitorOnly) "
sSQL &= "SELECT MonitorID, Name, Process, Path, AbsolutePath, FolderSave, FileType, TimeStamp, ExcludeList, ProcessPath, Icon, Hours, Version, Company, Enabled, MonitorOnly FROM monitorlist;"
sSQL &= "DROP TABLE monitorlist; ALTER TABLE monitorlist_new RENAME TO monitorlist;"
'Overhaul Variables Table
sSQL &= "CREATE TABLE variables_new (VariableID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, Path TEXT NOT NULL);"
sSQL &= "INSERT INTO variables_new (VariableID, Name, Path) SELECT VariableID, Name, Path FROM variables;"
sSQL &= "DROP TABLE variables; ALTER TABLE variables_new RENAME TO variables;"
'Overhaul Manifest Table
sSQL &= "CREATE TABLE manifest_new (ManifestID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, FileName TEXT NOT NULL, RestorePath TEXT NOT NULL, AbsolutePath BOOLEAN NOT NULL, DateUpdated TEXT NOT NULL, UpdatedBy TEXT NOT NULL, CheckSum TEXT);"
sSQL &= "INSERT INTO manifest_new (ManifestID, Name, FileName, RestorePath, AbsolutePath, DateUpdated, UpdatedBy) "
sSQL &= "SELECT ManifestID, Name, FileName, RestorePath, AbsolutePath, DateUpdated, UpdatedBy FROM manifest;"
sSQL &= "DROP TABLE manifest; ALTER TABLE manifest_new RENAME TO manifest;"
'Add new settings
sSQL &= "ALTER TABLE settings ADD COLUMN Sync BOOLEAN NOT NULL DEFAULT 1;"
sSQL &= "ALTER TABLE settings ADD COLUMN CheckSum BOOLEAN NOT NULL DEFAULT 1;"
sSQL &= "PRAGMA user_version=91"
RunParamQuery(sSQL, New Hashtable)
'Upgrade IDs to GUIDs
UpgradeToGUID("monitorlist", "MonitorID")
UpgradeToGUID("variables", "VariableID")
UpgradeToGUID("manifest", "ManifestID")
'Run a compact due to the large operations
CompactDatabase()
End If
If eDatabase = Database.Remote Then
'Backup DB before starting
BackupDB("v84")
'Overhaul Monitor List Table
sSQL = "CREATE TABLE monitorlist_new (MonitorID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL, Process TEXT NOT NULL, Path TEXT, AbsolutePath BOOLEAN NOT NULL, FolderSave BOOLEAN NOT NULL, FileType TEXT, TimeStamp BOOLEAN NOT NULL, ExcludeList TEXT NOT NULL, ProcessPath TEXT, Icon TEXT, Hours REAL, Version TEXT, Company TEXT, Enabled BOOLEAN NOT NULL, MonitorOnly BOOLEAN NOT NULL, PRIMARY KEY(Name, Process));"
sSQL &= "INSERT INTO monitorlist_new (MonitorID, Name, Process, Path, AbsolutePath, FolderSave, FileType, TimeStamp, ExcludeList, ProcessPath, Icon, Hours, Version, Company, Enabled, MonitorOnly) "
sSQL &= "SELECT MonitorID, Name, Process, Path, AbsolutePath, FolderSave, FileType, TimeStamp, ExcludeList, ProcessPath, Icon, Hours, Version, Company, Enabled, MonitorOnly FROM monitorlist;"
sSQL &= "DROP TABLE monitorlist; ALTER TABLE monitorlist_new RENAME TO monitorlist;"
'Overhaul Manifest Table
sSQL &= "CREATE TABLE manifest_new (ManifestID TEXT NOT NULL UNIQUE, Name TEXT NOT NULL PRIMARY KEY, FileName TEXT NOT NULL, RestorePath TEXT NOT NULL, AbsolutePath BOOLEAN NOT NULL, DateUpdated TEXT NOT NULL, UpdatedBy TEXT NOT NULL, CheckSum TEXT);"
sSQL &= "INSERT INTO manifest_new (ManifestID, Name, FileName, RestorePath, AbsolutePath, DateUpdated, UpdatedBy) "
sSQL &= "SELECT ManifestID, Name, FileName, RestorePath, AbsolutePath, DateUpdated, UpdatedBy FROM manifest;"
sSQL &= "DROP TABLE manifest; ALTER TABLE manifest_new RENAME TO manifest;"
sSQL &= "PRAGMA user_version=91"
RunParamQuery(sSQL, New Hashtable)
'Upgrade IDs to GUIDs
UpgradeToGUID("monitorlist", "MonitorID")
UpgradeToGUID("manifest", "ManifestID")
'Run a compact due to the large operations
CompactDatabase()
End If
End If
'0.92 Upgrade
If GetDatabaseVersion() < 92 Then
If eDatabase = Database.Local Then
'Backup DB before starting
BackupDB("v91")
'Add new setting
sSQL = "ALTER TABLE settings ADD COLUMN StartWithWindows BOOLEAN NOT NULL DEFAULT 0;"
sSQL &= "PRAGMA user_version=92"
RunParamQuery(sSQL, New Hashtable)
End If
If eDatabase = Database.Remote Then
'Backup DB before starting
BackupDB("v91")
sSQL = "PRAGMA user_version=92"
RunParamQuery(sSQL, New Hashtable)
End If
End If
'0.93 Upgrade
If GetDatabaseVersion() < 93 Then
If eDatabase = Database.Local Then
'Backup DB before starting
BackupDB("v92")
UpgradeToUnixTime("manifest", "DateUpdated", "ManifestID")
sSQL = "PRAGMA user_version=93"
RunParamQuery(sSQL, New Hashtable)
End If
If eDatabase = Database.Remote Then
'Backup DB before starting
BackupDB("v92")
UpgradeToUnixTime("manifest", "DateUpdated", "ManifestID")
sSQL = "PRAGMA user_version=93"
RunParamQuery(sSQL, New Hashtable)
End If
End If
End Sub
Public Function GetDBSize() As Long
Dim oFileInfo As New FileInfo(sDatabaseLocation)
Return Math.Round(oFileInfo.Length / 1024, 2)
End Function
Public Sub CompactDatabase()
Dim sSQL As String
Dim command As SQLiteCommand
sSQL = "VACUUM"
Connect()
command = New SQLiteCommand(sSQL, db)
Try
command.ExecuteNonQuery()
Catch e As Exception
MsgBox("An error has occured attempting run the query." & vbCrLf & vbCrLf & sSQL & vbCrLf & vbCrLf & e.Message)
Finally
command.Dispose()
Disconnect()
End Try
End Sub
End Class
+181
View File
@@ -0,0 +1,181 @@
Imports System.IO
Public Class mgrSettings
Private bStartWithWindows As Boolean = False
Private bMonitoronStartup As Boolean = True
Private bStartToTray As Boolean = False
Private bShowDetectionToolTips As Boolean = True
Private bDisableConfirmation As Boolean = False
Private bCreateSubFolder As Boolean = False
Private bShowOverwriteWarning As Boolean = True
Private bRestoreOnLaunch As Boolean = False
Private bSync As Boolean = True
Private bCheckSum As Boolean = True
Private sBackupFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).TrimEnd(New Char() {"\", "/"})
Property StartWithWindows As Boolean
Get
Return bStartWithWindows
End Get
Set(value As Boolean)
bStartWithWindows = value
End Set
End Property
Property MonitorOnStartup As Boolean
Get
Return bMonitoronStartup
End Get
Set(value As Boolean)
bMonitoronStartup = value
End Set
End Property
Property StartToTray As Boolean
Get
Return bStartToTray
End Get
Set(value As Boolean)
bStartToTray = value
End Set
End Property
Property ShowDetectionToolTips As Boolean
Get
Return bShowDetectionToolTips
End Get
Set(value As Boolean)
bShowDetectionToolTips = value
End Set
End Property
Property DisableConfirmation As Boolean
Get
Return bDisableConfirmation
End Get
Set(value As Boolean)
bDisableConfirmation = value
End Set
End Property
Property CreateSubFolder As Boolean
Get
Return bCreateSubFolder
End Get
Set(value As Boolean)
bCreateSubFolder = value
End Set
End Property
Property ShowOverwriteWarning As Boolean
Get
Return bShowOverwriteWarning
End Get
Set(value As Boolean)
bShowOverwriteWarning = value
End Set
End Property
Property RestoreOnLaunch As Boolean
Get
Return bRestoreOnLaunch
End Get
Set(value As Boolean)
bRestoreOnLaunch = value
End Set
End Property
Property Sync As Boolean
Get
Return bSync
End Get
Set(value As Boolean)
bSync = value
End Set
End Property
Property CheckSum As Boolean
Get
Return bCheckSum
End Get
Set(value As Boolean)
bCheckSum = value
End Set
End Property
Property BackupFolder As String
Get
Return sBackupFolder
End Get
Set(value As String)
sBackupFolder = value.TrimEnd(New Char() {"\", "/"})
End Set
End Property
Private Sub SaveFromClass()
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM settings WHERE SettingsID = 1"
oDatabase.RunParamQuery(sSQL, New Hashtable)
sSQL = "INSERT INTO settings VALUES (1, @MonitorOnStartup, @StartToTray, @ShowDetectionToolTips, @DisableConfirmation, "
sSQL &= "@CreateSubFolder, @ShowOverwriteWarning, @RestoreOnLaunch, @BackupFolder, @Sync, @CheckSum, @StartWithWindows)"
hshParams.Add("MonitorOnStartup", MonitorOnStartup)
hshParams.Add("StartToTray", StartToTray)
hshParams.Add("ShowDetectionToolTips", ShowDetectionToolTips)
hshParams.Add("DisableConfirmation", DisableConfirmation)
hshParams.Add("CreateSubFolder", CreateSubFolder)
hshParams.Add("ShowOverwriteWarning", ShowOverwriteWarning)
hshParams.Add("RestoreOnLaunch", RestoreOnLaunch)
hshParams.Add("BackupFolder", BackupFolder)
hshParams.Add("Sync", Sync)
hshParams.Add("CheckSum", CheckSum)
hshParams.Add("StartWithWindows", StartWithWindows)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Private Sub MapToClass()
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim oData As DataSet
Dim sSQL As String
oDatabase.Connect()
sSQL = "SELECT * FROM settings WHERE SettingsID = 1"
oData = oDatabase.ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
MonitorOnStartup = CBool(dr(1))
StartToTray = CBool(dr(2))
ShowDetectionToolTips = CBool(dr(3))
DisableConfirmation = CBool(dr(4))
CreateSubFolder = CBool(dr(5))
ShowOverwriteWarning = CBool(dr(6))
RestoreOnLaunch = CBool(dr(7))
BackupFolder = CStr(dr(8))
Sync = CBool(dr(9))
CheckSum = CBool(dr(10))
StartWithWindows = CBool(dr(11))
Next
oDatabase.Disconnect()
End Sub
Public Sub LoadSettings()
MapToClass()
'Set Remote Manifest Location
mgrPath.RemoteDatabaseLocation = Me.BackupFolder
End Sub
Public Sub SaveSettings()
SaveFromClass()
'Set Remote Manifest Location
mgrPath.RemoteDatabaseLocation = Me.BackupFolder
End Sub
End Class
+152
View File
@@ -0,0 +1,152 @@
Imports System.IO
Public Class mgrVariables
Public Shared Sub DoPathUpdate(ByVal sOld As String, ByVal sNew As String)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE monitorlist SET Path = replace(Path, @Old, @New) WHERE Path LIKE @Match"
hshParams.Add("Old", sOld)
hshParams.Add("New", sNew)
hshParams.Add("Match", sOld & "%")
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoVariableAdd(ByVal oCustomVariable As clsPathVariable)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "INSERT INTO variables VALUES (@ID, @Name, @Path)"
hshParams.Add("ID", oCustomVariable.ID)
hshParams.Add("Name", oCustomVariable.Name)
hshParams.Add("Path", oCustomVariable.Path)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoVariableUpdate(ByVal oCustomVariable As clsPathVariable)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "UPDATE variables SET Name=@Name, Path = @Path "
sSQL &= "WHERE VariableID = @ID"
hshParams.Add("Name", oCustomVariable.Name)
hshParams.Add("Path", oCustomVariable.Path)
hshParams.Add("ID", oCustomVariable.ID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Sub DoVariableDelete(ByVal sVariableID As String)
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim hshParams As New Hashtable
sSQL = "DELETE FROM variables "
sSQL &= "WHERE VariableID = @ID"
hshParams.Add("ID", sVariableID)
oDatabase.RunParamQuery(sSQL, hshParams)
End Sub
Public Shared Function DoVariableGetbyID(ByVal sVariableID As String) As clsPathVariable
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim oData As DataSet
Dim oCustomVariable As New clsPathVariable
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM variables "
sSQL &= "WHERE VariableID = @ID"
hshParams.Add("ID", sVariableID)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oCustomVariable = New clsPathVariable
oCustomVariable.ID = CStr(dr(0))
oCustomVariable.Name = CStr(dr(1))
oCustomVariable.Path = CStr(dr(2))
Next
Return oCustomVariable
End Function
Public Shared Function DoVariableGetbyName(ByVal sVariableName As String) As clsPathVariable
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim oData As DataSet
Dim oCustomVariable As New clsPathVariable
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM variables "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", sVariableName)
oData = oDatabase.ReadParamData(sSQL, hshParams)
For Each dr As DataRow In oData.Tables(0).Rows
oCustomVariable = New clsPathVariable
oCustomVariable.ID = CStr(dr(0))
oCustomVariable.Name = CStr(dr(1))
oCustomVariable.Path = CStr(dr(2))
Next
Return oCustomVariable
End Function
Public Shared Function DoCheckDuplicate(ByVal sName As String, Optional ByVal sExcludeID As String = "") As Boolean
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim sSQL As String
Dim oData As DataSet
Dim hshParams As New Hashtable
sSQL = "SELECT * FROM variables "
sSQL &= "WHERE Name = @Name"
hshParams.Add("Name", sName)
If sExcludeID <> String.Empty Then
sSQL &= " AND VariableID <> @VariableID"
hshParams.Add("VariableID", sExcludeID)
End If
oData = oDatabase.ReadParamData(sSQL, hshParams)
If oData.Tables(0).Rows.Count > 0 Then
Return True
Else
Return False
End If
End Function
Public Shared Function ReadVariables() As Hashtable
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
Dim oData As DataSet
Dim sSQL As String
Dim hshList As New Hashtable
Dim oCustomVariable As clsPathVariable
sSQL = "SELECT * from variables"
oData = oDatabase.ReadParamData(sSQL, New Hashtable)
For Each dr As DataRow In oData.Tables(0).Rows
oCustomVariable = New clsPathVariable
oCustomVariable.ID = CStr(dr(0))
oCustomVariable.Name = CStr(dr(1))
oCustomVariable.Path = CStr(dr(2))
hshList.Add(oCustomVariable.Name, oCustomVariable)
Next
Return hshList
End Function
End Class
+99
View File
@@ -0,0 +1,99 @@
Imports System.Xml
Imports System.IO
Imports System.Text
Public Class mgrXML
Public Shared Function ReadMonitorList(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) As Hashtable
Dim xFileReader As XmlTextReader
Dim hshList As New Hashtable
Dim hshDupeList As New Hashtable
Dim oGame As clsGame
Dim oDupeGame As clsGame
'If the file doesn't exist return an empty list
If Not File.Exists(sLocation) And Not bWebRead Then
Return hshList
End If
Try
xFileReader = New XmlTextReader(sLocation)
xFileReader.WhitespaceHandling = WhitespaceHandling.None
While (xFileReader.Read())
If xFileReader.Name = "app" Then
oGame = New clsGame
oGame.Name = xFileReader.GetAttribute("name")
xFileReader.Read()
oGame.ProcessName = xFileReader.ReadElementString("process")
oGame.AbsolutePath = xFileReader.ReadElementString("absolutepath")
oGame.Path = xFileReader.ReadElementString("savelocation")
oGame.FolderSave = xFileReader.ReadElementString("foldersave")
oGame.FileType = xFileReader.ReadElementString("filetype")
oGame.AppendTimeStamp = xFileReader.ReadElementString("appendtimestamp")
oGame.ExcludeList = xFileReader.ReadElementString("excludelist")
If hshList.Contains(oGame.ProcessName) Or hshDupeList.Contains(oGame.ProcessName) Then
oDupeGame = DirectCast(hshList.Item(oGame.ProcessName), clsGame)
If Not hshDupeList.Contains(oGame.ProcessName) Then
hshDupeList.Add(oGame.ProcessName, oDupeGame)
hshList.Remove(oDupeGame.ProcessName)
oDupeGame.Duplicate = True
oDupeGame.ProcessName = oDupeGame.ProcessName & ":" & oDupeGame.Name
hshList.Add(oDupeGame.ProcessName, oDupeGame)
End If
oGame.ProcessName = oGame.ProcessName & ":" & oGame.Name
oGame.Duplicate = True
End If
hshList.Add(oGame.ProcessName, oGame)
End If
End While
xFileReader.Close()
'We need to trigger a manual garbage collection here to prevent issues with the reader freezing up with multiple uses.
'There's no way to properly dispose a xml text reader in .NET 4, that's only fixed in 4.5+.
GC.Collect()
Catch ex As Exception
MsgBox("An error occured reading the monitor list import file." & vbCrLf & ex.Message, MsgBoxStyle.Exclamation, "Game Backup Monitor")
End Try
Return hshList
End Function
Public Shared Function ExportMonitorList(ByVal hshList As Hashtable, ByVal sLocation As String) As Boolean
Dim xFileWriter As XmlTextWriter
Try
xFileWriter = New XmlTextWriter(sLocation, System.Text.Encoding.Unicode)
xFileWriter.Formatting = Formatting.Indented
xFileWriter.WriteStartDocument()
xFileWriter.WriteComment("GBM Export: " & Date.Now)
xFileWriter.WriteComment("Entries: " & hshList.Count)
xFileWriter.WriteStartElement("aMon")
For Each o As clsGame In hshList.Values
xFileWriter.WriteStartElement("app")
xFileWriter.WriteAttributeString("name", o.Name)
xFileWriter.WriteElementString("process", o.TrueProcess)
xFileWriter.WriteElementString("absolutepath", o.AbsolutePath)
xFileWriter.WriteElementString("savelocation", o.TruePath)
xFileWriter.WriteElementString("foldersave", o.FolderSave)
xFileWriter.WriteElementString("filetype", o.FileType)
xFileWriter.WriteElementString("appendtimestamp", o.AppendTimeStamp)
xFileWriter.WriteElementString("excludelist", o.ExcludeList)
xFileWriter.WriteEndElement()
Next
xFileWriter.WriteEndElement()
xFileWriter.WriteEndDocument()
xFileWriter.Flush()
xFileWriter.Close()
Return True
Catch ex As Exception
MsgBox("An error occured exporting the monitor list. " & ex.Message, MsgBoxStyle.Exclamation, "Game Backup Monitor")
Return False
End Try
End Function
End Class