C# Class Crisis.Ionic.Zip.SharedUtilities

Collects general purpose utility methods.
ファイルを表示 Open project: teeknofil/Crisis-Wordlist-Generator Class Usage Examples

Public Methods

Method Description
CreateAndOpenUniqueTempFile ( string dir, Stream &fs, string &filename ) : void

Create a pseudo-random filename, suitable for use as a temporary file, and open it.

The System.IO.Path.GetRandomFileName() method is not available on the Compact Framework, so this library provides its own substitute on NETCF.

This method produces a filename of the form CrisisZip-xxxxxxxx.tmp, where xxxxxxxx is replaced by randomly chosen characters, and creates that file.

GetFileLength ( string fileName ) : System.Int64
InternalGetTempFileName ( ) : string
NormalizePathForUseInZipFile ( string pathName ) : string

Utility routine for transforming path names from filesystem format (on Windows that means backslashes) to a format suitable for use within zipfiles. This means trimming the volume letter and colon (if any) And swapping backslashes for forward slashes.

RoundToEvenSecond ( System.DateTime source ) : System.DateTime

Round the given DateTime value to an even second value.

Round up in the case of an odd second value. The rounding does not consider fractional seconds.

This is useful because the Zip spec allows storage of time only to the nearest even second. So if you want to compare the time of an entry in the archive with it's actual time in the filesystem, you need to round the actual filesystem time, or use a 2-second threshold for the comparison.

This is most nautrally an extension method for the DateTime class but this library is built for .NET 2.0, not for .NET 3.5; This means extension methods are a no-no.

Private Methods

Method Description
AdjustTime_Forward ( System.DateTime time ) : System.DateTime
AdjustTime_Reverse ( System.DateTime time ) : System.DateTime
DateTimeToPacked ( System.DateTime time ) : Int32
FindSignature ( System stream, int SignatureToFind ) : long

Finds a signature in the zip stream. This is useful for finding the end of a zip entry, for example, or the beginning of the next ZipEntry.

Scans through 64k at a time.

If the method fails to find the requested signature, the stream Position after completion of this method is unchanged. If the method succeeds in finding the requested signature, the stream position after completion is direct AFTER the signature found in the stream.

GenerateRandomStringImpl ( int length, int delta ) : string
NormalizePath ( string path ) : string
PackedToDateTime ( Int32 packedDateTime ) : System.DateTime
ReadEntrySignature ( System s ) : int
ReadInt ( System s ) : int
ReadSignature ( System s ) : int
ReadWithRetry ( System s, byte buffer, int offset, int count, string FileName ) : int

Workitem 7889: handle ERROR_LOCK_VIOLATION during read

This could be gracefully handled with an extension attribute, but This assembly is built for .NET 2.0, so I cannot use them.

SimplifyFwdSlashPath ( string path ) : string
StringFromBuffer ( byte buf, System encoding ) : string
StringToByteArray ( string value ) : byte[]
StringToByteArray ( string value, System encoding ) : byte[]
Utf8StringFromBuffer ( byte buf ) : string
Workaround_Ladybug318918 ( Stream s ) : void
_HRForException ( System ex1 ) : uint
_ReadFourBytes ( System s, string message ) : int

Method Details

CreateAndOpenUniqueTempFile() public static method

Create a pseudo-random filename, suitable for use as a temporary file, and open it.

The System.IO.Path.GetRandomFileName() method is not available on the Compact Framework, so this library provides its own substitute on NETCF.

This method produces a filename of the form CrisisZip-xxxxxxxx.tmp, where xxxxxxxx is replaced by randomly chosen characters, and creates that file.

public static CreateAndOpenUniqueTempFile ( string dir, Stream &fs, string &filename ) : void
dir string
fs Stream
filename string
return void

GetFileLength() public static method

public static GetFileLength ( string fileName ) : System.Int64
fileName string
return System.Int64

InternalGetTempFileName() public static method

public static InternalGetTempFileName ( ) : string
return string

NormalizePathForUseInZipFile() public static method

Utility routine for transforming path names from filesystem format (on Windows that means backslashes) to a format suitable for use within zipfiles. This means trimming the volume letter and colon (if any) And swapping backslashes for forward slashes.
public static NormalizePathForUseInZipFile ( string pathName ) : string
pathName string source path.
return string

RoundToEvenSecond() public static method

Round the given DateTime value to an even second value.

Round up in the case of an odd second value. The rounding does not consider fractional seconds.

This is useful because the Zip spec allows storage of time only to the nearest even second. So if you want to compare the time of an entry in the archive with it's actual time in the filesystem, you need to round the actual filesystem time, or use a 2-second threshold for the comparison.

This is most nautrally an extension method for the DateTime class but this library is built for .NET 2.0, not for .NET 3.5; This means extension methods are a no-no.

public static RoundToEvenSecond ( System.DateTime source ) : System.DateTime
source System.DateTime The DateTime value to round
return System.DateTime