1using DotNetZip;
2using System;
3using System.Collections;
4using System.ComponentModel;
5using System.Data;
6using System.Drawing;
7using System.IO;
8using System.Windows.Forms;
9using java.util.zip;
10
11namespace ZipUtilsTester
12{
13 public class frmMain : System.Windows.Forms.Form
14 {
15 #region Form vars ...
16
17 private System.Windows.Forms.OpenFileDialog openFileDialog1;
18 private System.Windows.Forms.Button cmdCreateEmptyZipFile;
19 private System.Windows.Forms.Button cmdUpdateZipFile;
20 private System.Windows.Forms.Button cmdExtractZipFile;
21 private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
22
23 private System.ComponentModel.Container components = null;
24
25 public frmMain()
26 {
27 InitializeComponent();
28 }
29
30 protected override void Dispose( bool disposing )
31 {
32 if( disposing )
33 {
34 if (components != null)
35 {
36 components.Dispose();
37 }
38 }
39 base.Dispose( disposing );
40 }
41 #endregion
42 #region Windows Form Designer generated code ...
43
44 /// <summary>
45 /// Required method for Designer support - do not modify
46 /// the contents of this method with the code editor.
47 /// </summary>
48 private void InitializeComponent()
49 {
50 this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
51 this.cmdExtractZipFile = new System.Windows.Forms.Button();
52 this.cmdCreateEmptyZipFile = new System.Windows.Forms.Button();
53 this.cmdUpdateZipFile = new System.Windows.Forms.Button();
54 this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
55 this.SuspendLayout();
56 //
57 // cmdExtractZipFile
58 //
59 this.cmdExtractZipFile.Location = new System.Drawing.Point(8, 70);
60 this.cmdExtractZipFile.Name = "cmdExtractZipFile";
61 this.cmdExtractZipFile.Size = new System.Drawing.Size(138, 23);
62 this.cmdExtractZipFile.TabIndex = 3;
63 this.cmdExtractZipFile.Text = "Extract a Zip File";
64 this.cmdExtractZipFile.Click += new System.EventHandler(this.cmdExtractZipFile_Click);
65 //
66 // cmdCreateEmptyZipFile
67 //
68 this.cmdCreateEmptyZipFile.Location = new System.Drawing.Point(8, 10);
69 this.cmdCreateEmptyZipFile.Name = "cmdCreateEmptyZipFile";
70 this.cmdCreateEmptyZipFile.Size = new System.Drawing.Size(138, 23);
71 this.cmdCreateEmptyZipFile.TabIndex = 1;
72 this.cmdCreateEmptyZipFile.Text = "Create Empty Zip File";
73 this.cmdCreateEmptyZipFile.Click += new System.EventHandler(this.cmdCreateEmptyZipFile_Click);
74 //
75 // cmdUpdateZipFile
76 //
77 this.cmdUpdateZipFile.Location = new System.Drawing.Point(8, 40);
78 this.cmdUpdateZipFile.Name = "cmdUpdateZipFile";
79 this.cmdUpdateZipFile.Size = new System.Drawing.Size(138, 23);
80 this.cmdUpdateZipFile.TabIndex = 2;
81 this.cmdUpdateZipFile.Text = "Update a Zip File";
82 this.cmdUpdateZipFile.Click += new System.EventHandler(this.cmdUpdateZipFile_Click);
83 //
84 // frmMain
85 //
86 this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
87 this.ClientSize = new System.Drawing.Size(154, 99);
88 this.Controls.Add(this.cmdUpdateZipFile);
89 this.Controls.Add(this.cmdCreateEmptyZipFile);
90 this.Controls.Add(this.cmdExtractZipFile);
91 this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
92 this.MaximizeBox = false;
93 this.MinimizeBox = false;
94 this.Name = "frmMain";
95 this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
96 this.Text = ".NET Zip Utility";
97 this.ResumeLayout(false);
98
99 }
100 #endregion
101 #region Main ...
102
103 [STAThread]
104 static void Main()
105 {
106 Application.Run(new frmMain());
107 }
108 #endregion
109 #region Private vars ...
110
111 private const string APPTITLE = ".NET Zip Utility";
112 #endregion
113
114 private void cmdCreateEmptyZipFile_Click(object sender, System.EventArgs e)
115 {
116 try
117 {
118 //Ask the user to select a folder
119 folderBrowserDialog1.Description = "Select a location for the empty zip file";
120 if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
121 {
122 //Ask the user to enter a filename
123 InputBox frmInputBox = new InputBox("Enter the zip filename");
124 frmInputBox.ShowDialog();
125 string strFileName = frmInputBox.Value;
126 string strFullFileName = folderBrowserDialog1.SelectedPath + "\\" + strFileName;
127 //Create the empty zip file
128 ZipUtils.CreateEmptyZipFile(strFullFileName);
129 frmInputBox = null;
130 //Success!
131 MessageBox.Show("Empty zip file successfully created", APPTITLE);
132 }
133 }
134 catch (Exception ex)
135 {
136 MessageBox.Show("Error: " + ex.Message, APPTITLE);
137 }
138 }
139
140 private void cmdUpdateZipFile_Click(object sender, System.EventArgs e)
141 {
142 try
143 {
144 //Ask the user to select a zip file
145 openFileDialog1.Title = "Select the zip file to add files to";
146 openFileDialog1.Multiselect = false;
147 if (openFileDialog1.ShowDialog() == DialogResult.OK)
148 {
149 string strZipFile = openFileDialog1.FileName;
150 //Ask the user to select files to add to zip file
151 openFileDialog1.Title = "Select files to add to the zip file";
152 openFileDialog1.Multiselect = true;
153 if (openFileDialog1.ShowDialog() == DialogResult.OK)
154 {
155 //Add files to the zip file
156 ZipFile CurrentFile = new ZipFile(strZipFile);
157 ZipUtils.UpdateZipFile(CurrentFile, null, openFileDialog1.FileNames);
158 }
159 //Success!
160 MessageBox.Show("Files successfully added", APPTITLE);
161 }
162 }
163 catch (Exception ex)
164 {
165 MessageBox.Show("Error: " + ex.Message, APPTITLE);
166 }
167 }
168
169 private void cmdExtractZipFile_Click(object sender, System.EventArgs e)
170 {
171 try
172 {
173 //Ask the user to select a zip file
174 openFileDialog1.Title = "Select a zip file to extract";
175 openFileDialog1.Multiselect = false;
176 if (openFileDialog1.ShowDialog() == DialogResult.OK)
177 {
178 //Ask the user to select a folder
179 folderBrowserDialog1.Description = "Select a location to extract the files";
180 if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
181 {
182 string strDirectory = folderBrowserDialog1.SelectedPath;
183 //Extract the files
184 ZipFile CurrentFile = new ZipFile(openFileDialog1.FileName);
185 ZipUtils.ExtractZipFile(CurrentFile, strDirectory, null, false);
186 //Success!
187 MessageBox.Show("Files successfully extracted", APPTITLE);
188 }
189 }
190 }
191 catch (Exception ex)
192 {
193 MessageBox.Show("Error: " + ex.Message, APPTITLE);
194 }
195 }
196 }
197}