diff --git a/BizHawk.Emulation/BizHawk.Emulation_v4.5.csproj b/BizHawk.Emulation/BizHawk.Emulation_v4.5.csproj
deleted file mode 100644
index 0ff914c21d..0000000000
--- a/BizHawk.Emulation/BizHawk.Emulation_v4.5.csproj
+++ /dev/null
@@ -1,608 +0,0 @@
-
-
-
- Debug
- AnyCPU
- 9.0.30729
- 2.0
- {197D4314-8A9F-49BA-977D-54ACEFAEB6BA}
- Library
- Properties
- BizHawk.Emulation
- BizHawk.Emulation
- v4.5
- 512
-
-
- 3.5
-
- publish\
- true
- Disk
- false
- Foreground
- 7
- Days
- false
- false
- true
- 0
- 1.0.0.%2a
- false
- false
- true
-
-
-
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
- x86
- true
- false
- AllRules.ruleset
- false
-
-
- pdbonly
- true
- bin\Release\
- TRACE;VS2012
- prompt
- 4
- x86
- true
- AllRules.ruleset
- false
- false
-
-
-
- False
- ..\BizHawk.MultiClient\output\dll\EMU7800.dll
-
-
-
- 3.5
-
-
-
-
- 3.5
-
-
- 3.5
-
-
-
-
-
-
- VersionInfo.cs
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
- Code
-
-
-
- Code
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- Code
-
-
- Code
-
-
- Code
-
-
-
-
-
-
-
-
-
- Code
-
-
-
- Code
-
-
- Code
-
-
-
- Code
-
-
- Code
-
-
-
- Code
-
-
- Code
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- False
- .NET Framework 3.5 SP1 Client Profile
- false
-
-
- False
- .NET Framework 3.5 SP1
- true
-
-
- False
- Windows Installer 3.1
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- "$(SolutionDir)subwcrev.bat" "$(ProjectDir)"
- "$(SolutionDir)subwcrev.sh" "$(ProjectDir)"
-
-
-
\ No newline at end of file
diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
index 30ea61310b..f5fc2c0380 100644
--- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
+++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs
@@ -194,9 +194,14 @@ namespace BizHawk.Emulation.Consoles.GB
LibGambatte.gambatte_runfor(GambatteState, VideoBuffer, 160, soundbuff, ref nsamp);
if (rendersound)
+ {
soundbuffcontains = (int)nsamp;
+ ProcessSound();
+ }
else
+ {
soundbuffcontains = 0;
+ }
FrameAdvancePost();
}
@@ -777,7 +782,7 @@ namespace BizHawk.Emulation.Consoles.GB
#region ISoundProvider
public ISoundProvider SoundProvider { get { return null; } }
- public ISyncSoundProvider SyncSoundProvider { get { return dcfilter; } }
+ public ISyncSoundProvider SyncSoundProvider { get { return this; } }
public bool StartAsyncSound() { return false; }
public void EndAsyncSound() { }
@@ -790,21 +795,58 @@ namespace BizHawk.Emulation.Consoles.GB
///
int soundbuffcontains = 0;
- Sound.Utilities.SpeexResampler resampler;
- Sound.Utilities.DCFilter dcfilter;
+ int soundoutbuffcontains = 0;
+
+ short[] soundoutbuff = new short[2048];
+
+ int latchaudio = 0;
+
+ //Sound.Utilities.SpeexResampler resampler;
+ //Sound.Utilities.DCFilter dcfilter;
+
+ Sound.Utilities.BlipBuffer blip;
+
+ void ProcessSound()
+ {
+ for (uint i = 0; i < soundbuffcontains; i++)
+ {
+ int curr = soundbuff[i * 2];
+
+ if (curr != latchaudio)
+ {
+ int diff = latchaudio - curr;
+ latchaudio = curr;
+ blip.AddDelta(i, diff);
+ }
+ }
+ blip.EndFrame((uint)soundbuffcontains);
+
+ soundoutbuffcontains = blip.SamplesAvailable();
+
+ blip.ReadSamples(soundoutbuff, soundoutbuffcontains, true);
+ for (int i = 0; i < soundoutbuffcontains * 2; i += 2)
+ soundoutbuff[i + 1] = soundoutbuff[i];
+
+ soundbuffcontains = 0;
+
+ }
void InitSound()
{
- resampler = new Sound.Utilities.SpeexResampler(2, 2097152, 44100, 2097152, 44100, null, this);
+ //resampler = new Sound.Utilities.SpeexResampler(2, 2097152, 44100, 2097152, 44100, null, this);
//dcfilter = Sound.Utilities.DCFilter.AsISyncSoundProvider(resampler, 65536);
// lowpass filtering on an actual GB was probably pretty aggressive?
- dcfilter = Sound.Utilities.DCFilter.AsISyncSoundProvider(resampler, 2048);
+ //dcfilter = Sound.Utilities.DCFilter.AsISyncSoundProvider(resampler, 2048);
+ blip = new Sound.Utilities.BlipBuffer(1024);
+ blip.SetRates(2097152, 44100);
}
void DisposeSound()
{
- resampler.Dispose();
- resampler = null;
+ blip.Dispose();
+ blip = null;
+ //resampler.Dispose();
+ //resampler = null;
}
public void DiscardSamples()
@@ -814,8 +856,8 @@ namespace BizHawk.Emulation.Consoles.GB
public void GetSamples(out short[] samples, out int nsamp)
{
- samples = soundbuff;
- nsamp = soundbuffcontains;
+ samples = soundoutbuff;
+ nsamp = soundoutbuffcontains;
}
#endregion
diff --git a/BizHawk.Emulation/Database/FirmwareDatabase.cs b/BizHawk.Emulation/Database/FirmwareDatabase.cs
index 82ef8a84a6..d50f79024f 100644
--- a/BizHawk.Emulation/Database/FirmwareDatabase.cs
+++ b/BizHawk.Emulation/Database/FirmwareDatabase.cs
@@ -33,7 +33,6 @@ namespace BizHawk
FirmwareAndOption("300C20DF6731A33952DED8C436F7F186D25D3492", "GBA", "Bios", "gbabios.rom", "Bios");
//FirmwareAndOption("24F67BDEA115A2C847C8813A262502EE1607B7DF", "NDS", "Bios_Arm7", "biosnds7.rom", "ARM7 Bios");
//FirmwareAndOption("BFAAC75F101C135E32E2AAF541DE6B1BE4C8C62D", "NDS", "Bios_Arm9", "biosnds9.rom", "ARM9 Bios");
- FirmwareAndOption("EF66DAD3E7B2B6A86F326765E7DFD7D1A308AD8F", "TI83", "Rom", "ti83_1.rom", "TI-83 Rom");
FirmwareAndOption("5A65B922B562CB1F57DAB51B73151283F0E20C7A", "INTV", "EROM", "erom.bin", "Executive Rom");
FirmwareAndOption("F9608BB4AD1CFE3640D02844C7AD8E0BCD974917", "INTV", "GROM", "grom.bin", "Graphics Rom");
FirmwareAndOption("1D503E56DF85A62FEE696E7618DC5B4E781DF1BB", "C64", "Kernal", "c64-kernal.bin", "Kernal Rom");
@@ -61,6 +60,25 @@ namespace BizHawk
Option("SAT", "E", ss_100a_ue);
Option("SAT", "E", ss_100_j);
Option("SAT", "E", ss_101_j);
+
+ var ti83_102 = File("CE08F6A808701FC6672230A790167EE485157561", "ti83_102.rom", "TI-83 Rom v1.02");
+ var ti83_103 = File("8399E384804D8D29866CAA4C8763D7A61946A467", "ti83_103.rom", "TI-83 Rom v1.03");
+ var ti83_104 = File("33877FF637DC5F4C5388799FD7E2159B48E72893", "ti83_104.rom", "TI-83 Rom v1.04");
+ var ti83_106 = File("3D65C2A1B771CE8E5E5A0476EC1AA9C9CDC0E833", "ti83_106.rom", "TI-83 Rom v1.06");
+ var ti83_107 = File("EF66DAD3E7B2B6A86F326765E7DFD7D1A308AD8F", "ti83_107.rom", "TI-83 Rom v1.07"); //formerly the 1.?? recommended one
+ var ti83_108 = File("9C74F0B61655E9E160E92164DB472AD7EE02B0F8", "ti83_108.rom", "TI-83 Rom v1.08");
+ var ti83p_103 = File("37EAEEB9FB5C18FB494E322B75070E80CC4D858E", "ti83p_103b.rom", "TI-83 Plus Rom v1.03");
+ var ti83p_112 = File("6615DF5554076B6B81BD128BF847D2FF046E556B", "ti83p_112.rom", "TI-83 Plus Rom v1.12");
+
+ Firmware("TI83", "Rom", "TI-83 Rom");
+ Option("TI83", "Rom", ti83_102);
+ Option("TI83", "Rom", ti83_103);
+ Option("TI83", "Rom", ti83_104);
+ Option("TI83", "Rom", ti83_106);
+ Option("TI83", "Rom", ti83_107);
+ Option("TI83", "Rom", ti83_108);
+ Option("TI83", "Rom", ti83p_103);
+ Option("TI83", "Rom", ti83p_112);
}
//adds a defined firmware ID to the database
diff --git a/BizHawk.Util/7z/ArchiveEmulationStreamProxy.cs b/BizHawk.Util/7z/ArchiveEmulationStreamProxy.cs
deleted file mode 100644
index c0bdaed292..0000000000
--- a/BizHawk.Util/7z/ArchiveEmulationStreamProxy.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-using System.IO;
-using System;
-
-namespace SevenZip
-{
- ///
- /// The Stream extension class to emulate the archive part of a stream.
- ///
- internal class ArchiveEmulationStreamProxy : Stream, IDisposable
- {
- ///
- /// Gets the file offset.
- ///
- public int Offset { get; private set; }
-
- ///
- /// The source wrapped stream.
- ///
- public Stream Source { get; private set; }
-
- ///
- /// Initializes a new instance of the ArchiveEmulationStream class.
- ///
- /// The stream to wrap.
- /// The stream offset.
- public ArchiveEmulationStreamProxy(Stream stream, int offset)
- {
- Source = stream;
- Offset = offset;
- Source.Position = offset;
- }
-
- public override bool CanRead
- {
- get { return Source.CanRead; }
- }
-
- public override bool CanSeek
- {
- get { return Source.CanSeek; }
- }
-
- public override bool CanWrite
- {
- get { return Source.CanWrite; }
- }
-
- public override void Flush()
- {
- Source.Flush();
- }
-
- public override long Length
- {
- get { return Source.Length - Offset; }
- }
-
- public override long Position
- {
- get
- {
- return Source.Position - Offset;
- }
- set
- {
- Source.Position = value;
- }
- }
-
- public override int Read(byte[] buffer, int offset, int count)
- {
- return Source.Read(buffer, offset, count);
- }
-
- public override long Seek(long offset, SeekOrigin origin)
- {
- return Source.Seek(origin == SeekOrigin.Begin ? offset + Offset : offset,
- origin) - Offset;
- }
-
- public override void SetLength(long value)
- {
- Source.SetLength(value);
- }
-
- public override void Write(byte[] buffer, int offset, int count)
- {
- Source.Write(buffer, offset, count);
- }
-
- public new void Dispose()
- {
- Source.Dispose();
- }
-
- public override void Close()
- {
- Source.Close();
- }
- }
-}
diff --git a/BizHawk.Util/7z/ArchiveExtractCallback.cs b/BizHawk.Util/7z/ArchiveExtractCallback.cs
deleted file mode 100644
index d9aedc0f7a..0000000000
--- a/BizHawk.Util/7z/ArchiveExtractCallback.cs
+++ /dev/null
@@ -1,602 +0,0 @@
-/* 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;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-#if MONO
-using SevenZip.Mono.COM;
-using System.Runtime.InteropServices;
-#endif
-
-namespace SevenZip
-{
-#if UNMANAGED
- ///
- /// Archive extraction callback to handle the process of unpacking files
- ///
- internal sealed class ArchiveExtractCallback : CallbackBase, IArchiveExtractCallback, ICryptoGetTextPassword,
- IDisposable
- {
- private List _actualIndexes;
- private IInArchive _archive;
-
- ///
- /// For Compressing event.
- ///
- private long _bytesCount;
-
- private long _bytesWritten;
- private long _bytesWrittenOld;
- private string _directory;
-
- ///
- /// Rate of the done work from [0, 1].
- ///
- private float _doneRate;
-
- private SevenZipExtractor _extractor;
- private FakeOutStreamWrapper _fakeStream;
- private uint? _fileIndex;
- private int _filesCount;
- private OutStreamWrapper _fileStream;
- private bool _directoryStructure;
- private int _currentIndex;
-#if !WINCE
- const int MEMORY_PRESSURE = 64 * 1024 * 1024; //64mb seems to be the maximum value
-#endif
- #region Constructors
-
- ///
- /// Initializes a new instance of the ArchiveExtractCallback class
- ///
- /// IInArchive interface for the archive
- /// Directory where files are to be unpacked to
- /// The archive files count'
- /// The owner of the callback
- /// The list of actual indexes (solid archives support)
- /// The value indicating whether to preserve directory structure of extracted files.
- public ArchiveExtractCallback(IInArchive archive, string directory, int filesCount, bool directoryStructure,
- List actualIndexes, SevenZipExtractor extractor)
- {
- Init(archive, directory, filesCount, directoryStructure, actualIndexes, extractor);
- }
-
- ///
- /// Initializes a new instance of the ArchiveExtractCallback class
- ///
- /// IInArchive interface for the archive
- /// Directory where files are to be unpacked to
- /// The archive files count
- /// Password for the archive
- /// The owner of the callback
- /// The list of actual indexes (solid archives support)
- /// The value indicating whether to preserve directory structure of extracted files.
- public ArchiveExtractCallback(IInArchive archive, string directory, int filesCount, bool directoryStructure,
- List actualIndexes, string password, SevenZipExtractor extractor)
- : base(password)
- {
- Init(archive, directory, filesCount, directoryStructure, actualIndexes, extractor);
- }
-
- ///
- /// Initializes a new instance of the ArchiveExtractCallback class
- ///
- /// IInArchive interface for the archive
- /// The stream where files are to be unpacked to
- /// The archive files count
- /// The file index for the stream
- /// The owner of the callback
- public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex,
- SevenZipExtractor extractor)
- {
- Init(archive, stream, filesCount, fileIndex, extractor);
- }
-
- ///
- /// Initializes a new instance of the ArchiveExtractCallback class
- ///
- /// IInArchive interface for the archive
- /// The stream where files are to be unpacked to
- /// The archive files count
- /// The file index for the stream
- /// Password for the archive
- /// The owner of the callback
- public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex, string password,
- SevenZipExtractor extractor)
- : base(password)
- {
- Init(archive, stream, filesCount, fileIndex, extractor);
- }
-
- private void Init(IInArchive archive, string directory, int filesCount, bool directoryStructure,
- List actualIndexes, SevenZipExtractor extractor)
- {
- CommonInit(archive, filesCount, extractor);
- _directory = directory;
- _actualIndexes = actualIndexes;
- _directoryStructure = directoryStructure;
- if (!directory.EndsWith("" + Path.DirectorySeparatorChar, StringComparison.CurrentCulture))
- {
- _directory += Path.DirectorySeparatorChar;
- }
- }
-
- private void Init(IInArchive archive, Stream stream, int filesCount, uint fileIndex, SevenZipExtractor extractor)
- {
- CommonInit(archive, filesCount, extractor);
- _fileStream = new OutStreamWrapper(stream, false);
- _fileStream.BytesWritten += IntEventArgsHandler;
- _fileIndex = fileIndex;
- }
-
- private void CommonInit(IInArchive archive, int filesCount, SevenZipExtractor extractor)
- {
- _archive = archive;
- _filesCount = filesCount;
- _fakeStream = new FakeOutStreamWrapper();
- _fakeStream.BytesWritten += IntEventArgsHandler;
- _extractor = extractor;
-#if !WINCE
- GC.AddMemoryPressure(MEMORY_PRESSURE);
-#endif
- }
- #endregion
-
- #region Events
-
- ///
- /// Occurs when a new file is going to be unpacked
- ///
- /// Occurs when 7-zip engine requests for an output stream for a new file to unpack in
- public event EventHandler FileExtractionStarted;
-
- ///
- /// Occurs when a file has been successfully unpacked
- ///
- public event EventHandler FileExtractionFinished;
-
- ///
- /// Occurs when the archive is opened and 7-zip sends the size of unpacked data
- ///
- public event EventHandler Open;
-
- ///
- /// Occurs when the extraction is performed
- ///
- public event EventHandler Extracting;
-
- ///
- /// Occurs during the extraction when a file already exists
- ///
- public event EventHandler FileExists;
-
- private void OnFileExists(FileOverwriteEventArgs e)
- {
- if (FileExists != null)
- {
- FileExists(this, e);
- }
- }
-
- private void OnOpen(OpenEventArgs e)
- {
- if (Open != null)
- {
- Open(this, e);
- }
- }
-
- private void OnFileExtractionStarted(FileInfoEventArgs e)
- {
- if (FileExtractionStarted != null)
- {
- FileExtractionStarted(this, e);
- }
- }
-
- private void OnFileExtractionFinished(FileInfoEventArgs e)
- {
- if (FileExtractionFinished != null)
- {
- FileExtractionFinished(this, e);
- }
- }
-
- private void OnExtracting(ProgressEventArgs e)
- {
- if (Extracting != null)
- {
- Extracting(this, e);
- }
- }
-
- private void IntEventArgsHandler(object sender, IntEventArgs e)
- {
- var pold = (int)((_bytesWrittenOld * 100) / _bytesCount);
- _bytesWritten += e.Value;
- var pnow = (int)((_bytesWritten * 100) / _bytesCount);
- if (pnow > pold)
- {
- if (pnow > 100)
- {
- pold = pnow = 0;
- }
- _bytesWrittenOld = _bytesWritten;
- OnExtracting(new ProgressEventArgs((byte)pnow, (byte)(pnow - pold)));
- }
- }
-
- #endregion
-
- #region IArchiveExtractCallback Members
-
- ///
- /// Gives the size of the unpacked archive files
- ///
- /// Size of the unpacked archive files (in bytes)
- public void SetTotal(ulong total)
- {
- _bytesCount = (long)total;
- OnOpen(new OpenEventArgs(total));
- }
-
- public void SetCompleted(ref ulong completeValue) { }
-
- ///
- /// Sets output stream for writing unpacked data
- ///
- /// Current file index
- /// Output stream pointer
- /// Extraction mode
- /// 0 if OK
- public int GetStream(uint index, out
-#if !MONO
- ISequentialOutStream
-#else
- HandleRef
-#endif
- outStream, AskMode askExtractMode)
- {
-#if !MONO
- outStream = null;
-#else
- outStream = new System.Runtime.InteropServices.HandleRef(null, IntPtr.Zero);
-#endif
- if (Canceled)
- {
- return -1;
- }
- _currentIndex = (int)index;
- if (askExtractMode == AskMode.Extract)
- {
- var fileName = _directory;
- if (!_fileIndex.HasValue)
- {
- #region Extraction to a file
-
- if (_actualIndexes == null || _actualIndexes.Contains(index))
- {
- var data = new PropVariant();
- _archive.GetProperty(index, ItemPropId.Path, ref data);
- string entryName = NativeMethods.SafeCast(data, "");
-
- #region Get entryName
-
- if (String.IsNullOrEmpty(entryName))
- {
- if (_filesCount == 1)
- {
- var archName = Path.GetFileName(_extractor.FileName);
- archName = archName.Substring(0, archName.LastIndexOf('.'));
- if (!archName.EndsWith(".tar", StringComparison.OrdinalIgnoreCase))
- {
- archName += ".tar";
- }
- entryName = archName;
- }
- else
- {
- entryName = "[no name] " + index.ToString(CultureInfo.InvariantCulture);
- }
- }
-
- #endregion
-
- fileName = Path.Combine(_directory, _directoryStructure? entryName : Path.GetFileName(entryName));
- _archive.GetProperty(index, ItemPropId.IsDirectory, ref data);
- try
- {
- fileName = ValidateFileName(fileName);
- }
- catch (Exception e)
- {
- AddException(e);
- goto FileExtractionStartedLabel;
- }
- if (!NativeMethods.SafeCast(data, false))
- {
- #region Branch
-
- _archive.GetProperty(index, ItemPropId.LastWriteTime, ref data);
- var time = NativeMethods.SafeCast(data, DateTime.MinValue);
- if (File.Exists(fileName))
- {
- var fnea = new FileOverwriteEventArgs(fileName);
- OnFileExists(fnea);
- if (fnea.Cancel)
- {
- Canceled = true;
- return -1;
- }
- if (String.IsNullOrEmpty(fnea.FileName))
- {
-#if !MONO
- outStream = _fakeStream;
-#else
- outStream = _fakeStream.Handle;
-#endif
- goto FileExtractionStartedLabel;
- }
- fileName = fnea.FileName;
- }
- try
- {
- _fileStream = new OutStreamWrapper(File.Create(fileName), fileName, time, true);
- }
- catch (Exception e)
- {
- if (e is FileNotFoundException)
- {
- AddException(
- new IOException("The file \"" + fileName +
- "\" was not extracted due to the File.Create fail."));
- }
- else
- {
- AddException(e);
- }
- outStream = _fakeStream;
- goto FileExtractionStartedLabel;
- }
- _fileStream.BytesWritten += IntEventArgsHandler;
- outStream = _fileStream;
-
- #endregion
- }
- else
- {
- #region Branch
-
- if (!Directory.Exists(fileName))
- {
- try
- {
- Directory.CreateDirectory(fileName);
- }
- catch (Exception e)
- {
- AddException(e);
- }
- outStream = _fakeStream;
- }
-
- #endregion
- }
- }
- else
- {
- outStream = _fakeStream;
- }
-
- #endregion
- }
- else
- {
- #region Extraction to a stream
-
- if (index == _fileIndex)
- {
- outStream = _fileStream;
- _fileIndex = null;
- }
- else
- {
- outStream = _fakeStream;
- }
-
- #endregion
- }
-
- FileExtractionStartedLabel:
- _doneRate += 1.0f / _filesCount;
- var iea = new FileInfoEventArgs(
- _extractor.ArchiveFileData[(int)index], PercentDoneEventArgs.ProducePercentDone(_doneRate));
- OnFileExtractionStarted(iea);
- if (iea.Cancel)
- {
- if (!String.IsNullOrEmpty(fileName))
- {
- _fileStream.Dispose();
- if (File.Exists(fileName))
- {
- try
- {
- File.Delete(fileName);
- }
- catch (Exception e)
- {
- AddException(e);
- }
- }
- }
- Canceled = true;
- return -1;
- }
- }
- return 0;
- }
-
- public void PrepareOperation(AskMode askExtractMode) { }
-
- ///
- /// Called when the archive was extracted
- ///
- ///
- public void SetOperationResult(OperationResult operationResult)
- {
- if (operationResult != OperationResult.Ok && ReportErrors)
- {
- switch (operationResult)
- {
- case OperationResult.CrcError:
- AddException(new ExtractionFailedException("File is corrupted. Crc check has failed."));
- break;
- case OperationResult.DataError:
- AddException(new ExtractionFailedException("File is corrupted. Data error has occured."));
- break;
- case OperationResult.UnsupportedMethod:
- AddException(new ExtractionFailedException("Unsupported method error has occured."));
- break;
- }
- }
- else
- {
- if (_fileStream != null && !_fileIndex.HasValue)
- {
- try
- {
- _fileStream.BytesWritten -= IntEventArgsHandler;
- _fileStream.Dispose();
- }
- catch (ObjectDisposedException) { }
- _fileStream = null;
- GC.Collect();
- GC.WaitForPendingFinalizers();
- }
- var iea = new FileInfoEventArgs(
- _extractor.ArchiveFileData[_currentIndex], PercentDoneEventArgs.ProducePercentDone(_doneRate));
- OnFileExtractionFinished(iea);
- if (iea.Cancel)
- {
- Canceled = true;
- }
- }
- }
-
- #endregion
-
- #region ICryptoGetTextPassword Members
-
- ///
- /// Sets password for the archive
- ///
- /// Password for the archive
- /// Zero if everything is OK
- public int CryptoGetTextPassword(out string password)
- {
- password = Password;
- return 0;
- }
-
- #endregion
-
- #region IDisposable Members
-
- public void Dispose()
- {
-#if !WINCE
- GC.RemoveMemoryPressure(MEMORY_PRESSURE);
-#endif
- if (_fileStream != null)
- {
- try
- {
- _fileStream.Dispose();
- }
- catch (ObjectDisposedException) { }
- _fileStream = null;
- }
- if (_fakeStream != null)
- {
- try
- {
- _fakeStream.Dispose();
- }
- catch (ObjectDisposedException) { }
- _fakeStream = null;
- }
- }
-
- #endregion
-
- ///
- /// Validates the file name and ensures that the directory to the file name is valid and creates intermediate directories if necessary
- ///
- /// File name
- /// The valid file name
- private static string ValidateFileName(string fileName)
- {
- if (String.IsNullOrEmpty(fileName))
- {
- throw new SevenZipArchiveException("some archive name is null or empty.");
- }
- var splittedFileName = new List(fileName.Split(Path.DirectorySeparatorChar));
-#if !WINCE
- foreach (char chr in Path.GetInvalidFileNameChars())
- {
- for (int i = 0; i < splittedFileName.Count; i++)
- {
- if (chr == ':' && i == 0)
- {
- continue;
- }
- if (String.IsNullOrEmpty(splittedFileName[i]))
- {
- continue;
- }
- while (splittedFileName[i].IndexOf(chr) > -1)
- {
- splittedFileName[i] = splittedFileName[i].Replace(chr, '_');
- }
- }
- }
-#endif
- if (fileName.StartsWith(new string(Path.DirectorySeparatorChar, 2),
- StringComparison.CurrentCultureIgnoreCase))
- {
- splittedFileName.RemoveAt(0);
- splittedFileName.RemoveAt(0);
- splittedFileName[0] = new string(Path.DirectorySeparatorChar, 2) + splittedFileName[0];
- }
- if (splittedFileName.Count > 2)
- {
- string tfn = splittedFileName[0];
- for (int i = 1; i < splittedFileName.Count - 1; i++)
- {
- tfn += Path.DirectorySeparatorChar + splittedFileName[i];
- if (!Directory.Exists(tfn))
- {
- Directory.CreateDirectory(tfn);
- }
- }
- }
- return String.Join(new string(Path.DirectorySeparatorChar, 1), splittedFileName.ToArray());
- }
- }
-#endif
-}
diff --git a/BizHawk.Util/7z/ArchiveOpenCallback.cs b/BizHawk.Util/7z/ArchiveOpenCallback.cs
deleted file mode 100644
index d870be30bb..0000000000
--- a/BizHawk.Util/7z/ArchiveOpenCallback.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-/* 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;
-using System.Collections.Generic;
-using System.IO;
-using System.Runtime.InteropServices;
-#if MONO
-using SevenZip.Mono;
-using SevenZip.Mono.COM;
-#endif
-
-namespace SevenZip
-{
- #if UNMANAGED
- ///
- /// Callback to handle the archive opening
- ///
- internal sealed class ArchiveOpenCallback : CallbackBase, IArchiveOpenCallback, IArchiveOpenVolumeCallback,
- ICryptoGetTextPassword, IDisposable
- {
- private FileInfo _fileInfo;
- private Dictionary _wrappers =
- new Dictionary();
- public readonly List VolumeFileNames = new List();
-
- ///
- /// Performs the common initialization.
- ///
- /// Volume file name.
- private void Init(string fileName)
- {
- if (!String.IsNullOrEmpty(fileName))
- {
- _fileInfo = new FileInfo(fileName);
- VolumeFileNames.Add(fileName);
- }
- }
-
- ///
- /// Initializes a new instance of the ArchiveOpenCallback class.
- ///
- /// The archive file name.
- public ArchiveOpenCallback(string fileName)
- {
- Init(fileName);
- }
-
- ///
- /// Initializes a new instance of the ArchiveOpenCallback class.
- ///
- /// The archive file name.
- /// Password for the archive.
- public ArchiveOpenCallback(string fileName, string password) : base(password)
- {
- Init(fileName);
- }
-
- #region IArchiveOpenCallback Members
-
- public void SetTotal(IntPtr files, IntPtr bytes) {}
-
- public void SetCompleted(IntPtr files, IntPtr bytes) {}
-
- #endregion
-
- #region IArchiveOpenVolumeCallback Members
-
- public int GetProperty(ItemPropId propId, ref PropVariant value)
- {
- switch (propId)
- {
- case ItemPropId.Name:
- value.VarType = VarEnum.VT_BSTR;
- value.Value = Marshal.StringToBSTR(_fileInfo.FullName);
- break;
- case ItemPropId.IsDirectory:
- value.VarType = VarEnum.VT_BOOL;
- value.UInt64Value = (byte) (_fileInfo.Attributes & FileAttributes.Directory);
- break;
- case ItemPropId.Size:
- value.VarType = VarEnum.VT_UI8;
- value.UInt64Value = (UInt64) _fileInfo.Length;
- break;
- case ItemPropId.Attributes:
- value.VarType = VarEnum.VT_UI4;
- value.UInt32Value = (uint) _fileInfo.Attributes;
- break;
- case ItemPropId.CreationTime:
- value.VarType = VarEnum.VT_FILETIME;
- value.Int64Value = _fileInfo.CreationTime.ToFileTime();
- break;
- case ItemPropId.LastAccessTime:
- value.VarType = VarEnum.VT_FILETIME;
- value.Int64Value = _fileInfo.LastAccessTime.ToFileTime();
- break;
- case ItemPropId.LastWriteTime:
- value.VarType = VarEnum.VT_FILETIME;
- value.Int64Value = _fileInfo.LastWriteTime.ToFileTime();
- break;
- }
- return 0;
- }
-
- public int GetStream(string name, out IInStream inStream)
- {
- if (!File.Exists(name))
- {
- name = Path.Combine(Path.GetDirectoryName(_fileInfo.FullName), name);
- if (!File.Exists(name))
- {
- inStream = null;
- AddException(new FileNotFoundException("The volume \"" + name + "\" was not found. Extraction can be impossible."));
- return 1;
- }
- }
- VolumeFileNames.Add(name);
- if (_wrappers.ContainsKey(name))
- {
- inStream = _wrappers[name];
- }
- else
- {
- try
- {
- var wrapper = new InStreamWrapper(
- new FileStream(name, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true);
- _wrappers.Add(name, wrapper);
- inStream = wrapper;
- }
- catch (Exception)
- {
- AddException(new FileNotFoundException("Failed to open the volume \"" + name + "\". Extraction is impossible."));
- inStream = null;
- return 1;
- }
- }
- return 0;
- }
-
- #endregion
-
- #region ICryptoGetTextPassword Members
-
- ///
- /// Sets password for the archive
- ///
- /// Password for the archive
- /// Zero if everything is OK
- public int CryptoGetTextPassword(out string password)
- {
- password = Password;
- return 0;
- }
-
- #endregion
-
- #region IDisposable Members
-
- public void Dispose()
- {
- if (_wrappers != null)
- {
- foreach (InStreamWrapper wrap in _wrappers.Values)
- {
- wrap.Dispose();
- }
- _wrappers = null;
- }
-#if MONO
- libp7zInvokerRaw.FreeObject(Handle);
-#endif
- GC.SuppressFinalize(this);
- }
-
- #endregion
- }
-#endif
-}
diff --git a/BizHawk.Util/7z/ArchiveUpdateCallback.cs b/BizHawk.Util/7z/ArchiveUpdateCallback.cs
deleted file mode 100644
index 9e8be21990..0000000000
--- a/BizHawk.Util/7z/ArchiveUpdateCallback.cs
+++ /dev/null
@@ -1,806 +0,0 @@
-/* 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;
-using System.Collections.Generic;
-using System.IO;
-using System.Runtime.InteropServices;
-#if MONO
-using SevenZip.Mono.COM;
-#endif
-
-namespace SevenZip
-{
-#if UNMANAGED
-#if COMPRESS
- ///
- /// Archive update callback to handle the process of packing files
- ///
- internal sealed class ArchiveUpdateCallback : CallbackBase, IArchiveUpdateCallback, ICryptoGetTextPassword2,
- IDisposable
- {
- #region Fields
- ///
- /// _files.Count if do not count directories
- ///
- private int _actualFilesCount;
-
- ///
- /// For Compressing event.
- ///
- private long _bytesCount;
-
- private long _bytesWritten;
- private long _bytesWrittenOld;
- private SevenZipCompressor _compressor;
-
- ///
- /// No directories.
- ///
- private bool _directoryStructure;
-
- ///
- /// Rate of the done work from [0, 1]
- ///
- private float _doneRate;
-
- ///
- /// The names of the archive entries
- ///
- private string[] _entries;
-
- ///
- /// Array of files to pack
- ///
- private FileInfo[] _files;
-
- private InStreamWrapper _fileStream;
-
- private uint _indexInArchive;
- private uint _indexOffset;
-
- ///
- /// Common root of file names length.
- ///
- private int _rootLength;
-
- ///
- /// Input streams to be compressed.
- ///
- private Stream[] _streams;
-
- private UpdateData _updateData;
- private List _wrappersToDispose;
-
- ///
- /// Gets or sets the default item name used in MemoryStream compression.
- ///
- public string DefaultItemName { private get; set; }
-
- ///
- /// Gets or sets the value indicating whether to compress as fast as possible, without calling events.
- ///
- public bool FastCompression { private get; set; }
-#if !WINCE
- private int _memoryPressure;
-#endif
- #endregion
-
- #region Constructors
-
- ///
- /// Initializes a new instance of the ArchiveUpdateCallback class
- ///
- /// Array of files to pack
- /// Common file names root length
- /// The owner of the callback
- /// The compression parameters.
- /// Preserve directory structure.
- public ArchiveUpdateCallback(
- FileInfo[] files, int rootLength,
- SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- {
- Init(files, rootLength, compressor, updateData, directoryStructure);
- }
-
- ///
- /// Initializes a new instance of the ArchiveUpdateCallback class
- ///
- /// Array of files to pack
- /// Common file names root length
- /// The archive password
- /// The owner of the callback
- /// The compression parameters.
- /// Preserve directory structure.
- public ArchiveUpdateCallback(
- FileInfo[] files, int rootLength, string password,
- SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- : base(password)
- {
- Init(files, rootLength, compressor, updateData, directoryStructure);
- }
-
- ///
- /// Initializes a new instance of the ArchiveUpdateCallback class
- ///
- /// The input stream
- /// The owner of the callback
- /// The compression parameters.
- /// Preserve directory structure.
- public ArchiveUpdateCallback(
- Stream stream, SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- {
- Init(stream, compressor, updateData, directoryStructure);
- }
-
- ///
- /// Initializes a new instance of the ArchiveUpdateCallback class
- ///
- /// The input stream
- /// The archive password
- /// The owner of the callback
- /// The compression parameters.
- /// Preserve directory structure.
- public ArchiveUpdateCallback(
- Stream stream, string password, SevenZipCompressor compressor, UpdateData updateData,
- bool directoryStructure)
- : base(password)
- {
- Init(stream, compressor, updateData, directoryStructure);
- }
-
- ///
- /// Initializes a new instance of the ArchiveUpdateCallback class
- ///
- /// Dictionary<file stream, name of the archive entry>
- /// The owner of the callback
- /// The compression parameters.
- /// Preserve directory structure.
- public ArchiveUpdateCallback(
- Dictionary streamDict,
- SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- {
- Init(streamDict, compressor, updateData, directoryStructure);
- }
-
- ///
- /// Initializes a new instance of the ArchiveUpdateCallback class
- ///
- /// Dictionary<file stream, name of the archive entry>
- /// The archive password
- /// The owner of the callback
- /// The compression parameters.
- /// Preserve directory structure.
- public ArchiveUpdateCallback(
- Dictionary streamDict, string password,
- SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- : base(password)
- {
- Init(streamDict, compressor, updateData, directoryStructure);
- }
-
- private void CommonInit(SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- {
- _compressor = compressor;
- _indexInArchive = updateData.FilesCount;
- _indexOffset = updateData.Mode != InternalCompressionMode.Append ? 0 : _indexInArchive;
- if (_compressor.ArchiveFormat == OutArchiveFormat.Zip)
- {
- _wrappersToDispose = new List();
- }
- _updateData = updateData;
- _directoryStructure = directoryStructure;
- DefaultItemName = "default";
- }
-
- private void Init(
- FileInfo[] files, int rootLength, SevenZipCompressor compressor,
- UpdateData updateData, bool directoryStructure)
- {
- _files = files;
- _rootLength = rootLength;
- if (files != null)
- {
- foreach (var fi in files)
- {
- if (fi.Exists)
- {
- _bytesCount += fi.Length;
- if ((fi.Attributes & FileAttributes.Directory) == 0)
- {
- _actualFilesCount++;
- }
- }
- }
- }
- CommonInit(compressor, updateData, directoryStructure);
- }
-
- private void Init(
- Stream stream, SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- {
- _fileStream = new InStreamWrapper(stream, false);
- _fileStream.BytesRead += IntEventArgsHandler;
- _actualFilesCount = 1;
- try
- {
- _bytesCount = stream.Length;
- }
- catch (NotSupportedException)
- {
- _bytesCount = -1;
- }
- try
- {
- stream.Seek(0, SeekOrigin.Begin);
- }
- catch (NotSupportedException)
- {
- _bytesCount = -1;
- }
- CommonInit(compressor, updateData, directoryStructure);
- }
-
- private void Init(
- Dictionary streamDict,
- SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
- {
- _streams = new Stream[streamDict.Count];
- streamDict.Values.CopyTo(_streams, 0);
- _entries = new string[streamDict.Count];
- streamDict.Keys.CopyTo(_entries, 0);
- _actualFilesCount = streamDict.Count;
- foreach (Stream str in _streams)
- {
- if (str != null)
- {
- _bytesCount += str.Length;
- }
- }
- CommonInit(compressor, updateData, directoryStructure);
- }
-
- #endregion
-
- ///
- /// Gets or sets the dictionary size.
- ///
- public float DictionarySize
- {
- set
- {
-#if !WINCE
- _memoryPressure = (int)(value * 1024 * 1024);
- GC.AddMemoryPressure(_memoryPressure);
-#endif
- }
- }
-
- ///
- /// Raises events for the GetStream method.
- ///
- /// The current item index.
- /// True if not cancelled; otherwise, false.
- private bool EventsForGetStream(uint index)
- {
- if (!FastCompression)
- {
- if (_fileStream != null)
- {
- _fileStream.BytesRead += IntEventArgsHandler;
- }
- _doneRate += 1.0f / _actualFilesCount;
- var fiea = new FileNameEventArgs(_files != null? _files[index].Name : _entries[index],
- PercentDoneEventArgs.ProducePercentDone(_doneRate));
- OnFileCompression(fiea);
- if (fiea.Cancel)
- {
- Canceled = true;
- return false;
- }
- }
- return true;
- }
-
- #region Events
-
- ///
- /// Occurs when the next file is going to be packed.
- ///
- /// Occurs when 7-zip engine requests for an input stream for the next file to pack it
- public event EventHandler FileCompressionStarted;
-
- ///
- /// Occurs when data are being compressed.
- ///
- public event EventHandler Compressing;
-
- ///
- /// Occurs when the current file was compressed.
- ///
- public event EventHandler FileCompressionFinished;
-
- private void OnFileCompression(FileNameEventArgs e)
- {
- if (FileCompressionStarted != null)
- {
- FileCompressionStarted(this, e);
- }
- }
-
- private void OnCompressing(ProgressEventArgs e)
- {
- if (Compressing != null)
- {
- Compressing(this, e);
- }
- }
-
- private void OnFileCompressionFinished(EventArgs e)
- {
- if (FileCompressionFinished != null)
- {
- FileCompressionFinished(this, e);
- }
- }
-
- #endregion
-
- #region IArchiveUpdateCallback Members
-
- public void SetTotal(ulong total) {}
-
- public void SetCompleted(ref ulong completeValue) {}
-
- public int GetUpdateItemInfo(uint index, ref int newData, ref int newProperties, ref uint indexInArchive)
- {
- switch (_updateData.Mode)
- {
- case InternalCompressionMode.Create:
- newData = 1;
- newProperties = 1;
- indexInArchive = UInt32.MaxValue;
- break;
- case InternalCompressionMode.Append:
- if (index < _indexInArchive)
- {
- newData = 0;
- newProperties = 0;
- indexInArchive = index;
- }
- else
- {
- newData = 1;
- newProperties = 1;
- indexInArchive = UInt32.MaxValue;
- }
- break;
- case InternalCompressionMode.Modify:
- newData = 0;
- newProperties = Convert.ToInt32(_updateData.FileNamesToModify.ContainsKey((int)index)
- && _updateData.FileNamesToModify[(int)index] != null);
- if (_updateData.FileNamesToModify.ContainsKey((int)index)
- && _updateData.FileNamesToModify[(int)index] == null)
- {
- indexInArchive = (UInt32)_updateData.ArchiveFileData.Count;
- foreach (KeyValuePair pairModification in _updateData.FileNamesToModify)
- if ((pairModification.Key <= index) && (pairModification.Value == null))
- {
- do
- {
- indexInArchive--;
- }
- while ((indexInArchive > 0) && _updateData.FileNamesToModify.ContainsKey((Int32)indexInArchive)
- && (_updateData.FileNamesToModify[(Int32)indexInArchive] == null));
- }
- }
- else
- {
- indexInArchive = index;
- }
- break;
- }
- return 0;
- }
-
- public int GetProperty(uint index, ItemPropId propID, ref PropVariant value)
- {
- index -= _indexOffset;
- try
- {
- switch (propID)
- {
- case ItemPropId.IsAnti:
- value.VarType = VarEnum.VT_BOOL;
- value.UInt64Value = 0;
- break;
- case ItemPropId.Path:
- #region Path
-
- value.VarType = VarEnum.VT_BSTR;
- string val = DefaultItemName;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- if (_files == null)
- {
- if (_entries != null)
- {
- val = _entries[index];
- }
- }
- else
- {
- if (_directoryStructure)
- {
- if (_rootLength > 0)
- {
- val = _files[index].FullName.Substring(_rootLength);
- }
- else
- {
- val = _files[index].FullName[0] + _files[index].FullName.Substring(2);
- }
- }
- else
- {
- val = _files[index].Name;
- }
- }
- }
- else
- {
- val = _updateData.FileNamesToModify[(int) index];
- }
- value.Value = Marshal.StringToBSTR(val);
- #endregion
- break;
- case ItemPropId.IsDirectory:
- value.VarType = VarEnum.VT_BOOL;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- if (_files == null)
- {
- if (_streams == null)
- {
- value.UInt64Value = 0;
- }
- else
- {
- value.UInt64Value = (ulong)(_streams[index] == null ? 1 : 0);
- }
- }
- else
- {
- value.UInt64Value = (byte)(_files[index].Attributes & FileAttributes.Directory);
- }
- }
- else
- {
- value.UInt64Value = Convert.ToUInt64(_updateData.ArchiveFileData[(int) index].IsDirectory);
- }
- break;
- case ItemPropId.Size:
- #region Size
-
- value.VarType = VarEnum.VT_UI8;
- UInt64 size;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- if (_files == null)
- {
- if (_streams == null)
- {
- size = _bytesCount > 0 ? (ulong) _bytesCount : 0;
- }
- else
- {
- size = (ulong) (_streams[index] == null? 0 : _streams[index].Length);
- }
- }
- else
- {
- size = (_files[index].Attributes & FileAttributes.Directory) == 0
- ? (ulong) _files[index].Length
- : 0;
- }
- }
- else
- {
- size = _updateData.ArchiveFileData[(int) index].Size;
- }
- value.UInt64Value = size;
-
- #endregion
- break;
- case ItemPropId.Attributes:
- value.VarType = VarEnum.VT_UI4;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- if (_files == null)
- {
- if (_streams == null)
- {
- value.UInt32Value = (uint)FileAttributes.Normal;
- }
- else
- {
- value.UInt32Value = (uint)(_streams[index] == null ? FileAttributes.Directory : FileAttributes.Normal);
- }
- }
- else
- {
- value.UInt32Value = (uint) _files[index].Attributes;
- }
- }
- else
- {
- value.UInt32Value = _updateData.ArchiveFileData[(int) index].Attributes;
- }
- break;
- #region Times
- case ItemPropId.CreationTime:
- value.VarType = VarEnum.VT_FILETIME;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- value.Int64Value = _files == null
- ? DateTime.Now.ToFileTime()
- : _files[index].CreationTime.ToFileTime();
- }
- else
- {
- value.Int64Value = _updateData.ArchiveFileData[(int) index].CreationTime.ToFileTime();
- }
- break;
- case ItemPropId.LastAccessTime:
- value.VarType = VarEnum.VT_FILETIME;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- value.Int64Value = _files == null
- ? DateTime.Now.ToFileTime()
- : _files[index].LastAccessTime.ToFileTime();
- }
- else
- {
- value.Int64Value = _updateData.ArchiveFileData[(int) index].LastAccessTime.ToFileTime();
- }
- break;
- case ItemPropId.LastWriteTime:
- value.VarType = VarEnum.VT_FILETIME;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- value.Int64Value = _files == null
- ? DateTime.Now.ToFileTime()
- : _files[index].LastWriteTime.ToFileTime();
- }
- else
- {
- value.Int64Value = _updateData.ArchiveFileData[(int) index].LastWriteTime.ToFileTime();
- }
- break;
- #endregion
- case ItemPropId.Extension:
- #region Extension
-
- value.VarType = VarEnum.VT_BSTR;
- if (_updateData.Mode != InternalCompressionMode.Modify)
- {
- try
- {
- val = _files != null
- ? _files[index].Extension.Substring(1)
- : _entries == null
- ? ""
- : Path.GetExtension(_entries[index]);
- value.Value = Marshal.StringToBSTR(val);
- }
- catch (ArgumentException)
- {
- value.Value = Marshal.StringToBSTR("");
- }
- }
- else
- {
- val = Path.GetExtension(_updateData.ArchiveFileData[(int) index].FileName);
- value.Value = Marshal.StringToBSTR(val);
- }
-
- #endregion
- break;
- }
- }
- catch (Exception e)
- {
- AddException(e);
- }
- return 0;
- }
-
- ///
- /// Gets the stream for 7-zip library.
- ///
- /// File index
- /// Input file stream
- /// Zero if Ok
- public int GetStream(uint index, out
-#if !MONO
- ISequentialInStream
-#else
- HandleRef
-#endif
- inStream)
- {
- index -= _indexOffset;
- if (_files != null)
- {
- _fileStream = null;
- try
- {
- if (File.Exists(_files[index].FullName))
- {
- _fileStream = new InStreamWrapper(
- new FileStream(_files[index].FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite),
- true);
- }
- }
- catch (Exception e)
- {
- AddException(e);
- inStream = null;
- return -1;
- }
- inStream = _fileStream;
- if (!EventsForGetStream(index))
- {
- return -1;
- }
- }
- else
- {
- if (_streams == null)
- {
- inStream = _fileStream;
- }
- else
- {
- _fileStream = new InStreamWrapper(_streams[index], true);
- inStream = _fileStream;
- if (!EventsForGetStream(index))
- {
- return -1;
- }
- }
- }
- return 0;
- }
-
- public long EnumProperties(IntPtr enumerator)
- {
- //Not implemented HRESULT
- return 0x80004001L;
- }
-
- public void SetOperationResult(OperationResult operationResult)
- {
- if (operationResult != OperationResult.Ok && ReportErrors)
- {
- switch (operationResult)
- {
- case OperationResult.CrcError:
- AddException(new ExtractionFailedException("File is corrupted. Crc check has failed."));
- break;
- case OperationResult.DataError:
- AddException(new ExtractionFailedException("File is corrupted. Data error has occured."));
- break;
- case OperationResult.UnsupportedMethod:
- AddException(new ExtractionFailedException("Unsupported method error has occured."));
- break;
- }
- }
- if (_fileStream != null)
- {
-
- _fileStream.BytesRead -= IntEventArgsHandler;
- //Specific Zip implementation - can not Dispose files for Zip.
- if (_compressor.ArchiveFormat != OutArchiveFormat.Zip)
- {
- try
- {
- _fileStream.Dispose();
- }
- catch (ObjectDisposedException) {}
- }
- else
- {
- _wrappersToDispose.Add(_fileStream);
- }
- _fileStream = null;
- GC.Collect();
- // Issue #6987
- //GC.WaitForPendingFinalizers();
- }
- OnFileCompressionFinished(EventArgs.Empty);
- }
-
- #endregion
-
- #region ICryptoGetTextPassword2 Members
-
- public int CryptoGetTextPassword2(ref int passwordIsDefined, out string password)
- {
- passwordIsDefined = String.IsNullOrEmpty(Password) ? 0 : 1;
- password = Password;
- return 0;
- }
-
- #endregion
-
- #region IDisposable Members
-
- public void Dispose()
- {
-#if !WINCE
- GC.RemoveMemoryPressure(_memoryPressure);
-#endif
- if (_fileStream != null)
- {
- try
- {
- _fileStream.Dispose();
- }
- catch (ObjectDisposedException) {}
- }
- if (_wrappersToDispose != null)
- {
- foreach (var wrapper in _wrappersToDispose)
- {
- try
- {
- wrapper.Dispose();
- }
- catch (ObjectDisposedException) {}
- }
- }
- GC.SuppressFinalize(this);
- }
-
- #endregion
-
- private void IntEventArgsHandler(object sender, IntEventArgs e)
- {
- lock (this)
- {
- var pold = (byte) ((_bytesWrittenOld*100)/_bytesCount);
- _bytesWritten += e.Value;
- byte pnow;
- if (_bytesCount < _bytesWritten) //Holy shit, this check for ZIP is golden
- {
- pnow = 100;
- }
- else
- {
- pnow = (byte)((_bytesWritten * 100) / _bytesCount);
- }
- if (pnow > pold)
- {
- _bytesWrittenOld = _bytesWritten;
- OnCompressing(new ProgressEventArgs(pnow, (byte) (pnow - pold)));
- }
- }
- }
- }
-#endif
-#endif
-}
diff --git a/BizHawk.Util/7z/COM.cs b/BizHawk.Util/7z/COM.cs
deleted file mode 100644
index 31d2a4d863..0000000000
--- a/BizHawk.Util/7z/COM.cs
+++ /dev/null
@@ -1,1244 +0,0 @@
-/* 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;
-using System.Collections.Generic;
-using System.Globalization;
-using System.IO;
-using System.Runtime.InteropServices;
-using System.Security.Permissions;
-#if !WINCE
-using FILETIME=System.Runtime.InteropServices.ComTypes.FILETIME;
-#elif WINCE
-using FILETIME=OpenNETCF.Runtime.InteropServices.ComTypes.FILETIME;
-#endif
-
-namespace SevenZip
-{
- #if UNMANAGED
-
- ///
- /// The structure to fix x64 and x32 variant size mismatch.
- ///
- [StructLayout(LayoutKind.Sequential)]
- internal struct PropArray
- {
- uint _cElems;
- IntPtr _pElems;
- }
-
- ///
- /// COM VARIANT structure with special interface routines.
- ///
- [StructLayout(LayoutKind.Explicit)]
- internal struct PropVariant
- {
- [FieldOffset(0)] private ushort _vt;
-
- ///
- /// IntPtr variant value.
- ///
- [FieldOffset(8)] private IntPtr _value;
-
- /*///
- /// Byte variant value.
- ///
- [FieldOffset(8)]
- private byte _ByteValue;*/
-
- ///
- /// Signed int variant value.
- ///
- [FieldOffset(8)]
- private Int32 _int32Value;
-
- ///
- /// Unsigned int variant value.
- ///
- [FieldOffset(8)] private UInt32 _uInt32Value;
-
- ///
- /// Long variant value.
- ///
- [FieldOffset(8)] private Int64 _int64Value;
-
- ///
- /// Unsigned long variant value.
- ///
- [FieldOffset(8)] private UInt64 _uInt64Value;
-
- ///
- /// FILETIME variant value.
- ///
- [FieldOffset(8)] private FILETIME _fileTime;
-
- ///
- /// The PropArray instance to fix the variant size on x64 bit systems.
- ///
- [FieldOffset(8)]
- private PropArray _propArray;
-
- ///
- /// Gets or sets variant type.
- ///
- public VarEnum VarType
- {
- private get
- {
- return (VarEnum) _vt;
- }
-
- set
- {
- _vt = (ushort) value;
- }
- }
-
- ///
- /// Gets or sets the pointer value of the COM variant
- ///
- public IntPtr Value
- {
- private get
- {
- return _value;
- }
-
- set
- {
- _value = value;
- }
- }
-
- /*
- ///
- /// Gets or sets the byte value of the COM variant
- ///
- public byte ByteValue
- {
- get
- {
- return _ByteValue;
- }
-
- set
- {
- _ByteValue = value;
- }
- }
-*/
-
- ///
- /// Gets or sets the UInt32 value of the COM variant.
- ///
- public UInt32 UInt32Value
- {
- private get
- {
- return _uInt32Value;
- }
- set
- {
- _uInt32Value = value;
- }
- }
-
- ///
- /// Gets or sets the UInt32 value of the COM variant.
- ///
- public Int32 Int32Value
- {
- private get
- {
- return _int32Value;
- }
- set
- {
- _int32Value = value;
- }
- }
-
- ///
- /// Gets or sets the Int64 value of the COM variant
- ///
- public Int64 Int64Value
- {
- private get
- {
- return _int64Value;
- }
-
- set
- {
- _int64Value = value;
- }
- }
-
- ///
- /// Gets or sets the UInt64 value of the COM variant
- ///
- public UInt64 UInt64Value
- {
- private get
- {
- return _uInt64Value;
- }
- set
- {
- _uInt64Value = value;
- }
- }
-
- /*
- ///
- /// Gets or sets the FILETIME value of the COM variant
- ///
- public System.Runtime.InteropServices.ComTypes.FILETIME FileTime
- {
- get
- {
- return _fileTime;
- }
-
- set
- {
- _fileTime = value;
- }
- }
-*/
-
- /*///
- /// Gets or sets variant type (ushort).
- ///
- public ushort VarTypeNative
- {
- get
- {
- return _vt;
- }
-
- set
- {
- _vt = value;
- }
- }*/
-
- /*///
- /// Clears variant
- ///
- public void Clear()
- {
- switch (VarType)
- {
- case VarEnum.VT_EMPTY:
- break;
- case VarEnum.VT_NULL:
- case VarEnum.VT_I2:
- case VarEnum.VT_I4:
- case VarEnum.VT_R4:
- case VarEnum.VT_R8:
- case VarEnum.VT_CY:
- case VarEnum.VT_DATE:
- case VarEnum.VT_ERROR:
- case VarEnum.VT_BOOL:
- case VarEnum.VT_I1:
- case VarEnum.VT_UI1:
- case VarEnum.VT_UI2:
- case VarEnum.VT_UI4:
- case VarEnum.VT_I8:
- case VarEnum.VT_UI8:
- case VarEnum.VT_INT:
- case VarEnum.VT_UINT:
- case VarEnum.VT_HRESULT:
- case VarEnum.VT_FILETIME:
- _vt = 0;
- break;
- default:
- if (NativeMethods.PropVariantClear(ref this) != (int)OperationResult.Ok)
- {
- throw new ArgumentException("PropVariantClear has failed for some reason.");
- }
- break;
- }
- }*/
-
- ///
- /// Gets the object for this PropVariant.
- ///
- ///
- public object Object
- {
- get
- {
-#if !WINCE
- var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
- sp.Demand();
-#endif
- switch (VarType)
- {
- case VarEnum.VT_EMPTY:
- return null;
- case VarEnum.VT_FILETIME:
- try
- {
- return DateTime.FromFileTime(Int64Value);
- }
- catch (ArgumentOutOfRangeException)
- {
- return DateTime.MinValue;
- }
- default:
- GCHandle propHandle = GCHandle.Alloc(this, GCHandleType.Pinned);
- try
- {
- return Marshal.GetObjectForNativeVariant(propHandle.AddrOfPinnedObject());
- }
-#if WINCE
- catch (NotSupportedException)
- {
- switch (VarType)
- {
- case VarEnum.VT_UI8:
- return UInt64Value;
- case VarEnum.VT_UI4:
- return UInt32Value;
- case VarEnum.VT_I8:
- return Int64Value;
- case VarEnum.VT_I4:
- return Int32Value;
- default:
- return 0;
- }
- }
-#endif
- finally
- {
- propHandle.Free();
- }
- }
- }
- }
-
- ///
- /// Determines whether the specified System.Object is equal to the current PropVariant.
- ///
- /// The System.Object to compare with the current PropVariant.
- /// true if the specified System.Object is equal to the current PropVariant; otherwise, false.
- public override bool Equals(object obj)
- {
- return (obj is PropVariant) ? Equals((PropVariant) obj) : false;
- }
-
- ///
- /// Determines whether the specified PropVariant is equal to the current PropVariant.
- ///
- /// The PropVariant to compare with the current PropVariant.
- /// true if the specified PropVariant is equal to the current PropVariant; otherwise, false.
- private bool Equals(PropVariant afi)
- {
- if (afi.VarType != VarType)
- {
- return false;
- }
- if (VarType != VarEnum.VT_BSTR)
- {
- return afi.Int64Value == Int64Value;
- }
- return afi.Value == Value;
- }
-
- ///
- /// Serves as a hash function for a particular type.
- ///
- /// A hash code for the current PropVariant.
- public override int GetHashCode()
- {
- return Value.GetHashCode();
- }
-
- ///
- /// Returns a System.String that represents the current PropVariant.
- ///
- /// A System.String that represents the current PropVariant.
- public override string ToString()
- {
- return "[" + Value + "] " + Int64Value.ToString(CultureInfo.CurrentCulture);
- }
-
- ///
- /// Determines whether the specified PropVariant instances are considered equal.
- ///
- /// The first PropVariant to compare.
- /// The second PropVariant to compare.
- /// true if the specified PropVariant instances are considered equal; otherwise, false.
- public static bool operator ==(PropVariant afi1, PropVariant afi2)
- {
- return afi1.Equals(afi2);
- }
-
- ///
- /// Determines whether the specified PropVariant instances are not considered equal.
- ///
- /// The first PropVariant to compare.
- /// The second PropVariant to compare.
- /// true if the specified PropVariant instances are not considered equal; otherwise, false.
- public static bool operator !=(PropVariant afi1, PropVariant afi2)
- {
- return !afi1.Equals(afi2);
- }
- }
-
- ///
- /// Stores file extraction modes.
- ///
- internal enum AskMode
- {
- ///
- /// Extraction mode
- ///
- Extract = 0,
- ///
- /// Test mode
- ///
- Test,
- ///
- /// Skip mode
- ///
- Skip
- }
-
- ///
- /// Stores operation result values
- ///
- public enum OperationResult
- {
- ///
- /// Success
- ///
- Ok = 0,
- ///
- /// Method is unsupported
- ///
- UnsupportedMethod,
- ///
- /// Data error has occured
- ///
- DataError,
- ///
- /// CrcError has occured
- ///
- CrcError
- }
-
- ///
- /// Codes of item properities
- ///
- internal enum ItemPropId : uint
- {
- ///
- /// No property
- ///
- NoProperty = 0,
- ///
- /// Handler item index
- ///
- HandlerItemIndex = 2,
- ///
- /// Item path
- ///
- Path,
- ///
- /// Item name
- ///
- Name,
- ///
- /// Item extension
- ///
- Extension,
- ///
- /// true if the item is a folder; otherwise, false
- ///
- IsDirectory,
- ///
- /// Item size
- ///
- Size,
- ///
- /// Item packed sise; usually absent
- ///
- PackedSize,
- ///
- /// Item attributes; usually absent
- ///
- Attributes,
- ///
- /// Item creation time; usually absent
- ///
- CreationTime,
- ///
- /// Item last access time; usually absent
- ///
- LastAccessTime,
- ///
- /// Item last write time
- ///
- LastWriteTime,
- ///
- /// true if the item is solid; otherwise, false
- ///
- Solid,
- ///
- /// true if the item is commented; otherwise, false
- ///
- Commented,
- ///
- /// true if the item is encrypted; otherwise, false
- ///
- Encrypted,
- ///
- /// (?)
- ///
- SplitBefore,
- ///
- /// (?)
- ///
- SplitAfter,
- ///
- /// Dictionary size(?)
- ///
- DictionarySize,
- ///
- /// Item CRC checksum
- ///
- Crc,
- ///
- /// Item type(?)
- ///
- Type,
- ///
- /// (?)
- ///
- IsAnti,
- ///
- /// Compression method
- ///
- Method,
- ///
- /// (?); usually absent
- ///
- HostOS,
- ///
- /// Item file system; usually absent
- ///
- FileSystem,
- ///
- /// Item user(?); usually absent
- ///
- User,
- ///
- /// Item group(?); usually absent
- ///
- Group,
- ///
- /// Bloack size(?)
- ///
- Block,
- ///
- /// Item comment; usually absent
- ///
- Comment,
- ///
- /// Item position
- ///
- Position,
- ///
- /// Item prefix(?)
- ///
- Prefix,
- ///
- /// Number of subdirectories
- ///
- NumSubDirs,
- ///
- /// Numbers of subfiles
- ///
- NumSubFiles,
- ///
- /// The archive legacy unpacker version
- ///
- UnpackVersion,
- ///
- /// Volume(?)
- ///
- Volume,
- ///
- /// Is a volume
- ///
- IsVolume,
- ///
- /// Offset value(?)
- ///
- Offset,
- ///
- /// Links(?)
- ///
- Links,
- ///
- /// Number of blocks
- ///
- NumBlocks,
- ///
- /// Number of volumes(?)
- ///
- NumVolumes,
- ///
- /// Time type(?)
- ///
- TimeType,
- ///
- /// 64-bit(?)
- ///
- Bit64,
- ///
- /// BigEndian
- ///
- BigEndian,
- ///
- /// Cpu(?)
- ///
- Cpu,
- ///
- /// Physical archive size
- ///
- PhysicalSize,
- ///
- /// Headers size
- ///
- HeadersSize,
- ///
- /// Archive checksum
- ///
- Checksum,
- ///
- /// (?)
- ///
- TotalSize = 0x1100,
- ///
- /// (?)
- ///
- FreeSpace,
- ///
- /// Cluster size(?)
- ///
- ClusterSize,
- ///
- /// Volume name(?)
- ///
- VolumeName,
- ///
- /// Local item name(?); usually absent
- ///
- LocalName = 0x1200,
- ///
- /// (?)
- ///
- Provider,
- ///
- /// User defined property; usually absent
- ///
- UserDefined = 0x10000
- }
-
- /*///
- /// Codes of archive properties or modes.
- ///
- internal enum ArchivePropId : uint
- {
- Name = 0,
- ClassID,
- Extension,
- AddExtension,
- Update,
- KeepName,
- StartSignature,
- FinishSignature,
- Associate
- }*/
-
- ///
- /// PropId string names dictionary wrapper.
- ///
- internal static class PropIdToName
- {
- ///
- /// PropId string names
- ///
- public static readonly Dictionary PropIdNames =
- #region Initialization
- new Dictionary(46)
- {
- {ItemPropId.Path, "Path"},
- {ItemPropId.Name, "Name"},
- {ItemPropId.IsDirectory, "Folder"},
- {ItemPropId.Size, "Size"},
- {ItemPropId.PackedSize, "Packed Size"},
- {ItemPropId.Attributes, "Attributes"},
- {ItemPropId.CreationTime, "Created"},
- {ItemPropId.LastAccessTime, "Accessed"},
- {ItemPropId.LastWriteTime, "Modified"},
- {ItemPropId.Solid, "Solid"},
- {ItemPropId.Commented, "Commented"},
- {ItemPropId.Encrypted, "Encrypted"},
- {ItemPropId.SplitBefore, "Split Before"},
- {ItemPropId.SplitAfter, "Split After"},
- {
- ItemPropId.DictionarySize,
- "Dictionary Size"
- },
- {ItemPropId.Crc, "CRC"},
- {ItemPropId.Type, "Type"},
- {ItemPropId.IsAnti, "Anti"},
- {ItemPropId.Method, "Method"},
- {ItemPropId.HostOS, "Host OS"},
- {ItemPropId.FileSystem, "File System"},
- {ItemPropId.User, "User"},
- {ItemPropId.Group, "Group"},
- {ItemPropId.Block, "Block"},
- {ItemPropId.Comment, "Comment"},
- {ItemPropId.Position, "Position"},
- {ItemPropId.Prefix, "Prefix"},
- {
- ItemPropId.NumSubDirs,
- "Number of subdirectories"
- },
- {
- ItemPropId.NumSubFiles,
- "Number of subfiles"
- },
- {
- ItemPropId.UnpackVersion,
- "Unpacker version"
- },
- {ItemPropId.Volume, "Volume"},
- {ItemPropId.IsVolume, "IsVolume"},
- {ItemPropId.Offset, "Offset"},
- {ItemPropId.Links, "Links"},
- {
- ItemPropId.NumBlocks,
- "Number of blocks"
- },
- {
- ItemPropId.NumVolumes,
- "Number of volumes"
- },
- {ItemPropId.TimeType, "Time type"},
- {ItemPropId.Bit64, "64-bit"},
- {ItemPropId.BigEndian, "Big endian"},
- {ItemPropId.Cpu, "CPU"},
- {
- ItemPropId.PhysicalSize,
- "Physical Size"
- },
- {ItemPropId.HeadersSize, "Headers Size"},
- {ItemPropId.Checksum, "Checksum"},
- {ItemPropId.FreeSpace, "Free Space"},
- {ItemPropId.ClusterSize, "Cluster Size"}
- };
- #endregion
- }
-
- ///
- /// 7-zip IArchiveOpenCallback imported interface to handle the opening of an archive.
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000600100000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IArchiveOpenCallback
- {
- // ref ulong replaced with IntPtr because handlers often pass null value
- // read actual value with Marshal.ReadInt64
- ///
- /// Sets total data size
- ///
- /// Files pointer
- /// Total size in bytes
- void SetTotal(
- IntPtr files,
- IntPtr bytes);
-
- ///
- /// Sets completed size
- ///
- /// Files pointer
- /// Completed size in bytes
- void SetCompleted(
- IntPtr files,
- IntPtr bytes);
- }
-
- ///
- /// 7-zip ICryptoGetTextPassword imported interface to get the archive password.
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000500100000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface ICryptoGetTextPassword
- {
- ///
- /// Gets password for the archive
- ///
- /// Password for the archive
- /// Zero if everything is OK
- [PreserveSig]
- int CryptoGetTextPassword(
- [MarshalAs(UnmanagedType.BStr)] out string password);
- }
-
- ///
- /// 7-zip ICryptoGetTextPassword2 imported interface for setting the archive password.
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000500110000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface ICryptoGetTextPassword2
- {
- ///
- /// Sets password for the archive
- ///
- /// Specifies whether archive has a password or not (0 if not)
- /// Password for the archive
- /// Zero if everything is OK
- [PreserveSig]
- int CryptoGetTextPassword2(
- ref int passwordIsDefined,
- [MarshalAs(UnmanagedType.BStr)] out string password);
- }
-
- ///
- /// 7-zip IArchiveExtractCallback imported interface.
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000600200000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IArchiveExtractCallback
- {
- ///
- /// Gives the size of the unpacked archive files
- ///
- /// Size of the unpacked archive files (in bytes)
- void SetTotal(ulong total);
-
- ///
- /// SetCompleted 7-zip function
- ///
- ///
- void SetCompleted([In] ref ulong completeValue);
-
- ///
- /// Gets the stream for file extraction
- ///
- /// File index in the archive file table
- /// Pointer to the stream
- /// Extraction mode
- /// S_OK - OK, S_FALSE - skip this file
- [PreserveSig]
- int GetStream(
- uint index,
- [Out, MarshalAs(UnmanagedType.Interface)] out ISequentialOutStream outStream,
- AskMode askExtractMode);
-
- ///
- /// PrepareOperation 7-zip function
- ///
- /// Ask mode
- void PrepareOperation(AskMode askExtractMode);
-
- ///
- /// Sets the operaton result
- ///
- /// The operation result
- void SetOperationResult(OperationResult operationResult);
- }
-
- ///
- /// 7-zip IArchiveUpdateCallback imported interface.
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000600800000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IArchiveUpdateCallback
- {
- ///
- /// Gives the size of the unpacked archive files.
- ///
- /// Size of the unpacked archive files (in bytes)
- void SetTotal(ulong total);
-
- ///
- /// SetCompleted 7-zip internal function.
- ///
- ///
- void SetCompleted([In] ref ulong completeValue);
-
- ///
- /// Gets archive update mode.
- ///
- /// File index
- /// 1 if new, 0 if not
- /// 1 if new, 0 if not
- /// -1 if doesn't matter
- ///
- [PreserveSig]
- int GetUpdateItemInfo(
- uint index, ref int newData,
- ref int newProperties, ref uint indexInArchive);
-
- ///
- /// Gets the archive item property data.
- ///
- /// Item index
- /// Property identificator
- /// Property value
- /// Zero if Ok
- [PreserveSig]
- int GetProperty(uint index, ItemPropId propId, ref PropVariant value);
-
- ///
- /// Gets the stream for reading.
- ///
- /// The item index.
- /// The ISequentialInStream pointer for reading.
- /// Zero if Ok
- [PreserveSig]
- int GetStream(
- uint index,
- [Out, MarshalAs(UnmanagedType.Interface)] out ISequentialInStream inStream);
-
- ///
- /// Sets the result for currently performed operation.
- ///
- /// The result value.
- void SetOperationResult(OperationResult operationResult);
-
- ///
- /// EnumProperties 7-zip internal function.
- ///
- /// The enumerator pointer.
- ///
- long EnumProperties(IntPtr enumerator);
- }
-
- ///
- /// 7-zip IArchiveOpenVolumeCallback imported interface to handle archive volumes.
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000600300000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IArchiveOpenVolumeCallback
- {
- ///
- /// Gets the archive property data.
- ///
- /// The property identificator.
- /// The property value.
- [PreserveSig]
- int GetProperty(
- ItemPropId propId, ref PropVariant value);
-
- ///
- /// Gets the stream for reading the volume.
- ///
- /// The volume file name.
- /// The IInStream pointer for reading.
- /// Zero if Ok
- [PreserveSig]
- int GetStream(
- [MarshalAs(UnmanagedType.LPWStr)] string name,
- [Out, MarshalAs(UnmanagedType.Interface)] out IInStream inStream);
- }
-
- ///
- /// 7-zip ISequentialInStream imported interface
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000300010000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface ISequentialInStream
- {
- ///
- /// Writes data to 7-zip packer
- ///
- /// Array of bytes available for writing
- /// Array size
- /// S_OK if success
- /// If (size > 0) and there are bytes in stream,
- /// this function must read at least 1 byte.
- /// This function is allowed to read less than "size" bytes.
- /// You must call Read function in loop, if you need exact amount of data.
- ///
- int Read(
- [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] data,
- uint size);
- }
-
- ///
- /// 7-zip ISequentialOutStream imported interface
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000300020000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface ISequentialOutStream
- {
- ///
- /// Writes data to unpacked file stream
- ///
- /// Array of bytes available for reading
- /// Array size
- /// Processed data size
- /// S_OK if success
- /// If size != 0, return value is S_OK and (*processedSize == 0),
- /// then there are no more bytes in stream.
- /// If (size > 0) and there are bytes in stream,
- /// this function must read at least 1 byte.
- /// This function is allowed to rwrite less than "size" bytes.
- /// You must call Write function in loop, if you need exact amount of data.
- ///
- [PreserveSig]
- int Write(
- [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] data,
- uint size, IntPtr processedSize);
- }
-
- ///
- /// 7-zip IInStream imported interface
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000300030000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IInStream
- {
- ///
- /// Read routine
- ///
- /// Array of bytes to set
- /// Array size
- /// Zero if Ok
- int Read(
- [Out, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] data,
- uint size);
-
- ///
- /// Seek routine
- ///
- /// Offset value
- /// Seek origin value
- /// New position pointer
- void Seek(
- long offset, SeekOrigin seekOrigin, IntPtr newPosition);
- }
-
- ///
- /// 7-zip IOutStream imported interface
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000300040000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IOutStream
- {
- ///
- /// Write routine
- ///
- /// Array of bytes to get
- /// Array size
- /// Processed size
- /// Zero if Ok
- [PreserveSig]
- int Write(
- [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] byte[] data,
- uint size,
- IntPtr processedSize);
-
- ///
- /// Seek routine
- ///
- /// Offset value
- /// Seek origin value
- /// New position pointer
- void Seek(
- long offset, SeekOrigin seekOrigin, IntPtr newPosition);
-
- ///
- /// Set size routine
- ///
- /// New size value
- /// Zero if Ok
- [PreserveSig]
- int SetSize(long newSize);
- }
-
- ///
- /// 7-zip essential in archive interface
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000600600000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IInArchive
- {
- ///
- /// Opens archive for reading.
- ///
- /// Archive file stream
- /// Maximum start position for checking
- /// Callback for opening archive
- ///
- [PreserveSig]
- int Open(
- IInStream stream,
- [In] ref ulong maxCheckStartPosition,
- [MarshalAs(UnmanagedType.Interface)] IArchiveOpenCallback openArchiveCallback);
-
- ///
- /// Closes the archive.
- ///
- void Close();
-
- ///
- /// Gets the number of files in the archive file table .
- ///
- /// The number of files in the archive
- uint GetNumberOfItems();
-
- ///
- /// Retrieves specific property data.
- ///
- /// File index in the archive file table
- /// Property code
- /// Property variant value
- void GetProperty(
- uint index,
- ItemPropId propId,
- ref PropVariant value); // PropVariant
-
- ///
- /// Extracts files from the opened archive.
- ///
- /// indexes of files to be extracted (must be sorted)
- /// 0xFFFFFFFF means all files
- /// testMode != 0 means "test files operation"
- /// IArchiveExtractCallback for operations handling
- /// 0 if success
- [PreserveSig]
- int Extract(
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] uint[] indexes,
- uint numItems,
- int testMode,
- [MarshalAs(UnmanagedType.Interface)] IArchiveExtractCallback extractCallback);
-
- ///
- /// Gets archive property data
- ///
- /// Archive property identificator
- /// Archive property value
- void GetArchiveProperty(
- ItemPropId propId, // PROPID
- ref PropVariant value); // PropVariant
-
- ///
- /// Gets the number of properties
- ///
- /// The number of properties
- uint GetNumberOfProperties();
-
- ///
- /// Gets property information
- ///
- /// Item index
- /// Name
- /// Property identificator
- /// Variant type
- void GetPropertyInfo(
- uint index,
- [MarshalAs(UnmanagedType.BStr)] out string name,
- out ItemPropId propId, // PROPID
- out ushort varType); //VARTYPE
-
- ///
- /// Gets the number of archive properties
- ///
- /// The number of archive properties
- uint GetNumberOfArchiveProperties();
-
- ///
- /// Gets the archive property information
- ///
- /// Item index
- /// Name
- /// Property identificator
- /// Variant type
- void GetArchivePropertyInfo(
- uint index,
- [MarshalAs(UnmanagedType.BStr)] out string name,
- out ItemPropId propId, // PROPID
- out ushort varType); //VARTYPE
- }
-
- ///
- /// 7-zip essential out archive interface
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000600A00000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface IOutArchive
- {
- ///
- /// Updates archive items
- ///
- /// The ISequentialOutStream pointer for writing the archive data
- /// Number of archive items
- /// The IArchiveUpdateCallback pointer
- /// Zero if Ok
- [PreserveSig]
- int UpdateItems(
- [MarshalAs(UnmanagedType.Interface)] ISequentialOutStream outStream,
- uint numItems,
- [MarshalAs(UnmanagedType.Interface)] IArchiveUpdateCallback updateCallback);
-
- ///
- /// Gets file time type(?)
- ///
- /// Type pointer
- void GetFileTimeType(IntPtr type);
- }
-
- ///
- /// 7-zip ISetProperties interface for setting various archive properties
- ///
- [ComImport]
- [Guid("23170F69-40C1-278A-0000-000600030000")]
- [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
- internal interface ISetProperties
- {
- ///
- /// Sets the archive properties
- ///
- /// The names of the properties
- /// The values of the properties
- /// The properties count
- ///
- int SetProperties(IntPtr names, IntPtr values, int numProperties);
- }
-#endif
-}
\ No newline at end of file
diff --git a/BizHawk.Util/7z/Common.cs b/BizHawk.Util/7z/Common.cs
deleted file mode 100644
index dd88cfbf2c..0000000000
--- a/BizHawk.Util/7z/Common.cs
+++ /dev/null
@@ -1,833 +0,0 @@
-/* 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;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Globalization;
-#if !WINCE
-using System.Runtime.Remoting.Messaging;
-#endif
-#if DOTNET20
-using System.Threading;
-#else
-using System.Windows.Threading;
-#endif
-#if MONO
-using SevenZip.Mono.COM;
-#endif
-
-namespace SevenZip
-{
-#if UNMANAGED
-
- ///
- /// The way of the event synchronization.
- ///
- public enum EventSynchronizationStrategy
- {
- ///
- /// Events are called synchronously if user can do some action; that is, cancel the execution process for example.
- ///
- Default,
- ///
- /// Always call events asynchronously.
- ///
- AlwaysAsynchronous,
- ///
- /// Always call events synchronously.
- ///
- AlwaysSynchronous
- }
-
- ///
- /// SevenZip Extractor/Compressor base class. Implements Password string, ReportErrors flag.
- ///
- public class SevenZipBase : MarshalByRefObject
- {
- private readonly string _password;
- private readonly bool _reportErrors;
- private readonly int _uniqueID;
- private static readonly List Identificators = new List();
-#if !WINCE
- internal static readonly AsyncCallback AsyncCallbackImplementation = AsyncCallbackMethod;
-
- ///
- /// True if the instance of the class needs to be recreated in new thread context; otherwise, false.
- ///
- protected internal bool NeedsToBeRecreated;
-
- ///
- /// AsyncCallback implementation used in asynchronous invocations.
- ///
- /// IAsyncResult instance.
- internal static void AsyncCallbackMethod(IAsyncResult ar)
- {
- var result = (AsyncResult) ar;
- result.AsyncDelegate.GetType().GetMethod("EndInvoke").Invoke(result.AsyncDelegate, new[] { ar });
- ((SevenZipBase)ar.AsyncState).ReleaseContext();
- }
-
- virtual internal void SaveContext(
-#if !DOTNET20
- DispatcherPriority priority = DispatcherPriority.Normal
-#endif
- )
- {
-#if !DOTNET20
- Dispatcher = Dispatcher.CurrentDispatcher;
- Priority = priority;
-#else
- Context = SynchronizationContext.Current;
-#endif
- NeedsToBeRecreated = true;
- }
-
- internal void ReleaseContext()
- {
-#if !DOTNET20
- Dispatcher = null;
-#else
- Context = null;
-#endif
- NeedsToBeRecreated = true;
- }
-
- private delegate void EventHandlerDelegate(EventHandler handler, T e) where T : EventArgs;
-
- internal void OnEvent(EventHandler handler, T e, bool synchronous) where T: EventArgs
- {
- try
- {
- if (handler != null)
- {
- switch (EventSynchronization)
- {
- case EventSynchronizationStrategy.AlwaysAsynchronous:
- synchronous = false;
- break;
- case EventSynchronizationStrategy.AlwaysSynchronous:
- synchronous = true;
- break;
- }
- if (
-#if !DOTNET20
- Dispatcher == null
-#else
- Context == null
-#endif
-)
- {
- // Usual synchronous call
- handler(this, e);
- }
- else
- {
-#if !DOTNET20
- var eventHandlerDelegate = new EventHandlerDelegate((h, ee) => h(this, ee));
- if (synchronous)
- {
- // Could be just handler(this, e);
- Dispatcher.Invoke(eventHandlerDelegate, Priority, handler, e);
- }
- else
- {
- Dispatcher.BeginInvoke(eventHandlerDelegate, Priority, handler, e);
- }
-#else
- var callback = new SendOrPostCallback((obj) =>
- {
- var array = (object[])obj;
- ((EventHandler)array[0])(array[1], (T)array[2]);
- });
- if (synchronous)
- {
- // Could be just handler(this, e);
- this.Context.Send(callback, new object[] { handler, this, e });
- }
- else
- {
- this.Context.Post(callback, new object[] { handler, this, e });
- }
-#endif
- }
- }
- }
- catch (Exception ex)
- {
- AddException(ex);
- }
- }
-
-#if !DOTNET20
- ///
- /// Gets or sets the Dispatcher object for this instance.
- /// It will be used to fire events in the user context.
- ///
- internal Dispatcher Dispatcher { get; set; }
-
- ///
- /// Gets or sets the Dispatcher priority of calling user events.
- ///
- internal DispatcherPriority Priority { get; set; }
-#else
- internal SynchronizationContext Context { get; set; }
-#endif
- ///
- /// Gets or sets the event synchronization strategy.
- ///
- public EventSynchronizationStrategy EventSynchronization { get; set; }
-#else // WINCE
- internal void OnEvent(EventHandler handler, T e, bool synchronous) where T : System.EventArgs
- {
- try
- {
- handler(this, e);
- }
- catch (Exception ex)
- {
- AddException(ex);
- }
- }
-#endif
- ///
- /// Gets the unique identificator of this SevenZipBase instance.
- ///
- public int UniqueID
- {
- get
- {
- return _uniqueID;
- }
- }
-
- ///
- /// User exceptions thrown during the requested operations, for example, in events.
- ///
- private readonly List _exceptions = new List();
-
- private static int GetUniqueID()
- {
- int id;
- var rnd = new Random(DateTime.Now.Millisecond);
- do
- {
- id = rnd.Next(Int32.MaxValue);
- }
- while (Identificators.Contains(id));
- Identificators.Add(id);
- return id;
- }
-
- #region Constructors
- ///
- /// Initializes a new instance of the SevenZipBase class.
- ///
- protected SevenZipBase()
- {
- _password = "";
- _reportErrors = true;
- _uniqueID = GetUniqueID();
- }
-
- ///
- /// Initializes a new instance of the SevenZipBase class
- ///
- /// The archive password.
- protected SevenZipBase(string password)
- {
- if (String.IsNullOrEmpty(password))
- {
- throw new SevenZipException("Empty password was specified.");
- }
- _password = password;
- _reportErrors = true;
- _uniqueID = GetUniqueID();
- }
- #endregion
-
- ///
- /// Removes the UniqueID from the list.
- ///
- ~SevenZipBase()
- {
- Identificators.Remove(_uniqueID);
- }
-
- ///
- /// Gets or sets the archive password
- ///
- public string Password
- {
- get
- {
- return _password;
- }
- }
-
- ///
- /// Gets or sets throw exceptions on archive errors flag
- ///
- internal bool ReportErrors
- {
- get
- {
- return _reportErrors;
- }
- }
-
- ///
- /// Gets the user exceptions thrown during the requested operations, for example, in events.
- ///
- internal ReadOnlyCollection Exceptions
- {
- get
- {
- return new ReadOnlyCollection(_exceptions);
- }
- }
-
- internal void AddException(Exception e)
- {
- _exceptions.Add(e);
- }
-
- internal void ClearExceptions()
- {
- _exceptions.Clear();
- }
-
- internal bool HasExceptions
- {
- get
- {
- return _exceptions.Count > 0;
- }
- }
-
- ///
- /// Throws the specified exception when is able to.
- ///
- /// The exception to throw.
- /// The handler responsible for the exception.
- internal bool ThrowException(CallbackBase handler, params Exception[] e)
- {
- if (_reportErrors && (handler == null || !handler.Canceled))
- {
- throw e[0];
- }
- return false;
- }
-
- internal void ThrowUserException()
- {
- if (HasExceptions)
- {
- throw new SevenZipException(SevenZipException.USER_EXCEPTION_MESSAGE);
- }
- }
-
- ///
- /// Throws exception if HRESULT != 0.
- ///
- /// Result code to check.
- /// Exception message.
- /// The class responsible for the callback.
- internal void CheckedExecute(int hresult, string message, CallbackBase handler)
- {
- if (hresult != (int) OperationResult.Ok || handler.HasExceptions)
- {
- if (!handler.HasExceptions)
- {
- if (hresult < -2000000000)
- {
- ThrowException(handler,
- new SevenZipException(
- "The execution has failed due to the bug in the SevenZipSharp.\n" +
- "Please report about it to http://sevenzipsharp.codeplex.com/WorkItem/List.aspx, post the release number and attach the archive."));
- }
- else
- {
- ThrowException(handler,
- new SevenZipException(message + hresult.ToString(CultureInfo.InvariantCulture) +
- '.'));
- }
- }
- else
- {
- ThrowException(handler, handler.Exceptions[0]);
- }
- }
- }
-
-#if !WINCE && !MONO
- ///
- /// Changes the path to the 7-zip native library.
- ///
- /// The path to the 7-zip native library.
- public static void SetLibraryPath(string libraryPath)
- {
- SevenZipLibraryManager.SetLibraryPath(libraryPath);
- }
-#endif
- ///
- /// Gets the current library features.
- ///
- public static LibraryFeature CurrentLibraryFeatures
- {
- get
- {
- return SevenZipLibraryManager.CurrentLibraryFeatures;
- }
- }
-
- ///
- /// Determines whether the specified System.Object is equal to the current SevenZipBase.
- ///
- /// The System.Object to compare with the current SevenZipBase.
- /// true if the specified System.Object is equal to the current SevenZipBase; otherwise, false.
- public override bool Equals(object obj)
- {
- var inst = obj as SevenZipBase;
- if (inst == null)
- {
- return false;
- }
- return _uniqueID == inst._uniqueID;
- }
-
- ///
- /// Serves as a hash function for a particular type.
- ///
- /// A hash code for the current SevenZipBase.
- public override int GetHashCode()
- {
- return _uniqueID;
- }
-
- ///
- /// Returns a System.String that represents the current SevenZipBase.
- ///
- /// A System.String that represents the current SevenZipBase.
- public override string ToString()
- {
- var type = "SevenZipBase";
- if (this is SevenZipExtractor)
- {
- type = "SevenZipExtractor";
- }
- if (this is SevenZipCompressor)
- {
- type = "SevenZipCompressor";
- }
- return string.Format("{0} [{1}]", type, _uniqueID);
- }
- }
-
- internal class CallbackBase : MarshalByRefObject
- {
- private readonly string _password;
- private readonly bool _reportErrors;
- ///
- /// User exceptions thrown during the requested operations, for example, in events.
- ///
- private readonly List _exceptions = new List();
-
- #region Constructors
- ///
- /// Initializes a new instance of the CallbackBase class.
- ///
- protected CallbackBase()
- {
- _password = "";
- _reportErrors = true;
- }
-
- ///
- /// Initializes a new instance of the CallbackBase class.
- ///
- /// The archive password.
- protected CallbackBase(string password)
- {
- if (String.IsNullOrEmpty(password))
- {
- throw new SevenZipException("Empty password was specified.");
- }
- _password = password;
- _reportErrors = true;
- }
- #endregion
-
- ///
- /// Gets or sets the archive password
- ///
- public string Password
- {
- get
- {
- return _password;
- }
- }
-
- ///
- /// Gets or sets the value indicating whether the current procedure was cancelled.
- ///
- public bool Canceled { get; set; }
-
- ///
- /// Gets or sets throw exceptions on archive errors flag
- ///
- public bool ReportErrors
- {
- get
- {
- return _reportErrors;
- }
- }
-
- ///
- /// Gets the user exceptions thrown during the requested operations, for example, in events.
- ///
- public ReadOnlyCollection Exceptions
- {
- get
- {
- return new ReadOnlyCollection(_exceptions);
- }
- }
-
- public void AddException(Exception e)
- {
- _exceptions.Add(e);
- }
-
- public void ClearExceptions()
- {
- _exceptions.Clear();
- }
-
- public bool HasExceptions
- {
- get
- {
- return _exceptions.Count > 0;
- }
- }
-
- ///
- /// Throws the specified exception when is able to.
- ///
- /// The exception to throw.
- /// The handler responsible for the exception.
- public bool ThrowException(CallbackBase handler, params Exception[] e)
- {
- if (_reportErrors && (handler == null || !handler.Canceled))
- {
- throw e[0];
- }
- return false;
- }
-
- ///
- /// Throws the first exception in the list if any exists.
- ///
- /// True means no exceptions.
- public bool ThrowException()
- {
- if (HasExceptions && _reportErrors)
- {
- throw _exceptions[0];
- }
- return true;
- }
-
- public void ThrowUserException()
- {
- if (HasExceptions)
- {
- throw new SevenZipException(SevenZipException.USER_EXCEPTION_MESSAGE);
- }
- }
- }
-
- ///
- /// Struct for storing information about files in the 7-zip archive.
- ///
- public struct ArchiveFileInfo
- {
- ///
- /// Gets or sets index of the file in the archive file table.
- ///
- public int Index { get; set; }
-
- ///
- /// Gets or sets file name
- ///
- public string FileName { get; set; }
-
- ///
- /// Gets or sets the file last write time.
- ///
- public DateTime LastWriteTime { get; set; }
-
- ///
- /// Gets or sets the file creation time.
- ///
- public DateTime CreationTime { get; set; }
-
- ///
- /// Gets or sets the file creation time.
- ///
- public DateTime LastAccessTime { get; set; }
-
- ///
- /// Gets or sets size of the file (unpacked).
- ///
- public ulong Size { get; set; }
-
- ///
- /// Gets or sets CRC checksum of the file.
- ///
- public uint Crc { get; set; }
-
- ///
- /// Gets or sets file attributes.
- ///
- public uint Attributes { get; set; }
-
- ///
- /// Gets or sets being a directory.
- ///
- public bool IsDirectory { get; set; }
-
- ///
- /// Gets or sets being encrypted.
- ///
- public bool Encrypted { get; set; }
-
- ///
- /// Gets or sets comment for the file.
- ///
- public string Comment { get; set; }
-
- ///
- /// Determines whether the specified System.Object is equal to the current ArchiveFileInfo.
- ///
- /// The System.Object to compare with the current ArchiveFileInfo.
- /// true if the specified System.Object is equal to the current ArchiveFileInfo; otherwise, false.
- public override bool Equals(object obj)
- {
- return (obj is ArchiveFileInfo) ? Equals((ArchiveFileInfo) obj) : false;
- }
-
- ///
- /// Determines whether the specified ArchiveFileInfo is equal to the current ArchiveFileInfo.
- ///
- /// The ArchiveFileInfo to compare with the current ArchiveFileInfo.
- /// true if the specified ArchiveFileInfo is equal to the current ArchiveFileInfo; otherwise, false.
- public bool Equals(ArchiveFileInfo afi)
- {
- return afi.Index == Index && afi.FileName == FileName;
- }
-
- ///
- /// Serves as a hash function for a particular type.
- ///
- /// A hash code for the current ArchiveFileInfo.
- public override int GetHashCode()
- {
- return FileName.GetHashCode() ^ Index;
- }
-
- ///
- /// Returns a System.String that represents the current ArchiveFileInfo.
- ///
- /// A System.String that represents the current ArchiveFileInfo.
- public override string ToString()
- {
- return "[" + Index.ToString(CultureInfo.CurrentCulture) + "] " + FileName;
- }
-
- ///
- /// Determines whether the specified ArchiveFileInfo instances are considered equal.
- ///
- /// The first ArchiveFileInfo to compare.
- /// The second ArchiveFileInfo to compare.
- /// true if the specified ArchiveFileInfo instances are considered equal; otherwise, false.
- public static bool operator ==(ArchiveFileInfo afi1, ArchiveFileInfo afi2)
- {
- return afi1.Equals(afi2);
- }
-
- ///
- /// Determines whether the specified ArchiveFileInfo instances are not considered equal.
- ///
- /// The first ArchiveFileInfo to compare.
- /// The second ArchiveFileInfo to compare.
- /// true if the specified ArchiveFileInfo instances are not considered equal; otherwise, false.
- public static bool operator !=(ArchiveFileInfo afi1, ArchiveFileInfo afi2)
- {
- return !afi1.Equals(afi2);
- }
- }
-
- ///
- /// Archive property struct.
- ///
- public struct ArchiveProperty
- {
- ///
- /// Gets the name of the archive property.
- ///
- public string Name { get; internal set; }
-
- ///
- /// Gets the value of the archive property.
- ///
- public object Value { get; internal set; }
-
- ///
- /// Determines whether the specified System.Object is equal to the current ArchiveProperty.
- ///
- /// The System.Object to compare with the current ArchiveProperty.
- /// true if the specified System.Object is equal to the current ArchiveProperty; otherwise, false.
- public override bool Equals(object obj)
- {
- return (obj is ArchiveProperty) ? Equals((ArchiveProperty) obj) : false;
- }
-
- ///
- /// Determines whether the specified ArchiveProperty is equal to the current ArchiveProperty.
- ///
- /// The ArchiveProperty to compare with the current ArchiveProperty.
- /// true if the specified ArchiveProperty is equal to the current ArchiveProperty; otherwise, false.
- public bool Equals(ArchiveProperty afi)
- {
- return afi.Name == Name && afi.Value == Value;
- }
-
- ///
- /// Serves as a hash function for a particular type.
- ///
- /// A hash code for the current ArchiveProperty.
- public override int GetHashCode()
- {
- return Name.GetHashCode() ^ Value.GetHashCode();
- }
-
- ///
- /// Returns a System.String that represents the current ArchiveProperty.
- ///
- /// A System.String that represents the current ArchiveProperty.
- public override string ToString()
- {
- return Name + " = " + Value;
- }
-
- ///
- /// Determines whether the specified ArchiveProperty instances are considered equal.
- ///
- /// The first ArchiveProperty to compare.
- /// The second ArchiveProperty to compare.
- /// true if the specified ArchiveProperty instances are considered equal; otherwise, false.
- public static bool operator ==(ArchiveProperty afi1, ArchiveProperty afi2)
- {
- return afi1.Equals(afi2);
- }
-
- ///
- /// Determines whether the specified ArchiveProperty instances are not considered equal.
- ///
- /// The first ArchiveProperty to compare.
- /// The second ArchiveProperty to compare.
- /// true if the specified ArchiveProperty instances are not considered equal; otherwise, false.
- public static bool operator !=(ArchiveProperty afi1, ArchiveProperty afi2)
- {
- return !afi1.Equals(afi2);
- }
- }
-
-#if COMPRESS
-
- ///
- /// Archive compression mode.
- ///
- public enum CompressionMode
- {
- ///
- /// Create a new archive; overwrite the existing one.
- ///
- Create,
- ///
- /// Add data to the archive.
- ///
- Append,
- }
-
- internal enum InternalCompressionMode
- {
- ///
- /// Create a new archive; overwrite the existing one.
- ///
- Create,
- ///
- /// Add data to the archive.
- ///
- Append,
- ///
- /// Modify archive data.
- ///
- Modify
- }
-
- ///
- /// Zip encryption method enum.
- ///
- public enum ZipEncryptionMethod
- {
- ///
- /// ZipCrypto encryption method.
- ///
- ZipCrypto,
- ///
- /// AES 128 bit encryption method.
- ///
- Aes128,
- ///
- /// AES 192 bit encryption method.
- ///
- Aes192,
- ///
- /// AES 256 bit encryption method.
- ///
- Aes256
- }
-
- ///
- /// Archive update data for UpdateCallback.
- ///
- internal struct UpdateData
- {
- public uint FilesCount;
- public InternalCompressionMode Mode;
-
- public Dictionary FileNamesToModify { get; set; }
-
- public List ArchiveFileData { get; set; }
- }
-#endif
-#endif
-}
\ No newline at end of file
diff --git a/BizHawk.Util/7z/EventArgs.cs b/BizHawk.Util/7z/EventArgs.cs
deleted file mode 100644
index 8f3928b295..0000000000
--- a/BizHawk.Util/7z/EventArgs.cs
+++ /dev/null
@@ -1,383 +0,0 @@
-/* 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;
-using System.IO;
-
-namespace SevenZip
-{
- ///
- /// EventArgs for storing PercentDone property.
- ///
- public class PercentDoneEventArgs : EventArgs
- {
- private readonly byte _percentDone;
-
- ///
- /// Initializes a new instance of the PercentDoneEventArgs class.
- ///
- /// The percent of finished work.
- ///
- public PercentDoneEventArgs(byte percentDone)
- {
- if (percentDone > 100 || percentDone < 0)
- {
- throw new ArgumentOutOfRangeException("percentDone",
- "The percent of finished work must be between 0 and 100.");
- }
- _percentDone = percentDone;
- }
-
- ///
- /// Gets the percent of finished work.
- ///
- public byte PercentDone
- {
- get
- {
- return _percentDone;
- }
- }
-
- ///
- /// Gets or sets whether to stop the current archive operation.
- ///
- public bool Cancel { get; set; }
-
- ///
- /// Converts a [0, 1] rate to its percent equivalent.
- ///
- /// The rate of the done work.
- /// Percent integer equivalent.
- ///
- internal static byte ProducePercentDone(float doneRate)
- {
-#if !WINCE
- return (byte) Math.Round(Math.Min(100*doneRate, 100), MidpointRounding.AwayFromZero);
-#else
- return (byte) Math.Round(Math.Min(100*doneRate, 100));
-#endif
- }
- }
-
- ///
- /// The EventArgs class for accurate progress handling.
- ///
- public sealed class ProgressEventArgs : PercentDoneEventArgs
- {
- private readonly byte _delta;
-
- ///
- /// Initializes a new instance of the ProgressEventArgs class.
- ///
- /// The percent of finished work.
- /// The percent of work done after the previous event.
- public ProgressEventArgs(byte percentDone, byte percentDelta)
- : base(percentDone)
- {
- _delta = percentDelta;
- }
-
- ///
- /// Gets the change in done work percentage.
- ///
- public byte PercentDelta
- {
- get
- {
- return _delta;
- }
- }
- }
-
-#if UNMANAGED
- ///
- /// EventArgs used to report the file information which is going to be packed.
- ///
- public sealed class FileInfoEventArgs : PercentDoneEventArgs
- {
- private readonly ArchiveFileInfo _fileInfo;
-
- ///
- /// Initializes a new instance of the FileInfoEventArgs class.
- ///
- /// The current ArchiveFileInfo.
- /// The percent of finished work.
- public FileInfoEventArgs(ArchiveFileInfo fileInfo, byte percentDone)
- : base(percentDone)
- {
- _fileInfo = fileInfo;
- }
-
- ///
- /// Gets the corresponding FileInfo to the event.
- ///
- public ArchiveFileInfo FileInfo
- {
- get
- {
- return _fileInfo;
- }
- }
- }
-
- ///
- /// EventArgs used to report the size of unpacked archive data
- ///
- public sealed class OpenEventArgs : EventArgs
- {
- private readonly ulong _totalSize;
-
- ///
- /// Initializes a new instance of the OpenEventArgs class
- ///
- /// Size of unpacked archive data
- public OpenEventArgs(ulong totalSize)
- {
- _totalSize = totalSize;
- }
-
- ///
- /// Gets the size of unpacked archive data
- ///
- public ulong TotalSize
- {
- get
- {
- return _totalSize;
- }
- }
- }
-
- ///
- /// Stores an int number
- ///
- public sealed class IntEventArgs : EventArgs
- {
- private readonly int _value;
-
- ///
- /// Initializes a new instance of the IntEventArgs class
- ///
- /// Useful data carried by the IntEventArgs class
- public IntEventArgs(int value)
- {
- _value = value;
- }
-
- ///
- /// Gets the value of the IntEventArgs class
- ///
- public int Value
- {
- get
- {
- return _value;
- }
- }
- }
-
- ///
- /// EventArgs class which stores the file name.
- ///
- public sealed class FileNameEventArgs : PercentDoneEventArgs
- {
- private readonly string _fileName;
-
- ///
- /// Initializes a new instance of the FileNameEventArgs class.
- ///
- /// The file name.
- /// The percent of finished work
- public FileNameEventArgs(string fileName, byte percentDone) :
- base(percentDone)
- {
- _fileName = fileName;
- }
-
- ///
- /// Gets the file name.
- ///
- public string FileName
- {
- get
- {
- return _fileName;
- }
- }
- }
-
- ///
- /// EventArgs for FileExists event, stores the file name and asks whether to overwrite it in case it already exists.
- ///
- public sealed class FileOverwriteEventArgs : EventArgs
- {
- ///
- /// Initializes a new instance of the FileOverwriteEventArgs class
- ///
- /// The file name.
- public FileOverwriteEventArgs(string fileName)
- {
- FileName = fileName;
- }
-
- ///
- /// Gets or sets the value indicating whether to cancel the extraction.
- ///
- public bool Cancel { get; set; }
-
- ///
- /// Gets or sets the file name to extract to. Null means skip.
- ///
- public string FileName { get; set; }
- }
-
- ///
- /// The reason for calling .
- ///
- public enum ExtractFileCallbackReason
- {
- ///
- /// is called the first time for a file.
- ///
- Start,
-
- ///
- /// All data has been written to the target without any exceptions.
- ///
- Done,
-
- ///
- /// An exception occured during extraction of the file.
- ///
- Failure
- }
-
- ///
- /// The arguments passed to .
- ///
- ///
- /// For each file, is first called with
- /// set to . If the callback chooses to extract the
- /// file data by setting or , the callback
- /// will be called a second time with set to
- /// or
- /// to allow for any cleanup task like closing the stream.
- ///
- public class ExtractFileCallbackArgs : EventArgs
- {
- private readonly ArchiveFileInfo _archiveFileInfo;
- private Stream _extractToStream;
-
- ///
- /// Initializes a new instance of the class.
- ///
- /// The information about file in the archive.
- public ExtractFileCallbackArgs(ArchiveFileInfo archiveFileInfo)
- {
- Reason = ExtractFileCallbackReason.Start;
- _archiveFileInfo = archiveFileInfo;
- }
-
- ///
- /// Information about file in the archive.
- ///
- /// Information about file in the archive.
- public ArchiveFileInfo ArchiveFileInfo
- {
- get
- {
- return _archiveFileInfo;
- }
- }
-
- ///
- /// The reason for calling .
- ///
- ///
- /// If neither nor is set,
- /// will not be called after .
- ///
- /// The reason.
- public ExtractFileCallbackReason Reason { get; internal set; }
-
- ///
- /// The exception that occurred during extraction.
- ///
- /// The _Exception.
- ///
- /// If the callback is called with set to ,
- /// this member contains the _Exception that occurred.
- /// The default behavior is to rethrow the _Exception after return of the callback.
- /// However the callback can set to null to swallow the _Exception
- /// and continue extraction with the next file.
- ///
- public Exception Exception { get; set; }
-
- ///
- /// Gets or sets a value indicating whether to cancel the extraction.
- ///
- /// true to cancel the extraction; false to continue. The default is false.
- public bool CancelExtraction { get; set; }
-
- ///
- /// Gets or sets whether and where to extract the file.
- ///
- /// The path where to extract the file to.
- ///
- /// If is set, this mmember will be ignored.
- ///
- public string ExtractToFile { get; set; }
-
- ///
- /// Gets or sets whether and where to extract the file.
- ///
- /// The the extracted data is written to.
- ///
- /// If both this member and are null (the defualt), the file
- /// will not be extracted and the callback will be be executed a second time with the
- /// set to or .
- ///
- public Stream ExtractToStream
- {
- get
- {
- return _extractToStream;
- }
- set
- {
- if (_extractToStream != null && !_extractToStream.CanWrite)
- {
- throw new ExtractionFailedException("The specified stream is not writable!");
- }
- _extractToStream = value;
- }
- }
-
- ///
- /// Gets or sets any data that will be preserved between the callback call
- /// and the or calls.
- ///
- /// The data.
- public object ObjectData { get; set; }
- }
-
- ///
- /// Callback delegate for .
- ///
- public delegate void ExtractFileCallback(ExtractFileCallbackArgs extractFileCallbackArgs);
-#endif
-}
\ No newline at end of file
diff --git a/BizHawk.Util/7z/Exceptions.cs b/BizHawk.Util/7z/Exceptions.cs
deleted file mode 100644
index 8a8410e0d8..0000000000
--- a/BizHawk.Util/7z/Exceptions.cs
+++ /dev/null
@@ -1,464 +0,0 @@
-/* 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
-}
\ No newline at end of file
diff --git a/BizHawk.Util/7z/FileSignatureChecker.cs b/BizHawk.Util/7z/FileSignatureChecker.cs
deleted file mode 100644
index 7f89935697..0000000000
--- a/BizHawk.Util/7z/FileSignatureChecker.cs
+++ /dev/null
@@ -1,252 +0,0 @@
-/* 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;
-using System.IO;
-
-namespace SevenZip
-{
-#if UNMANAGED
- ///
- /// The signature checker class. Original code by Siddharth Uppal, adapted by Markhor.
- ///
- /// Based on the code at http://blog.somecreativity.com/2008/04/08/how-to-check-if-a-file-is-compressed-in-c/#
- public static class FileChecker
- {
- public static bool ThrowExceptions = true;
-
- private const int SIGNATURE_SIZE = 16;
- private const int SFX_SCAN_LENGTH = 256 * 1024;
-
- private static bool SpecialDetect(Stream stream, int offset, InArchiveFormat expectedFormat)
- {
- if (stream.Length > offset + SIGNATURE_SIZE)
- {
- var signature = new byte[SIGNATURE_SIZE];
- int bytesRequired = SIGNATURE_SIZE;
- int index = 0;
- stream.Seek(offset, SeekOrigin.Begin);
- while (bytesRequired > 0)
- {
- int bytesRead = stream.Read(signature, index, bytesRequired);
- bytesRequired -= bytesRead;
- index += bytesRead;
- }
- string actualSignature = BitConverter.ToString(signature);
- foreach (string expectedSignature in Formats.InSignatureFormats.Keys)
- {
- if (Formats.InSignatureFormats[expectedSignature] != expectedFormat)
- {
- continue;
- }
- if (actualSignature.StartsWith(expectedSignature, StringComparison.OrdinalIgnoreCase))
- {
- return true;
- }
- }
- }
- return false;
- }
-
- ///
- /// Gets the InArchiveFormat for a specific extension.
- ///
- /// The stream to identify.
- /// The archive beginning offset.
- /// True if the original format of the stream is PE; otherwise, false.
- /// Corresponding InArchiveFormat.
- public static InArchiveFormat CheckSignature(Stream stream, out int offset, out bool isExecutable)
- {
- offset = 0;
- isExecutable = false;
-
- if (!stream.CanRead)
- {
- if (ThrowExceptions)
- throw new ArgumentException("The stream must be readable.");
- else return InArchiveFormat.None;
- }
- if (stream.Length < SIGNATURE_SIZE)
- {
- if (ThrowExceptions)
- throw new ArgumentException("The stream is invalid.");
- else return InArchiveFormat.None;
- }
-
- #region Get file signature
-
- var signature = new byte[SIGNATURE_SIZE];
- int bytesRequired = SIGNATURE_SIZE;
- int index = 0;
- stream.Seek(0, SeekOrigin.Begin);
- while (bytesRequired > 0)
- {
- int bytesRead = stream.Read(signature, index, bytesRequired);
- bytesRequired -= bytesRead;
- index += bytesRead;
- }
- string actualSignature = BitConverter.ToString(signature);
-
- #endregion
-
- InArchiveFormat suspectedFormat = InArchiveFormat.XZ; // any except PE and Cab
- isExecutable = false;
-
- foreach (string expectedSignature in Formats.InSignatureFormats.Keys)
- {
- if (actualSignature.StartsWith(expectedSignature, StringComparison.OrdinalIgnoreCase) ||
- actualSignature.Substring(6).StartsWith(expectedSignature, StringComparison.OrdinalIgnoreCase) &&
- Formats.InSignatureFormats[expectedSignature] == InArchiveFormat.Lzh)
- {
- if (Formats.InSignatureFormats[expectedSignature] == InArchiveFormat.PE)
- {
- suspectedFormat = InArchiveFormat.PE;
- isExecutable = true;
- }
- else
- {
- return Formats.InSignatureFormats[expectedSignature];
- }
- }
- }
-
- // Many Microsoft formats
- if (actualSignature.StartsWith("D0-CF-11-E0-A1-B1-1A-E1", StringComparison.OrdinalIgnoreCase))
- {
- suspectedFormat = InArchiveFormat.Cab; // != InArchiveFormat.XZ
- }
-
- #region SpecialDetect
- try
- {
- SpecialDetect(stream, 257, InArchiveFormat.Tar);
- }
- catch (ArgumentException) {}
- if (SpecialDetect(stream, 0x8001, InArchiveFormat.Iso))
- {
- return InArchiveFormat.Iso;
- }
- if (SpecialDetect(stream, 0x8801, InArchiveFormat.Iso))
- {
- return InArchiveFormat.Iso;
- }
- if (SpecialDetect(stream, 0x9001, InArchiveFormat.Iso))
- {
- return InArchiveFormat.Iso;
- }
- if (SpecialDetect(stream, 0x9001, InArchiveFormat.Iso))
- {
- return InArchiveFormat.Iso;
- }
- if (SpecialDetect(stream, 0x400, InArchiveFormat.Hfs))
- {
- return InArchiveFormat.Hfs;
- }
- #region Last resort for tar - can mistake
- if (stream.Length >= 1024)
- {
- stream.Seek(-1024, SeekOrigin.End);
- byte[] buf = new byte[1024];
- stream.Read(buf, 0, 1024);
- bool istar = true;
- for (int i = 0; i < 1024; i++)
- {
- istar = istar && buf[i] == 0;
- }
- if (istar)
- {
- return InArchiveFormat.Tar;
- }
- }
- #endregion
- #endregion
-
- #region Check if it is an SFX archive or a file with an embedded archive.
- if (suspectedFormat != InArchiveFormat.XZ)
- {
- #region Get first Min(stream.Length, SFX_SCAN_LENGTH) bytes
- var scanLength = Math.Min(stream.Length, SFX_SCAN_LENGTH);
- signature = new byte[scanLength];
- bytesRequired = (int)scanLength;
- index = 0;
- stream.Seek(0, SeekOrigin.Begin);
- while (bytesRequired > 0)
- {
- int bytesRead = stream.Read(signature, index, bytesRequired);
- bytesRequired -= bytesRead;
- index += bytesRead;
- }
- actualSignature = BitConverter.ToString(signature);
- #endregion
-
- foreach (var format in new InArchiveFormat[]
- {
- InArchiveFormat.Zip,
- InArchiveFormat.SevenZip,
- InArchiveFormat.Rar,
- InArchiveFormat.Cab,
- InArchiveFormat.Arj
- })
- {
- int pos = actualSignature.IndexOf(Formats.InSignatureFormatsReversed[format]);
- if (pos > -1)
- {
- offset = pos / 3;
- return format;
- }
- }
- // Nothing
- if (suspectedFormat == InArchiveFormat.PE)
- {
- return InArchiveFormat.PE;
- }
- }
- #endregion
-
- if (ThrowExceptions)
- throw new ArgumentException("The stream is invalid or no corresponding signature was found.");
- else return InArchiveFormat.None;
- }
-
- ///
- /// Gets the InArchiveFormat for a specific file name.
- ///
- /// The archive file name.
- /// The archive beginning offset.
- /// True if the original format of the file is PE; otherwise, false.
- /// Corresponding InArchiveFormat.
- ///
- public static InArchiveFormat CheckSignature(string fileName, out int offset, out bool isExecutable)
- {
- using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- {
- try
- {
- InArchiveFormat format = CheckSignature(fs, out offset, out isExecutable);
- if (format != InArchiveFormat.None) return format;
- }
- catch (ArgumentException)
- {
- }
-
- offset = 0;
- isExecutable = false;
- return Formats.FormatByFileName(fileName, true);
- }
- }
- }
-#endif
-}
\ No newline at end of file
diff --git a/BizHawk.Util/7z/Formats.cs b/BizHawk.Util/7z/Formats.cs
deleted file mode 100644
index bd978baf18..0000000000
--- a/BizHawk.Util/7z/Formats.cs
+++ /dev/null
@@ -1,540 +0,0 @@
-/* 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;
-using System.Collections.Generic;
-using System.IO;
-
-namespace SevenZip
-{
-#if UNMANAGED
- ///
- /// Readable archive format enumeration.
- ///
- public enum InArchiveFormat
- {
- ///
- /// Open 7-zip archive format.
- ///
- /// Wikipedia information
- SevenZip,
- ///
- /// Proprietary Arj archive format.
- ///
- /// Wikipedia information
- Arj,
- ///
- /// Open Bzip2 archive format.
- ///
- /// Wikipedia information
- BZip2,
- ///
- /// Microsoft cabinet archive format.
- ///
- /// Wikipedia information
- Cab,
- ///
- /// Microsoft Compiled HTML Help file format.
- ///
- /// Wikipedia information
- Chm,
- ///
- /// Microsoft Compound file format.
- ///
- /// Wikipedia information
- Compound,
- ///
- /// Open Cpio archive format.
- ///
- /// Wikipedia information
- Cpio,
- ///
- /// Open Debian software package format.
- ///
- /// Wikipedia information
- Deb,
- ///
- /// Open Gzip archive format.
- ///
- /// Wikipedia information
- GZip,
- ///
- /// Open ISO disk image format.
- ///
- /// Wikipedia information
- Iso,
- ///
- /// Open Lzh archive format.
- ///
- /// Wikipedia information
- Lzh,
- ///
- /// Open core 7-zip Lzma raw archive format.
- ///
- /// Wikipedia information
- Lzma,
- ///
- /// Nullsoft installation package format.
- ///
- /// Wikipedia information
- Nsis,
- ///
- /// RarLab Rar archive format.
- ///
- /// Wikipedia information
- Rar,
- ///
- /// Open Rpm software package format.
- ///
- /// Wikipedia information
- Rpm,
- ///
- /// Open split file format.
- ///
- /// Wikipedia information
- Split,
- ///
- /// Open Tar archive format.
- ///
- /// Wikipedia information
- Tar,
- ///
- /// Microsoft Windows Imaging disk image format.
- ///
- /// Wikipedia information
- Wim,
- ///
- /// Open LZW archive format; implemented in "compress" program; also known as "Z" archive format.
- ///
- /// Wikipedia information
- Lzw,
- ///
- /// Open Zip archive format.
- ///
- /// Wikipedia information
- Zip,
- ///
- /// Open Udf disk image format.
- ///
- Udf,
- ///
- /// Xar open source archive format.
- ///
- /// Wikipedia information
- Xar,
- ///
- /// Mub
- ///
- Mub,
- ///
- /// Macintosh Disk Image on CD.
- ///
- /// Wikipedia information
- Hfs,
- ///
- /// Apple Mac OS X Disk Copy Disk Image format.
- ///
- Dmg,
- ///
- /// Open Xz archive format.
- ///
- /// Wikipedia information
- XZ,
- ///
- /// MSLZ archive format.
- ///
- Mslz,
- ///
- /// Flash video format.
- ///
- /// Wikipedia information
- Flv,
- ///
- /// Shockwave Flash format.
- ///
- /// Wikipedia information
- Swf,
- ///
- /// Windows PE executable format.
- ///
- /// Wikipedia information
- PE,
- ///
- /// Linux executable Elf format.
- ///
- /// Wikipedia information
- Elf,
- ///
- /// Windows Installer Database.
- ///
- /// Wikipedia information
- Msi,
- ///
- /// Microsoft virtual hard disk file format.
- ///
- /// Wikipedia information
- Vhd,
- ///
- /// Not an archive
- ///
- None
- }
-
-#if COMPRESS
- ///
- /// Writable archive format enumeration.
- ///
- public enum OutArchiveFormat
- {
- ///
- /// Open 7-zip archive format.
- ///
- /// Wikipedia information
- SevenZip,
- ///
- /// Open Zip archive format.
- ///
- /// Wikipedia information
- Zip,
- ///
- /// Open Gzip archive format.
- ///
- /// Wikipedia information
- GZip,
- ///
- /// Open Bzip2 archive format.
- ///
- /// Wikipedia information
- BZip2,
- ///
- /// Open Tar archive format.
- ///
- /// Wikipedia information
- Tar,
- ///
- /// Open Xz archive format.
- ///
- /// Wikipedia information
- XZ
- }
-
- ///
- /// Compression level enumeration
- ///
- public enum CompressionLevel
- {
- ///
- /// No compression
- ///
- None,
- ///
- /// Very low compression level
- ///
- Fast,
- ///
- /// Low compression level
- ///
- Low,
- ///
- /// Normal compression level (default)
- ///
- Normal,
- ///
- /// High compression level
- ///
- High,
- ///
- /// The best compression level (slow)
- ///
- Ultra
- }
-
- ///
- /// Compression method enumeration.
- ///
- /// Some methods are applicable only to Zip format, some - only to 7-zip.
- public enum CompressionMethod
- {
- ///
- /// Zip or 7-zip|no compression method.
- ///
- Copy,
- ///
- /// Zip|Deflate method.
- ///
- Deflate,
- ///
- /// Zip|Deflate64 method.
- ///
- Deflate64,
- ///
- /// Zip or 7-zip|Bzip2 method.
- ///
- /// Wikipedia information
- BZip2,
- ///
- /// Zip or 7-zip|LZMA method based on Lempel-Ziv algorithm, it is default for 7-zip.
- ///
- Lzma,
- ///
- /// 7-zip|LZMA version 2, LZMA with improved multithreading and usually slight archive size decrease.
- ///
- Lzma2,
- ///
- /// Zip or 7-zip|PPMd method based on Dmitry Shkarin's PPMdH source code, very efficient for compressing texts.
- ///
- /// Wikipedia information
- Ppmd,
- ///
- /// No method change.
- ///
- Default
- }
-#endif
-
- ///
- /// Archive format routines
- ///
- public static class Formats
- {
- /*///
- /// Gets the max value of the specified enum type.
- ///
- /// Type of the enum
- /// Max value
- internal static int GetMaxValue(Type type)
- {
- List enumList = new List((IEnumerable)Enum.GetValues(type));
- enumList.Sort();
- return enumList[enumList.Count - 1];
- }*/
-
- ///
- /// List of readable archive format interface guids for 7-zip COM interop.
- ///
- internal static readonly Dictionary InFormatGuids =
- new Dictionary(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
- ///
- /// List of writable archive format interface guids for 7-zip COM interop.
- ///
- internal static readonly Dictionary OutFormatGuids =
- new Dictionary(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 MethodNames =
- new Dictionary(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 InForOutFormats =
- new Dictionary(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
-
- ///
- /// List of archive formats corresponding to specific extensions
- ///
- private static readonly Dictionary InExtensionFormats =
- new Dictionary
- #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
-
- ///
- /// List of archive formats corresponding to specific signatures
- ///
- /// Based on the information at this site.
- internal static readonly Dictionary InSignatureFormats =
- new Dictionary
- #region InSignatureFormats initialization
-
- {{"37-7A-BC-AF-27-1C", InArchiveFormat.SevenZip},
- {"1F-8B-08", InArchiveFormat.GZip},
- {"75-73-74-61-72", InArchiveFormat.Tar},
- //257 byte offset
- {"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},
- //^ 2 byte offset
- {"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},
- //^ 0x8001, 0x8801 or 0x9001 byte offset
- //{"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},
- //0x400 byte offset
- //{"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},
- {"4E-45-53", InArchiveFormat.None}
- };
-
- #endregion
-
- internal static Dictionary InSignatureFormatsReversed;
-
- static Formats()
- {
- InSignatureFormatsReversed = new Dictionary(InSignatureFormats.Count);
- foreach (var pair in InSignatureFormats)
- {
- InSignatureFormatsReversed.Add(pair.Value, pair.Key);
- }
- }
-
- ///
- /// Gets InArchiveFormat for specified archive file name
- ///
- /// Archive file name
- /// Indicates whether to throw exceptions
- /// InArchiveFormat recognized by the file name extension
- ///
- 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);
- if (extension.StartsWith("."))
- extension = extension.Substring(1);
- if (!InExtensionFormats.ContainsKey(extension) && reportErrors)
- {
- if (FileChecker.ThrowExceptions)
- throw new ArgumentException("Extension \"" + extension + "\" is not a supported archive file name extension.");
- else return InArchiveFormat.None;
-
- }
- return InExtensionFormats[extension];
- }
- }
-#endif
-}
\ No newline at end of file
diff --git a/BizHawk.Util/7z/LibraryFeature.cs b/BizHawk.Util/7z/LibraryFeature.cs
deleted file mode 100644
index fdc1d5a3bf..0000000000
--- a/BizHawk.Util/7z/LibraryFeature.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-/* 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;
-
-namespace SevenZip
-{
- ///
- /// The set of features supported by the library.
- ///
- [Flags]
- public enum LibraryFeature : uint
- {
- ///
- /// Default feature.
- ///
- None = 0,
- ///
- /// The library can extract 7zip archives compressed with LZMA method.
- ///
- Extract7z = 0x1,
- ///
- /// The library can extract 7zip archives compressed with LZMA2 method.
- ///
- Extract7zLZMA2 = 0x2,
- ///
- /// The library can extract 7z archives compressed with all known methods.
- ///
- Extract7zAll = Extract7z|Extract7zLZMA2|0x4,
- ///
- /// The library can extract zip archives.
- ///
- ExtractZip = 0x8,
- ///
- /// The library can extract rar archives.
- ///
- ExtractRar = 0x10,
- ///
- /// The library can extract gzip archives.
- ///
- ExtractGzip = 0x20,
- ///
- /// The library can extract bzip2 archives.
- ///
- ExtractBzip2 = 0x40,
- ///
- /// The library can extract tar archives.
- ///
- ExtractTar = 0x80,
- ///
- /// The library can extract xz archives.
- ///
- ExtractXz = 0x100,
- ///
- /// The library can extract all types of archives supported.
- ///
- ExtractAll = Extract7zAll|ExtractZip|ExtractRar|ExtractGzip|ExtractBzip2|ExtractTar|ExtractXz,
- ///
- /// The library can compress data to 7zip archives with LZMA method.
- ///
- Compress7z = 0x200,
- ///
- /// The library can compress data to 7zip archives with LZMA2 method.
- ///
- Compress7zLZMA2 = 0x400,
- ///
- /// The library can compress data to 7zip archives with all methods known.
- ///
- Compress7zAll = Compress7z|Compress7zLZMA2|0x800,
- ///
- /// The library can compress data to tar archives.
- ///
- CompressTar = 0x1000,
- ///
- /// The library can compress data to gzip archives.
- ///
- CompressGzip = 0x2000,
- ///
- /// The library can compress data to bzip2 archives.
- ///
- CompressBzip2 = 0x4000,
- ///
- /// The library can compress data to xz archives.
- ///
- CompressXz = 0x8000,
- ///
- /// The library can compress data to zip archives.
- ///
- CompressZip = 0x10000,
- ///
- /// The library can compress data to all types of archives supported.
- ///
- CompressAll = Compress7zAll|CompressTar|CompressGzip|CompressBzip2|CompressXz|CompressZip,
- ///
- /// The library can modify archives.
- ///
- Modify = 0x20000
- }
-}
diff --git a/BizHawk.Util/7z/LibraryManager.cs b/BizHawk.Util/7z/LibraryManager.cs
deleted file mode 100644
index 86ad2f7c86..0000000000
--- a/BizHawk.Util/7z/LibraryManager.cs
+++ /dev/null
@@ -1,567 +0,0 @@
-/* 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;
-using System.Collections.Generic;
-#if !WINCE && !MONO
-using System.Configuration;
-using System.Diagnostics;
-using System.Security.Permissions;
-#endif
-#if WINCE
-using OpenNETCF.Diagnostics;
-#endif
-using System.IO;
-using System.Reflection;
-using System.Runtime.InteropServices;
-using System.Text;
-#if MONO
-using SevenZip.Mono.COM;
-#endif
-
-namespace SevenZip
-{
-#if UNMANAGED
- ///
- /// 7-zip library low-level wrapper.
- ///
- internal static class SevenZipLibraryManager
- {
-#if !WINCE && !MONO
- ///
- /// Path to the 7-zip dll.
- ///
- /// 7zxa.dll supports only decoding from .7z archives.
- /// Features of 7za.dll:
- /// - Supporting 7z format;
- /// - Built encoders: LZMA, PPMD, BCJ, BCJ2, COPY, AES-256 Encryption.
- /// - Built decoders: LZMA, PPMD, BCJ, BCJ2, COPY, AES-256 Encryption, BZip2, Deflate.
- /// 7z.dll (from the 7-zip distribution) supports every InArchiveFormat for encoding and decoding.
- ///
- //private static string _libraryFileName = ConfigurationManager.AppSettings["7zLocation"] ?? Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "7z.dll");
- private static string _libraryFileName = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "7z.dll");
-#endif
-#if WINCE
- private static string _libraryFileName =
- Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase), "7z.dll");
-#endif
- ///
- /// 7-zip library handle.
- ///
- private static IntPtr _modulePtr;
-
- ///
- /// 7-zip library features.
- ///
- private static LibraryFeature? _features;
-
- private static Dictionary