You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@@ -21,16 +21,28 @@ namespace zipsharp
|
||||
internal delegate IntPtr OpenFileFunc (IntPtr opaque, string filename, int mode);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* ulong */ IntPtr ReadFileFunc (IntPtr opaque, IntPtr stream, IntPtr buffer, /* ulong */ IntPtr size);
|
||||
internal delegate /* uLong */ uint ReadFileFunc32 (IntPtr opaque, IntPtr stream, IntPtr buffer, /* uLong */ uint size);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* ulong */ IntPtr WriteFileFunc (IntPtr opaque, IntPtr stream, IntPtr buffer, /* ulong */ IntPtr size);
|
||||
internal delegate /* uLong */ uint WriteFileFunc32 (IntPtr opaque, IntPtr stream, IntPtr buffer, /* uLong */ uint size);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* long */ IntPtr TellFileFunc (IntPtr opaque, IntPtr stream);
|
||||
internal delegate /* long */ int TellFileFunc32 (IntPtr opaque, IntPtr stream);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* long */ IntPtr SeekFileFunc (IntPtr opaque, IntPtr stream, /* ulong */ IntPtr offset, int origin);
|
||||
internal delegate /* long */ int SeekFileFunc32 (IntPtr opaque, IntPtr stream, /* uLong */ uint offset, int origin);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* uLong */ ulong ReadFileFunc64 (IntPtr opaque, IntPtr stream, IntPtr buffer, /* uLong */ ulong size);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* uLong */ ulong WriteFileFunc64 (IntPtr opaque, IntPtr stream, IntPtr buffer, /* uLong */ ulong size);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* long */ long TellFileFunc64 (IntPtr opaque, IntPtr stream);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate /* long */ long SeekFileFunc64 (IntPtr opaque, IntPtr stream, /* uLong */ ulong offset, int origin);
|
||||
|
||||
[UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)]
|
||||
internal delegate int CloseFileFunc (IntPtr opaque, IntPtr stream);
|
||||
@@ -39,13 +51,26 @@ namespace zipsharp
|
||||
internal delegate int TestErrorFileFunc (IntPtr opaque, IntPtr stream);
|
||||
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
internal struct ZlibFileFuncDef
|
||||
internal struct ZlibFileFuncDef32
|
||||
{
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public OpenFileFunc zopen_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public ReadFileFunc zread_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public WriteFileFunc zwrite_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public TellFileFunc ztell_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public SeekFileFunc zseek_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public ReadFileFunc32 zread_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public WriteFileFunc32 zwrite_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public TellFileFunc32 ztell_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public SeekFileFunc32 zseek_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public CloseFileFunc zclose_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public TestErrorFileFunc zerror_file;
|
||||
public IntPtr opaque;
|
||||
}
|
||||
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
internal struct ZlibFileFuncDef64
|
||||
{
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public OpenFileFunc zopen_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public ReadFileFunc64 zread_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public WriteFileFunc64 zwrite_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public TellFileFunc64 ztell_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public SeekFileFunc64 zseek_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public CloseFileFunc zclose_file;
|
||||
[MarshalAs (UnmanagedType.FunctionPtr)] public TestErrorFileFunc zerror_file;
|
||||
public IntPtr opaque;
|
||||
|
||||
@@ -65,43 +65,58 @@ namespace zipsharp
|
||||
return unztell(handle).ToInt64 ();
|
||||
}
|
||||
|
||||
public static long CurrentFileLength (UnzipHandle handle)
|
||||
public static long CurrentFileLength32 (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;
|
||||
}
|
||||
|
||||
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 ();
|
||||
UnzipFileInfo32 info;
|
||||
int result = unzGetCurrentFileInfo_32 (handle, out info, null, 0, IntPtr.Zero, 0, null, 0);
|
||||
return result != 0 ? -1 : (long) info.uncompressed_size;
|
||||
}
|
||||
|
||||
public static string[] GetFiles (UnzipHandle handle)
|
||||
public static long CurrentFileLength64 (UnzipHandle handle)
|
||||
{
|
||||
List<string> files = new List<string> ();
|
||||
UnzipFileInfo64 info;
|
||||
int result = unzGetCurrentFileInfo_64 (handle, out info, null, 0, IntPtr.Zero, 0, null, 0);
|
||||
return result != 0 ? -1 : (long) info.uncompressed_size;
|
||||
}
|
||||
|
||||
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 GetCurrentFileName64 (UnzipHandle handle)
|
||||
{
|
||||
UnzipFileInfo64 info;
|
||||
if (unzGetCurrentFileInfo_64 (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_64 (handle, out info, sbName, (uint) sbName.Capacity, IntPtr.Zero, 0, null, 0) != 0)
|
||||
return null;
|
||||
return sbName.ToString ();
|
||||
}
|
||||
|
||||
public static string[] GetFiles32 (UnzipHandle handle)
|
||||
{
|
||||
return GetFiles (handle, GetCurrentFileName32);
|
||||
}
|
||||
|
||||
public static string[] GetFiles64 (UnzipHandle handle)
|
||||
{
|
||||
return GetFiles (handle, GetCurrentFileName64);
|
||||
}
|
||||
|
||||
private static string[] GetFiles (UnzipHandle handle, Func<UnzipHandle, string> getCurrentFileName)
|
||||
{
|
||||
GoToFirstFile (handle);
|
||||
|
||||
var files = new List<string> ();
|
||||
string name;
|
||||
while ((name = GetCurrentFileName(handle)) != null)
|
||||
{
|
||||
while ((name = getCurrentFileName (handle)) != null) {
|
||||
files.Add (name);
|
||||
if (!NativeUnzip.GoToNextFile (handle))
|
||||
break;
|
||||
@@ -121,9 +136,17 @@ namespace zipsharp
|
||||
return unzGoToNextFile(handle) == 0;
|
||||
}
|
||||
|
||||
public static UnzipHandle OpenArchive (ZlibFileFuncDef fileFuncs)
|
||||
public static UnzipHandle OpenArchive32 (ZlibFileFuncDef32 fileFuncs)
|
||||
{
|
||||
UnzipHandle handle = unzOpen2 ("", ref fileFuncs);
|
||||
UnzipHandle handle = unzOpen2_32 ("", ref fileFuncs);
|
||||
if (handle.IsInvalid)
|
||||
throw new Exception ("Could not open unzip archive");
|
||||
return handle;
|
||||
}
|
||||
|
||||
public static UnzipHandle OpenArchive64 (ZlibFileFuncDef64 fileFuncs)
|
||||
{
|
||||
UnzipHandle handle = unzOpen2_64 ("", ref fileFuncs);
|
||||
if (handle.IsInvalid)
|
||||
throw new Exception ("Could not open unzip archive");
|
||||
return handle;
|
||||
@@ -160,9 +183,13 @@ namespace zipsharp
|
||||
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
|
||||
static extern int unzGoToFirstFile (UnzipHandle handle);
|
||||
|
||||
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
|
||||
static extern UnzipHandle unzOpen2 (string path,
|
||||
ref ZlibFileFuncDef pzlib_filefunc_def);
|
||||
[DllImport ("MonoPosixHelper", EntryPoint="unzOpen2", CallingConvention=CallingConvention.Cdecl)]
|
||||
static extern UnzipHandle unzOpen2_32 (string path,
|
||||
ref ZlibFileFuncDef32 pzlib_filefunc_def);
|
||||
|
||||
[DllImport ("MonoPosixHelper", EntryPoint="unzOpen2", CallingConvention=CallingConvention.Cdecl)]
|
||||
static extern UnzipHandle unzOpen2_64 (string path,
|
||||
ref ZlibFileFuncDef64 pzlib_filefunc_def);
|
||||
|
||||
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
|
||||
static extern int unzGoToNextFile (UnzipHandle handle);
|
||||
@@ -178,15 +205,25 @@ namespace zipsharp
|
||||
out int level,
|
||||
int raw);
|
||||
|
||||
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
|
||||
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
|
||||
[DllImport ("MonoPosixHelper", EntryPoint="unzGetCurrentFileInfo", CallingConvention=CallingConvention.Cdecl)]
|
||||
static extern int unzGetCurrentFileInfo_32 (UnzipHandle handle,
|
||||
out UnzipFileInfo32 pfile_info,
|
||||
StringBuilder szFileName,
|
||||
uint fileNameBufferSize, // uLong
|
||||
IntPtr extraField, // void *
|
||||
uint extraFieldBufferSize, // uLong
|
||||
StringBuilder szComment,
|
||||
uint commentBufferSize); // uLong
|
||||
|
||||
[DllImport ("MonoPosixHelper", EntryPoint="unzGetCurrentFileInfo", CallingConvention=CallingConvention.Cdecl)]
|
||||
static extern int unzGetCurrentFileInfo_64 (UnzipHandle handle,
|
||||
out UnzipFileInfo64 pfile_info,
|
||||
StringBuilder szFileName,
|
||||
ulong fileNameBufferSize, // uLong
|
||||
IntPtr extraField, // void *
|
||||
ulong extraFieldBufferSize, // uLong
|
||||
StringBuilder szComment,
|
||||
ulong commentBufferSize); // uLong
|
||||
|
||||
[DllImport ("MonoPosixHelper", CallingConvention=CallingConvention.Cdecl)]
|
||||
static unsafe extern int unzReadCurrentFile (UnzipHandle handle,
|
||||
|
||||
20
mcs/class/WindowsBase/ZipSharp/NativeVersion.cs
Executable file
20
mcs/class/WindowsBase/ZipSharp/NativeVersion.cs
Executable file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace zipsharp {
|
||||
static class NativeVersion {
|
||||
|
||||
/// <summary>
|
||||
/// ZipSharp code needs different code paths
|
||||
/// depending on the size of the C long type on the underlying platform. On
|
||||
/// gcc/clang the C long type follows the bitness of the targeted architecture,
|
||||
/// it's 32-bit on 32-bit systems and 64-bit on 64-bit systems. With the VS
|
||||
/// compiler however, the C long type is always 32-bit regardless of the
|
||||
/// target architecture. zlib and minizip uses C long in a number of
|
||||
/// different function signatures and structs.
|
||||
///
|
||||
/// This field is used to easily determine if the 32 bit version of
|
||||
/// functions and structs should be used when interacting with zlib.
|
||||
/// </summary>
|
||||
public static readonly bool Use32Bit = IntPtr.Size == 4 || Environment.OSVersion.Platform != PlatformID.Unix;
|
||||
}
|
||||
}
|
||||
@@ -31,24 +31,44 @@ namespace zipsharp
|
||||
zipCloseFileInZip (handle);
|
||||
}
|
||||
|
||||
public static ZipHandle OpenArchive (ZlibFileFuncDef funcDef, Append append)
|
||||
public static ZipHandle OpenArchive32 (ZlibFileFuncDef32 funcDef, Append append)
|
||||
{
|
||||
ZipHandle h = zipOpen2 ("", (int) append, IntPtr.Zero, ref funcDef);
|
||||
ZipHandle h = zipOpen2_32 ("", (int) append, IntPtr.Zero, ref funcDef);
|
||||
if (h.IsInvalid)
|
||||
throw new Exception ("Could not open the zip archive");
|
||||
return h;
|
||||
}
|
||||
|
||||
public static int OpenFile (ZipHandle handle, string filename)
|
||||
|
||||
public static ZipHandle OpenArchive64 (ZlibFileFuncDef64 funcDef, Append append)
|
||||
{
|
||||
return OpenFile (handle, filename, DEFAULT_COMPRESSION);
|
||||
ZipHandle h = zipOpen2_64 ("", (int) append, IntPtr.Zero, ref funcDef);
|
||||
if (h.IsInvalid)
|
||||
throw new Exception ("Could not open the zip archive");
|
||||
return h;
|
||||
}
|
||||
|
||||
public static int OpenFile (ZipHandle handle, string filename, int compressionLevel)
|
||||
public static int OpenFile32 (ZipHandle handle, string filename)
|
||||
{
|
||||
ZipFileInfo fileInfo = new ZipFileInfo (DateTime.Now);
|
||||
return OpenFile32 (handle, filename, DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
public static int OpenFile32 (ZipHandle handle, string filename, int compressionLevel)
|
||||
{
|
||||
ZipFileInfo32 fileInfo = new ZipFileInfo32 (DateTime.Now);
|
||||
int method = compressionLevel == 0 ? 0 : Z_DEFLATED;
|
||||
return zipOpenNewFileInZip (handle, filename, ref fileInfo, IntPtr.Zero, 0, IntPtr.Zero, 0, "", method, compressionLevel);
|
||||
return zipOpenNewFileInZip_32 (handle, filename, ref fileInfo, IntPtr.Zero, 0, IntPtr.Zero, 0, "", method, compressionLevel);
|
||||
}
|
||||
|
||||
public static int OpenFile64 (ZipHandle handle, string filename)
|
||||
{
|
||||
return OpenFile64 (handle, filename, DEFAULT_COMPRESSION);
|
||||
}
|
||||
|
||||
public static int OpenFile64 (ZipHandle handle, string filename, int compressionLevel)
|
||||
{
|
||||
ZipFileInfo64 fileInfo = new ZipFileInfo64 (DateTime.Now);
|
||||
int method = compressionLevel == 0 ? 0 : Z_DEFLATED;
|
||||
return zipOpenNewFileInZip_64 (handle, filename, ref fileInfo, IntPtr.Zero, 0, IntPtr.Zero, 0, "", method, compressionLevel);
|
||||
}
|
||||
|
||||
public static unsafe void Write (ZipHandle handle, byte[] buffer, int offset, uint count)
|
||||
@@ -65,26 +85,43 @@ namespace zipsharp
|
||||
[DllImport ("MonoPosixHelper")]
|
||||
static extern int zipCloseFileInZip (ZipHandle handle);
|
||||
|
||||
[DllImport ("MonoPosixHelper")]
|
||||
static extern ZipHandle zipOpen2 (string pathname,
|
||||
int append,
|
||||
IntPtr globalcomment, // zipcharpc*
|
||||
ref ZlibFileFuncDef pzlib_filefunc_def); // zlib_filefunc_def*
|
||||
[DllImport ("MonoPosixHelper", EntryPoint = "zipOpen2")]
|
||||
static extern ZipHandle zipOpen2_32 (string pathname,
|
||||
int append,
|
||||
IntPtr globalcomment, // zipcharpc*
|
||||
ref ZlibFileFuncDef32 pzlib_filefunc_def); // zlib_filefunc_def*
|
||||
|
||||
[DllImport ("MonoPosixHelper", EntryPoint = "zipOpen2")]
|
||||
static extern ZipHandle zipOpen2_64 (string pathname,
|
||||
int append,
|
||||
IntPtr globalcomment, // zipcharpc*
|
||||
ref ZlibFileFuncDef64 pzlib_filefunc_def); // zlib_filefunc_def*
|
||||
|
||||
|
||||
[DllImport ("MonoPosixHelper")]
|
||||
static extern int zipClose (ZipHandle handle, string globalComment);
|
||||
|
||||
[DllImport ("MonoPosixHelper")]
|
||||
static extern int zipOpenNewFileInZip (ZipHandle handle,
|
||||
string filename,
|
||||
ref ZipFileInfo zipfi,
|
||||
IntPtr extrafield_local,
|
||||
uint size_extrafield_local,
|
||||
IntPtr extrafield_global,
|
||||
uint size_extrafield_global,
|
||||
string comment,
|
||||
int method,
|
||||
int level);
|
||||
[DllImport ("MonoPosixHelper", EntryPoint = "zipOpenNewFileInZip")]
|
||||
static extern int zipOpenNewFileInZip_32 (ZipHandle handle,
|
||||
string filename,
|
||||
ref ZipFileInfo32 zipfi,
|
||||
IntPtr extrafield_local,
|
||||
uint size_extrafield_local,
|
||||
IntPtr extrafield_global,
|
||||
uint size_extrafield_global,
|
||||
string comment,
|
||||
int method,
|
||||
int level);
|
||||
|
||||
[DllImport ("MonoPosixHelper", EntryPoint = "zipOpenNewFileInZip")]
|
||||
static extern int zipOpenNewFileInZip_64 (ZipHandle handle,
|
||||
string filename,
|
||||
ref ZipFileInfo64 zipfi,
|
||||
IntPtr extrafield_local,
|
||||
uint size_extrafield_local,
|
||||
IntPtr extrafield_global,
|
||||
uint size_extrafield_global,
|
||||
string comment,
|
||||
int method,
|
||||
int level);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace zipsharp
|
||||
string[] Files {
|
||||
get {
|
||||
if (files == null)
|
||||
files = NativeUnzip.GetFiles (Handle);
|
||||
files = NativeVersion.Use32Bit ? NativeUnzip.GetFiles32 (Handle) : NativeUnzip.GetFiles64 (Handle);
|
||||
return files;
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace zipsharp
|
||||
public UnzipArchive (Stream stream, bool ownsStream)
|
||||
{
|
||||
Stream = new ZipStream (stream, ownsStream);
|
||||
Handle = NativeUnzip.OpenArchive (Stream.IOFunctions);
|
||||
Handle = NativeVersion.Use32Bit ? NativeUnzip.OpenArchive32 (Stream.IOFunctions32) : NativeUnzip.OpenArchive64 (Stream.IOFunctions64);
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
|
||||
@@ -10,103 +10,46 @@ using System.Runtime.InteropServices;
|
||||
namespace zipsharp
|
||||
{
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
struct UnzipFileInfo
|
||||
struct UnzipFileInfo32
|
||||
{
|
||||
IntPtr version; /* version made by 2 bytes */
|
||||
IntPtr version_needed; /* version needed to extract 2 bytes */
|
||||
IntPtr flag; /* general purpose bit flag 2 bytes */
|
||||
IntPtr compression_method; /* compression method 2 bytes */
|
||||
IntPtr dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
IntPtr crc; /* crc-32 4 bytes */
|
||||
IntPtr compressed_size; /* compressed size 4 bytes */
|
||||
IntPtr uncompressed_size; /* uncompressed size 4 bytes */
|
||||
IntPtr size_filename; /* filename length 2 bytes */
|
||||
IntPtr size_file_extra; /* extra field length 2 bytes */
|
||||
IntPtr size_file_comment; /* file comment length 2 bytes */
|
||||
public uint version; /* version made by 2 bytes */
|
||||
public uint version_needed; /* version needed to extract 2 bytes */
|
||||
public uint flag; /* general purpose bit flag 2 bytes */
|
||||
public uint compression_method; /* compression method 2 bytes */
|
||||
public uint dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
public uint crc; /* crc-32 4 bytes */
|
||||
public uint compressed_size; /* compressed size 4 bytes */
|
||||
public uint uncompressed_size; /* uncompressed size 4 bytes */
|
||||
public uint size_filename; /* filename length 2 bytes */
|
||||
public uint size_file_extra; /* extra field length 2 bytes */
|
||||
public uint size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
IntPtr disk_num_start; /* disk number start 2 bytes */
|
||||
IntPtr internal_fa; /* internal file attributes 2 bytes */
|
||||
IntPtr external_fa; /* external file attributes 4 bytes */
|
||||
public uint disk_num_start; /* disk number start 2 bytes */
|
||||
public uint internal_fa; /* internal file attributes 2 bytes */
|
||||
public uint external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
ZipTime tmu_date;
|
||||
|
||||
public ulong VersionNeeded {
|
||||
get { return (ulong)version_needed.ToInt64 (); }
|
||||
set { version_needed = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong Version {
|
||||
get { return (ulong)version.ToInt64 (); }
|
||||
set { version = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong UncompressedSize {
|
||||
get { return (ulong)uncompressed_size.ToInt64 (); }
|
||||
set { uncompressed_size = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ZipTime TmuDate {
|
||||
get { return tmu_date; }
|
||||
set { tmu_date = value; }
|
||||
}
|
||||
|
||||
public ulong SizeFilename {
|
||||
get { return (ulong)size_filename.ToInt64 (); }
|
||||
set { size_filename = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong SizeFileExtra {
|
||||
get { return (ulong)size_file_extra.ToInt64 (); }
|
||||
set { size_file_extra = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong SizeFileComment {
|
||||
get {
|
||||
return (ulong)size_file_comment.ToInt64 ();
|
||||
}
|
||||
set {
|
||||
size_file_comment = new IntPtr ((int)value);
|
||||
}
|
||||
}
|
||||
|
||||
public ulong InternalFa {
|
||||
get { return (ulong)internal_fa.ToInt64 (); }
|
||||
set { internal_fa = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong Flag {
|
||||
get { return (ulong)flag.ToInt64 (); }
|
||||
set { flag = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong ExternalFa {
|
||||
get { return (ulong)external_fa.ToInt64 (); }
|
||||
set { external_fa = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong DosDate {
|
||||
get { return (ulong)dosDate.ToInt64 (); }
|
||||
set { dosDate = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong DiskNumStart {
|
||||
get { return (ulong)disk_num_start.ToInt64 (); }
|
||||
set { disk_num_start = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong Crc {
|
||||
get { return (ulong)crc.ToInt64 (); }
|
||||
set { crc = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong CompressionMethod {
|
||||
get { return (ulong)compression_method.ToInt64 (); }
|
||||
set { compression_method = new IntPtr ((int)value); }
|
||||
}
|
||||
|
||||
public ulong CompressedSize {
|
||||
get { return (ulong)compressed_size.ToInt64 (); }
|
||||
set { compressed_size = new IntPtr ((int)value); }
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
struct UnzipFileInfo64
|
||||
{
|
||||
public ulong version; /* version made by 2 bytes */
|
||||
public ulong version_needed; /* version needed to extract 2 bytes */
|
||||
public ulong flag; /* general purpose bit flag 2 bytes */
|
||||
public ulong compression_method; /* compression method 2 bytes */
|
||||
public ulong dosDate; /* last mod file date in Dos fmt 4 bytes */
|
||||
public ulong crc; /* crc-32 4 bytes */
|
||||
public ulong compressed_size; /* compressed size 4 bytes */
|
||||
public ulong uncompressed_size; /* uncompressed size 4 bytes */
|
||||
public ulong size_filename; /* filename length 2 bytes */
|
||||
public ulong size_file_extra; /* extra field length 2 bytes */
|
||||
public ulong size_file_comment; /* file comment length 2 bytes */
|
||||
|
||||
public ulong disk_num_start; /* disk number start 2 bytes */
|
||||
public ulong internal_fa; /* internal file attributes 2 bytes */
|
||||
public ulong external_fa; /* external file attributes 4 bytes */
|
||||
|
||||
ZipTime tmu_date;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace zipsharp
|
||||
Archive = archive;
|
||||
Archive.FileActive = true;
|
||||
CompressionLevel = compressionLevel;
|
||||
length = NativeUnzip.CurrentFileLength (Archive.Handle);
|
||||
length = NativeVersion.Use32Bit ? NativeUnzip.CurrentFileLength32 (Archive.Handle) : NativeUnzip.CurrentFileLength64 (Archive.Handle);
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace zipsharp
|
||||
public ZipArchive (Stream stream, Append append, bool ownsStream)
|
||||
{
|
||||
Stream = new ZipStream (stream, ownsStream);
|
||||
Handle = NativeZip.OpenArchive (Stream.IOFunctions, append);
|
||||
Handle = NativeVersion.Use32Bit ? NativeZip.OpenArchive32 (Stream.IOFunctions32, append) : NativeZip.OpenArchive64 (Stream.IOFunctions64, append);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,8 +61,11 @@ namespace zipsharp
|
||||
{
|
||||
if (FileActive)
|
||||
throw new InvalidOperationException ("A file is already open");
|
||||
|
||||
NativeZip.OpenFile (Handle, filename, ConvertCompression (option));
|
||||
|
||||
if (NativeVersion.Use32Bit)
|
||||
NativeZip.OpenFile32 (Handle, filename, ConvertCompression (option));
|
||||
else
|
||||
NativeZip.OpenFile64 (Handle, filename, ConvertCompression (option));
|
||||
return new ZipWriteStream (this);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,40 +10,36 @@ using System.Runtime.InteropServices;
|
||||
namespace zipsharp
|
||||
{
|
||||
[StructLayoutAttribute (LayoutKind.Sequential)]
|
||||
struct ZipFileInfo
|
||||
struct ZipFileInfo32
|
||||
{
|
||||
ZipTime date;
|
||||
IntPtr dosDate;
|
||||
IntPtr internalFileAttributes;
|
||||
IntPtr externalFileAttributes;
|
||||
uint dosDate;
|
||||
uint internalFileAttributes;
|
||||
uint externalFileAttributes;
|
||||
|
||||
public DateTime FileTime
|
||||
{
|
||||
get { return date.Date; }
|
||||
}
|
||||
|
||||
public long DosDate
|
||||
{
|
||||
get { return dosDate.ToInt64 (); }
|
||||
}
|
||||
|
||||
internal long InternalFileAttributes
|
||||
{
|
||||
get { return internalFileAttributes.ToInt64 (); }
|
||||
}
|
||||
|
||||
internal long ExternalFileAttributes
|
||||
{
|
||||
get { return externalFileAttributes.ToInt64 (); }
|
||||
}
|
||||
|
||||
public ZipFileInfo (DateTime fileTime)
|
||||
public ZipFileInfo32 (DateTime fileTime)
|
||||
{
|
||||
date = new ZipTime (fileTime);
|
||||
dosDate = IntPtr.Zero;
|
||||
internalFileAttributes = IntPtr.Zero;
|
||||
externalFileAttributes = IntPtr.Zero;
|
||||
dosDate = 0;
|
||||
internalFileAttributes = 0;
|
||||
externalFileAttributes = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[StructLayoutAttribute (LayoutKind.Sequential)]
|
||||
struct ZipFileInfo64
|
||||
{
|
||||
ZipTime date;
|
||||
ulong dosDate;
|
||||
ulong internalFileAttributes;
|
||||
ulong externalFileAttributes;
|
||||
|
||||
public ZipFileInfo64 (DateTime fileTime)
|
||||
{
|
||||
date = new ZipTime (fileTime);
|
||||
dosDate = 0;
|
||||
internalFileAttributes = 0;
|
||||
externalFileAttributes = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,11 @@ namespace zipsharp
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ZlibFileFuncDef IOFunctions {
|
||||
public ZlibFileFuncDef32 IOFunctions32 {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public ZlibFileFuncDef64 IOFunctions64 {
|
||||
get; set;
|
||||
}
|
||||
|
||||
@@ -67,18 +71,27 @@ namespace zipsharp
|
||||
DataStream = dataStream;
|
||||
OwnsStream = ownsStream;
|
||||
|
||||
ZlibFileFuncDef f = new ZlibFileFuncDef();
|
||||
|
||||
f.opaque = IntPtr.Zero;
|
||||
f.zclose_file = CloseFile_Native;
|
||||
f.zerror_file = TestError_Native;
|
||||
f.zopen_file = OpenFile_Native;
|
||||
f.zread_file = ReadFile_Native;
|
||||
f.zseek_file = SeekFile_Native;
|
||||
f.ztell_file = TellFile_Native;
|
||||
f.zwrite_file = WriteFile_Native;
|
||||
ZlibFileFuncDef32 f32 = new ZlibFileFuncDef32 ();
|
||||
f32.opaque = IntPtr.Zero;
|
||||
f32.zclose_file = CloseFile_Native;
|
||||
f32.zerror_file = TestError_Native;
|
||||
f32.zopen_file = OpenFile_Native;
|
||||
f32.zread_file = ReadFile_Native32;
|
||||
f32.zseek_file = SeekFile_Native32;
|
||||
f32.ztell_file = TellFile_Native32;
|
||||
f32.zwrite_file = WriteFile_Native32;
|
||||
IOFunctions32 = f32;
|
||||
|
||||
IOFunctions = f;
|
||||
ZlibFileFuncDef64 f64 = new ZlibFileFuncDef64 ();
|
||||
f64.opaque = IntPtr.Zero;
|
||||
f64.zclose_file = CloseFile_Native;
|
||||
f64.zerror_file = TestError_Native;
|
||||
f64.zopen_file = OpenFile_Native;
|
||||
f64.zread_file = ReadFile_Native64;
|
||||
f64.zseek_file = SeekFile_Native64;
|
||||
f64.ztell_file = TellFile_Native64;
|
||||
f64.zwrite_file = WriteFile_Native64;
|
||||
IOFunctions64 = f64;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
@@ -130,9 +143,14 @@ namespace zipsharp
|
||||
return new IntPtr (1);
|
||||
}
|
||||
|
||||
unsafe IntPtr ReadFile_Native (IntPtr opaque, IntPtr stream, IntPtr buffer, IntPtr size)
|
||||
unsafe uint ReadFile_Native32 (IntPtr opaque, IntPtr stream, IntPtr buffer, uint size)
|
||||
{
|
||||
int count = size.ToInt32 ();
|
||||
return (uint) ReadFile_Native64 (opaque, stream, buffer, size);
|
||||
}
|
||||
|
||||
unsafe ulong ReadFile_Native64 (IntPtr opaque, IntPtr stream, IntPtr buffer, ulong size)
|
||||
{
|
||||
int count = (int) size;
|
||||
byte[] b = new byte[count];
|
||||
int read;
|
||||
|
||||
@@ -145,10 +163,15 @@ namespace zipsharp
|
||||
read = -1;
|
||||
}
|
||||
|
||||
return new IntPtr (read);
|
||||
return (ulong) read;
|
||||
}
|
||||
|
||||
IntPtr SeekFile_Native (IntPtr opaque, IntPtr stream, IntPtr offset, int origin)
|
||||
int SeekFile_Native32 (IntPtr opaque, IntPtr stream, uint offset, int origin)
|
||||
{
|
||||
return (int) SeekFile_Native64 (opaque, stream, offset, origin);
|
||||
}
|
||||
|
||||
long SeekFile_Native64 (IntPtr opaque, IntPtr stream, ulong offset, int origin)
|
||||
{
|
||||
SeekOrigin seek;
|
||||
if (origin == ZipStream.ZLIB_FILEFUNC_SEEK_CUR)
|
||||
@@ -158,21 +181,21 @@ namespace zipsharp
|
||||
else if (origin == ZLIB_FILEFUNC_SEEK_SET)
|
||||
seek = SeekOrigin.Begin;
|
||||
else
|
||||
return new IntPtr (-1);
|
||||
return -1;
|
||||
|
||||
Seek (offset.ToInt64 (), seek);
|
||||
Seek ((long) offset, seek);
|
||||
|
||||
return new IntPtr (0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
IntPtr TellFile_Native (IntPtr opaque, IntPtr stream)
|
||||
int TellFile_Native32 (IntPtr opaque, IntPtr stream)
|
||||
{
|
||||
if (IntPtr.Size == 4)
|
||||
return new IntPtr ((int)Position);
|
||||
else if (IntPtr.Size == 8)
|
||||
return new IntPtr (Position);
|
||||
else
|
||||
return new IntPtr (-1);
|
||||
return (int) TellFile_Native64 (opaque, stream);
|
||||
}
|
||||
|
||||
long TellFile_Native64 (IntPtr opaque, IntPtr stream)
|
||||
{
|
||||
return Position;
|
||||
}
|
||||
|
||||
int TestError_Native (IntPtr opaque, IntPtr stream)
|
||||
@@ -181,9 +204,14 @@ namespace zipsharp
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsafe IntPtr WriteFile_Native (IntPtr opaque, IntPtr stream, IntPtr buffer, /* ulong */ IntPtr size)
|
||||
unsafe uint WriteFile_Native32 (IntPtr opaque, IntPtr stream, IntPtr buffer, /* ulong */ uint size)
|
||||
{
|
||||
int count = size.ToInt32 ();
|
||||
return (uint) WriteFile_Native64 (opaque, stream, buffer, size);
|
||||
}
|
||||
|
||||
unsafe ulong WriteFile_Native64 (IntPtr opaque, IntPtr stream, IntPtr buffer, /* ulong */ ulong size)
|
||||
{
|
||||
int count = (int) size;
|
||||
byte[] b = new byte[count];
|
||||
|
||||
byte* ptrBuffer = (byte*) buffer.ToPointer ();
|
||||
@@ -196,7 +224,7 @@ namespace zipsharp
|
||||
|
||||
}
|
||||
|
||||
return new IntPtr (count);
|
||||
return (ulong) count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user