Example #1
0
		static Tuple<string, CompressionOption> GetCurrentFileNameAndCompression(UnzipHandle handle)
		{
			UnzipFileInfo info;
			string filename = String.Empty;
			int result = unzGetCurrentFileInfo (handle, out info, null, IntPtr.Zero, IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);

			if (result != 0)
				return null;

			StringBuilder sbName = new StringBuilder ((int)info.SizeFilename+1); // +1 to account for extra \0 at the end
			result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);

			if (result != 0)
				return null;
			else
				filename = sbName.ToString ();

			int method, compression;
			// '0' means do not open in raw mode (raw == do not decompress)
			if (unzOpenCurrentFile2 (handle, out method, out compression, 0) != 0)
				throw new Exception ("The file could not be opened");

			CompressionOption level = ConvertCompression (method == 0 ? 0 : compression);
			return Tuple.Create (filename, level);
		}
Example #2
0
		public static long CurrentFileLength (UnzipHandle handle)
		{
			UnzipFileInfo info;
			int result = unzGetCurrentFileInfo (handle, out info, null, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, null,  IntPtr.Zero);
			
			if (result != 0)
				return -1;
			else
				return (long)info.UncompressedSize;
		}
Example #3
0
		static string GetCurrentFileName32 (UnzipHandle handle)
		{
			UnzipFileInfo32 info;
			if (unzGetCurrentFileInfo_32 (handle, out info, null, 0, IntPtr.Zero, 0, null, 0) != 0)
				return null;
			var sbName = new StringBuilder ((int) info.size_filename + 1); // +1 to account for extra \0 at the end
			if (unzGetCurrentFileInfo_32 (handle, out info, sbName, (uint) sbName.Capacity, IntPtr.Zero, 0, null, 0) != 0)
				return null;
			return sbName.ToString ();
		}
		static string GetCurrentFileName (UnzipHandle handle)
		{
			UnzipFileInfo info;
			StringBuilder sbName = new StringBuilder (128);
			int result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);
			
			if (result != 0)
				return null;
			else
				return sbName.ToString ();
		}
		public static long CurrentFileLength (UnzipHandle handle)
		{
			UnzipFileInfo info;
			StringBuilder sbName = new StringBuilder (128);
			int result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, IntPtr.Zero, null,  IntPtr.Zero);
			
			if (result != 0)
				return -1;
			else
				return (long)info.UncompressedSize;
		}
Example #6
0
		static string GetCurrentFileName (UnzipHandle handle)
		{
			UnzipFileInfo info;
			int result = unzGetCurrentFileInfo (handle, out info, null, IntPtr.Zero, IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);

			if (result != 0)
				return null;
			
			StringBuilder sbName = new StringBuilder ((int)info.SizeFilename+1); // +1 to account for extra \0 at the end
			result = unzGetCurrentFileInfo (handle, out info, sbName, new IntPtr (sbName.Capacity), IntPtr.Zero, new IntPtr (0), null,  IntPtr.Zero);
			
			if (result != 0)
				return null;
			else
				return sbName.ToString ();
		}
		static bool GoToNextFile (UnzipHandle handle)
		{
			return unzGoToNextFile(handle) == 0;
		}
Example #8
0
		public static long CurrentFileLength64 (UnzipHandle handle)
		{
			UnzipFileInfo64 info;
			int result = unzGetCurrentFileInfo_64 (handle, out info, null, 0, IntPtr.Zero, 0, null,  0);
			return result != 0 ? -1 : (long) info.uncompressed_size;
		}
		public static void CloseArchive (UnzipHandle handle)
		{
			unzClose (handle);
			handle.SetHandleAsInvalid ();
		}
		static unsafe extern int unzReadCurrentFile (UnzipHandle handle,
		                                              byte* buf, // voidp
		                                              uint len);
		static extern int unzOpenCurrentFile2 (UnzipHandle handle,
		                                       out int method,
		                                       out int level,
		                                       int raw);
		static extern int unzGoToNextFile (UnzipHandle handle);
		static extern int unzCloseCurrentFile (UnzipHandle handle);
Example #14
0
 static extern int unzOpenCurrentFile2(UnzipHandle handle,
                                       out int method,
                                       out int level,
                                       int raw);
Example #15
0
 static extern int unzLocateFile(UnzipHandle handle,
                                 string szFileName,
                                 int iCaseSensitivity);
Example #16
0
 static extern int unzGoToNextFile(UnzipHandle handle);
Example #17
0
 static extern IntPtr unztell(UnzipHandle handle);
Example #18
0
 static extern int unzCloseCurrentFile(UnzipHandle handle);
Example #19
0
 static bool GoToNextFile(UnzipHandle handle)
 {
     return(unzGoToNextFile(handle) == 0);
 }
Example #20
0
		public static string[] GetFiles64 (UnzipHandle handle)
		{
			return GetFiles (handle, GetCurrentFileName64);
		}
		public static void OpenFile (UnzipHandle handle, string name, out CompressionOption level)
		{
			if (unzLocateFile (handle, name, (int) ZipStringComparison.CaseInsensitive) != 0)
				throw new Exception ("The file doesn't exist");
			
			int method, compression;
			// '0' means do not open in raw mode (raw == do not decompress)
			if (unzOpenCurrentFile2 (handle, out method, out compression, 0) != 0)
				throw new Exception ("The file could not be opened");

			level = ConvertCompression (method == 0 ? 0 : compression);
		}
		public static unsafe int Read (UnzipHandle handle, byte[] buffer, int offset, int count)
		{
			if ((buffer.Length - offset) > count)
				throw new ArgumentOutOfRangeException ("count", "Buffer is too small to read that amount of data");
			
			fixed (byte * b = &buffer[offset])
				return unzReadCurrentFile (handle, b, (uint)count);
		}
Example #23
0
 static unsafe extern int unzReadCurrentFile(UnzipHandle handle,
                                             byte *buf,           // voidp
                                             uint len);
		static extern IntPtr unztell (UnzipHandle handle);
Example #25
0
 static extern int unzClose(UnzipHandle handle);
		static extern int unzLocateFile (UnzipHandle handle,
		                                         string szFileName,
		                                         int iCaseSensitivity);
Example #27
0
		public static Dictionary<string, CompressionOption> GetFiles (UnzipHandle handle)
		{
			var result = new Dictionary<string, CompressionOption> ();

			GoToFirstFile (handle);

			Tuple<string, CompressionOption> info;
			while ((info = GetCurrentFileNameAndCompression(handle)) != null)
			{
				result.Add (info.Item1, info.Item2);
				if (!NativeUnzip.GoToNextFile (handle))
					break;
			}
			
			return result;
		}
		static extern int unzGetCurrentFileInfo (UnzipHandle handle,
		                                                 out UnzipFileInfo pfile_info,
		                                                 StringBuilder szFileName,
		                                                 IntPtr fileNameBufferSize,   // uLong
		                                                 IntPtr extraField,           // void *
		                                                 IntPtr extraFieldBufferSize, // uLong
		                                                 StringBuilder szComment,
		                                                 IntPtr commentBufferSize);   // uLong
		public static long CurrentFilePosition (UnzipHandle handle)
		{
			return unztell(handle).ToInt64 ();
		}
		static extern int unzClose (UnzipHandle handle);
		static void GoToFirstFile (UnzipHandle handle)
		{
			if (NativeUnzip.unzGoToFirstFile (handle) != 0)
				throw new Exception ("Zip file is invalid");
		}
		public static void CloseCurrentFile (UnzipHandle handle)
		{
			if (unzCloseCurrentFile (handle) != 0)
				throw new Exception ("Could not close the active file");
		}
Example #33
0
		private static string[] GetFiles (UnzipHandle handle, Func<UnzipHandle, string> getCurrentFileName)
		{
			GoToFirstFile (handle);
			var files = new List<string> ();
			string name;
			while ((name = getCurrentFileName (handle)) != null) {
				files.Add (name);
				if (!NativeUnzip.GoToNextFile (handle))
					break;
			}
			
			return files.ToArray ();
		}
Example #34
0
 public static void CloseArchive(UnzipHandle handle)
 {
     unzClose(handle);
     handle.SetHandleAsInvalid();
 }
Example #35
0
 public static long CurrentFilePosition(UnzipHandle handle)
 {
     return(unztell(handle).ToInt64());
 }
		public static string[] GetFiles (UnzipHandle handle)
		{
			List<string> files = new List<string> ();

			GoToFirstFile (handle);

			string name;
			while ((name = GetCurrentFileName(handle)) != null)
			{
				files.Add (name);
				if (!NativeUnzip.GoToNextFile (handle))
					break;
			}
			
			return files.ToArray ();
		}
Example #37
0
 public static string[] GetFiles64(UnzipHandle handle)
 {
     return(GetFiles(handle, GetCurrentFileName64));
 }