/* This file is part of SevenZipSharp.
SevenZipSharp is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SevenZipSharp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with SevenZipSharp. If not, see .
*/
using System;
#if !WINCE
using System.Runtime.Serialization;
#endif
namespace SevenZip
{
///
/// Base SevenZip exception class.
///
[Serializable]
public class SevenZipException : Exception
{
///
/// The message for thrown user exceptions.
///
internal const string USER_EXCEPTION_MESSAGE = "The extraction was successful but" +
"some exceptions were thrown in your events. Check UserExceptions for details.";
///
/// Initializes a new instance of the SevenZipException class
///
public SevenZipException() : base("SevenZip unknown exception.") {}
///
/// Initializes a new instance of the SevenZipException class
///
/// Default exception message
public SevenZipException(string defaultMessage)
: base(defaultMessage) {}
///
/// Initializes a new instance of the SevenZipException class
///
/// Default exception message
/// Additional detailed message
public SevenZipException(string defaultMessage, string message)
: base(defaultMessage + " Message: " + message) {}
///
/// Initializes a new instance of the SevenZipException class
///
/// Default exception message
/// Additional detailed message
/// Inner exception occured
public SevenZipException(string defaultMessage, string message, Exception inner)
: base(
defaultMessage + (defaultMessage.EndsWith(" ", StringComparison.CurrentCulture) ? "" : " Message: ") +
message, inner) {}
///
/// Initializes a new instance of the SevenZipException class
///
/// Default exception message
/// Inner exception occured
public SevenZipException(string defaultMessage, Exception inner)
: base(defaultMessage, inner) {}
#if !WINCE
///
/// Initializes a new instance of the SevenZipException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected SevenZipException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if UNMANAGED
///
/// Exception class for ArchiveExtractCallback.
///
[Serializable]
public class ExtractionFailedException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE = "Could not extract files!";
///
/// Initializes a new instance of the ExtractionFailedException class
///
public ExtractionFailedException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the ExtractionFailedException class
///
/// Additional detailed message
public ExtractionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the ExtractionFailedException class
///
/// Additional detailed message
/// Inner exception occured
public ExtractionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the ExtractionFailedException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected ExtractionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if COMPRESS
///
/// Exception class for ArchiveUpdateCallback.
///
[Serializable]
public class CompressionFailedException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE = "Could not pack files!";
///
/// Initializes a new instance of the CompressionFailedException class
///
public CompressionFailedException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the CompressionFailedException class
///
/// Additional detailed message
public CompressionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the CompressionFailedException class
///
/// Additional detailed message
/// Inner exception occured
public CompressionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the CompressionFailedException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected CompressionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
#endif
///
/// Exception class for LZMA operations.
///
[Serializable]
public class LzmaException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE = "Specified stream is not a valid LZMA compressed stream!";
///
/// Initializes a new instance of the LzmaException class
///
public LzmaException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the LzmaException class
///
/// Additional detailed message
public LzmaException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the LzmaException class
///
/// Additional detailed message
/// Inner exception occured
public LzmaException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the LzmaException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected LzmaException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if UNMANAGED
///
/// Exception class for 7-zip archive open or read operations.
///
[Serializable]
public class SevenZipArchiveException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE =
"Invalid archive: open/read error! Is it encrypted and a wrong password was provided?\n" +
"If your archive is an exotic one, it is possible that SevenZipSharp has no signature for "+
"its format and thus decided it is TAR by mistake.";
///
/// Initializes a new instance of the SevenZipArchiveException class
///
public SevenZipArchiveException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the SevenZipArchiveException class
///
/// Additional detailed message
public SevenZipArchiveException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the SevenZipArchiveException class
///
/// Additional detailed message
/// Inner exception occured
public SevenZipArchiveException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the SevenZipArchiveException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected SevenZipArchiveException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
///
/// Exception class for empty common root if file name array in SevenZipCompressor.
///
[Serializable]
public class SevenZipInvalidFileNamesException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE = "Invalid file names have been specified: ";
///
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
///
public SevenZipInvalidFileNamesException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
///
/// Additional detailed message
public SevenZipInvalidFileNamesException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
///
/// Additional detailed message
/// Inner exception occured
public SevenZipInvalidFileNamesException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected SevenZipInvalidFileNamesException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if COMPRESS
///
/// Exception class for fail to create an archive in SevenZipCompressor.
///
[Serializable]
public class SevenZipCompressionFailedException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE = "The compression has failed for an unknown reason with code ";
///
/// Initializes a new instance of the SevenZipCompressionFailedException class
///
public SevenZipCompressionFailedException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the SevenZipCompressionFailedException class
///
/// Additional detailed message
public SevenZipCompressionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the SevenZipCompressionFailedException class
///
/// Additional detailed message
/// Inner exception occured
public SevenZipCompressionFailedException(string message, Exception inner)
: base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the SevenZipCompressionFailedException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected SevenZipCompressionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
///
/// Exception class for fail to extract an archive in SevenZipExtractor.
///
[Serializable]
public class SevenZipExtractionFailedException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE = "The extraction has failed for an unknown reason with code ";
///
/// Initializes a new instance of the SevenZipExtractionFailedException class
///
public SevenZipExtractionFailedException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the SevenZipExtractionFailedException class
///
/// Additional detailed message
public SevenZipExtractionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the SevenZipExtractionFailedException class
///
/// Additional detailed message
/// Inner exception occured
public SevenZipExtractionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the SevenZipExtractionFailedException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected SevenZipExtractionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
///
/// Exception class for 7-zip library operations.
///
[Serializable]
public class SevenZipLibraryException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public const string DEFAULT_MESSAGE = "Can not load 7-zip library or internal COM error!";
///
/// Initializes a new instance of the SevenZipLibraryException class
///
public SevenZipLibraryException() : base(DEFAULT_MESSAGE) {}
///
/// Initializes a new instance of the SevenZipLibraryException class
///
/// Additional detailed message
public SevenZipLibraryException(string message) : base(DEFAULT_MESSAGE, message) {}
///
/// Initializes a new instance of the SevenZipLibraryException class
///
/// Additional detailed message
/// Inner exception occured
public SevenZipLibraryException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the SevenZipLibraryException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected SevenZipLibraryException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
#if SFX
///
/// Exception class for 7-zip sfx settings validation.
///
[Serializable]
public class SevenZipSfxValidationException : SevenZipException
{
///
/// Exception dafault message which is displayed if no extra information is specified
///
public static readonly string DefaultMessage = "Sfx settings validation failed.";
///
/// Initializes a new instance of the SevenZipSfxValidationException class
///
public SevenZipSfxValidationException() : base(DefaultMessage) {}
///
/// Initializes a new instance of the SevenZipSfxValidationException class
///
/// Additional detailed message
public SevenZipSfxValidationException(string message) : base(DefaultMessage, message) {}
///
/// Initializes a new instance of the SevenZipSfxValidationException class
///
/// Additional detailed message
/// Inner exception occured
public SevenZipSfxValidationException(string message, Exception inner) : base(DefaultMessage, message, inner) {}
#if !WINCE
///
/// Initializes a new instance of the SevenZipSfxValidationException class
///
/// All data needed for serialization or deserialization
/// Serialized stream descriptor
protected SevenZipSfxValidationException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
}