Public Sub test()
Dim settings As New Ingredient.Properties()
Dim encoder As New Ingredient
settings.Contents = settings.StreamFile("D:\test.zip")
settings.IngredientVersion = "1.0"
settings.MineCraftVersion = "Minecraft Beta 1.3_03"
encoder.Encode("D:\", settings)
End Sub
<Serializable()> Public Class Ingredient
<Serializable()> Public Class Properties
Public Function StreamFile(ByVal filename As String) As Byte()
Dim fs As New FileStream(filename, FileMode.Open, FileAccess.Read)
' Create a byte array of file stream length
Dim ImageData As Byte() = New Byte(fs.Length - 1) {}
'Read block of bytes from stream into the byte array
fs.Read(ImageData, 0, System.Convert.ToInt32(fs.Length))
'Close the File Stream
fs.Close()
'return the byte data
Return ImageData
End Function
'*.mpi FileType information
Private iVersion As String 'Ingredient version
Private impVersion As String 'MeltingPot version
Private imcVersion As String 'Minecraft version
Private iContents As Array 'Contents of the mod, a zipfile
Private iContentsHash As String 'Hash of the mod contents, the zipfile
Private iTitle As String 'The name of the mod/ingredient
Private iCreator As String 'The creator of the mod/ingredient
Private iOnErr As String 'The string to be displayed on an error involving the mod/ingredient
Public Property IngredientVersion() As String
Get
Return iVersion
End Get
Set(ByVal value As String)
iVersion = value
End Set
End Property
Public Property ProgramVersion() As String
Get
Return impVersion
End Get
Set(ByVal value As String)
impVersion = value
End Set
End Property
Public Property MineCraftVersion() As String
Get
Return imcVersion
End Get
Set(ByVal value As String)
imcVersion = value
End Set
End Property
Public Property Contents() As Array
Get
Return iContents
End Get
Set(ByVal value As Array)
iContents = value
End Set
End Property
Public Property ContentsHash As String
Get
Return iContentsHash
End Get
Set(ByVal value As String)
iContentsHash = value
End Set
End Property
Public Property Name() As String
Get
Return iTitle
End Get
Set(ByVal value As String)
iTitle = value
End Set
End Property
Public Property Creator As String
Get
Return iCreator
End Get
Set(ByVal value As String)
iCreator = value
End Set
End Property
Public Property OnErrEvent As String
Get
Return iOnErr
End Get
Set(ByVal value As String)
iOnErr = value
End Set
End Property
End Class
Public Sub Encode(ByVal strPath As String, ByVal options As Ingredient.Properties)
' create a filestream to allow saving the file after it has
' been serialized in this method
Dim fs As New FileStream(strPath, FileMode.OpenOrCreate)
' create a new instance of the binary formatter
Dim formatter As New BinaryFormatter
Try
' save the serialized data to the file path specified
formatter.Serialize(fs, options)
fs.Close()
Catch ex As SerializationException
Debugger.append(System.DateTime.Now, "CRITICAL", "FileEncode-Error! " & ex.ToString & Environment.NewLine & ex.StackTrace)
MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Class Decode
Public Function Deserialize(ByVal strPath As String) As Ingredient.Properties
' create filestream allowing the user to open an existing file
Dim fs As New FileStream(strPath, FileMode.Open)
' create a new instance of the Personal Data class
Dim strings As Ingredient.Properties
strings = New Ingredient.Properties
Try
' create a binary formatter
Dim formatter As New BinaryFormatter
' deserialize the data stored in the specified file and
' use that data to populate the new instance of the personal data class.
strings = formatter.Deserialize(fs)
fs.Close()
' return the deserialized data back to the calling application
Return strings
Catch ex As SerializationException
debugger.append(System.DateTime.Now, "CRITICAL", "FileEncode-Error! " & ex.ToString & Environment.NewLine & ex.StackTrace)
MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error)
Return strings
End Try
End Function
End Class