Rewrote import / export
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
Public Class Game
|
||||
Private sGameName As String
|
||||
Private sProcessName As String
|
||||
Private sPath As String
|
||||
Private bAbsolutePath As Boolean
|
||||
Private bFolderSave As Boolean
|
||||
Private sFileType As String
|
||||
Private sExcludeList As String
|
||||
Private oTags As List(Of Tag)
|
||||
|
||||
Property Name As String
|
||||
Set(value As String)
|
||||
sGameName = value
|
||||
End Set
|
||||
Get
|
||||
Return sGameName
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property ProcessName As String
|
||||
Set(value As String)
|
||||
sProcessName = value
|
||||
End Set
|
||||
Get
|
||||
Return sProcessName
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property Path As String
|
||||
Set(value As String)
|
||||
sPath = mgrPath.ReverseSpecialPaths(value)
|
||||
End Set
|
||||
Get
|
||||
Return mgrPath.ReplaceSpecialPaths(sPath)
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property AbsolutePath As Boolean
|
||||
Set(value As Boolean)
|
||||
bAbsolutePath = value
|
||||
End Set
|
||||
Get
|
||||
Return bAbsolutePath
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property FolderSave As Boolean
|
||||
Set(value As Boolean)
|
||||
bFolderSave = value
|
||||
End Set
|
||||
Get
|
||||
Return bFolderSave
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property FileType As String
|
||||
Set(value As String)
|
||||
sFileType = value
|
||||
End Set
|
||||
Get
|
||||
Return sFileType
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property ExcludeList As String
|
||||
Set(value As String)
|
||||
sExcludeList = value
|
||||
End Set
|
||||
Get
|
||||
Return sExcludeList
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Property Tags As List(Of Tag)
|
||||
Get
|
||||
Return oTags
|
||||
End Get
|
||||
Set(value As List(Of Tag))
|
||||
oTags = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
End Class
|
||||
@@ -0,0 +1,13 @@
|
||||
Public Class Tag
|
||||
Private sTagName As String
|
||||
|
||||
Property Name As String
|
||||
Get
|
||||
Return sTagName
|
||||
End Get
|
||||
Set(value As String)
|
||||
sTagName = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
End Class
|
||||
+25
-15
@@ -18,6 +18,7 @@
|
||||
Private bDuplicate As Boolean = False
|
||||
Private sDOSBoxProcess As String = String.Empty
|
||||
Private bTempGame As Boolean = False
|
||||
Private oImportTags As New List(Of Tag)
|
||||
|
||||
Property ID As String
|
||||
Set(value As String)
|
||||
@@ -156,40 +157,40 @@
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property Enabled As Boolean
|
||||
Set(value As Boolean)
|
||||
bEnabled = value
|
||||
End Set
|
||||
Property Enabled As Boolean
|
||||
Get
|
||||
Return bEnabled
|
||||
End Get
|
||||
Set(value As Boolean)
|
||||
bEnabled = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property MonitorOnly As Boolean
|
||||
Set(value As Boolean)
|
||||
bMonitorOnly = value
|
||||
End Set
|
||||
Property MonitorOnly As Boolean
|
||||
Get
|
||||
Return bMonitorOnly
|
||||
End Get
|
||||
Set(value As Boolean)
|
||||
bMonitorOnly = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property Duplicate As Boolean
|
||||
Set(value As Boolean)
|
||||
bDuplicate = value
|
||||
End Set
|
||||
Get
|
||||
Return bDuplicate
|
||||
End Get
|
||||
Set(value As Boolean)
|
||||
bDuplicate = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property DOSBoxProcess As String
|
||||
Set(value As String)
|
||||
sDOSBoxProcess = value
|
||||
End Set
|
||||
Property DOSBoxProcess As String
|
||||
Get
|
||||
Return sDOSBoxProcess
|
||||
End Get
|
||||
Set(value As String)
|
||||
sDOSBoxProcess = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
ReadOnly Property TruePath As String
|
||||
@@ -213,6 +214,15 @@
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Property ImportTags As List(Of Tag)
|
||||
Get
|
||||
Return oImportTags
|
||||
End Get
|
||||
Set(value As List(Of Tag))
|
||||
oImportTags = value
|
||||
End Set
|
||||
End Property
|
||||
|
||||
Public Function SyncEquals(obj As Object) As Boolean
|
||||
Dim oGame As clsGame = TryCast(obj, clsGame)
|
||||
If oGame Is Nothing Then
|
||||
|
||||
@@ -113,6 +113,8 @@
|
||||
<Import Include="System.Windows.Forms" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Classes\XML Serialize Classes\Tag.vb" />
|
||||
<Compile Include="Classes\XML Serialize Classes\Game.vb" />
|
||||
<Compile Include="Classes\clsGameTag.vb" />
|
||||
<Compile Include="Classes\clsPathVariable.vb" />
|
||||
<Compile Include="Classes\clsBackup.vb" />
|
||||
|
||||
@@ -100,6 +100,29 @@
|
||||
Return hshList
|
||||
End Function
|
||||
|
||||
Public Shared Function GetTagsByGameForExport(ByVal sMonitorID As String) As List(Of Tag)
|
||||
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
|
||||
Dim oData As DataSet
|
||||
Dim sSQL As String
|
||||
Dim oList As New List(Of Tag)
|
||||
Dim hshParams As New Hashtable
|
||||
Dim oTag As Tag
|
||||
|
||||
sSQL = "SELECT TagID, tags.Name FROM gametags NATURAL JOIN tags WHERE MonitorID = @ID"
|
||||
|
||||
hshParams.Add("ID", sMonitorID)
|
||||
|
||||
oData = oDatabase.ReadParamData(sSQL, hshParams)
|
||||
|
||||
For Each dr As DataRow In oData.Tables(0).Rows
|
||||
oTag = New Tag
|
||||
oTag.Name = CStr(dr(1))
|
||||
oList.Add(oTag)
|
||||
Next
|
||||
|
||||
Return oList
|
||||
End Function
|
||||
|
||||
Public Shared Function GetTagsByGameMulti(ByVal sMonitorIDs As List(Of String)) As Hashtable
|
||||
Dim oDatabase As New mgrSQLite(mgrSQLite.Database.Local)
|
||||
Dim oData As DataSet
|
||||
@@ -116,7 +139,7 @@
|
||||
hshParams.Add("MonitorID" & iCounter, s)
|
||||
iCounter += 1
|
||||
Next
|
||||
|
||||
|
||||
sSQL = sSQL.TrimEnd(",")
|
||||
sSQL &= ")"
|
||||
|
||||
|
||||
@@ -45,6 +45,8 @@ Public Class mgrMonitorList
|
||||
Dim hshSyncItems As Hashtable
|
||||
Dim oFromItem As clsGame
|
||||
Dim oToItem As clsGame
|
||||
Dim oTag As clsTag
|
||||
Dim oGameTag As clsGameTag
|
||||
Dim iItems As Integer = 0
|
||||
|
||||
Cursor.Current = Cursors.WaitCursor
|
||||
@@ -74,6 +76,20 @@ Public Class mgrMonitorList
|
||||
For Each oGame As clsGame In frm.ImportData.Values
|
||||
If Not DoDuplicateListCheck(oGame.Name, oGame.TrueProcess) Then
|
||||
DoListAdd(oGame, mgrSQLite.Database.Local)
|
||||
'Handle Tag Import (TODO: This could use some optimization, way too many DB hits.)
|
||||
For Each t As Tag In oGame.ImportTags
|
||||
If mgrTags.DoCheckDuplicate(t.Name) Then
|
||||
oTag = mgrTags.DoTagGetbyName(t.Name)
|
||||
Else
|
||||
oTag = New clsTag
|
||||
oTag.Name = t.Name
|
||||
mgrTags.DoTagAdd(oTag)
|
||||
End If
|
||||
oGameTag = New clsGameTag
|
||||
oGameTag.MonitorID = oGame.ID
|
||||
oGameTag.TagID = oTag.ID
|
||||
mgrGameTags.DoGameTagAdd(oGameTag)
|
||||
Next
|
||||
iItems += 1
|
||||
End If
|
||||
Next
|
||||
@@ -88,12 +104,16 @@ Public Class mgrMonitorList
|
||||
End Sub
|
||||
|
||||
Public Shared Sub ExportMonitorList(ByVal sLocation As String)
|
||||
Dim hshList As Hashtable = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
|
||||
'Dim hshList As Hashtable = ReadList(eListTypes.FullList, mgrSQLite.Database.Local)
|
||||
'Dim bSuccess As Boolean
|
||||
'bSuccess = mgrXML.ExportMonitorList(hshList, sLocation)
|
||||
|
||||
Dim oList As List(Of Game) = ReadListForExport()
|
||||
Dim bSuccess As Boolean
|
||||
bSuccess = mgrXML.ExportMonitorList(hshList, sLocation)
|
||||
bSuccess = mgrXML.SerializeAndExport(oList, sLocation)
|
||||
|
||||
If bSuccess Then
|
||||
MsgBox("Export Complete. " & hshList.Count & " entries have been exported.", MsgBoxStyle.Information, "Game Backup Monitor")
|
||||
MsgBox("Export Complete. " & oList.Count & " entries have been exported.", MsgBoxStyle.Information, "Game Backup Monitor")
|
||||
End If
|
||||
End Sub
|
||||
|
||||
@@ -207,6 +227,7 @@ Public Class mgrMonitorList
|
||||
Return False
|
||||
End If
|
||||
End If
|
||||
Return True
|
||||
End Function
|
||||
|
||||
Public Shared Function ReadList(ByVal eListType As eListTypes, Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As Hashtable
|
||||
@@ -272,6 +293,34 @@ Public Class mgrMonitorList
|
||||
Return hshList
|
||||
End Function
|
||||
|
||||
Public Shared Function ReadListForExport(Optional ByVal iSelectDB As mgrSQLite.Database = mgrSQLite.Database.Local) As List(Of Game)
|
||||
Dim oDatabase As New mgrSQLite(iSelectDB)
|
||||
Dim oData As DataSet
|
||||
Dim sSQL As String
|
||||
Dim sID As String
|
||||
Dim oList As New List(Of Game)
|
||||
Dim oGame As Game
|
||||
|
||||
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 Game
|
||||
sID = 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))
|
||||
If Not IsDBNull(dr(8)) Then oGame.ExcludeList = CStr(dr(8))
|
||||
oGame.Tags = mgrGameTags.GetTagsByGameForExport(sID)
|
||||
oList.Add(oGame)
|
||||
Next
|
||||
|
||||
Return oList
|
||||
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
|
||||
|
||||
+62
-65
@@ -1,11 +1,12 @@
|
||||
Imports System.Xml
|
||||
Imports System.Xml.Serialization
|
||||
Imports System.IO
|
||||
Imports System.Text
|
||||
Imports System.Net
|
||||
|
||||
|
||||
Public Class mgrXML
|
||||
|
||||
Public Shared Function ReadMonitorList(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) As Hashtable
|
||||
Dim xFileReader As XmlTextReader
|
||||
Dim oList As List(Of Game)
|
||||
Dim hshList As New Hashtable
|
||||
Dim hshDupeList As New Hashtable
|
||||
Dim oGame As clsGame
|
||||
@@ -16,82 +17,78 @@ Public Class mgrXML
|
||||
Return hshList
|
||||
End If
|
||||
|
||||
Try
|
||||
xFileReader = New XmlTextReader(sLocation)
|
||||
xFileReader.WhitespaceHandling = WhitespaceHandling.None
|
||||
oList = ImportandDeserialize(sLocation, bWebRead)
|
||||
|
||||
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.ExcludeList = xFileReader.ReadElementString("excludelist")
|
||||
For Each g As Game In oList
|
||||
oGame = New clsGame
|
||||
oGame.Name = g.Name
|
||||
oGame.ProcessName = g.ProcessName
|
||||
oGame.AbsolutePath = g.AbsolutePath
|
||||
oGame.Path = g.Path
|
||||
oGame.FolderSave = g.FolderSave
|
||||
oGame.FileType = g.FileType
|
||||
oGame.ExcludeList = g.ExcludeList
|
||||
For Each t As Tag In g.Tags
|
||||
oGame.ImportTags.Add(t)
|
||||
Next
|
||||
|
||||
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)
|
||||
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
|
||||
End While
|
||||
oGame.ProcessName = oGame.ProcessName & ":" & oGame.Name
|
||||
oGame.Duplicate = True
|
||||
End If
|
||||
|
||||
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
|
||||
hshList.Add(oGame.ProcessName, oGame)
|
||||
Next
|
||||
|
||||
Return hshList
|
||||
End Function
|
||||
|
||||
Public Shared Function ExportMonitorList(ByVal hshList As Hashtable, ByVal sLocation As String) As Boolean
|
||||
Dim xFileWriter As XmlTextWriter
|
||||
Public Shared Function ImportandDeserialize(ByVal sLocation As String, Optional ByVal bWebRead As Boolean = False) As List(Of Game)
|
||||
Dim oReader As StreamReader
|
||||
Dim oWebClient As WebClient
|
||||
Dim oSerializer As XmlSerializer
|
||||
Dim oList As New List(Of Game)
|
||||
|
||||
Try
|
||||
xFileWriter = New XmlTextWriter(sLocation, System.Text.Encoding.UTF8)
|
||||
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("excludelist", o.ExcludeList)
|
||||
xFileWriter.WriteEndElement()
|
||||
Next
|
||||
xFileWriter.WriteEndElement()
|
||||
xFileWriter.WriteEndDocument()
|
||||
xFileWriter.Flush()
|
||||
xFileWriter.Close()
|
||||
If bWebRead Then
|
||||
oWebClient = New WebClient
|
||||
oReader = New StreamReader(oWebClient.OpenRead(sLocation))
|
||||
Else
|
||||
oReader = New StreamReader(sLocation)
|
||||
End If
|
||||
|
||||
oSerializer = New XmlSerializer(oList.GetType(), New XmlRootAttribute("gbm"))
|
||||
oList = oSerializer.Deserialize(oReader)
|
||||
oReader.Close()
|
||||
Catch ex As Exception
|
||||
MsgBox("The XML file cannot be read, it may be an invalid format or corrupted." & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Exclamation, "Game Backup Monitor")
|
||||
End Try
|
||||
|
||||
Return oList
|
||||
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
|
||||
|
||||
Try
|
||||
oSerializer = New XmlSerializer(oList.GetType(), New XmlRootAttribute("gbm"))
|
||||
oWriter = New StreamWriter(sLocation)
|
||||
oSerializer.Serialize(oWriter.BaseStream, oList)
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
MsgBox("An error occured exporting the monitor list. " & ex.Message, MsgBoxStyle.Exclamation, "Game Backup Monitor")
|
||||
MsgBox("An error occured exporting the XML data." & vbCrLf & vbCrLf & ex.Message, MsgBoxStyle.Exclamation, "Game Backup Monitor")
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user