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   ...		#endregion
42		#region Windows Form Designer generated code   ...		#endregion
101		#region Main   ...		#endregion
109		#region Private vars   ...		#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}