123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529 |
-
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace SevenZip
- {
- #if UNMANAGED
-
-
-
- public enum InArchiveFormat
- {
-
-
-
-
- SevenZip,
-
-
-
-
- Arj,
-
-
-
-
- BZip2,
-
-
-
-
- Cab,
-
-
-
-
- Chm,
-
-
-
-
- Compound,
-
-
-
-
- Cpio,
-
-
-
-
- Deb,
-
-
-
-
- GZip,
-
-
-
-
- Iso,
-
-
-
-
- Lzh,
-
-
-
-
- Lzma,
-
-
-
-
- Nsis,
-
-
-
-
- Rar,
-
-
-
-
- Rpm,
-
-
-
-
- Split,
-
-
-
-
- Tar,
-
-
-
-
- Wim,
-
-
-
-
- Lzw,
-
-
-
-
- Zip,
-
-
-
- Udf,
-
-
-
-
- Xar,
-
-
-
- Mub,
-
-
-
-
- Hfs,
-
-
-
- Dmg,
-
-
-
-
- XZ,
-
-
-
- Mslz,
-
-
-
-
- Flv,
-
-
-
-
- Swf,
-
-
-
-
- PE,
-
-
-
-
- Elf,
-
-
-
-
- Msi,
-
-
-
-
- Vhd
- }
- #if COMPRESS
-
-
-
- public enum OutArchiveFormat
- {
-
-
-
-
- SevenZip,
-
-
-
-
- Zip,
-
-
-
-
- GZip,
-
-
-
-
- BZip2,
-
-
-
-
- Tar,
-
-
-
-
- XZ
- }
-
-
-
- public enum CompressionLevel
- {
-
-
-
- None,
-
-
-
- Fast,
-
-
-
- Low,
-
-
-
- Normal,
-
-
-
- High,
-
-
-
- Ultra
- }
-
-
-
-
- public enum CompressionMethod
- {
-
-
-
- Copy,
-
-
-
- Deflate,
-
-
-
- Deflate64,
-
-
-
-
- BZip2,
-
-
-
- Lzma,
-
-
-
- Lzma2,
-
-
-
-
- Ppmd,
-
-
-
- Default
- }
- #endif
-
-
-
- public static class Formats
- {
-
-
-
-
- internal static readonly Dictionary<InArchiveFormat, Guid> InFormatGuids =
- new Dictionary<InArchiveFormat, Guid>(20)
- #region InFormatGuids initialization
- {
- {InArchiveFormat.SevenZip, new Guid("23170f69-40c1-278a-1000-000110070000")},
- {InArchiveFormat.Arj, new Guid("23170f69-40c1-278a-1000-000110040000")},
- {InArchiveFormat.BZip2, new Guid("23170f69-40c1-278a-1000-000110020000")},
- {InArchiveFormat.Cab, new Guid("23170f69-40c1-278a-1000-000110080000")},
- {InArchiveFormat.Chm, new Guid("23170f69-40c1-278a-1000-000110e90000")},
- {InArchiveFormat.Compound, new Guid("23170f69-40c1-278a-1000-000110e50000")},
- {InArchiveFormat.Cpio, new Guid("23170f69-40c1-278a-1000-000110ed0000")},
- {InArchiveFormat.Deb, new Guid("23170f69-40c1-278a-1000-000110ec0000")},
- {InArchiveFormat.GZip, new Guid("23170f69-40c1-278a-1000-000110ef0000")},
- {InArchiveFormat.Iso, new Guid("23170f69-40c1-278a-1000-000110e70000")},
- {InArchiveFormat.Lzh, new Guid("23170f69-40c1-278a-1000-000110060000")},
- {InArchiveFormat.Lzma, new Guid("23170f69-40c1-278a-1000-0001100a0000")},
- {InArchiveFormat.Nsis, new Guid("23170f69-40c1-278a-1000-000110090000")},
- {InArchiveFormat.Rar, new Guid("23170f69-40c1-278a-1000-000110030000")},
- {InArchiveFormat.Rpm, new Guid("23170f69-40c1-278a-1000-000110eb0000")},
- {InArchiveFormat.Split, new Guid("23170f69-40c1-278a-1000-000110ea0000")},
- {InArchiveFormat.Tar, new Guid("23170f69-40c1-278a-1000-000110ee0000")},
- {InArchiveFormat.Wim, new Guid("23170f69-40c1-278a-1000-000110e60000")},
- {InArchiveFormat.Lzw, new Guid("23170f69-40c1-278a-1000-000110050000")},
- {InArchiveFormat.Zip, new Guid("23170f69-40c1-278a-1000-000110010000")},
- {InArchiveFormat.Udf, new Guid("23170f69-40c1-278a-1000-000110E00000")},
- {InArchiveFormat.Xar, new Guid("23170f69-40c1-278a-1000-000110E10000")},
- {InArchiveFormat.Mub, new Guid("23170f69-40c1-278a-1000-000110E20000")},
- {InArchiveFormat.Hfs, new Guid("23170f69-40c1-278a-1000-000110E30000")},
- {InArchiveFormat.Dmg, new Guid("23170f69-40c1-278a-1000-000110E40000")},
- {InArchiveFormat.XZ, new Guid("23170f69-40c1-278a-1000-0001100C0000")},
- {InArchiveFormat.Mslz, new Guid("23170f69-40c1-278a-1000-000110D50000")},
- {InArchiveFormat.PE, new Guid("23170f69-40c1-278a-1000-000110DD0000")},
- {InArchiveFormat.Elf, new Guid("23170f69-40c1-278a-1000-000110DE0000")},
- {InArchiveFormat.Swf, new Guid("23170f69-40c1-278a-1000-000110D70000")},
- {InArchiveFormat.Vhd, new Guid("23170f69-40c1-278a-1000-000110DC0000")}
- };
- #endregion
- #if COMPRESS
-
-
-
- internal static readonly Dictionary<OutArchiveFormat, Guid> OutFormatGuids =
- new Dictionary<OutArchiveFormat, Guid>(2)
- #region OutFormatGuids initialization
- {
- {OutArchiveFormat.SevenZip, new Guid("23170f69-40c1-278a-1000-000110070000")},
- {OutArchiveFormat.Zip, new Guid("23170f69-40c1-278a-1000-000110010000")},
- {OutArchiveFormat.BZip2, new Guid("23170f69-40c1-278a-1000-000110020000")},
- {OutArchiveFormat.GZip, new Guid("23170f69-40c1-278a-1000-000110ef0000")},
- {OutArchiveFormat.Tar, new Guid("23170f69-40c1-278a-1000-000110ee0000")},
- {OutArchiveFormat.XZ, new Guid("23170f69-40c1-278a-1000-0001100C0000")},
- };
- #endregion
- internal static readonly Dictionary<CompressionMethod, string> MethodNames =
- new Dictionary<CompressionMethod, string>(6)
- #region MethodNames initialization
- {
- {CompressionMethod.Copy, "Copy"},
- {CompressionMethod.Deflate, "Deflate"},
- {CompressionMethod.Deflate64, "Deflate64"},
- {CompressionMethod.Lzma, "LZMA"},
- {CompressionMethod.Lzma2, "LZMA2"},
- {CompressionMethod.Ppmd, "PPMd"},
- {CompressionMethod.BZip2, "BZip2"}
- };
- #endregion
- internal static readonly Dictionary<OutArchiveFormat, InArchiveFormat> InForOutFormats =
- new Dictionary<OutArchiveFormat, InArchiveFormat>(6)
- #region InForOutFormats initialization
- {
- {OutArchiveFormat.SevenZip, InArchiveFormat.SevenZip},
- {OutArchiveFormat.GZip, InArchiveFormat.GZip},
- {OutArchiveFormat.BZip2, InArchiveFormat.BZip2},
- {OutArchiveFormat.Tar, InArchiveFormat.Tar},
- {OutArchiveFormat.XZ, InArchiveFormat.XZ},
- {OutArchiveFormat.Zip, InArchiveFormat.Zip}
- };
- #endregion
- #endif
-
-
-
- private static readonly Dictionary<string, InArchiveFormat> InExtensionFormats =
- new Dictionary<string, InArchiveFormat>
- #region InExtensionFormats initialization
- {{"7z", InArchiveFormat.SevenZip},
- {"gz", InArchiveFormat.GZip},
- {"tar", InArchiveFormat.Tar},
- {"rar", InArchiveFormat.Rar},
- {"zip", InArchiveFormat.Zip},
- {"lzma", InArchiveFormat.Lzma},
- {"lzh", InArchiveFormat.Lzh},
- {"arj", InArchiveFormat.Arj},
- {"bz2", InArchiveFormat.BZip2},
- {"cab", InArchiveFormat.Cab},
- {"chm", InArchiveFormat.Chm},
- {"deb", InArchiveFormat.Deb},
- {"iso", InArchiveFormat.Iso},
- {"rpm", InArchiveFormat.Rpm},
- {"wim", InArchiveFormat.Wim},
- {"udf", InArchiveFormat.Udf},
- {"mub", InArchiveFormat.Mub},
- {"xar", InArchiveFormat.Xar},
- {"hfs", InArchiveFormat.Hfs},
- {"dmg", InArchiveFormat.Dmg},
- {"Z", InArchiveFormat.Lzw},
- {"xz", InArchiveFormat.XZ},
- {"flv", InArchiveFormat.Flv},
- {"swf", InArchiveFormat.Swf},
- {"exe", InArchiveFormat.PE},
- {"dll", InArchiveFormat.PE},
- {"vhd", InArchiveFormat.Vhd}
- };
- #endregion
-
-
-
-
- internal static readonly Dictionary<string, InArchiveFormat> InSignatureFormats =
- new Dictionary<string, InArchiveFormat>
- #region InSignatureFormats initialization
- {{"37-7A-BC-AF-27-1C", InArchiveFormat.SevenZip},
- {"1F-8B-08", InArchiveFormat.GZip},
- {"75-73-74-61-72", InArchiveFormat.Tar},
-
- {"52-61-72-21-1A-07-00", InArchiveFormat.Rar},
- {"50-4B-03-04", InArchiveFormat.Zip},
- {"5D-00-00-40-00", InArchiveFormat.Lzma},
- {"2D-6C-68", InArchiveFormat.Lzh},
-
- {"1F-9D-90", InArchiveFormat.Lzw},
- {"60-EA", InArchiveFormat.Arj},
- {"42-5A-68", InArchiveFormat.BZip2},
- {"4D-53-43-46", InArchiveFormat.Cab},
- {"49-54-53-46", InArchiveFormat.Chm},
- {"21-3C-61-72-63-68-3E-0A-64-65-62-69-61-6E-2D-62-69-6E-61-72-79", InArchiveFormat.Deb},
- {"43-44-30-30-31", InArchiveFormat.Iso},
-
- {"ED-AB-EE-DB", InArchiveFormat.Rpm},
- {"4D-53-57-49-4D-00-00-00", InArchiveFormat.Wim},
- {"udf", InArchiveFormat.Udf},
- {"mub", InArchiveFormat.Mub},
- {"78-61-72-21", InArchiveFormat.Xar},
-
- {"48-2B", InArchiveFormat.Hfs},
- {"FD-37-7A-58-5A", InArchiveFormat.XZ},
- {"46-4C-56", InArchiveFormat.Flv},
- {"46-57-53", InArchiveFormat.Swf},
- {"4D-5A", InArchiveFormat.PE},
- {"7F-45-4C-46", InArchiveFormat.Elf},
- {"78", InArchiveFormat.Dmg},
- {"63-6F-6E-65-63-74-69-78", InArchiveFormat.Vhd}};
- #endregion
- internal static Dictionary<InArchiveFormat, string> InSignatureFormatsReversed;
- static Formats()
- {
- InSignatureFormatsReversed = new Dictionary<InArchiveFormat, string>(InSignatureFormats.Count);
- foreach (var pair in InSignatureFormats)
- {
- InSignatureFormatsReversed.Add(pair.Value, pair.Key);
- }
- }
-
-
-
-
-
-
-
- public static InArchiveFormat FormatByFileName(string fileName, bool reportErrors)
- {
- if (String.IsNullOrEmpty(fileName) && reportErrors)
- {
- throw new ArgumentException("File name is null or empty string!");
- }
- string extension = Path.GetExtension(fileName).Substring(1);
- if (!InExtensionFormats.ContainsKey(extension) && reportErrors)
- {
- throw new ArgumentException("Extension \"" + extension +
- "\" is not a supported archive file name extension.");
- }
- return InExtensionFormats[extension];
- }
- }
- #endif
- }
|