C# Class Nexus.Client.Util.Archive

Encapsulates the interactions with an archive file.
Inheritance: IDisposable
Show file Open project: NexusMods/NexusModManager-4.5 Class Usage Examples

Protected Properties

Property Type Description
m_lstNonArchiveExtensions List

Public Methods

Method Description
Archive ( string p_strPath ) : System

A simple constructor the initializes the object with the given values.

BeginReadOnlyTransaction ( FileUtil p_futFileUtil ) : void

Starts a read-only transaction.

This puts the archive into read-only mode.

ChangeArchiveDirectory ( string p_strArchivePath, string p_strNewArchiveDirectory ) : string

Changes the directory of the archive referenced in the given path to the specified new directory.

This changes something of the form: arch:old\path\archive.zip//interior/path/file.txt to: arch:new\path\archive.zip//interior/path/file.txt

ContainsFile ( string p_strPath ) : bool

Determins if the archive contains the specified file.

DeleteFile ( string p_strFileName ) : void

Deletes the specified file from the archive.

If the specified file doesn't exist in the archive, nothing is done.

Dispose ( ) : void

Disposes of the resources used by the object.

EndReadOnlyTransaction ( ) : void

Ends a read-only transaction.

This takes the archive out of read-only mode, and releases any used resources.

GenerateArchivePath ( string p_strArchivePath, string p_strInternalPath ) : string

Generates a path to a file in an archive.

GetDirectories ( string p_strDirectory ) : string[]

Gets a list of directories that are in the specified directory in this archive.

GetExtractor ( string p_strPath ) : SevenZip.SevenZipExtractor

Gets a SevenZipExtractor for the given path.

This builds a SevenZipExtractor for the given path. The path can be to a nested archive (an archive in another archive).

GetFileContents ( string p_strPath ) : byte[]

Gets the contents of the specified file in the archive.

GetFiles ( string p_strDirectory, bool p_booRecurse ) : string[]

Gets a list of files that are in the specified directory in this archive.

GetFiles ( string p_strDirectory, string p_strPattern, bool p_booRecurse ) : string[]

Gets a list of files that are in the specified directory and match the given pattern in this archive.

GetThreadSafeExtractor ( string p_strPath ) : ThreadSafeSevenZipExtractor

Gets a ThreadSafeSevenZipExtractor for the given path.

This builds a ThreadSafeSevenZipExtractor for the given path. The path can be to a nested archive (an archive in another archive).

IsArchive ( string p_strPath ) : bool

Determines whether or not the file specified by the given path is an archive.

IsArchivePath ( string p_strPath ) : bool

Determines whether or not the given path points to a file in an archive.

IsDirectory ( string p_strPath ) : bool

Determins if the given path is a directory in this archive.

ParseArchivePath ( string p_strPath ) : string>.KeyValuePair

Parses the given path to extract the path to the archive file, and the path to a file within said archive.

ReplaceFile ( string p_strFileName, byte p_bteData ) : void

Replaces the specified file in the archive with the given data.

If the specified file doesn't exist in the archive, the file is added.

ReplaceFile ( string p_strFileName, string p_strData ) : void

Replaces the specified file in the archive with the given data.

If the specified file doesn't exist in the archive, the file is added.

Protected Methods

Method Description
LoadFileIndices ( ) : void

Caches information about the files in the archive.

Private Methods

Method Description
FileExtractionFinished ( object sender, SevenZip.FileInfoEventArgs e ) : void

Called when a file has been extracted from a source archive.

This notifies listeners that a read-only initialization step has finished.

GetExtractor ( string p_strPath, bool p_booThreadSafe ) : object

Gets a SevenZipExtractor for the given path.

This builds a SevenZipExtractor for the given path. The path can be to a nested archive (an archive in another archive).

Method Details

Archive() public method

A simple constructor the initializes the object with the given values.
public Archive ( string p_strPath ) : System
p_strPath string The path to the archive file.
return System

BeginReadOnlyTransaction() public method

Starts a read-only transaction.
This puts the archive into read-only mode.
Thrown if is null.
public BeginReadOnlyTransaction ( FileUtil p_futFileUtil ) : void
p_futFileUtil FileUtil An instance of a class.
return void

ChangeArchiveDirectory() public static method

Changes the directory of the archive referenced in the given path to the specified new directory.
This changes something of the form: arch:old\path\archive.zip//interior/path/file.txt to: arch:new\path\archive.zip//interior/path/file.txt
public static ChangeArchiveDirectory ( string p_strArchivePath, string p_strNewArchiveDirectory ) : string
p_strArchivePath string The archive path whose directory is to be replaced.
p_strNewArchiveDirectory string The new directory to put into the given archive path.
return string

ContainsFile() public method

Determins if the archive contains the specified file.
public ContainsFile ( string p_strPath ) : bool
p_strPath string The path of the file whose presence in the archive is to be determined.
return bool

DeleteFile() public method

Deletes the specified file from the archive.
If the specified file doesn't exist in the archive, nothing is done.
Thrown if modification of archives of the current /// archive type is not supported. Thrown if modification of archive is attempted /// while the archive is in a ready only transaction.
public DeleteFile ( string p_strFileName ) : void
p_strFileName string The path to the file to delete from the archive.
return void

Dispose() public method

Disposes of the resources used by the object.
public Dispose ( ) : void
return void

EndReadOnlyTransaction() public method

Ends a read-only transaction.
This takes the archive out of read-only mode, and releases any used resources.
public EndReadOnlyTransaction ( ) : void
return void

GenerateArchivePath() public static method

Generates a path to a file in an archive.
public static GenerateArchivePath ( string p_strArchivePath, string p_strInternalPath ) : string
p_strArchivePath string The path of the archive file.
p_strInternalPath string The path of the file in the archive.
return string

GetDirectories() public method

Gets a list of directories that are in the specified directory in this archive.
public GetDirectories ( string p_strDirectory ) : string[]
p_strDirectory string The directory in the archive whose descendents are to be returned.
return string[]

GetExtractor() public static method

Gets a SevenZipExtractor for the given path.
This builds a SevenZipExtractor for the given path. The path can be to a nested archive (an archive in another archive).
public static GetExtractor ( string p_strPath ) : SevenZip.SevenZipExtractor
p_strPath string The path to the archive for which to get a .
return SevenZip.SevenZipExtractor

GetFileContents() public method

Gets the contents of the specified file in the archive.
public GetFileContents ( string p_strPath ) : byte[]
p_strPath string The file whose contents are to be retrieved.
return byte[]

GetFiles() public method

Gets a list of files that are in the specified directory in this archive.
public GetFiles ( string p_strDirectory, bool p_booRecurse ) : string[]
p_strDirectory string The directory in the archive whose descendents are to be returned.
p_booRecurse bool Whether to return files that are in subdirectories of the given directory.
return string[]

GetFiles() public method

Gets a list of files that are in the specified directory and match the given pattern in this archive.
public GetFiles ( string p_strDirectory, string p_strPattern, bool p_booRecurse ) : string[]
p_strDirectory string The directory in the archive whose descendents are to be returned.
p_strPattern string The filename pattern of the files to be returned.
p_booRecurse bool Whether to return files that are in subdirectories of the given directory.
return string[]

GetThreadSafeExtractor() public static method

Gets a ThreadSafeSevenZipExtractor for the given path.
This builds a ThreadSafeSevenZipExtractor for the given path. The path can be to a nested archive (an archive in another archive).
public static GetThreadSafeExtractor ( string p_strPath ) : ThreadSafeSevenZipExtractor
p_strPath string The path to the archive for which to get a .
return ThreadSafeSevenZipExtractor

IsArchive() public static method

Determines whether or not the file specified by the given path is an archive.
public static IsArchive ( string p_strPath ) : bool
p_strPath string
return bool

IsArchivePath() public static method

Determines whether or not the given path points to a file in an archive.
public static IsArchivePath ( string p_strPath ) : bool
p_strPath string
return bool

IsDirectory() public method

Determins if the given path is a directory in this archive.
public IsDirectory ( string p_strPath ) : bool
p_strPath string The path to examine.
return bool

LoadFileIndices() protected method

Caches information about the files in the archive.
protected LoadFileIndices ( ) : void
return void

ParseArchivePath() public static method

Parses the given path to extract the path to the archive file, and the path to a file within said archive.
public static ParseArchivePath ( string p_strPath ) : string>.KeyValuePair
p_strPath string The file path to parse.
return string>.KeyValuePair

ReplaceFile() public method

Replaces the specified file in the archive with the given data.
If the specified file doesn't exist in the archive, the file is added.
Thrown if modification of archives of the current /// archive type is not supported. Thrown if modification of archive is attempted /// while the archive is in a ready only transaction.
public ReplaceFile ( string p_strFileName, byte p_bteData ) : void
p_strFileName string The path to the file to replace in the archive.
p_bteData byte The new file data.
return void

ReplaceFile() public method

Replaces the specified file in the archive with the given data.
If the specified file doesn't exist in the archive, the file is added.
public ReplaceFile ( string p_strFileName, string p_strData ) : void
p_strFileName string The path to the file to replace in the archive.
p_strData string The new file data.
return void

Property Details

m_lstNonArchiveExtensions protected static property

A list of well-known extensions of files that are not archives.
This list is used to speed up determination of whether or not a given file is an archive.
protected static List m_lstNonArchiveExtensions
return List