From ddee7372227dcde38f1f1e80541da4d5165fb7a8 Mon Sep 17 00:00:00 2001 From: MikeMaximus Date: Sun, 4 Mar 2018 21:23:01 -0600 Subject: [PATCH] Added game id sync to import --- GBM/Forms/frmGameManager.vb | 4 ++ GBM/Managers/mgrMonitorList.vb | 78 +++++++++++++++++++++++++++- GBM/My Project/Resources.Designer.vb | 27 ++++++++++ GBM/My Project/Resources.resx | 9 ++++ GBM/readme.txt | 6 +-- 5 files changed, 119 insertions(+), 5 deletions(-) diff --git a/GBM/Forms/frmGameManager.vb b/GBM/Forms/frmGameManager.vb index 490d4ca..cfc6554 100644 --- a/GBM/Forms/frmGameManager.vb +++ b/GBM/Forms/frmGameManager.vb @@ -1497,7 +1497,9 @@ Public Class frmGameManager If sLocation <> String.Empty Then If mgrMonitorList.DoImport(sLocation) Then + mgrMonitorList.SyncMonitorLists(Settings.SyncFields) LoadData() + LoadBackupData() End If End If @@ -1525,7 +1527,9 @@ Public Class frmGameManager If mgrCommon.ShowMessage(frmGameManager_ConfirmOfficialImport, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then If mgrMonitorList.DoImport(sImportURL) Then + mgrMonitorList.SyncMonitorLists(Settings.SyncFields) LoadData() + LoadBackupData() End If End If End Sub diff --git a/GBM/Managers/mgrMonitorList.vb b/GBM/Managers/mgrMonitorList.vb index 98b5122..61d0473 100644 --- a/GBM/Managers/mgrMonitorList.vb +++ b/GBM/Managers/mgrMonitorList.vb @@ -163,7 +163,6 @@ Public Class mgrMonitorList End If 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) @@ -787,6 +786,9 @@ Public Class mgrMonitorList If (sPath.IndexOf("http://", 0, StringComparison.CurrentCultureIgnoreCase) > -1) Or (sPath.IndexOf("https://", 0, StringComparison.CurrentCultureIgnoreCase) > -1) Then If mgrCommon.CheckAddress(sPath) Then + If mgrCommon.ShowMessage(mgrMonitorList_ConfirmGameIDSync, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then + ImportSyncGameID(sPath, True) + End If ImportMonitorList(sPath, True) Return True Else @@ -795,6 +797,9 @@ Public Class mgrMonitorList End If Else If File.Exists(sPath) Then + If mgrCommon.ShowMessage(mgrMonitorList_ConfirmGameIDSync, MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then + ImportSyncGameID(sPath) + End If ImportMonitorList(sPath) Return True Else @@ -815,8 +820,14 @@ Public Class mgrMonitorList Cursor.Current = Cursors.WaitCursor - 'Add / Update Sync hshCompareFrom = mgrXML.ReadMonitorList(sLocation, oExportInfo, bWebRead) + + If oExportInfo.AppVer < 110 Then + If mgrCommon.ShowMessage(mgrMonitorList_ImportVersionWarning, MsgBoxStyle.YesNo) = MsgBoxResult.No Then + Exit Sub + End If + End If + hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) hshSyncItems = hshCompareFrom.Clone @@ -829,7 +840,11 @@ Public Class mgrMonitorList hshSyncItems.Remove(oFromItem.ID) Else DirectCast(hshSyncItems(oFromItem.ID), clsGame).ImportUpdate = True + 'These fields need to be set via the object or they will be lost when the configuration is updated + DirectCast(hshSyncItems(oFromItem.ID), clsGame).Hours = oToItem.Hours + DirectCast(hshSyncItems(oFromItem.ID), clsGame).CleanFolder = oToItem.CleanFolder End If + End If End If Next @@ -856,6 +871,65 @@ Public Class mgrMonitorList Application.DoEvents() End Sub + Private Shared Sub ImportSyncGameID(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) + Dim oLocalDatabase As New mgrSQLite(mgrSQLite.Database.Local) + Dim oRemoteDatabase As New mgrSQLite(mgrSQLite.Database.Remote) + Dim sSQL As String + Dim hshParams As Hashtable + Dim oParamList As New List(Of Hashtable) + Dim hshCompareFrom As Hashtable + Dim hshCompareTo As Hashtable + Dim hshSyncIDs As New Hashtable + Dim oFromItem As clsGame + Dim oToItem As clsGame + Dim oExportInfo As New ExportData + + Cursor.Current = Cursors.WaitCursor + + hshCompareFrom = mgrXML.ReadMonitorList(sLocation, oExportInfo, bWebRead) + + If oExportInfo.AppVer < 110 Then + mgrCommon.ShowMessage(mgrMonitorList_ErrorGameIDVerFailure, MsgBoxStyle.Exclamation) + Exit Sub + End If + + hshCompareTo = ReadList(eListTypes.FullList, mgrSQLite.Database.Local) + + For Each oFromItem In hshCompareFrom.Values + If Not hshCompareTo.Contains(oFromItem.ID) Then + For Each oToItem In hshCompareTo.Values + 'Strip all special characters and compare names + If Regex.Replace(oToItem.Name, "[^\w]+", "") = Regex.Replace(oFromItem.Name, "[^\w]+", "") Then + 'Ignore games with duplicate names + If Not hshSyncIDs.Contains(oFromItem.ID) Then + hshSyncIDs.Add(oToItem.ID, oFromItem.ID) + End If + End If + Next + End If + Next + + For Each de As DictionaryEntry In hshSyncIDs + hshParams = New Hashtable + hshParams.Add("MonitorID", CStr(de.Value)) + hshParams.Add("QueryID", CStr(de.Key)) + oParamList.Add(hshParams) + Next + + sSQL = "UPDATE monitorlist SET MonitorID=@MonitorID WHERE MonitorID=@QueryID;" + sSQL &= "UPDATE gametags SET MonitorID=@MonitorID WHERE MonitorID=@QueryID;" + sSQL &= "UPDATE manifest SET MonitorID=@MonitorID WHERE MonitorID=@QueryID;" + + oRemoteDatabase.RunMassParamQuery(sSQL, oParamList) + + sSQL &= "UPDATE sessions SET MonitorID=@MonitorID WHERE MonitorID=@QueryID;" + + oLocalDatabase.RunMassParamQuery(sSQL, oParamList) + + Cursor.Current = Cursors.Default + + End Sub + Public Shared Sub ExportMonitorList(ByVal sLocation As String) Dim oList As List(Of Game) Dim bSuccess As Boolean = False diff --git a/GBM/My Project/Resources.Designer.vb b/GBM/My Project/Resources.Designer.vb index 029f27a..a03ee87 100644 --- a/GBM/My Project/Resources.Designer.vb +++ b/GBM/My Project/Resources.Designer.vb @@ -5437,6 +5437,24 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to GBM now uses a unique identifier for each game. For the import feature to work as intended, your existing game configurations need to use the same identifiers.[BR][BR]Do you want to sync your game identifiers? (Recommened). + ''' + Friend ReadOnly Property mgrMonitorList_ConfirmGameIDSync() As String + Get + Return ResourceManager.GetString("mgrMonitorList_ConfirmGameIDSync", resourceCulture) + End Get + End Property + + ''' + ''' Looks up a localized string similar to This file cannot be used to sync game indentifiers. It was created with an older version of GBM.. + ''' + Friend ReadOnly Property mgrMonitorList_ErrorGameIDVerFailure() As String + Get + Return ResourceManager.GetString("mgrMonitorList_ErrorGameIDVerFailure", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to Export Complete. [PARAM] item(s) have been exported.. ''' @@ -5473,6 +5491,15 @@ Namespace My.Resources End Get End Property + ''' + ''' Looks up a localized string similar to This export file was created with a version of GBM prior to 1.1.0 and does not contain unique game identifiers.[BR][BR]Do you still want to import configurations from this file? (Not Recommended). + ''' + Friend ReadOnly Property mgrMonitorList_ImportVersionWarning() As String + Get + Return ResourceManager.GetString("mgrMonitorList_ImportVersionWarning", resourceCulture) + End Get + End Property + ''' ''' Looks up a localized string similar to [PARAM] change(s) synced.. ''' diff --git a/GBM/My Project/Resources.resx b/GBM/My Project/Resources.resx index 94c78d7..4dc637f 100644 --- a/GBM/My Project/Resources.resx +++ b/GBM/My Project/Resources.resx @@ -2026,4 +2026,13 @@ Game ID + + GBM now uses a unique identifier for each game. For the import feature to work as intended, your existing game configurations need to use the same identifiers.[BR][BR]Do you want to sync your game identifiers? (Recommened) + + + This file cannot be used to sync game indentifiers. It was created with an older version of GBM. + + + This export file was created with a version of GBM prior to 1.1.0 and does not contain unique game identifiers.[BR][BR]Do you still want to import configurations from this file? (Not Recommended) + \ No newline at end of file diff --git a/GBM/readme.txt b/GBM/readme.txt index 255d119..b2ecf99 100644 --- a/GBM/readme.txt +++ b/GBM/readme.txt @@ -8,9 +8,9 @@ New in 1.1.0 Disclaimer: -1. This is pre-release software intended for testing. -2. Database files from this version (gbm.s3db) may not be compatible with the full release. GBM makes automatic backups of your database files if you need to revert to a prior version. -3. Do not make external links to this release, it will be available for a limited time. +Version 1.1.0 makes fundamental changes to how GBM works with game configurations and backup data. Please read the changes below carefully. + +I've done my best to make sure the upgrade process is seamless and allows everyone to continue using their existing data and configurations. All Platforms: