using System;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;

namespace testEditor
{
	/// <summary>
	/// Summary description for utilities.
	/// </summary>
	public class utilities
	{
		public utilities()
		{
			//
			// TODO: Add constructor logic here
			//
		}

		public static void unzipLOPackage(string zipfile,string unzipPath)
		{
			ZipInputStream s = new ZipInputStream(File.OpenRead(zipfile));
		
			ZipEntry theEntry;
			while ((theEntry = s.GetNextEntry()) != null) 
			{
			
				string directoryName = Path.GetDirectoryName(theEntry.Name);
				string fileName = Path.GetFileName(theEntry.Name);
						
				if (fileName != String.Empty) 
				{
					string unzippedFile = "";
					/* When subdirectories are in the zip file*/
					if (directoryName != "")
					{
						string subDir = unzipPath + "\\" + directoryName;
						if (!Directory.Exists(subDir))
						{
							Directory.CreateDirectory(subDir);
						}

						unzippedFile = subDir + "\\" + fileName;
					}
					else
					{
						unzippedFile = unzipPath + "\\" + fileName; 
					}

					FileStream streamWriter = File.Create(unzippedFile);
				
					int size = 2048;
					byte[] data = new byte[2048];
					while (true) 
					{
						size = s.Read(data, 0, data.Length);
						if (size > 0) 
						{
							streamWriter.Write(data, 0, size);
						} 
						else 
						{
							break;
						}
					}
				
					streamWriter.Close();
				}
			}
			s.Close();

		}
	}
}
