Public Sub Form1_Load(ByVal sender as Object, ByVal e as EventArgs) Handles Me.Load
Dim path As String = AppDataPath & "\D01 Software Manager\XML"
If IO.Directory.Exists(path) = True Then
Dim intIndex As Integer = 0
For Each strFile As String In GetFiles(path)
Dim bar As New ProgramBar
bar.ID = intIndex
bar.Info = LoadInfo(strFile, GetType(ProgramInfo))
'bar.picIcon.Image = ReturnIcon(bar.Info.exe, 0).ToBitmap
barList.Add(bar)
intIndex += 1
Next
End If
If barList.Count <> 0 Then
For Each bar As ProgramBar In barList
Me.Controls.Add(bar)
bar.Location = New Point(20, 200)
bar.Size = New Size(544, 100)
bar.Parent = FlowLayoutPanel1
Next
Else
Dim lblInfo As New Label
lblInfo.ForeColor = Color.Gray
lblInfo.BackColor = Color.Transparent
lblInfo.Text = "You don't have programs from D01 MicroApps."
Me.Controls.Add(lblInfo)
lblInfo.Parent = FlowLayoutPanel1
lblInfo.AutoSize = True
End If
End Sub
Public Shared Function LoadInfo(ByVal filename As String, ByVal newType As Type) As Object
'Does the file exist?
Dim fileInfo As New FileInfo(filename)
If fileInfo.Exists = False Then
'create a blank version of the object and return that..
Return System.Activator.CreateInstance(newType)
End If
'open the file
Dim stream As New FileStream(filename, FileMode.Open)
'load the object from the stream..
Dim newObject As Object = LoadInfo(filename, newType)
'Close the stream
stream.Close()
'return the object..
Return newObject
End Function
'Load-actually perform the deserialization
Public Shared Function LoadInfo(ByVal stream As Stream, ByVal newType As Type) As Object
'create a serializer and load the object..
Dim serializer As New XmlSerializer(newType)
Dim newObject As Object = serializer.Deserialize(stream)
'return the new object
Return newObject
End Function