Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public NotInheritable Class Form1
- ''' <summary>
- ''' Handles the <see cref="FileSplitter"/> instance.
- ''' </summary>
- Private WithEvents splitter As New FileSplitter() With {.BufferSize = .BufferSize}
- ' Splitter settings.
- Private ReadOnly workingDir As String = "C:\Test"
- Private ReadOnly fileName As String = "File.mp3"
- Private ReadOnly filePath As String = IO.Path.Combine(workingDir, fileName)
- Private ReadOnly chunkName As String = "File.Part"
- Private ReadOnly chunkExt As String = "fs"
- ' Merger settings.
- Private ReadOnly firstChunkPath As String = String.Format("{0}\{1}.01.{2}", workingDir, chunkName, chunkExt)
- Private ReadOnly targetFileName As String = String.Format("{0}\{1}.{2}", workingDir, "Merged", IO.Path.GetExtension(fileName))
- ' Some default chunk sizes to split a file.
- Private ReadOnly kilobyte As Integer = 1024
- Private ReadOnly megabyte As Integer = 1048576
- Private ReadOnly gigabyte As Integer = 1073741824
- Private ReadOnly halfFileSize As Integer = CInt(New IO.FileInfo(filePath).Length / 2)
- ' The label controls that will display the progress.
- Private labelSplit1, labelSplit2, labelSplit3 As New Label
- Private labelMerge1, labelMerge2, labelMerge3 As New Label
- ' The button controls to start a split or merge operation.
- Private WithEvents buttonSplit, buttonMerge As New Button
- ''' <summary>
- ''' Initializes a new instance of the <see cref="Form1"/> class.
- ''' </summary>
- Public Sub New()
- ' This call is required by the designer.
- Me.InitializeComponent()
- ' Set the controls properties.
- With buttonSplit
- .Text = "Split"
- .Font = New Font(Me.Font.FontFamily, 14.0F, FontStyle.Bold)
- .Size = New Size(200, 75)
- .Location = New Point(0, 0)
- .Cursor = Cursors.Hand
- End With
- With buttonMerge
- .Text = "Merge"
- .Font = New Font(Me.Font.FontFamily, 14.0F, FontStyle.Bold)
- .Size = New Size(200, 75)
- .Location = New Point(buttonSplit.Location.X + buttonSplit.Width, 0)
- .Cursor = Cursors.Hand
- End With
- With labelSplit1
- .Text = "Total Progress:"
- .AutoSize = True
- .Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
- .Location = New Point(0, buttonSplit.Location.Y + buttonSplit.Height + 10)
- End With
- With labelSplit2
- .Text = "Chunk Progress:"
- .AutoSize = True
- .Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
- .Location = New Point(0, labelSplit1.Location.Y + labelSplit1.Height)
- End With
- With labelSplit3
- .Text = "Chunk Count:"
- .AutoSize = True
- .Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
- .Location = New Point(0, labelSplit2.Location.Y + labelSplit2.Height)
- End With
- With labelMerge1
- .Text = "Total Progress:"
- .AutoSize = True
- .Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
- .Location = New Point(buttonMerge.Location.X, buttonMerge.Location.Y + buttonMerge.Height + 10)
- End With
- With labelMerge2
- .Text = "Chunk Progress:"
- .AutoSize = True
- .Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
- .Location = New Point(buttonMerge.Location.X, labelMerge1.Location.Y + labelMerge1.Height)
- End With
- With labelMerge3
- .Text = "Chunk Count:"
- .AutoSize = True
- .Font = New Font(Me.Font.FontFamily, 9.0F, FontStyle.Regular)
- .Location = New Point(buttonMerge.Location.X, labelMerge2.Location.Y + labelMerge2.Height)
- End With
- ' Add the controls on the UI.
- Me.Controls.AddRange({labelSplit1, labelSplit2, labelSplit3,
- labelMerge1, labelMerge2, labelMerge3,
- buttonSplit, buttonMerge})
- ' Set the Form properties.
- With Me
- .Size = New Size(buttonSplit.Width + buttonMerge.Width + 20, 200)
- .FormBorderStyle = Windows.Forms.FormBorderStyle.FixedDialog
- .MaximizeBox = False
- End With
- End Sub
- ''' <summary>
- ''' Handles the <see cref="Button.Click"/> event of the <see cref="ButtonSplit"/> control.
- ''' </summary>
- Private Sub ButtonSplit_Click() Handles buttonSplit.Click
- Me.splitter.Split(sourceFile:=Me.filePath,
- chunkSize:=Me.halfFileSize,
- chunkName:=Me.chunkName,
- chunkExt:=Me.chunkExt,
- overwrite:=True,
- deleteAfterSplit:=False)
- ' Or...
- 'Me.splitter.Split(sourceFile:=Me.filePath,
- ' chunkCount:=2,
- ' chunkName:=Me.chunkName,
- ' chunkExt:=Me.chunkExt,
- ' overwrite:=True,
- ' deleteAfterSplit:=False)
- End Sub
- ''' <summary>
- ''' Handles the <see cref="Button.Click"/> event of the <see cref="ButtonMerge"/> control.
- ''' </summary>
- Private Sub ButtonMerge_Click() Handles buttonMerge.Click
- Me.splitter.Merge(sourceChunk:=Me.firstChunkPath,
- targetFile:=Me.targetFileName,
- overwrite:=True,
- deleteChunksAfterMerged:=False)
- End Sub
- ''' <summary>
- ''' Handles the <see cref="FileSplitter.SplitProgressChangedArgs"/> event of the <see cref="Splitter"/> instance.
- ''' </summary>
- ''' <param name="sender">The source of the event.</param>
- ''' <param name="e">The <see cref="FileSplitter.SplitProgressChangedArgs"/> instance containing the event data.</param>
- Private Sub Splitter_SplitProgressChangedArgs(ByVal sender As Object, ByVal e As FileSplitter.SplitProgressChangedArgs) _
- Handles splitter.SplitProgressChanged
- labelSplit1.Text = String.Format("Total Progress: {0}%", e.TotalProgress.ToString("n1"))
- labelSplit2.Text = String.Format("Chunk Progress: {0}%", e.ChunkProgress.ToString("n1"))
- labelSplit3.Text = String.Format("Current Chunk: {0} of {1}", CStr(e.ChunksCreated + 1), CStr(e.ChunksToCreate))
- Application.DoEvents()
- End Sub
- ''' <summary>
- ''' Handles the <see cref="FileSplitter.MergeProgressChangedArgs"/> event of the <see cref="Splitter"/> instance.
- ''' </summary>
- ''' <param name="sender">The source of the event.</param>
- ''' <param name="e">The <see cref="FileSplitter.MergeProgressChangedArgs"/> instance containing the event data.</param>
- Private Sub Splitter_MergeProgressChangedArgs(ByVal sender As Object, ByVal e As FileSplitter.MergeProgressChangedArgs) _
- Handles splitter.MergeProgressChanged
- labelMerge1.Text = String.Format("Total Progress: {0}%", e.TotalProgress.ToString("n1"))
- labelMerge2.Text = String.Format("Chunk Progress: {0}%", e.ChunkProgress.ToString("n1"))
- labelMerge3.Text = String.Format("Current Chunk: {0} of {1}", CStr(e.ChunksMerged + 1), CStr(e.ChunksToMerge))
- Application.DoEvents()
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement