Repository navigation
Expand file tree
/
Copy pathWpfCreateZipFileWindow.xaml.vb
More file actions
81 lines (63 loc) · 2.12 KB
/
Copy pathWpfCreateZipFileWindow.xaml.vb
File metadata and controls
81 lines (63 loc) · 2.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
Imports System.IO
Imports ICSharpCode.SharpZipLib.Core
Imports ICSharpCode.SharpZipLib.Zip
Imports WpfFolderBrowser
Class WpfCreateZipFileWindow
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub btnZipIt_Click(sender As Object, e As RoutedEventArgs) Handles btnZipIt.Click
Dim sourceDir As String = tbSourceDir.Text.Trim()
' Simple sanity checks
If sourceDir.Length = 0 Then
MessageBox.Show("Please specify a directory")
Return
Else
If Not Directory.Exists(sourceDir) Then
MessageBox.Show(sourceDir, "Directory not found")
Return
End If
End If
Dim targetName As String = tbZipFileName.Text.Trim()
If targetName.Length = 0 Then
MessageBox.Show("No name specified", "Zip file name error")
Return
End If
Dim astrFileNames() As String = Directory.GetFiles(sourceDir)
Dim strmZipOutputStream As ZipOutputStream
strmZipOutputStream = New ZipOutputStream(File.Create(targetName))
Try
REM Compression Level: 0-9
REM 0: no(Compression)
REM 9: maximum compression
strmZipOutputStream.SetLevel(5)
Dim strFile As String
Dim abyBuffer(4096) As Byte
For Each strFile In astrFileNames
Dim strmFile As FileStream = File.OpenRead(strFile)
Try
Dim objZipEntry As ZipEntry = New ZipEntry(strFile)
objZipEntry.DateTime = DateTime.Now
objZipEntry.Size = strmFile.Length
strmZipOutputStream.PutNextEntry(objZipEntry)
StreamUtils.Copy(strmFile, strmZipOutputStream, abyBuffer)
Finally
strmFile.Close()
End Try
Next
strmZipOutputStream.Finish()
Finally
strmZipOutputStream.Close()
End Try
MessageBox.Show("Operation complete")
End Sub
Private Sub btnBrowseForFolder_Click(sender As Object, e As RoutedEventArgs) Handles btnBrowseForFolder.Click
Dim FolderBrowserDialog As WpfFolderBrowserDialog
FolderBrowserDialog = New WpfFolderBrowserDialog
If FolderBrowserDialog.ShowDialog() = True Then
tbSourceDir.Text = FolderBrowserDialog.FileName
End If
End Sub
End Class