From 644d073af0d08ce010b82787cd546989d1715627 Mon Sep 17 00:00:00 2001 From: MikeMaximus Date: Mon, 20 Nov 2017 10:54:06 -0600 Subject: [PATCH] Changes for issue #109 --- .../XML Serialize Classes/ExportData.vb | 32 +++++++++++++ .../ExportInformation.vb | 32 +++++++++++++ GBM/Game Backup Monitor.vbproj | 2 + GBM/Managers/mgrXML.vb | 46 ++++++++++++++----- 4 files changed, 100 insertions(+), 12 deletions(-) create mode 100644 GBM/Classes/XML Serialize Classes/ExportData.vb create mode 100644 GBM/Classes/XML Serialize Classes/ExportInformation.vb diff --git a/GBM/Classes/XML Serialize Classes/ExportData.vb b/GBM/Classes/XML Serialize Classes/ExportData.vb new file mode 100644 index 0000000..306516e --- /dev/null +++ b/GBM/Classes/XML Serialize Classes/ExportData.vb @@ -0,0 +1,32 @@ +Public Class ExportData + Dim oExportInformation As ExportInformation + Dim oConfigs As List(Of Game) + + Property Information As ExportInformation + Set(value As ExportInformation) + oExportInformation = value + End Set + Get + Return oExportInformation + End Get + End Property + + Property Configurations As List(Of Game) + Set(value As List(Of Game)) + oConfigs = value + End Set + Get + Return oConfigs + End Get + End Property + + Public Sub New() + oExportInformation = New ExportInformation() + oConfigs = New List(Of Game) + End Sub + + Public Sub New(ByVal oInitExportInformation As ExportInformation, ByVal oInitConfigs As List(Of Game)) + oExportInformation = oInitExportInformation + oConfigs = oInitConfigs + End Sub +End Class diff --git a/GBM/Classes/XML Serialize Classes/ExportInformation.vb b/GBM/Classes/XML Serialize Classes/ExportInformation.vb new file mode 100644 index 0000000..8d4ad4a --- /dev/null +++ b/GBM/Classes/XML Serialize Classes/ExportInformation.vb @@ -0,0 +1,32 @@ +Public Class ExportInformation + Private dExported As Int64 + Private iAppVer As Integer + + Property Exported As Int64 + Set(value As Int64) + dExported = value + End Set + Get + Return dExported + End Get + End Property + + Property AppVer As Integer + Set(value As Integer) + iAppVer = value + End Set + Get + Return iAppVer + End Get + End Property + + Public Sub New() + dExported = 0 + iAppVer = 0 + End Sub + + Public Sub New(ByVal dInitExported As Int64, ByVal iInitAppVer As Integer) + dExported = dInitExported + iAppVer = iInitAppVer + End Sub +End Class diff --git a/GBM/Game Backup Monitor.vbproj b/GBM/Game Backup Monitor.vbproj index d747e38..b543ad8 100644 --- a/GBM/Game Backup Monitor.vbproj +++ b/GBM/Game Backup Monitor.vbproj @@ -126,6 +126,8 @@ + + diff --git a/GBM/Managers/mgrXML.vb b/GBM/Managers/mgrXML.vb index 7b4258c..73f512a 100644 --- a/GBM/Managers/mgrXML.vb +++ b/GBM/Managers/mgrXML.vb @@ -46,38 +46,60 @@ Public Class mgrXML Return hshList End Function - Public Shared Function ImportandDeserialize(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) As List(Of Game) + Private Shared Function ReadImportData(ByVal sLocation As String, ByVal bWebRead As Boolean) Dim oReader As StreamReader Dim oWebClient As WebClient + + If bWebRead Then + oWebClient = New WebClient + oReader = New StreamReader(oWebClient.OpenRead(sLocation)) + Else + oReader = New StreamReader(sLocation) + End If + + Return oReader + End Function + + Public Shared Function ImportandDeserialize(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) As List(Of Game) + Dim oReader As StreamReader Dim oSerializer As XmlSerializer - Dim oList As New List(Of Game) + Dim oExportData As New ExportData + Dim oConfigurations As New List(Of Game) Try - If bWebRead Then - oWebClient = New WebClient - oReader = New StreamReader(oWebClient.OpenRead(sLocation)) + oReader = ReadImportData(sLocation, bWebRead) + oSerializer = New XmlSerializer(oExportData.GetType(), New XmlRootAttribute("gbm")) + oExportData = oSerializer.Deserialize(oReader) + oReader.Close() + + 'Compatability Mode + If oExportData.Information.AppVer = 0 Then + oReader = ReadImportData(sLocation, bWebRead) + oSerializer = New XmlSerializer(oConfigurations.GetType(), New XmlRootAttribute("gbm")) + oConfigurations = oSerializer.Deserialize(oReader) + oReader.Close() Else - oReader = New StreamReader(sLocation) + oConfigurations = oExportData.Configurations End If - oSerializer = New XmlSerializer(oList.GetType(), New XmlRootAttribute("gbm")) - oList = oSerializer.Deserialize(oReader) - oReader.Close() Catch ex As Exception mgrCommon.ShowMessage(mgrXML_ErrorImportFailure, ex.Message, MsgBoxStyle.Exclamation) End Try - Return oList + Return oConfigurations End Function Public Shared Function SerializeAndExport(ByVal oList As List(Of Game), ByVal sLocation As String) As Boolean Dim oSerializer As XmlSerializer Dim oWriter As StreamWriter + Dim oExportInformation = New ExportInformation(mgrCommon.DateToUnix(Now), mgrCommon.AppVersion) + Dim oExportData As ExportData Try - oSerializer = New XmlSerializer(oList.GetType(), New XmlRootAttribute("gbm")) + oExportData = New ExportData(oExportInformation, oList) + oSerializer = New XmlSerializer(oExportData.GetType(), New XmlRootAttribute("gbm")) oWriter = New StreamWriter(sLocation) - oSerializer.Serialize(oWriter.BaseStream, oList) + oSerializer.Serialize(oWriter.BaseStream, oExportData) oWriter.Flush() oWriter.Close() Return True