From de7a993abeb1bc169e757f5f839d79849785caea Mon Sep 17 00:00:00 2001 From: "Michael J. Seiferling" Date: Mon, 29 Feb 2016 12:24:56 -0600 Subject: [PATCH] Changes for multi-platform support --- GBM/Forms/frmMain.vb | 61 +++++++++++++++----------- GBM/Managers/mgrBackup.vb | 10 ++--- GBM/Managers/mgrCommon.vb | 2 - GBM/Managers/mgrPath.vb | 47 ++++++++++---------- GBM/Managers/mgrRestore.vb | 6 +-- GBM/My Project/Resources.Designer.vb | 65 ++++++++++++++++------------ GBM/My Project/Resources.resx | 3 ++ 7 files changed, 108 insertions(+), 86 deletions(-) diff --git a/GBM/Forms/frmMain.vb b/GBM/Forms/frmMain.vb index e11a1b0..16be855 100644 --- a/GBM/Forms/frmMain.vb +++ b/GBM/Forms/frmMain.vb @@ -23,6 +23,7 @@ Public Class frmMain Private eCurrentOperation As eOperation = eOperation.None Private bCancelledByUser As Boolean = False Private bShutdown As Boolean = False + Private bInitFail As Boolean = False Private bMenuEnabled As Boolean = True Private bLockdown As Boolean = True Private bFirstRun As Boolean = False @@ -812,15 +813,13 @@ Public Class frmMain Private Sub ToggleState() 'Toggle State with Tray Clicks - If Me.WindowState = FormWindowState.Minimized Then + If Me.Visible = False Then Me.Visible = True Me.ShowInTaskbar = True - Me.WindowState = FormWindowState.Normal Me.Focus() Else Me.Visible = False Me.ShowInTaskbar = False - Me.WindowState = FormWindowState.Minimized End If End Sub @@ -1173,8 +1172,8 @@ Public Class frmMain Private Sub VerifyGameDataPath() 'Important: This function cannot access mgrPath for settings, as that will trigger a database creation and destroy the reason for this function - Dim sSettingsRoot As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "\gbm" - Dim sDBLocation As String = sSettingsRoot & "\gbm.s3db" + Dim sSettingsRoot As String = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) & "/gbm" + Dim sDBLocation As String = sSettingsRoot & "/gbm.s3db" If Not IO.Directory.Exists(sSettingsRoot) Then Try @@ -1400,7 +1399,6 @@ Public Class frmMain Private Sub gMonTray_BalloonTipClicked(sender As System.Object, e As System.EventArgs) Handles gMonTray.BalloonTipClicked Me.Visible = True Me.ShowInTaskbar = True - Me.WindowState = FormWindowState.Normal Me.Focus() End Sub @@ -1422,8 +1420,7 @@ Public Class frmMain If bShutdown = False Then e.Cancel = True Me.Visible = False - Me.ShowInTaskbar = False - Me.WindowState = FormWindowState.Minimized + Me.ShowInTaskbar = False End If End Sub @@ -1537,32 +1534,46 @@ Public Class frmMain End Sub Private Sub Main_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load - SetForm() - VerifyGameDataPath() - LoadAndVerify() - VerifyCustomPathVariables() - If oSettings.StartToTray Then - Me.Visible = False - Me.ShowInTaskbar = False - Me.WindowState = FormWindowState.Minimized - End If + 'Init + Try + SetForm() + VerifyGameDataPath() + LoadAndVerify() + VerifyCustomPathVariables() - If oSettings.MonitorOnStartup Then - eCurrentStatus = eStatus.Stopped - Else - eCurrentStatus = eStatus.Running - End If + If oSettings.StartToTray Then + Me.Visible = False + Me.ShowInTaskbar = False + End If - HandleScan() - CheckForNewBackups() + If oSettings.MonitorOnStartup Then + eCurrentStatus = eStatus.Stopped + Else + eCurrentStatus = eStatus.Running + End If + + HandleScan() + CheckForNewBackups() + Catch niex As NotImplementedException + 'Ignore for Mono runtime tests + Catch ex As Exception + mgrCommon.ShowMessage(frmMain_ErrorInitFailure, ex.Message, MsgBoxStyle.Critical) + bInitFail = True + End Try End Sub Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles MyBase.Shown - If bFirstRun Then + + If bFirstRun And Not bInitFail Then OpenStartupWizard() End If + + If bInitFail Then + bShutdown = True + Me.Close() + End If End Sub Private Sub txtGameInfo_Enter(sender As Object, e As EventArgs) diff --git a/GBM/Managers/mgrBackup.vb b/GBM/Managers/mgrBackup.vb index 2a2c590..1f94a3c 100644 --- a/GBM/Managers/mgrBackup.vb +++ b/GBM/Managers/mgrBackup.vb @@ -42,7 +42,7 @@ Public Class mgrBackup 'Create manifest item oItem.Name = oGameInfo.Name 'Keep the path relative to the manifest location - oItem.FileName = sBackupFile.Replace(Path.GetDirectoryName(mgrPath.RemoteDatabaseLocation) & "\", "") + oItem.FileName = sBackupFile.Replace(Path.GetDirectoryName(mgrPath.RemoteDatabaseLocation) & Path.DirectorySeparatorChar, "") oItem.RestorePath = oGameInfo.TruePath oItem.AbsolutePath = oGameInfo.AbsolutePath oItem.DateUpdated = dTimeStamp @@ -75,7 +75,7 @@ Public Class mgrBackup Using oStream If sList <> String.Empty Then For Each sTypeItem As String In sList.Split(":") - oStream.WriteLine("""" & sBackupPath & "\" & sTypeItem & """") + oStream.WriteLine("""" & sBackupPath & Path.DirectorySeparatorChar & sTypeItem & """") Next End If oStream.Flush() @@ -129,9 +129,9 @@ Public Class mgrBackup End If If oGame.AppendTimeStamp Then - sBackupFile = sBackupFile & "\" & oGame.Name & sTimeStamp & ".7z" + sBackupFile = sBackupFile & Path.DirectorySeparatorChar & oGame.Name & sTimeStamp & ".7z" Else - sBackupFile = sBackupFile & "\" & oGame.Name & ".7z" + sBackupFile = sBackupFile & Path.DirectorySeparatorChar & oGame.Name & ".7z" End If If oSettings.ShowOverwriteWarning And File.Exists(sBackupFile) Then @@ -144,7 +144,7 @@ Public Class mgrBackup If bDoBackup Then If oGame.AbsolutePath = False Then If oGame.Path <> String.Empty Then - sSavePath = oGame.ProcessPath & "\" & oGame.Path + sSavePath = oGame.ProcessPath & Path.DirectorySeparatorChar & oGame.Path Else sSavePath = oGame.ProcessPath End If diff --git a/GBM/Managers/mgrCommon.vb b/GBM/Managers/mgrCommon.vb index a1e39fa..e23bbdd 100644 --- a/GBM/Managers/mgrCommon.vb +++ b/GBM/Managers/mgrCommon.vb @@ -160,8 +160,6 @@ Public Class mgrCommon End Try End Function - - 'Handles no extra parameters Public Shared Function ShowMessage(ByVal sMsg As String, ByVal oType As MsgBoxStyle) As MsgBoxResult Dim oResult As MsgBoxResult diff --git a/GBM/Managers/mgrPath.vb b/GBM/Managers/mgrPath.vb index 5aa2747..8afbf4d 100644 --- a/GBM/Managers/mgrPath.vb +++ b/GBM/Managers/mgrPath.vb @@ -5,11 +5,11 @@ 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 sLogFile As String = sSettingsRoot & "\gbm_log_" & Date.Now.ToString("dd-MM-yyyy-HH-mm-ss") & ".txt" + 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 sLogFile As String = sSettingsRoot & "/gbm_log_" & Date.Now.ToString("dd-MM-yyyy-HH-mm-ss") & ".txt" Private Shared sRemoteDatabaseLocation As String Private Shared hshCustomVariables As Hashtable Private Shared oReleaseType As ProcessorArchitecture = AssemblyName.GetAssemblyName(Application.ExecutablePath()).ProcessorArchitecture @@ -41,18 +41,18 @@ Public Class mgrPath Get Select Case oReleaseType Case ProcessorArchitecture.Amd64 - Return Application.StartupPath & "\Utilities\x64\7za.exe" + Return Application.StartupPath & "/Utilities/x64/7za.exe" Case ProcessorArchitecture.IA64 - Return Application.StartupPath & "\Utilities\x64\7za.exe" + Return Application.StartupPath & "/Utilities/x64/7za.exe" Case ProcessorArchitecture.MSIL - Return Application.StartupPath & "\Utilities\x86\7za.exe" + Return Application.StartupPath & "/Utilities/x86/7za.exe" Case ProcessorArchitecture.X86 - Return Application.StartupPath & "\Utilities\x86\7za.exe" + Return Application.StartupPath & "/Utilities/x86/7za.exe" Case ProcessorArchitecture.None - Return Application.StartupPath & "\Utilities\x86\7za.exe" + Return Application.StartupPath & "/Utilities/x86/7za.exe" End Select - Return Application.StartupPath & "\Utilities\x86\7za.exe" + Return Application.StartupPath & "/Utilities/x86/7za.exe" End Get End Property @@ -119,19 +119,20 @@ Public Class mgrPath Dim iRemove As Integer = 0 Dim iBackFolders As Integer = 0 Dim bDeep As Boolean + Dim cPathChars As Char() = {"\", "/"} '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 &= "\" + sProcessPath = sProcessPath.TrimEnd(cPathChars) + sSavePath = sSavePath.TrimEnd(cPathChars) + 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 + If sSavePath.Split(cPathChars).Length > sProcessPath.Split(cPathChars).Length Then sPath1 = sProcessPath sPath2 = sSavePath bDeep = True @@ -142,8 +143,8 @@ Public Class mgrPath End If 'Build an array of folders to work with from each path - sPath1Array = sPath1.Split("\") - sPath2Array = sPath2.Split("\") + sPath1Array = sPath1.Split(cPathChars) + sPath2Array = sPath2.Split(cPathChars) 'Take the shortest path and remove the common folders from both For Each s As String In sPath1Array @@ -155,25 +156,25 @@ Public Class mgrPath Next 'Remove the trailing slashes - sPath1 = sPath1.TrimEnd("\") - sPath2 = sPath2.TrimEnd("\") + sPath1 = sPath1.TrimEnd(cPathChars) + sPath2 = sPath2.TrimEnd(cPathChars) 'Determine which way we go If bDeep Then If sPath1.Length > 0 Then - iBackFolders = sPath1.Split("\").Length + iBackFolders = sPath1.Split(cPathChars).Length End If sResult = sPath2 Else If sPath2.Length > 0 Then - iBackFolders = sPath2.Split("\").Length + iBackFolders = sPath2.Split(cPathChars).Length End If sResult = sPath1 End If 'Insert direction modifiers based on how many folders are left For i = 1 To iBackFolders - sResult = "..\" & sResult + sResult = ".." & Path.DirectorySeparatorChar & sResult Next i 'Done diff --git a/GBM/Managers/mgrRestore.vb b/GBM/Managers/mgrRestore.vb index 43e794e..c8a2ac1 100644 --- a/GBM/Managers/mgrRestore.vb +++ b/GBM/Managers/mgrRestore.vb @@ -60,7 +60,7 @@ Public Class mgrRestore If Not oRestoreInfo.AbsolutePath Then If oGame.ProcessPath <> String.Empty Then - oRestoreInfo.RelativeRestorePath = oGame.ProcessPath & "\" & oRestoreInfo.RestorePath + oRestoreInfo.RelativeRestorePath = oGame.ProcessPath & Path.DirectorySeparatorChar & oRestoreInfo.RestorePath Else sProcess = oGame.TrueProcess If mgrCommon.IsProcessNotSearchable(oGame) Then bNoAuto = True @@ -73,7 +73,7 @@ Public Class mgrRestore bTriggerReload = True 'Set path for restore - oRestoreInfo.RelativeRestorePath = sRestorePath & "\" & oRestoreInfo.RestorePath + oRestoreInfo.RelativeRestorePath = sRestorePath & Path.DirectorySeparatorChar & oRestoreInfo.RestorePath Else Return False End If @@ -183,7 +183,7 @@ Public Class mgrRestore For Each oBackupInfo In oRestoreList 'Init prs7z = New Process - sBackupFile = oSettings.BackupFolder & "\" & oBackupInfo.FileName + sBackupFile = oSettings.BackupFolder & Path.DirectorySeparatorChar & oBackupInfo.FileName sExtractPath = String.Empty bDoRestore = True bRestoreCompleted = False diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index 7919599..f638bd3 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -2111,7 +2111,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_CommandFail", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to The command was executed successfully.. ''' @@ -2120,7 +2120,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_CommandSucess", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Do you wish to backup data from [PARAM]?. ''' @@ -2129,7 +2129,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ConfirmBackup", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Are you sure you want to clear the log?. ''' @@ -2138,7 +2138,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ConfirmLogClear", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to This tool removes orphaned backup information from the local manifest based on the current backup folder. Data can become orphaned when backups are deleted by various computers that share the same backup folder on a cloud or network.[BR][BR]When alternating between different backup folders you should NOT use this tool.[BR][BR]Do you wish to proceed?. ''' @@ -2147,7 +2147,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ConfirmManifestClean", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Do you wish to cancel the monitoring of [PARAM]?[BR][BR]Warning: When monitoring is cancelled, session time is NOT saved.. ''' @@ -2156,7 +2156,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ConfirmMonitorCancel", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to This will rebuild all databases and shrink them to an optimal size.[BR]This should only be used if your gbm.s3db files are becoming very large.[BR][BR]Do you wish to continue?. ''' @@ -2165,7 +2165,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ConfirmRebuild", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Do you want to restart Game Backup Monitor as Administrator?. ''' @@ -2174,7 +2174,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ConfirmRunAsAdmin", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Game Backup Monitor Log. ''' @@ -2183,7 +2183,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_DefaultLogFileName", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Developer Console. ''' @@ -2192,7 +2192,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_DeveloperConsole", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Enter Command. ''' @@ -2201,7 +2201,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_EnterCommand", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to [PARAM] is a 64-bit game, GBM cannot detect the required information to save your backup.. ''' @@ -2210,7 +2210,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_Error64Backup", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to 7-Zip was not found in the Game Backup Monitor utilities folder. The application cannot continue.. ''' @@ -2219,7 +2219,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_Error7zip", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to [PARAM] is running as Administrator and GBM is not, GBM cannot detect the required information to save your backup.. ''' @@ -2228,7 +2228,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorAdminBackup", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to [PARAM] is running as Administrator and GBM is not.[BR]You cannot cancel monitoring at this time.[BR][BR]Run GBM as Administrator to prevent this issue.. ''' @@ -2237,7 +2237,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorAdminDetect", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Game Backup Monitor is already running as Administrator.. ''' @@ -2246,7 +2246,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorAlreadyAdmin", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to GBM is running from a new location, the Windows startup entry has been updated.. ''' @@ -2255,7 +2255,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorAppLocationChanged", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to [PARAM] backup was cancelled.. ''' @@ -2264,7 +2264,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorBackupCancel", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to [PARAM] backup was cancelled due to session length.. ''' @@ -2273,7 +2273,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorBackupSessionLength", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to [PARAM] backup was cancelled due to unknown path.. ''' @@ -2282,7 +2282,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorBackupUnknownPath", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Bad parameter ([PARAM]) for command [PARAM].. ''' @@ -2291,7 +2291,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorCommandBadParam", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to The command [PARAM] was not recognized.. ''' @@ -2300,7 +2300,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorCommandInvalid", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to The following monitored game(s) contain a custom path variable that is not set.[BR][PARAM][BR][BR]You will encounter backup/restore errors with these games until the variables are set.. ''' @@ -2309,7 +2309,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorCustomVariable", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Your local GBM data (Version [PARAM]) is too new for your version of GBM (Version [PARAM]).[BR][BR]Please upgrade GBM or restore the database file appropriate for your version. The application cannot proceed.. ''' @@ -2318,7 +2318,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorDBVerLocal", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to The GBM data (Version [PARAM]) in your backup folder is too new for your version of GBM (Version [PARAM])[BR][BR]All computers sharing a backup folder must use the same version of GBM. The application cannot proceed.. ''' @@ -2327,7 +2327,16 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorDBVerRemote", resourceCulture) End Get End Property - + + ''' + ''' Looks up a localized string similar to An unexpected error occured while initializing GBM.[BR][BR][PARAM][BR][BR]The application will now exit.. + ''' + Friend ReadOnly Property frmMain_ErrorInitFailure() As String + Get + Return ResourceManager.GetString("frmMain_ErrorInitFailure", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to The command [PARAM] requires more parameters.. ''' @@ -2336,7 +2345,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorMissingParams", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Multiple possible 64-bit games have been detected, GBM cannot detect the path to identify your game or save your backup.[BR][BR]Please install the 64-bit version of GBM to detect and backup this game properly.. ''' @@ -2345,7 +2354,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorMulti64", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to Multiple possible games have been detected running as Administrator and GBM is not, GBM cannot detect the path to identify your game or save your backup.[BR][BR]Please run GBM as Administrator to properly detect and backup this game.. ''' @@ -2354,7 +2363,7 @@ Namespace My.Resources Return ResourceManager.GetString("frmMain_ErrorMultiAdmin", resourceCulture) End Get End Property - + ''' ''' Looks up a localized string similar to [PARAM] uses a relative path and has never been detected on this computer.. ''' diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index bcbc1f5..9dd1530 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -1558,4 +1558,7 @@ The command [PARAM] requires more parameters. + + An unexpected error occured while initializing GBM.[BR][BR][PARAM][BR][BR]The application will now exit. + \ No newline at end of file