Class SgaArchiveFile
- Namespace
- OpenCompote.SGA
- Assembly
- OpenCompote.dll
Provides static methods for opening, creating, and extracting SGA archives.
public class SgaArchiveFile
- Inheritance
-
SgaArchiveFile
- Inherited Members
Methods
Create(Stream, SgaVersion, bool)
Creates new SGA archive from existing stream, in the specified SgaVersion.
public static SgaArchive Create(Stream existingStream, SgaVersion version, bool leaveOpen)
Parameters
existingStreamStreamEmpty Stream for the archive.
versionSgaVersionVersion of the new SGA archive.
leaveOpenbooltrueto leave theexistingStreamopen after sgaArchive is disposed.falseto close theexistingStreamwhen the archive is disposed.
Returns
- SgaArchive
The newly opened SGA archive.
Remarks
The new existingStream is always created with mode set to Create.
Not all version of Sga archive file are supported. For more info see status page.
The existingStream must be empty and support reading, writing and seeking. If the existingStream does not meet this criteria an ArgumentException is thrown.
Exceptions
- ArgumentNullException
The
existingStreamparameter is null.- ArgumentException
The
existingStreamdoes not support reading, writing or seeking.
Create(string, SgaVersion, bool)
Creates a new SGA archive at the path specified by sourceFileName in the specified version.
public static SgaArchive Create(string sourceFileName, SgaVersion version, bool overwrite = false)
Parameters
sourceFileNamestringThe path to the new SGA archive, specified as a relative or absolute path. Relative path is relative to the current working directory.
versionSgaVersionVersion of the new SGA archive.
overwriteboolIf true, it overwrites an existing file; otherwise, it throws an exception when the file already exists.
Returns
- SgaArchive
The newly opened SGA archive.
Remarks
The new 'SgaArchive' is always created with mode set to Create.
Not all version of Sga archive file are supported. For more info see status page.
Exceptions
- ArgumentNullException
The
sourceFileNameparameter is null.
CreateFromDirectory(string, Stream, SgaVersion, StorageType, bool)
Creates a SGA archive in the specified stream that contains the files and directories from the specified directory.
public static void CreateFromDirectory(string sourceDirectoryName, Stream destination, SgaVersion version, StorageType defaultStorageType, bool leaveOpen = false)
Parameters
sourceDirectoryNamestringThe path to the directory containing the drives to be archived.
destinationStreamEmpty Stream for the archive.
versionSgaVersionVersion of the new SGA archive.
defaultStorageTypeStorageTypeDefault storage type that should be used while importing files.
leaveOpenbooltrue to leave the
destinationopen after this method finishes. false to close thedestinationwhen this method finishes.
Exceptions
- ArgumentException
sourceDirectoryNameis an empty string or invalid path.- ArgumentNullException
sourceDirectoryNameis null.-OR-
destinationis null.- IOException
The directory or one of its entries could not be accessed or imported.
CreateFromDirectory(string, string, SgaVersion, StorageType, bool)
Creates a SGA archive that contains the files and directories from the specified directory.
public static void CreateFromDirectory(string sourceDirectoryName, string destinationArchiveFileName, SgaVersion version, StorageType defaultStorageType, bool overwrite = false)
Parameters
sourceDirectoryNamestringThe path to the directory to be archived.
destinationArchiveFileNamestringThe path of the archive to be created
versionSgaVersionVersion of the new SGA archive.
defaultStorageTypeStorageTypeDefault storage type that should be used while importing files.
overwriteboolIf true, it overwrites an existing file; otherwise, it throws an exception when the file already exists.
Exceptions
- ArgumentException
sourceDirectoryNameis an empty string or invalid path.-OR-
destinationArchiveFileNameis an empty string or invalid path.- ArgumentNullException
destinationArchiveFileNameis null.-OR-
sourceDirectoryNameis null.- IOException
The directory or one of its entries could not be accessed or imported.
ExtractToDirectory(Stream, string, bool, bool)
Extracts all the files in the specified sga archive to a directory on the file system.
public static void ExtractToDirectory(Stream existingStream, string destinationDirectoryName, bool leaveOpen = false, bool overwrite = false)
Parameters
existingStreamStreamStream containing the SGA archive.
destinationDirectoryNamestringThe path to the destination directory to which the archive will be exported. If the directory is missing it creates it.
leaveOpenbooltrue to leave the
existingStreamopen after this function. false to close theexistingStreamwhen this method finishes.overwritebool
Exceptions
- ArgumentNullException
The
existingStreamordestinationDirectoryNameparameter is null.- ArgumentException
The
destinationDirectoryNameparameter is empty string or invalid path./>.
ExtractToDirectory(string, string, bool)
Extracts all the files in the specified sga archive to a directory on the file system.
public static void ExtractToDirectory(string sourceFileName, string destinationDirectoryName, bool overwrite = false)
Parameters
sourceFileNamestringThe path on the file system to the archive that is to be extracted.
destinationDirectoryNamestringThe path to the destination directory to which the archive will be exported. If the directory is missing it creates it.
overwritebool
Exceptions
- ArgumentNullException
The
sourceFileNameordestinationDirectoryNameparameter is null.- ArgumentException
The
sourceFileNameordestinationDirectoryNameis empty string or invalid path./>.
Open(Stream, SgaMode, bool)
Opens a SGA archive from existing stream, in the specified 'SgaMode' mode.
public static SgaArchive Open(Stream existingStream, SgaMode mode, bool leaveOpen = false)
Parameters
existingStreamStreamStream containing the SGA archive.
modeSgaModeOne of the enumeration values that specifies the actions that are allowed on the opened archive.
leaveOpenbooltrueto leave theexistingStreamopen after sgaArchive is disposed.falseto close theexistingStreamwhen the archive is disposed.
Returns
- SgaArchive
The opened SGA archive.
Remarks
existingStream must support reading and seeking and if the mode is set to Write also reading. If the existingStream does not meet this criteria an ArgumentException is thrown.
This function cannot be used with mode set to Create. For creating a new archive use the Create(Stream, SgaVersion, bool) function. When you set the mode to Create an ArgumentException is thrown.
When you set the mode to Read or Write, the archive is opened with Open from the FileMode enumeration as the file mode value. If the archive does not exist, a FileNotFoundException exception is thrown.
If the mode is Write, the archive entries can be modified.
If the mode is Read, you can only read the archive entries. Attempt to write to the archive will cause NotSupportedException exception.
The archive SgaVersion is automatically detected based on the input file. If the version cannot be detected, a InvalidDataException is thrown.
Exceptions
- ArgumentNullException
The
existingStreamparameter is null.- ArgumentException
The
existingStreamdoes not support reading, writing or seeking, ormodeis set to Create.
Open(string, SgaMode)
Opens a SGA Archive at the specific source path, in the specified mode.
public static SgaArchive Open(string sourceFileName, SgaMode mode)
Parameters
sourceFileNamestringThe path to the SGA archive to open, specified as a relative or absolute path. Relative path is relative to the current working directory.
modeSgaModeOne of the enumeration values that specifies the actions that are allowed on the opened archive.
Returns
- SgaArchive
The opened SGA archive.
Remarks
This function cannot be used with mode set to Create. For creating a new archive use the Create(string, SgaVersion, bool) function. When you set the mode to Create an ArgumentException is thrown.
When you set the mode to Read or Write, the archive is opened with Open from the FileMode enumeration as the file mode value. If the archive does not exist, a FileNotFoundException exception is thrown.
If the mode is Write, the archive entries can be modified.
If the mode is Read, you can only read the archive entries. Attempt to write to the archive will cause NotSupportedException exception.
The archive SgaVersion is automatically detected based on the input file. If the version cannot be detected, a InvalidDataException is thrown.
Exceptions
- ArgumentNullException
The
sourceFileNameparameter is null.- ArgumentException
The
modeis set to Create.