continuing...

This commit is contained in:
zeromus 2013-10-25 01:00:31 +00:00
parent 6616a75cfb
commit 78603f1237
70 changed files with 83 additions and 20145 deletions

View File

@ -1,608 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>BizHawk.Emulation</RootNamespace>
<AssemblyName>BizHawk.Emulation</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>3.5</OldToolsVersion>
<UpgradeBackupLocation />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<UseVSHostingProcess>false</UseVSHostingProcess>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;VS2012</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>x86</PlatformTarget>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
<UseVSHostingProcess>false</UseVSHostingProcess>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="EMU7800, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\BizHawk.MultiClient\output\dll\EMU7800.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data.DataSetExtensions">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="..\VersionInfo.cs">
<Link>VersionInfo.cs</Link>
</Compile>
<Compile Include="Buffer.cs" />
<Compile Include="Computers\Commodore64\C64.Core.cs" />
<Compile Include="Computers\Commodore64\C64.cs" />
<Compile Include="Computers\Commodore64\C64.Motherboard.cs" />
<Compile Include="Computers\Commodore64\C64.MotherboardInterface.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0000.cs" />
<Compile Include="Computers\Commodore64\C64.Input.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0005.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper000B.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper000F.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0011.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0012.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0013.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Mapper0020.cs" />
<Compile Include="Computers\Commodore64\Disk\VIC1541.cs" />
<Compile Include="Computers\Commodore64\Disk\VIC1541.PLA.cs" />
<Compile Include="Computers\Commodore64\Experimental\C64.cs" />
<Compile Include="Computers\Commodore64\Experimental\C64.Glue.cs" />
<Compile Include="Computers\Commodore64\Experimental\C64Presets.NTSC.cs" />
<Compile Include="Computers\Commodore64\Experimental\C64Presets.PAL.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cassette.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cia.Interface.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cia.Internal.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cia.Registers.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cia.Settings.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cpu.Interface.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cpu.Internal.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Cpu.State.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Expansion.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Joystick.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Keyboard.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Pla.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Ram.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Rom.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Serial.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Sid.Interface.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Sid.Internal.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Sid.Registers.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Sid.Settings.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Sid.SoundProvider.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Userport.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Graphics.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Interface.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Internal.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Registers.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Settings.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Sprite.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.State.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Synth.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.Timing.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Internals\Vic.VideoProvider.cs" />
<Compile Include="Computers\Commodore64\Experimental\Chips\Presets.cs" />
<Compile Include="Computers\Commodore64\Experimental\IMotherboard.cs" />
<Compile Include="Computers\Commodore64\InputFileInfo.cs" />
<Compile Include="Computers\Commodore64\Media\PRG.cs" />
<Compile Include="Computers\Commodore64\Cartridge\Cart.cs" />
<Compile Include="Computers\Commodore64\MOS\CartridgePort.cs" />
<Compile Include="Computers\Commodore64\MOS\CassettePort.cs" />
<Compile Include="Computers\Commodore64\MOS\Chip2114.cs" />
<Compile Include="Computers\Commodore64\MOS\Chip23XX.cs" />
<Compile Include="Computers\Commodore64\MOS\Chip4864.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6510.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6522.cs" />
<Compile Include="Computers\Commodore64\Media\D64.cs" />
<Compile Include="Computers\Commodore64\Media\Disk.cs" />
<Compile Include="Computers\Commodore64\Media\G64.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6526.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6567.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6581.cs" />
<Compile Include="Computers\Commodore64\MOS\MOS6569.cs" />
<Compile Include="Computers\Commodore64\C64.Savestate.cs" />
<Compile Include="Computers\Commodore64\MOS\MOSPLA.cs" />
<Compile Include="Computers\Commodore64\MOS\Port.cs" />
<Compile Include="Computers\Commodore64\MOS\SerialPort.cs" />
<Compile Include="Computers\Commodore64\MOS\Sid.cs" />
<Compile Include="Computers\Commodore64\MOS\Sid.Envelope.cs" />
<Compile Include="Computers\Commodore64\MOS\Sid.Voice.cs" />
<Compile Include="Computers\Commodore64\MOS\UserPort.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.GraphicsGenerator.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.Parse.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.Registers.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.Render.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.SpriteGenerator.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.State.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.TimingBuilder.cs" />
<Compile Include="Computers\Commodore64\MOS\Vic.VideoProvider.cs" />
<Compile Include="Computers\Commodore64\SaveState.cs" />
<Compile Include="Computers\Commodore64\Tape\VIC1530.cs" />
<Compile Include="Consoles\Atari\2600\Atari2600.cs" />
<Compile Include="Consoles\Atari\2600\Atari2600.Core.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m3Fe.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m0840.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m3E.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m3F.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m4A50.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mDPC.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mE0.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mE7.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mEF.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mF0.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mF4.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mCV.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m2K.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\m4K.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mF6.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mF8.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mFA.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mFE.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mMC.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mUA.cs" />
<Compile Include="Consoles\Atari\2600\Mappers\mX07.cs" />
<Compile Include="Consoles\Atari\2600\oldTIA.cs" />
<Compile Include="Consoles\Atari\2600\M6532.cs" />
<Compile Include="Consoles\Atari\2600\TIA.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Atari\7800\Atari7800.Core.cs" />
<Compile Include="Consoles\Atari\7800\Atari7800.cs" />
<Compile Include="Consoles\Atari\7800\Atari7800Control.cs" />
<Compile Include="Consoles\Calculator\TI83.cs" />
<Compile Include="Consoles\Coleco\ColecoVision.cs" />
<Compile Include="Consoles\Coleco\Input.cs" />
<Compile Include="Consoles\Coleco\MemoryMap.cs" />
<Compile Include="Consoles\Coleco\TMS9918A.cs" />
<Compile Include="Consoles\Intellivision\Cartridge.cs" />
<Compile Include="Consoles\Intellivision\ICart.cs" />
<Compile Include="Consoles\Intellivision\Intellicart.cs" />
<Compile Include="Consoles\Intellivision\Intellivision.cs" />
<Compile Include="Consoles\Intellivision\MemoryMap.cs" />
<Compile Include="Consoles\Intellivision\PSG.cs" />
<Compile Include="Consoles\Intellivision\STIC.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\Gambatte.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\GambatteLink.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\GBColors.cs" />
<Compile Include="Consoles\Nintendo\Gameboy\LibGambatte.cs" />
<Compile Include="Consoles\Nintendo\GBA\LibMeteor.cs" />
<Compile Include="Consoles\Nintendo\GBA\Meteor.cs" />
<Compile Include="Consoles\Nintendo\N64\mupen64plusApi.cs" />
<Compile Include="Consoles\Nintendo\N64\N64.cs" />
<Compile Include="Consoles\Nintendo\NES\APU.cs" />
<Compile Include="Consoles\Nintendo\NES\BoardSystem.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\AVE-NINA.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\AxROM.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\BANDAI-FCG-1.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\BANDAI_74_161_02_74.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\BANDAI_74_161_161_32.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\BxROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Camerica.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper028.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\CNROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\CPROM.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\ExROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\GxROM.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\IC_74x377.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\IREM-74_161_161_21_138.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Irem_G101.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Irem_H3001.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\IREM_TAM_S1.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Jaleco-JF_11_14.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\JALECO_JF_05_06_07.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\JALECO_JF_13.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\JALECO_JF_17.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\JALECO_JF_19.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\JALECO_SS8806.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper015.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper036.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper038.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper040.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper041.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper042.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper045.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper057.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper058.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper069.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper090.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper091.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper099.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper101.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper103.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper107.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper108.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper116.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper120.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper132.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper143.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper156.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper164.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper168.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper176.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper177.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper178.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper180.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper193.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper200.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper201.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper203.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper207.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper218.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper225.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper226.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper227.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper230.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper231.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper233.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper240.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper241.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper242.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper078.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper046.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper243.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper246.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper50.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper60.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper61.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Mapper62.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MLT-ACTION52.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MLT-MAX15.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\HKROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper012.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper037.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper044.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper049.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper052.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper074.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper115.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper165.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper182.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper189.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper191.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper192.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper194.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper197.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper205.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper245.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper249.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\Mapper250.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\MMC3.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\NES-QJ.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\TQROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\TLSROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\TVROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\MMC3_family\TxROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\DRROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Mapper076.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Mapper088.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Mapper095.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Mapper112.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Mapper154.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Mapper206.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Namco163Audio.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Namcot1xx\Namcot1xx.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\NAMCOT_m19_m210.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\NanJing.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\NES-EVENT.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\NovelDiamond.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\NROM.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\NROM368.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\PxROM_FxROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\SachenSimple.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\SEEPROM.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Sunsoft1.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Sunsoft2_m89.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Sunsoft2_m93.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Sunsoft3.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Sunsoft4.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\SxROM.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\TAITO_74_161_161_32.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Taito_TC0190FMC.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Taito_X1_005.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\Taito_X1_017.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\TENGEN-800032.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\TENGEN_800008.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\UxROM.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Consoles\Nintendo\NES\Boards\VRC1.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\VRC2_4.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\VRC3.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\VRC6.cs" />
<Compile Include="Consoles\Nintendo\NES\Boards\VRC7.cs" />
<Compile Include="Consoles\Nintendo\NES\BisqAPU.cs" />
<Compile Include="Consoles\Nintendo\NES\Core.cs" />
<Compile Include="Consoles\Nintendo\NES\FDS\FDS.cs" />
<Compile Include="Consoles\Nintendo\NES\FDS\FDSAudio.cs" />
<Compile Include="Consoles\Nintendo\NES\FDS\RamAdapter.cs" />
<Compile Include="Consoles\Nintendo\NES\iNES.cs" />
<Compile Include="Consoles\Nintendo\NES\NES.cs" />
<Compile Include="Consoles\Nintendo\NES\Palettes.cs" />
<Compile Include="Consoles\Nintendo\NES\PPU.cs" />
<Compile Include="Consoles\Nintendo\NES\PPU.regs.cs" />
<Compile Include="Consoles\Nintendo\NES\PPU.run.cs" />
<Compile Include="Consoles\Nintendo\NES\Unif.cs" />
<Compile Include="Consoles\Nintendo\SNES\LibsnesApi.cs" />
<Compile Include="Consoles\Nintendo\SNES\LibsnesCore.cs" />
<Compile Include="Consoles\Nintendo\SNES\SnesColors.cs" />
<Compile Include="Consoles\Nintendo\SNES\SNESGraphicsDecoder.cs" />
<Compile Include="Consoles\PC Engine\ADPCM.cs" />
<Compile Include="Consoles\PC Engine\ArcadeCard.cs" />
<Compile Include="Consoles\PC Engine\MemoryMap.TurboCD.cs" />
<Compile Include="Consoles\PC Engine\MemoryMap.Populous.cs" />
<Compile Include="Consoles\PC Engine\ScsiCDBus.cs" />
<Compile Include="Consoles\PC Engine\TurboCD.cs" />
<Compile Include="Consoles\PSX\LibMednahawkDll.cs" />
<Compile Include="Consoles\PSX\Octoshock.cs" />
<Compile Include="Consoles\Sega\Genesis\Cart\EEPROM.cs" />
<Compile Include="Consoles\Sega\Genesis\Cart\RomHeader.cs" />
<Compile Include="Consoles\Sega\Genesis\Cart\SaveRAM.cs" />
<Compile Include="Consoles\Sega\Genesis\Input.cs" />
<Compile Include="Consoles\Sega\Saturn\FilePiping.cs" />
<Compile Include="Consoles\Sega\Saturn\LibYabause.cs" />
<Compile Include="Consoles\Sega\Saturn\Yabause.cs" />
<Compile Include="Consoles\Sega\SMS\MemoryMap.CodeMasters.cs" />
<Compile Include="Consoles\Sega\SMS\MemoryMap.Sega.cs" />
<Compile Include="Consoles\Sega\SMS\VDP.ModeTMS.cs" />
<Compile Include="Consoles\Sega\SMS\VDP.Mode4.cs" />
<Compile Include="Consoles\Sega\SMS\VDP.Tables.cs" />
<Compile Include="Consoles\Sony\PSP\PPSSPPDll.cs" />
<Compile Include="Consoles\Sony\PSP\PSP.cs" />
<Compile Include="CPUs\68000\Diassembler.cs" />
<Compile Include="CPUs\68000\Instructions\BitArithemetic.cs" />
<Compile Include="CPUs\68000\Instructions\DataMovement.cs" />
<Compile Include="CPUs\68000\Instructions\IntegerMath.cs" />
<Compile Include="CPUs\68000\Instructions\ProgramFlow.cs" />
<Compile Include="CPUs\68000\Instructions\Supervisor.cs" />
<Compile Include="CPUs\68000\MC68000.cs" />
<Compile Include="CPUs\68000\Memory.cs" />
<Compile Include="CPUs\68000\OpcodeTable.cs" />
<Compile Include="CPUs\68000\Tables.cs" />
<Compile Include="CPUs\CP1610\CP1610.cs" />
<Compile Include="CPUs\CP1610\Disassembler.cs" />
<Compile Include="CPUs\CP1610\Execute.cs" />
<Compile Include="CPUs\HuC6280\Disassembler.cs" />
<Compile Include="CPUs\HuC6280\Execute.cs" />
<Compile Include="CPUs\HuC6280\HuC6280.cs" />
<Compile Include="CPUs\MOS 6502X\Disassembler.cs" />
<Compile Include="CPUs\MOS 6502X\Execute.cs" />
<Compile Include="CPUs\MOS 6502X\MOS6502X.cs" />
<Compile Include="CPUs\MOS 6502X\MOS6502XDouble.cs" />
<Compile Include="CPUs\MOS 6502X\MOS6502XNative.cs" />
<Compile Include="CPUs\Native68000\Musashi.cs" />
<Compile Include="CPUs\x86\Disassembler.cs" />
<Compile Include="CPUs\x86\Execute.cs" />
<Compile Include="CPUs\x86\Timing.cs" />
<Compile Include="CPUs\x86\x86.cs" />
<Compile Include="CPUs\Z80-GB\Execute.cs" />
<Compile Include="CPUs\Z80-GB\Interrupts.cs" />
<Compile Include="CPUs\Z80-GB\NewDisassembler.cs" />
<Compile Include="CPUs\Z80-GB\Registers.cs" />
<Compile Include="CPUs\Z80-GB\Tables.cs" />
<Compile Include="CPUs\Z80-GB\Z80.cs" />
<Compile Include="CPUs\Z80\Disassembler.cs" />
<Compile Include="CPUs\Z80\Execute.cs" />
<Compile Include="CPUs\Z80\Interrupts.cs" />
<Compile Include="CPUs\Z80\Registers.cs" />
<Compile Include="CPUs\Z80\Tables.cs" />
<Compile Include="CPUs\Z80\Z80A.cs" />
<Compile Include="Database\CRC32.cs" />
<Compile Include="Database\Database.cs" />
<Compile Include="Database\FirmwareDatabase.cs" />
<Compile Include="Database\GameInfo.cs" />
<Compile Include="DiscSystem\Blobs\Blob_ECM.cs" />
<Compile Include="DiscSystem\Blobs\Blob_WaveFile.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\Blobs\RiffMaster.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\CCD_format.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\cdfs\EndianBitConverter.cs" />
<Compile Include="DiscSystem\cdfs\ISODirectoryNode.cs" />
<Compile Include="DiscSystem\cdfs\ISOFile.cs" />
<Compile Include="DiscSystem\cdfs\ISOFileNode.cs" />
<Compile Include="DiscSystem\cdfs\ISONode.cs" />
<Compile Include="DiscSystem\cdfs\ISONodeRecord.cs" />
<Compile Include="DiscSystem\cdfs\ISOVolumeDescriptor.cs" />
<Compile Include="DiscSystem\CUE_format.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\Decoding.cs" />
<Compile Include="DiscSystem\Disc.API.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\Disc.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\Disc.ID.cs" />
<Compile Include="DiscSystem\DiscTOC.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\ECM.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\GPL_ECM.cs" />
<Compile Include="DiscSystem\Subcode.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="DiscSystem\TOC_format.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Interfaces\Base Implementations\IPS.cs" />
<Compile Include="Interfaces\Base Implementations\Movies.cs" />
<Compile Include="Interfaces\Base Implementations\NullController.cs" />
<Compile Include="Interfaces\Base Implementations\NullEmulator.cs" />
<Compile Include="Interfaces\CoreComms.cs" />
<Compile Include="Interfaces\ICoreFileProvider.cs" />
<Compile Include="Interfaces\ISyncSoundProvider.cs" />
<Compile Include="Properties\svnrev.cs" />
<Compile Include="QuickCollections.cs" />
<Compile Include="Sound\CDAudio.cs" />
<Compile Include="Sound\MMC5Audio.cs" />
<Compile Include="Sound\Sunsoft5BAudio.cs" />
<Compile Include="Sound\Utilities\BlipBuffer.cs" />
<Compile Include="Sound\Utilities\DCFilter.cs" />
<Compile Include="Sound\Utilities\Equalizer.cs" />
<Compile Include="Sound\Utilities\SpeexResampler.cs" />
<Compile Include="Sound\Utilities\BufferedAsync.cs" />
<Compile Include="Sound\Utilities\Metaspu.cs" />
<Compile Include="Interfaces\IController.cs" />
<Compile Include="Interfaces\IEmulator.cs" />
<Compile Include="Interfaces\ISoundProvider.cs" />
<Compile Include="Interfaces\IVideoProvider.cs" />
<Compile Include="Log.cs" />
<Compile Include="Consoles\PC Engine\Input.cs" />
<Compile Include="Consoles\PC Engine\MemoryMap.cs" />
<Compile Include="Consoles\PC Engine\MemoryMap.SF2.cs" />
<Compile Include="Consoles\PC Engine\MemoryMap.SuperGrafx.cs" />
<Compile Include="Consoles\PC Engine\PCEngine.cs" />
<Compile Include="Sound\HuC6280PSG.cs" />
<Compile Include="Consoles\PC Engine\VCE.cs" />
<Compile Include="Consoles\PC Engine\VDC.cs" />
<Compile Include="Consoles\PC Engine\VDC.Render.cs" />
<Compile Include="Consoles\PC Engine\VPC.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Consoles\Sega\Genesis\Genesis.cs" />
<Compile Include="Consoles\Sega\Genesis\GenVDP.cs" />
<Compile Include="Consoles\Sega\Genesis\GenVDP.DMA.cs" />
<Compile Include="Consoles\Sega\Genesis\GenVDP.Render.cs" />
<Compile Include="Consoles\Sega\Genesis\IO.cs" />
<Compile Include="Consoles\Sega\Genesis\MemoryMap.68000.cs" />
<Compile Include="Consoles\Sega\Genesis\MemoryMap.Z80.cs" />
<Compile Include="Sound\VRC6Alt.cs" />
<Compile Include="Sound\YM2612.cs" />
<Compile Include="Consoles\Sega\SMS\BIOS.cs" />
<Compile Include="Sound\Utilities\SoundMixer.cs" />
<Compile Include="Consoles\Sega\SMS\Input.cs" />
<Compile Include="Sound\SN76489.cs" />
<Compile Include="Consoles\Sega\SMS\SMS.cs" />
<Compile Include="Consoles\Sega\SMS\VDP.cs" />
<Compile Include="Sound\YM2413.cs" />
<Compile Include="Util.cs" />
<Compile Include="Sound\Utilities\Waves.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Computers\Commodore64\docs\CRT.TXT" />
<Content Include="Consoles\Coleco\docs\CV-Sound.txt" />
<Content Include="Consoles\Coleco\docs\CV-Tech.txt" />
<Content Include="Consoles\Nintendo\NES\Docs\sunsoft.txt" />
<Content Include="Consoles\Nintendo\NES\Docs\sxrom_notes.txt" />
<Content Include="Consoles\PC Engine\Compat.txt" />
<Content Include="Consoles\Sega\Genesis\Compat.txt" />
<Content Include="Consoles\Sega\SMS\Compat.txt" />
<Content Include="Notes.txt" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<Folder Include="Computers\Commodore64\Peripheral\" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="Consoles\Atari\docs\stella.pdf" />
<None Include="Consoles\Coleco\docs\colecovision tech1.pdf" />
<None Include="Consoles\Coleco\docs\colecovision tech2.pdf" />
<None Include="Consoles\Nintendo\NES\Docs\BoardTable.xlsx" />
<None Include="Consoles\Nintendo\NES\Docs\MapperCompatibilityList.url" />
<None Include="Consoles\Nintendo\NES\Docs\nesasm.pdf" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">"$(SolutionDir)subwcrev.bat" "$(ProjectDir)"</PreBuildEvent>
<PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">"$(SolutionDir)subwcrev.sh" "$(ProjectDir)"</PreBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -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
/// </summary>
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

View File

@ -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

View File

@ -1,101 +0,0 @@
using System.IO;
using System;
namespace SevenZip
{
/// <summary>
/// The Stream extension class to emulate the archive part of a stream.
/// </summary>
internal class ArchiveEmulationStreamProxy : Stream, IDisposable
{
/// <summary>
/// Gets the file offset.
/// </summary>
public int Offset { get; private set; }
/// <summary>
/// The source wrapped stream.
/// </summary>
public Stream Source { get; private set; }
/// <summary>
/// Initializes a new instance of the ArchiveEmulationStream class.
/// </summary>
/// <param name="stream">The stream to wrap.</param>
/// <param name="offset">The stream offset.</param>
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();
}
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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
/// <summary>
/// Archive extraction callback to handle the process of unpacking files
/// </summary>
internal sealed class ArchiveExtractCallback : CallbackBase, IArchiveExtractCallback, ICryptoGetTextPassword,
IDisposable
{
private List<uint> _actualIndexes;
private IInArchive _archive;
/// <summary>
/// For Compressing event.
/// </summary>
private long _bytesCount;
private long _bytesWritten;
private long _bytesWrittenOld;
private string _directory;
/// <summary>
/// Rate of the done work from [0, 1].
/// </summary>
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
/// <summary>
/// Initializes a new instance of the ArchiveExtractCallback class
/// </summary>
/// <param name="archive">IInArchive interface for the archive</param>
/// <param name="directory">Directory where files are to be unpacked to</param>
/// <param name="filesCount">The archive files count</param>'
/// <param name="extractor">The owner of the callback</param>
/// <param name="actualIndexes">The list of actual indexes (solid archives support)</param>
/// <param name="directoryStructure">The value indicating whether to preserve directory structure of extracted files.</param>
public ArchiveExtractCallback(IInArchive archive, string directory, int filesCount, bool directoryStructure,
List<uint> actualIndexes, SevenZipExtractor extractor)
{
Init(archive, directory, filesCount, directoryStructure, actualIndexes, extractor);
}
/// <summary>
/// Initializes a new instance of the ArchiveExtractCallback class
/// </summary>
/// <param name="archive">IInArchive interface for the archive</param>
/// <param name="directory">Directory where files are to be unpacked to</param>
/// <param name="filesCount">The archive files count</param>
/// <param name="password">Password for the archive</param>
/// <param name="extractor">The owner of the callback</param>
/// <param name="actualIndexes">The list of actual indexes (solid archives support)</param>
/// <param name="directoryStructure">The value indicating whether to preserve directory structure of extracted files.</param>
public ArchiveExtractCallback(IInArchive archive, string directory, int filesCount, bool directoryStructure,
List<uint> actualIndexes, string password, SevenZipExtractor extractor)
: base(password)
{
Init(archive, directory, filesCount, directoryStructure, actualIndexes, extractor);
}
/// <summary>
/// Initializes a new instance of the ArchiveExtractCallback class
/// </summary>
/// <param name="archive">IInArchive interface for the archive</param>
/// <param name="stream">The stream where files are to be unpacked to</param>
/// <param name="filesCount">The archive files count</param>
/// <param name="fileIndex">The file index for the stream</param>
/// <param name="extractor">The owner of the callback</param>
public ArchiveExtractCallback(IInArchive archive, Stream stream, int filesCount, uint fileIndex,
SevenZipExtractor extractor)
{
Init(archive, stream, filesCount, fileIndex, extractor);
}
/// <summary>
/// Initializes a new instance of the ArchiveExtractCallback class
/// </summary>
/// <param name="archive">IInArchive interface for the archive</param>
/// <param name="stream">The stream where files are to be unpacked to</param>
/// <param name="filesCount">The archive files count</param>
/// <param name="fileIndex">The file index for the stream</param>
/// <param name="password">Password for the archive</param>
/// <param name="extractor">The owner of the callback</param>
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<uint> 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
/// <summary>
/// Occurs when a new file is going to be unpacked
/// </summary>
/// <remarks>Occurs when 7-zip engine requests for an output stream for a new file to unpack in</remarks>
public event EventHandler<FileInfoEventArgs> FileExtractionStarted;
/// <summary>
/// Occurs when a file has been successfully unpacked
/// </summary>
public event EventHandler<FileInfoEventArgs> FileExtractionFinished;
/// <summary>
/// Occurs when the archive is opened and 7-zip sends the size of unpacked data
/// </summary>
public event EventHandler<OpenEventArgs> Open;
/// <summary>
/// Occurs when the extraction is performed
/// </summary>
public event EventHandler<ProgressEventArgs> Extracting;
/// <summary>
/// Occurs during the extraction when a file already exists
/// </summary>
public event EventHandler<FileOverwriteEventArgs> 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
/// <summary>
/// Gives the size of the unpacked archive files
/// </summary>
/// <param name="total">Size of the unpacked archive files (in bytes)</param>
public void SetTotal(ulong total)
{
_bytesCount = (long)total;
OnOpen(new OpenEventArgs(total));
}
public void SetCompleted(ref ulong completeValue) { }
/// <summary>
/// Sets output stream for writing unpacked data
/// </summary>
/// <param name="index">Current file index</param>
/// <param name="outStream">Output stream pointer</param>
/// <param name="askExtractMode">Extraction mode</param>
/// <returns>0 if OK</returns>
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) { }
/// <summary>
/// Called when the archive was extracted
/// </summary>
/// <param name="operationResult"></param>
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
/// <summary>
/// Sets password for the archive
/// </summary>
/// <param name="password">Password for the archive</param>
/// <returns>Zero if everything is OK</returns>
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
/// <summary>
/// Validates the file name and ensures that the directory to the file name is valid and creates intermediate directories if necessary
/// </summary>
/// <param name="fileName">File name</param>
/// <returns>The valid file name</returns>
private static string ValidateFileName(string fileName)
{
if (String.IsNullOrEmpty(fileName))
{
throw new SevenZipArchiveException("some archive name is null or empty.");
}
var splittedFileName = new List<string>(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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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
/// <summary>
/// Callback to handle the archive opening
/// </summary>
internal sealed class ArchiveOpenCallback : CallbackBase, IArchiveOpenCallback, IArchiveOpenVolumeCallback,
ICryptoGetTextPassword, IDisposable
{
private FileInfo _fileInfo;
private Dictionary<string, InStreamWrapper> _wrappers =
new Dictionary<string, InStreamWrapper>();
public readonly List<string> VolumeFileNames = new List<string>();
/// <summary>
/// Performs the common initialization.
/// </summary>
/// <param name="fileName">Volume file name.</param>
private void Init(string fileName)
{
if (!String.IsNullOrEmpty(fileName))
{
_fileInfo = new FileInfo(fileName);
VolumeFileNames.Add(fileName);
}
}
/// <summary>
/// Initializes a new instance of the ArchiveOpenCallback class.
/// </summary>
/// <param name="fileName">The archive file name.</param>
public ArchiveOpenCallback(string fileName)
{
Init(fileName);
}
/// <summary>
/// Initializes a new instance of the ArchiveOpenCallback class.
/// </summary>
/// <param name="fileName">The archive file name.</param>
/// <param name="password">Password for the archive.</param>
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
/// <summary>
/// Sets password for the archive
/// </summary>
/// <param name="password">Password for the archive</param>
/// <returns>Zero if everything is OK</returns>
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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
/// <summary>
/// Archive update callback to handle the process of packing files
/// </summary>
internal sealed class ArchiveUpdateCallback : CallbackBase, IArchiveUpdateCallback, ICryptoGetTextPassword2,
IDisposable
{
#region Fields
/// <summary>
/// _files.Count if do not count directories
/// </summary>
private int _actualFilesCount;
/// <summary>
/// For Compressing event.
/// </summary>
private long _bytesCount;
private long _bytesWritten;
private long _bytesWrittenOld;
private SevenZipCompressor _compressor;
/// <summary>
/// No directories.
/// </summary>
private bool _directoryStructure;
/// <summary>
/// Rate of the done work from [0, 1]
/// </summary>
private float _doneRate;
/// <summary>
/// The names of the archive entries
/// </summary>
private string[] _entries;
/// <summary>
/// Array of files to pack
/// </summary>
private FileInfo[] _files;
private InStreamWrapper _fileStream;
private uint _indexInArchive;
private uint _indexOffset;
/// <summary>
/// Common root of file names length.
/// </summary>
private int _rootLength;
/// <summary>
/// Input streams to be compressed.
/// </summary>
private Stream[] _streams;
private UpdateData _updateData;
private List<InStreamWrapper> _wrappersToDispose;
/// <summary>
/// Gets or sets the default item name used in MemoryStream compression.
/// </summary>
public string DefaultItemName { private get; set; }
/// <summary>
/// Gets or sets the value indicating whether to compress as fast as possible, without calling events.
/// </summary>
public bool FastCompression { private get; set; }
#if !WINCE
private int _memoryPressure;
#endif
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the ArchiveUpdateCallback class
/// </summary>
/// <param name="files">Array of files to pack</param>
/// <param name="rootLength">Common file names root length</param>
/// <param name="compressor">The owner of the callback</param>
/// <param name="updateData">The compression parameters.</param>
/// <param name="directoryStructure">Preserve directory structure.</param>
public ArchiveUpdateCallback(
FileInfo[] files, int rootLength,
SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
{
Init(files, rootLength, compressor, updateData, directoryStructure);
}
/// <summary>
/// Initializes a new instance of the ArchiveUpdateCallback class
/// </summary>
/// <param name="files">Array of files to pack</param>
/// <param name="rootLength">Common file names root length</param>
/// <param name="password">The archive password</param>
/// <param name="compressor">The owner of the callback</param>
/// <param name="updateData">The compression parameters.</param>
/// <param name="directoryStructure">Preserve directory structure.</param>
public ArchiveUpdateCallback(
FileInfo[] files, int rootLength, string password,
SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
: base(password)
{
Init(files, rootLength, compressor, updateData, directoryStructure);
}
/// <summary>
/// Initializes a new instance of the ArchiveUpdateCallback class
/// </summary>
/// <param name="stream">The input stream</param>
/// <param name="compressor">The owner of the callback</param>
/// <param name="updateData">The compression parameters.</param>
/// <param name="directoryStructure">Preserve directory structure.</param>
public ArchiveUpdateCallback(
Stream stream, SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
{
Init(stream, compressor, updateData, directoryStructure);
}
/// <summary>
/// Initializes a new instance of the ArchiveUpdateCallback class
/// </summary>
/// <param name="stream">The input stream</param>
/// <param name="password">The archive password</param>
/// <param name="compressor">The owner of the callback</param>
/// <param name="updateData">The compression parameters.</param>
/// <param name="directoryStructure">Preserve directory structure.</param>
public ArchiveUpdateCallback(
Stream stream, string password, SevenZipCompressor compressor, UpdateData updateData,
bool directoryStructure)
: base(password)
{
Init(stream, compressor, updateData, directoryStructure);
}
/// <summary>
/// Initializes a new instance of the ArchiveUpdateCallback class
/// </summary>
/// <param name="streamDict">Dictionary&lt;file stream, name of the archive entry&gt;</param>
/// <param name="compressor">The owner of the callback</param>
/// <param name="updateData">The compression parameters.</param>
/// <param name="directoryStructure">Preserve directory structure.</param>
public ArchiveUpdateCallback(
Dictionary<string, Stream> streamDict,
SevenZipCompressor compressor, UpdateData updateData, bool directoryStructure)
{
Init(streamDict, compressor, updateData, directoryStructure);
}
/// <summary>
/// Initializes a new instance of the ArchiveUpdateCallback class
/// </summary>
/// <param name="streamDict">Dictionary&lt;file stream, name of the archive entry&gt;</param>
/// <param name="password">The archive password</param>
/// <param name="compressor">The owner of the callback</param>
/// <param name="updateData">The compression parameters.</param>
/// <param name="directoryStructure">Preserve directory structure.</param>
public ArchiveUpdateCallback(
Dictionary<string, Stream> 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<InStreamWrapper>();
}
_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<string, Stream> 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
/// <summary>
/// Gets or sets the dictionary size.
/// </summary>
public float DictionarySize
{
set
{
#if !WINCE
_memoryPressure = (int)(value * 1024 * 1024);
GC.AddMemoryPressure(_memoryPressure);
#endif
}
}
/// <summary>
/// Raises events for the GetStream method.
/// </summary>
/// <param name="index">The current item index.</param>
/// <returns>True if not cancelled; otherwise, false.</returns>
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
/// <summary>
/// Occurs when the next file is going to be packed.
/// </summary>
/// <remarks>Occurs when 7-zip engine requests for an input stream for the next file to pack it</remarks>
public event EventHandler<FileNameEventArgs> FileCompressionStarted;
/// <summary>
/// Occurs when data are being compressed.
/// </summary>
public event EventHandler<ProgressEventArgs> Compressing;
/// <summary>
/// Occurs when the current file was compressed.
/// </summary>
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<Int32, string> 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;
}
/// <summary>
/// Gets the stream for 7-zip library.
/// </summary>
/// <param name="index">File index</param>
/// <param name="inStream">Input file stream</param>
/// <returns>Zero if Ok</returns>
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
}

File diff suppressed because it is too large Load Diff

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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
/// <summary>
/// The way of the event synchronization.
/// </summary>
public enum EventSynchronizationStrategy
{
/// <summary>
/// Events are called synchronously if user can do some action; that is, cancel the execution process for example.
/// </summary>
Default,
/// <summary>
/// Always call events asynchronously.
/// </summary>
AlwaysAsynchronous,
/// <summary>
/// Always call events synchronously.
/// </summary>
AlwaysSynchronous
}
/// <summary>
/// SevenZip Extractor/Compressor base class. Implements Password string, ReportErrors flag.
/// </summary>
public class SevenZipBase : MarshalByRefObject
{
private readonly string _password;
private readonly bool _reportErrors;
private readonly int _uniqueID;
private static readonly List<int> Identificators = new List<int>();
#if !WINCE
internal static readonly AsyncCallback AsyncCallbackImplementation = AsyncCallbackMethod;
/// <summary>
/// True if the instance of the class needs to be recreated in new thread context; otherwise, false.
/// </summary>
protected internal bool NeedsToBeRecreated;
/// <summary>
/// AsyncCallback implementation used in asynchronous invocations.
/// </summary>
/// <param name="ar">IAsyncResult instance.</param>
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<T>(EventHandler<T> handler, T e) where T : EventArgs;
internal void OnEvent<T>(EventHandler<T> 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<T>((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<T>)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
/// <summary>
/// Gets or sets the Dispatcher object for this instance.
/// It will be used to fire events in the user context.
/// </summary>
internal Dispatcher Dispatcher { get; set; }
/// <summary>
/// Gets or sets the Dispatcher priority of calling user events.
/// </summary>
internal DispatcherPriority Priority { get; set; }
#else
internal SynchronizationContext Context { get; set; }
#endif
/// <summary>
/// Gets or sets the event synchronization strategy.
/// </summary>
public EventSynchronizationStrategy EventSynchronization { get; set; }
#else // WINCE
internal void OnEvent<T>(EventHandler<T> handler, T e, bool synchronous) where T : System.EventArgs
{
try
{
handler(this, e);
}
catch (Exception ex)
{
AddException(ex);
}
}
#endif
/// <summary>
/// Gets the unique identificator of this SevenZipBase instance.
/// </summary>
public int UniqueID
{
get
{
return _uniqueID;
}
}
/// <summary>
/// User exceptions thrown during the requested operations, for example, in events.
/// </summary>
private readonly List<Exception> _exceptions = new List<Exception>();
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
/// <summary>
/// Initializes a new instance of the SevenZipBase class.
/// </summary>
protected SevenZipBase()
{
_password = "";
_reportErrors = true;
_uniqueID = GetUniqueID();
}
/// <summary>
/// Initializes a new instance of the SevenZipBase class
/// </summary>
/// <param name="password">The archive password.</param>
protected SevenZipBase(string password)
{
if (String.IsNullOrEmpty(password))
{
throw new SevenZipException("Empty password was specified.");
}
_password = password;
_reportErrors = true;
_uniqueID = GetUniqueID();
}
#endregion
/// <summary>
/// Removes the UniqueID from the list.
/// </summary>
~SevenZipBase()
{
Identificators.Remove(_uniqueID);
}
/// <summary>
/// Gets or sets the archive password
/// </summary>
public string Password
{
get
{
return _password;
}
}
/// <summary>
/// Gets or sets throw exceptions on archive errors flag
/// </summary>
internal bool ReportErrors
{
get
{
return _reportErrors;
}
}
/// <summary>
/// Gets the user exceptions thrown during the requested operations, for example, in events.
/// </summary>
internal ReadOnlyCollection<Exception> Exceptions
{
get
{
return new ReadOnlyCollection<Exception>(_exceptions);
}
}
internal void AddException(Exception e)
{
_exceptions.Add(e);
}
internal void ClearExceptions()
{
_exceptions.Clear();
}
internal bool HasExceptions
{
get
{
return _exceptions.Count > 0;
}
}
/// <summary>
/// Throws the specified exception when is able to.
/// </summary>
/// <param name="e">The exception to throw.</param>
/// <param name="handler">The handler responsible for the exception.</param>
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);
}
}
/// <summary>
/// Throws exception if HRESULT != 0.
/// </summary>
/// <param name="hresult">Result code to check.</param>
/// <param name="message">Exception message.</param>
/// <param name="handler">The class responsible for the callback.</param>
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
/// <summary>
/// Changes the path to the 7-zip native library.
/// </summary>
/// <param name="libraryPath">The path to the 7-zip native library.</param>
public static void SetLibraryPath(string libraryPath)
{
SevenZipLibraryManager.SetLibraryPath(libraryPath);
}
#endif
/// <summary>
/// Gets the current library features.
/// </summary>
public static LibraryFeature CurrentLibraryFeatures
{
get
{
return SevenZipLibraryManager.CurrentLibraryFeatures;
}
}
/// <summary>
/// Determines whether the specified System.Object is equal to the current SevenZipBase.
/// </summary>
/// <param name="obj">The System.Object to compare with the current SevenZipBase.</param>
/// <returns>true if the specified System.Object is equal to the current SevenZipBase; otherwise, false.</returns>
public override bool Equals(object obj)
{
var inst = obj as SevenZipBase;
if (inst == null)
{
return false;
}
return _uniqueID == inst._uniqueID;
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns> A hash code for the current SevenZipBase.</returns>
public override int GetHashCode()
{
return _uniqueID;
}
/// <summary>
/// Returns a System.String that represents the current SevenZipBase.
/// </summary>
/// <returns>A System.String that represents the current SevenZipBase.</returns>
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;
/// <summary>
/// User exceptions thrown during the requested operations, for example, in events.
/// </summary>
private readonly List<Exception> _exceptions = new List<Exception>();
#region Constructors
/// <summary>
/// Initializes a new instance of the CallbackBase class.
/// </summary>
protected CallbackBase()
{
_password = "";
_reportErrors = true;
}
/// <summary>
/// Initializes a new instance of the CallbackBase class.
/// </summary>
/// <param name="password">The archive password.</param>
protected CallbackBase(string password)
{
if (String.IsNullOrEmpty(password))
{
throw new SevenZipException("Empty password was specified.");
}
_password = password;
_reportErrors = true;
}
#endregion
/// <summary>
/// Gets or sets the archive password
/// </summary>
public string Password
{
get
{
return _password;
}
}
/// <summary>
/// Gets or sets the value indicating whether the current procedure was cancelled.
/// </summary>
public bool Canceled { get; set; }
/// <summary>
/// Gets or sets throw exceptions on archive errors flag
/// </summary>
public bool ReportErrors
{
get
{
return _reportErrors;
}
}
/// <summary>
/// Gets the user exceptions thrown during the requested operations, for example, in events.
/// </summary>
public ReadOnlyCollection<Exception> Exceptions
{
get
{
return new ReadOnlyCollection<Exception>(_exceptions);
}
}
public void AddException(Exception e)
{
_exceptions.Add(e);
}
public void ClearExceptions()
{
_exceptions.Clear();
}
public bool HasExceptions
{
get
{
return _exceptions.Count > 0;
}
}
/// <summary>
/// Throws the specified exception when is able to.
/// </summary>
/// <param name="e">The exception to throw.</param>
/// <param name="handler">The handler responsible for the exception.</param>
public bool ThrowException(CallbackBase handler, params Exception[] e)
{
if (_reportErrors && (handler == null || !handler.Canceled))
{
throw e[0];
}
return false;
}
/// <summary>
/// Throws the first exception in the list if any exists.
/// </summary>
/// <returns>True means no exceptions.</returns>
public bool ThrowException()
{
if (HasExceptions && _reportErrors)
{
throw _exceptions[0];
}
return true;
}
public void ThrowUserException()
{
if (HasExceptions)
{
throw new SevenZipException(SevenZipException.USER_EXCEPTION_MESSAGE);
}
}
}
/// <summary>
/// Struct for storing information about files in the 7-zip archive.
/// </summary>
public struct ArchiveFileInfo
{
/// <summary>
/// Gets or sets index of the file in the archive file table.
/// </summary>
public int Index { get; set; }
/// <summary>
/// Gets or sets file name
/// </summary>
public string FileName { get; set; }
/// <summary>
/// Gets or sets the file last write time.
/// </summary>
public DateTime LastWriteTime { get; set; }
/// <summary>
/// Gets or sets the file creation time.
/// </summary>
public DateTime CreationTime { get; set; }
/// <summary>
/// Gets or sets the file creation time.
/// </summary>
public DateTime LastAccessTime { get; set; }
/// <summary>
/// Gets or sets size of the file (unpacked).
/// </summary>
public ulong Size { get; set; }
/// <summary>
/// Gets or sets CRC checksum of the file.
/// </summary>
public uint Crc { get; set; }
/// <summary>
/// Gets or sets file attributes.
/// </summary>
public uint Attributes { get; set; }
/// <summary>
/// Gets or sets being a directory.
/// </summary>
public bool IsDirectory { get; set; }
/// <summary>
/// Gets or sets being encrypted.
/// </summary>
public bool Encrypted { get; set; }
/// <summary>
/// Gets or sets comment for the file.
/// </summary>
public string Comment { get; set; }
/// <summary>
/// Determines whether the specified System.Object is equal to the current ArchiveFileInfo.
/// </summary>
/// <param name="obj">The System.Object to compare with the current ArchiveFileInfo.</param>
/// <returns>true if the specified System.Object is equal to the current ArchiveFileInfo; otherwise, false.</returns>
public override bool Equals(object obj)
{
return (obj is ArchiveFileInfo) ? Equals((ArchiveFileInfo) obj) : false;
}
/// <summary>
/// Determines whether the specified ArchiveFileInfo is equal to the current ArchiveFileInfo.
/// </summary>
/// <param name="afi">The ArchiveFileInfo to compare with the current ArchiveFileInfo.</param>
/// <returns>true if the specified ArchiveFileInfo is equal to the current ArchiveFileInfo; otherwise, false.</returns>
public bool Equals(ArchiveFileInfo afi)
{
return afi.Index == Index && afi.FileName == FileName;
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns> A hash code for the current ArchiveFileInfo.</returns>
public override int GetHashCode()
{
return FileName.GetHashCode() ^ Index;
}
/// <summary>
/// Returns a System.String that represents the current ArchiveFileInfo.
/// </summary>
/// <returns>A System.String that represents the current ArchiveFileInfo.</returns>
public override string ToString()
{
return "[" + Index.ToString(CultureInfo.CurrentCulture) + "] " + FileName;
}
/// <summary>
/// Determines whether the specified ArchiveFileInfo instances are considered equal.
/// </summary>
/// <param name="afi1">The first ArchiveFileInfo to compare.</param>
/// <param name="afi2">The second ArchiveFileInfo to compare.</param>
/// <returns>true if the specified ArchiveFileInfo instances are considered equal; otherwise, false.</returns>
public static bool operator ==(ArchiveFileInfo afi1, ArchiveFileInfo afi2)
{
return afi1.Equals(afi2);
}
/// <summary>
/// Determines whether the specified ArchiveFileInfo instances are not considered equal.
/// </summary>
/// <param name="afi1">The first ArchiveFileInfo to compare.</param>
/// <param name="afi2">The second ArchiveFileInfo to compare.</param>
/// <returns>true if the specified ArchiveFileInfo instances are not considered equal; otherwise, false.</returns>
public static bool operator !=(ArchiveFileInfo afi1, ArchiveFileInfo afi2)
{
return !afi1.Equals(afi2);
}
}
/// <summary>
/// Archive property struct.
/// </summary>
public struct ArchiveProperty
{
/// <summary>
/// Gets the name of the archive property.
/// </summary>
public string Name { get; internal set; }
/// <summary>
/// Gets the value of the archive property.
/// </summary>
public object Value { get; internal set; }
/// <summary>
/// Determines whether the specified System.Object is equal to the current ArchiveProperty.
/// </summary>
/// <param name="obj">The System.Object to compare with the current ArchiveProperty.</param>
/// <returns>true if the specified System.Object is equal to the current ArchiveProperty; otherwise, false.</returns>
public override bool Equals(object obj)
{
return (obj is ArchiveProperty) ? Equals((ArchiveProperty) obj) : false;
}
/// <summary>
/// Determines whether the specified ArchiveProperty is equal to the current ArchiveProperty.
/// </summary>
/// <param name="afi">The ArchiveProperty to compare with the current ArchiveProperty.</param>
/// <returns>true if the specified ArchiveProperty is equal to the current ArchiveProperty; otherwise, false.</returns>
public bool Equals(ArchiveProperty afi)
{
return afi.Name == Name && afi.Value == Value;
}
/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns> A hash code for the current ArchiveProperty.</returns>
public override int GetHashCode()
{
return Name.GetHashCode() ^ Value.GetHashCode();
}
/// <summary>
/// Returns a System.String that represents the current ArchiveProperty.
/// </summary>
/// <returns>A System.String that represents the current ArchiveProperty.</returns>
public override string ToString()
{
return Name + " = " + Value;
}
/// <summary>
/// Determines whether the specified ArchiveProperty instances are considered equal.
/// </summary>
/// <param name="afi1">The first ArchiveProperty to compare.</param>
/// <param name="afi2">The second ArchiveProperty to compare.</param>
/// <returns>true if the specified ArchiveProperty instances are considered equal; otherwise, false.</returns>
public static bool operator ==(ArchiveProperty afi1, ArchiveProperty afi2)
{
return afi1.Equals(afi2);
}
/// <summary>
/// Determines whether the specified ArchiveProperty instances are not considered equal.
/// </summary>
/// <param name="afi1">The first ArchiveProperty to compare.</param>
/// <param name="afi2">The second ArchiveProperty to compare.</param>
/// <returns>true if the specified ArchiveProperty instances are not considered equal; otherwise, false.</returns>
public static bool operator !=(ArchiveProperty afi1, ArchiveProperty afi2)
{
return !afi1.Equals(afi2);
}
}
#if COMPRESS
/// <summary>
/// Archive compression mode.
/// </summary>
public enum CompressionMode
{
/// <summary>
/// Create a new archive; overwrite the existing one.
/// </summary>
Create,
/// <summary>
/// Add data to the archive.
/// </summary>
Append,
}
internal enum InternalCompressionMode
{
/// <summary>
/// Create a new archive; overwrite the existing one.
/// </summary>
Create,
/// <summary>
/// Add data to the archive.
/// </summary>
Append,
/// <summary>
/// Modify archive data.
/// </summary>
Modify
}
/// <summary>
/// Zip encryption method enum.
/// </summary>
public enum ZipEncryptionMethod
{
/// <summary>
/// ZipCrypto encryption method.
/// </summary>
ZipCrypto,
/// <summary>
/// AES 128 bit encryption method.
/// </summary>
Aes128,
/// <summary>
/// AES 192 bit encryption method.
/// </summary>
Aes192,
/// <summary>
/// AES 256 bit encryption method.
/// </summary>
Aes256
}
/// <summary>
/// Archive update data for UpdateCallback.
/// </summary>
internal struct UpdateData
{
public uint FilesCount;
public InternalCompressionMode Mode;
public Dictionary<int, string> FileNamesToModify { get; set; }
public List<ArchiveFileInfo> ArchiveFileData { get; set; }
}
#endif
#endif
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
namespace SevenZip
{
/// <summary>
/// EventArgs for storing PercentDone property.
/// </summary>
public class PercentDoneEventArgs : EventArgs
{
private readonly byte _percentDone;
/// <summary>
/// Initializes a new instance of the PercentDoneEventArgs class.
/// </summary>
/// <param name="percentDone">The percent of finished work.</param>
/// <exception cref="System.ArgumentOutOfRangeException"/>
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;
}
/// <summary>
/// Gets the percent of finished work.
/// </summary>
public byte PercentDone
{
get
{
return _percentDone;
}
}
/// <summary>
/// Gets or sets whether to stop the current archive operation.
/// </summary>
public bool Cancel { get; set; }
/// <summary>
/// Converts a [0, 1] rate to its percent equivalent.
/// </summary>
/// <param name="doneRate">The rate of the done work.</param>
/// <returns>Percent integer equivalent.</returns>
/// <exception cref="System.ArgumentException"/>
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
}
}
/// <summary>
/// The EventArgs class for accurate progress handling.
/// </summary>
public sealed class ProgressEventArgs : PercentDoneEventArgs
{
private readonly byte _delta;
/// <summary>
/// Initializes a new instance of the ProgressEventArgs class.
/// </summary>
/// <param name="percentDone">The percent of finished work.</param>
/// <param name="percentDelta">The percent of work done after the previous event.</param>
public ProgressEventArgs(byte percentDone, byte percentDelta)
: base(percentDone)
{
_delta = percentDelta;
}
/// <summary>
/// Gets the change in done work percentage.
/// </summary>
public byte PercentDelta
{
get
{
return _delta;
}
}
}
#if UNMANAGED
/// <summary>
/// EventArgs used to report the file information which is going to be packed.
/// </summary>
public sealed class FileInfoEventArgs : PercentDoneEventArgs
{
private readonly ArchiveFileInfo _fileInfo;
/// <summary>
/// Initializes a new instance of the FileInfoEventArgs class.
/// </summary>
/// <param name="fileInfo">The current ArchiveFileInfo.</param>
/// <param name="percentDone">The percent of finished work.</param>
public FileInfoEventArgs(ArchiveFileInfo fileInfo, byte percentDone)
: base(percentDone)
{
_fileInfo = fileInfo;
}
/// <summary>
/// Gets the corresponding FileInfo to the event.
/// </summary>
public ArchiveFileInfo FileInfo
{
get
{
return _fileInfo;
}
}
}
/// <summary>
/// EventArgs used to report the size of unpacked archive data
/// </summary>
public sealed class OpenEventArgs : EventArgs
{
private readonly ulong _totalSize;
/// <summary>
/// Initializes a new instance of the OpenEventArgs class
/// </summary>
/// <param name="totalSize">Size of unpacked archive data</param>
public OpenEventArgs(ulong totalSize)
{
_totalSize = totalSize;
}
/// <summary>
/// Gets the size of unpacked archive data
/// </summary>
public ulong TotalSize
{
get
{
return _totalSize;
}
}
}
/// <summary>
/// Stores an int number
/// </summary>
public sealed class IntEventArgs : EventArgs
{
private readonly int _value;
/// <summary>
/// Initializes a new instance of the IntEventArgs class
/// </summary>
/// <param name="value">Useful data carried by the IntEventArgs class</param>
public IntEventArgs(int value)
{
_value = value;
}
/// <summary>
/// Gets the value of the IntEventArgs class
/// </summary>
public int Value
{
get
{
return _value;
}
}
}
/// <summary>
/// EventArgs class which stores the file name.
/// </summary>
public sealed class FileNameEventArgs : PercentDoneEventArgs
{
private readonly string _fileName;
/// <summary>
/// Initializes a new instance of the FileNameEventArgs class.
/// </summary>
/// <param name="fileName">The file name.</param>
/// <param name="percentDone">The percent of finished work</param>
public FileNameEventArgs(string fileName, byte percentDone) :
base(percentDone)
{
_fileName = fileName;
}
/// <summary>
/// Gets the file name.
/// </summary>
public string FileName
{
get
{
return _fileName;
}
}
}
/// <summary>
/// EventArgs for FileExists event, stores the file name and asks whether to overwrite it in case it already exists.
/// </summary>
public sealed class FileOverwriteEventArgs : EventArgs
{
/// <summary>
/// Initializes a new instance of the FileOverwriteEventArgs class
/// </summary>
/// <param name="fileName">The file name.</param>
public FileOverwriteEventArgs(string fileName)
{
FileName = fileName;
}
/// <summary>
/// Gets or sets the value indicating whether to cancel the extraction.
/// </summary>
public bool Cancel { get; set; }
/// <summary>
/// Gets or sets the file name to extract to. Null means skip.
/// </summary>
public string FileName { get; set; }
}
/// <summary>
/// The reason for calling <see cref="ExtractFileCallback"/>.
/// </summary>
public enum ExtractFileCallbackReason
{
/// <summary>
/// <see cref="ExtractFileCallback"/> is called the first time for a file.
/// </summary>
Start,
/// <summary>
/// All data has been written to the target without any exceptions.
/// </summary>
Done,
/// <summary>
/// An exception occured during extraction of the file.
/// </summary>
Failure
}
/// <summary>
/// The arguments passed to <see cref="ExtractFileCallback"/>.
/// </summary>
/// <remarks>
/// For each file, <see cref="ExtractFileCallback"/> is first called with <see cref="Reason"/>
/// set to <see cref="ExtractFileCallbackReason.Start"/>. If the callback chooses to extract the
/// file data by setting <see cref="ExtractToFile"/> or <see cref="ExtractToStream"/>, the callback
/// will be called a second time with <see cref="Reason"/> set to
/// <see cref="ExtractFileCallbackReason.Done"/> or <see cref="ExtractFileCallbackReason.Failure"/>
/// to allow for any cleanup task like closing the stream.
/// </remarks>
public class ExtractFileCallbackArgs : EventArgs
{
private readonly ArchiveFileInfo _archiveFileInfo;
private Stream _extractToStream;
/// <summary>
/// Initializes a new instance of the <see cref="ExtractFileCallbackArgs"/> class.
/// </summary>
/// <param name="archiveFileInfo">The information about file in the archive.</param>
public ExtractFileCallbackArgs(ArchiveFileInfo archiveFileInfo)
{
Reason = ExtractFileCallbackReason.Start;
_archiveFileInfo = archiveFileInfo;
}
/// <summary>
/// Information about file in the archive.
/// </summary>
/// <value>Information about file in the archive.</value>
public ArchiveFileInfo ArchiveFileInfo
{
get
{
return _archiveFileInfo;
}
}
/// <summary>
/// The reason for calling <see cref="ExtractFileCallback"/>.
/// </summary>
/// <remarks>
/// If neither <see cref="ExtractToFile"/> nor <see cref="ExtractToStream"/> is set,
/// <see cref="ExtractFileCallback"/> will not be called after <see cref="ExtractFileCallbackReason.Start"/>.
/// </remarks>
/// <value>The reason.</value>
public ExtractFileCallbackReason Reason { get; internal set; }
/// <summary>
/// The exception that occurred during extraction.
/// </summary>
/// <value>The _Exception.</value>
/// <remarks>
/// If the callback is called with <see cref="Reason"/> set to <see cref="ExtractFileCallbackReason.Failure"/>,
/// 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 <see cref="Exception"/> to <c>null</c> to swallow the _Exception
/// and continue extraction with the next file.
/// </remarks>
public Exception Exception { get; set; }
/// <summary>
/// Gets or sets a value indicating whether to cancel the extraction.
/// </summary>
/// <value><c>true</c> to cancel the extraction; <c>false</c> to continue. The default is <c>false</c>.</value>
public bool CancelExtraction { get; set; }
/// <summary>
/// Gets or sets whether and where to extract the file.
/// </summary>
/// <value>The path where to extract the file to.</value>
/// <remarks>
/// If <see cref="ExtractToStream"/> is set, this mmember will be ignored.
/// </remarks>
public string ExtractToFile { get; set; }
/// <summary>
/// Gets or sets whether and where to extract the file.
/// </summary>
/// <value>The the extracted data is written to.</value>
/// <remarks>
/// If both this member and <see cref="ExtractToFile"/> are <c>null</c> (the defualt), the file
/// will not be extracted and the callback will be be executed a second time with the <see cref="Reason"/>
/// set to <see cref="ExtractFileCallbackReason.Done"/> or <see cref="ExtractFileCallbackReason.Failure"/>.
/// </remarks>
public Stream ExtractToStream
{
get
{
return _extractToStream;
}
set
{
if (_extractToStream != null && !_extractToStream.CanWrite)
{
throw new ExtractionFailedException("The specified stream is not writable!");
}
_extractToStream = value;
}
}
/// <summary>
/// Gets or sets any data that will be preserved between the <see cref="ExtractFileCallbackReason.Start"/> callback call
/// and the <see cref="ExtractFileCallbackReason.Done"/> or <see cref="ExtractFileCallbackReason.Failure"/> calls.
/// </summary>
/// <value>The data.</value>
public object ObjectData { get; set; }
}
/// <summary>
/// Callback delegate for <see cref="SevenZipExtractor.ExtractFiles(SevenZip.ExtractFileCallback)"/>.
/// </summary>
public delegate void ExtractFileCallback(ExtractFileCallbackArgs extractFileCallbackArgs);
#endif
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
using System;
#if !WINCE
using System.Runtime.Serialization;
#endif
namespace SevenZip
{
/// <summary>
/// Base SevenZip exception class.
/// </summary>
[Serializable]
public class SevenZipException : Exception
{
/// <summary>
/// The message for thrown user exceptions.
/// </summary>
internal const string USER_EXCEPTION_MESSAGE = "The extraction was successful but" +
"some exceptions were thrown in your events. Check UserExceptions for details.";
/// <summary>
/// Initializes a new instance of the SevenZipException class
/// </summary>
public SevenZipException() : base("SevenZip unknown exception.") {}
/// <summary>
/// Initializes a new instance of the SevenZipException class
/// </summary>
/// <param name="defaultMessage">Default exception message</param>
public SevenZipException(string defaultMessage)
: base(defaultMessage) {}
/// <summary>
/// Initializes a new instance of the SevenZipException class
/// </summary>
/// <param name="defaultMessage">Default exception message</param>
/// <param name="message">Additional detailed message</param>
public SevenZipException(string defaultMessage, string message)
: base(defaultMessage + " Message: " + message) {}
/// <summary>
/// Initializes a new instance of the SevenZipException class
/// </summary>
/// <param name="defaultMessage">Default exception message</param>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipException(string defaultMessage, string message, Exception inner)
: base(
defaultMessage + (defaultMessage.EndsWith(" ", StringComparison.CurrentCulture) ? "" : " Message: ") +
message, inner) {}
/// <summary>
/// Initializes a new instance of the SevenZipException class
/// </summary>
/// <param name="defaultMessage">Default exception message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipException(string defaultMessage, Exception inner)
: base(defaultMessage, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the SevenZipException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected SevenZipException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if UNMANAGED
/// <summary>
/// Exception class for ArchiveExtractCallback.
/// </summary>
[Serializable]
public class ExtractionFailedException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public const string DEFAULT_MESSAGE = "Could not extract files!";
/// <summary>
/// Initializes a new instance of the ExtractionFailedException class
/// </summary>
public ExtractionFailedException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the ExtractionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public ExtractionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the ExtractionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public ExtractionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the ExtractionFailedException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected ExtractionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if COMPRESS
/// <summary>
/// Exception class for ArchiveUpdateCallback.
/// </summary>
[Serializable]
public class CompressionFailedException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public const string DEFAULT_MESSAGE = "Could not pack files!";
/// <summary>
/// Initializes a new instance of the CompressionFailedException class
/// </summary>
public CompressionFailedException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the CompressionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public CompressionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the CompressionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public CompressionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the CompressionFailedException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected CompressionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
#endif
/// <summary>
/// Exception class for LZMA operations.
/// </summary>
[Serializable]
public class LzmaException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public const string DEFAULT_MESSAGE = "Specified stream is not a valid LZMA compressed stream!";
/// <summary>
/// Initializes a new instance of the LzmaException class
/// </summary>
public LzmaException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the LzmaException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public LzmaException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the LzmaException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public LzmaException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the LzmaException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected LzmaException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if UNMANAGED
/// <summary>
/// Exception class for 7-zip archive open or read operations.
/// </summary>
[Serializable]
public class SevenZipArchiveException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
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.";
/// <summary>
/// Initializes a new instance of the SevenZipArchiveException class
/// </summary>
public SevenZipArchiveException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the SevenZipArchiveException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public SevenZipArchiveException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the SevenZipArchiveException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipArchiveException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the SevenZipArchiveException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected SevenZipArchiveException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
/// <summary>
/// Exception class for empty common root if file name array in SevenZipCompressor.
/// </summary>
[Serializable]
public class SevenZipInvalidFileNamesException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public const string DEFAULT_MESSAGE = "Invalid file names have been specified: ";
/// <summary>
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
/// </summary>
public SevenZipInvalidFileNamesException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public SevenZipInvalidFileNamesException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipInvalidFileNamesException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the SevenZipInvalidFileNamesException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected SevenZipInvalidFileNamesException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#if COMPRESS
/// <summary>
/// Exception class for fail to create an archive in SevenZipCompressor.
/// </summary>
[Serializable]
public class SevenZipCompressionFailedException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public const string DEFAULT_MESSAGE = "The compression has failed for an unknown reason with code ";
/// <summary>
/// Initializes a new instance of the SevenZipCompressionFailedException class
/// </summary>
public SevenZipCompressionFailedException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the SevenZipCompressionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public SevenZipCompressionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the SevenZipCompressionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipCompressionFailedException(string message, Exception inner)
: base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the SevenZipCompressionFailedException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected SevenZipCompressionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
/// <summary>
/// Exception class for fail to extract an archive in SevenZipExtractor.
/// </summary>
[Serializable]
public class SevenZipExtractionFailedException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public const string DEFAULT_MESSAGE = "The extraction has failed for an unknown reason with code ";
/// <summary>
/// Initializes a new instance of the SevenZipExtractionFailedException class
/// </summary>
public SevenZipExtractionFailedException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the SevenZipExtractionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public SevenZipExtractionFailedException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the SevenZipExtractionFailedException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipExtractionFailedException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the SevenZipExtractionFailedException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected SevenZipExtractionFailedException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
/// <summary>
/// Exception class for 7-zip library operations.
/// </summary>
[Serializable]
public class SevenZipLibraryException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public const string DEFAULT_MESSAGE = "Can not load 7-zip library or internal COM error!";
/// <summary>
/// Initializes a new instance of the SevenZipLibraryException class
/// </summary>
public SevenZipLibraryException() : base(DEFAULT_MESSAGE) {}
/// <summary>
/// Initializes a new instance of the SevenZipLibraryException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public SevenZipLibraryException(string message) : base(DEFAULT_MESSAGE, message) {}
/// <summary>
/// Initializes a new instance of the SevenZipLibraryException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipLibraryException(string message, Exception inner) : base(DEFAULT_MESSAGE, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the SevenZipLibraryException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected SevenZipLibraryException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
#if SFX
/// <summary>
/// Exception class for 7-zip sfx settings validation.
/// </summary>
[Serializable]
public class SevenZipSfxValidationException : SevenZipException
{
/// <summary>
/// Exception dafault message which is displayed if no extra information is specified
/// </summary>
public static readonly string DefaultMessage = "Sfx settings validation failed.";
/// <summary>
/// Initializes a new instance of the SevenZipSfxValidationException class
/// </summary>
public SevenZipSfxValidationException() : base(DefaultMessage) {}
/// <summary>
/// Initializes a new instance of the SevenZipSfxValidationException class
/// </summary>
/// <param name="message">Additional detailed message</param>
public SevenZipSfxValidationException(string message) : base(DefaultMessage, message) {}
/// <summary>
/// Initializes a new instance of the SevenZipSfxValidationException class
/// </summary>
/// <param name="message">Additional detailed message</param>
/// <param name="inner">Inner exception occured</param>
public SevenZipSfxValidationException(string message, Exception inner) : base(DefaultMessage, message, inner) {}
#if !WINCE
/// <summary>
/// Initializes a new instance of the SevenZipSfxValidationException class
/// </summary>
/// <param name="info">All data needed for serialization or deserialization</param>
/// <param name="context">Serialized stream descriptor</param>
protected SevenZipSfxValidationException(
SerializationInfo info, StreamingContext context)
: base(info, context) {}
#endif
}
#endif
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
namespace SevenZip
{
#if UNMANAGED
/// <summary>
/// The signature checker class. Original code by Siddharth Uppal, adapted by Markhor.
/// </summary>
/// <remarks>Based on the code at http://blog.somecreativity.com/2008/04/08/how-to-check-if-a-file-is-compressed-in-c/#</remarks>
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;
}
/// <summary>
/// Gets the InArchiveFormat for a specific extension.
/// </summary>
/// <param name="stream">The stream to identify.</param>
/// <param name="offset">The archive beginning offset.</param>
/// <param name="isExecutable">True if the original format of the stream is PE; otherwise, false.</param>
/// <returns>Corresponding InArchiveFormat.</returns>
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;
}
/// <summary>
/// Gets the InArchiveFormat for a specific file name.
/// </summary>
/// <param name="fileName">The archive file name.</param>
/// <param name="offset">The archive beginning offset.</param>
/// <param name="isExecutable">True if the original format of the file is PE; otherwise, false.</param>
/// <returns>Corresponding InArchiveFormat.</returns>
/// <exception cref="System.ArgumentException"/>
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.IO;
namespace SevenZip
{
#if UNMANAGED
/// <summary>
/// Readable archive format enumeration.
/// </summary>
public enum InArchiveFormat
{
/// <summary>
/// Open 7-zip archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/7-zip">Wikipedia information</a></remarks>
SevenZip,
/// <summary>
/// Proprietary Arj archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/ARJ">Wikipedia information</a></remarks>
Arj,
/// <summary>
/// Open Bzip2 archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Bzip2">Wikipedia information</a></remarks>
BZip2,
/// <summary>
/// Microsoft cabinet archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Cabinet_(file_format)">Wikipedia information</a></remarks>
Cab,
/// <summary>
/// Microsoft Compiled HTML Help file format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Microsoft_Compiled_HTML_Help">Wikipedia information</a></remarks>
Chm,
/// <summary>
/// Microsoft Compound file format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Compound_File_Binary_Format">Wikipedia information</a></remarks>
Compound,
/// <summary>
/// Open Cpio archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Cpio">Wikipedia information</a></remarks>
Cpio,
/// <summary>
/// Open Debian software package format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Deb_(file_format)">Wikipedia information</a></remarks>
Deb,
/// <summary>
/// Open Gzip archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Gzip">Wikipedia information</a></remarks>
GZip,
/// <summary>
/// Open ISO disk image format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/ISO_image">Wikipedia information</a></remarks>
Iso,
/// <summary>
/// Open Lzh archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Lzh">Wikipedia information</a></remarks>
Lzh,
/// <summary>
/// Open core 7-zip Lzma raw archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Lzma">Wikipedia information</a></remarks>
Lzma,
/// <summary>
/// Nullsoft installation package format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/NSIS">Wikipedia information</a></remarks>
Nsis,
/// <summary>
/// RarLab Rar archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Rar">Wikipedia information</a></remarks>
Rar,
/// <summary>
/// Open Rpm software package format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/RPM_Package_Manager">Wikipedia information</a></remarks>
Rpm,
/// <summary>
/// Open split file format.
/// </summary>
/// <remarks><a href="?">Wikipedia information</a></remarks>
Split,
/// <summary>
/// Open Tar archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Tar_(file_format)">Wikipedia information</a></remarks>
Tar,
/// <summary>
/// Microsoft Windows Imaging disk image format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Windows_Imaging_Format">Wikipedia information</a></remarks>
Wim,
/// <summary>
/// Open LZW archive format; implemented in "compress" program; also known as "Z" archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Compress">Wikipedia information</a></remarks>
Lzw,
/// <summary>
/// Open Zip archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/ZIP_(file_format)">Wikipedia information</a></remarks>
Zip,
/// <summary>
/// Open Udf disk image format.
/// </summary>
Udf,
/// <summary>
/// Xar open source archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Xar_(archiver)">Wikipedia information</a></remarks>
Xar,
/// <summary>
/// Mub
/// </summary>
Mub,
/// <summary>
/// Macintosh Disk Image on CD.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/HFS_Plus">Wikipedia information</a></remarks>
Hfs,
/// <summary>
/// Apple Mac OS X Disk Copy Disk Image format.
/// </summary>
Dmg,
/// <summary>
/// Open Xz archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Xz">Wikipedia information</a></remarks>
XZ,
/// <summary>
/// MSLZ archive format.
/// </summary>
Mslz,
/// <summary>
/// Flash video format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Flv">Wikipedia information</a></remarks>
Flv,
/// <summary>
/// Shockwave Flash format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Swf">Wikipedia information</a></remarks>
Swf,
/// <summary>
/// Windows PE executable format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Portable_Executable">Wikipedia information</a></remarks>
PE,
/// <summary>
/// Linux executable Elf format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Executable_and_Linkable_Format">Wikipedia information</a></remarks>
Elf,
/// <summary>
/// Windows Installer Database.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Windows_Installer">Wikipedia information</a></remarks>
Msi,
/// <summary>
/// Microsoft virtual hard disk file format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/VHD_%28file_format%29">Wikipedia information</a></remarks>
Vhd,
/// <summary>
/// Not an archive
/// </summary>
None
}
#if COMPRESS
/// <summary>
/// Writable archive format enumeration.
/// </summary>
public enum OutArchiveFormat
{
/// <summary>
/// Open 7-zip archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/7-zip">Wikipedia information</a></remarks>
SevenZip,
/// <summary>
/// Open Zip archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/ZIP_(file_format)">Wikipedia information</a></remarks>
Zip,
/// <summary>
/// Open Gzip archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Gzip">Wikipedia information</a></remarks>
GZip,
/// <summary>
/// Open Bzip2 archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Bzip2">Wikipedia information</a></remarks>
BZip2,
/// <summary>
/// Open Tar archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Tar_(file_format)">Wikipedia information</a></remarks>
Tar,
/// <summary>
/// Open Xz archive format.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Xz">Wikipedia information</a></remarks>
XZ
}
/// <summary>
/// Compression level enumeration
/// </summary>
public enum CompressionLevel
{
/// <summary>
/// No compression
/// </summary>
None,
/// <summary>
/// Very low compression level
/// </summary>
Fast,
/// <summary>
/// Low compression level
/// </summary>
Low,
/// <summary>
/// Normal compression level (default)
/// </summary>
Normal,
/// <summary>
/// High compression level
/// </summary>
High,
/// <summary>
/// The best compression level (slow)
/// </summary>
Ultra
}
/// <summary>
/// Compression method enumeration.
/// </summary>
/// <remarks>Some methods are applicable only to Zip format, some - only to 7-zip.</remarks>
public enum CompressionMethod
{
/// <summary>
/// Zip or 7-zip|no compression method.
/// </summary>
Copy,
/// <summary>
/// Zip|Deflate method.
/// </summary>
Deflate,
/// <summary>
/// Zip|Deflate64 method.
/// </summary>
Deflate64,
/// <summary>
/// Zip or 7-zip|Bzip2 method.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Cabinet_(file_format)">Wikipedia information</a></remarks>
BZip2,
/// <summary>
/// Zip or 7-zip|LZMA method based on Lempel-Ziv algorithm, it is default for 7-zip.
/// </summary>
Lzma,
/// <summary>
/// 7-zip|LZMA version 2, LZMA with improved multithreading and usually slight archive size decrease.
/// </summary>
Lzma2,
/// <summary>
/// Zip or 7-zip|PPMd method based on Dmitry Shkarin's PPMdH source code, very efficient for compressing texts.
/// </summary>
/// <remarks><a href="http://en.wikipedia.org/wiki/Prediction_by_Partial_Matching">Wikipedia information</a></remarks>
Ppmd,
/// <summary>
/// No method change.
/// </summary>
Default
}
#endif
/// <summary>
/// Archive format routines
/// </summary>
public static class Formats
{
/*/// <summary>
/// Gets the max value of the specified enum type.
/// </summary>
/// <param name="type">Type of the enum</param>
/// <returns>Max value</returns>
internal static int GetMaxValue(Type type)
{
List<int> enumList = new List<int>((IEnumerable<int>)Enum.GetValues(type));
enumList.Sort();
return enumList[enumList.Count - 1];
}*/
/// <summary>
/// List of readable archive format interface guids for 7-zip COM interop.
/// </summary>
internal static readonly Dictionary<InArchiveFormat, Guid> InFormatGuids =
new Dictionary<InArchiveFormat, Guid>(20)
#region InFormatGuids initialization
{
{InArchiveFormat.SevenZip, new Guid("23170f69-40c1-278a-1000-000110070000")},
{InArchiveFormat.Arj, new Guid("23170f69-40c1-278a-1000-000110040000")},
{InArchiveFormat.BZip2, new Guid("23170f69-40c1-278a-1000-000110020000")},
{InArchiveFormat.Cab, new Guid("23170f69-40c1-278a-1000-000110080000")},
{InArchiveFormat.Chm, new Guid("23170f69-40c1-278a-1000-000110e90000")},
{InArchiveFormat.Compound, new Guid("23170f69-40c1-278a-1000-000110e50000")},
{InArchiveFormat.Cpio, new Guid("23170f69-40c1-278a-1000-000110ed0000")},
{InArchiveFormat.Deb, new Guid("23170f69-40c1-278a-1000-000110ec0000")},
{InArchiveFormat.GZip, new Guid("23170f69-40c1-278a-1000-000110ef0000")},
{InArchiveFormat.Iso, new Guid("23170f69-40c1-278a-1000-000110e70000")},
{InArchiveFormat.Lzh, new Guid("23170f69-40c1-278a-1000-000110060000")},
{InArchiveFormat.Lzma, new Guid("23170f69-40c1-278a-1000-0001100a0000")},
{InArchiveFormat.Nsis, new Guid("23170f69-40c1-278a-1000-000110090000")},
{InArchiveFormat.Rar, new Guid("23170f69-40c1-278a-1000-000110030000")},
{InArchiveFormat.Rpm, new Guid("23170f69-40c1-278a-1000-000110eb0000")},
{InArchiveFormat.Split, new Guid("23170f69-40c1-278a-1000-000110ea0000")},
{InArchiveFormat.Tar, new Guid("23170f69-40c1-278a-1000-000110ee0000")},
{InArchiveFormat.Wim, new Guid("23170f69-40c1-278a-1000-000110e60000")},
{InArchiveFormat.Lzw, new Guid("23170f69-40c1-278a-1000-000110050000")},
{InArchiveFormat.Zip, new Guid("23170f69-40c1-278a-1000-000110010000")},
{InArchiveFormat.Udf, new Guid("23170f69-40c1-278a-1000-000110E00000")},
{InArchiveFormat.Xar, new Guid("23170f69-40c1-278a-1000-000110E10000")},
{InArchiveFormat.Mub, new Guid("23170f69-40c1-278a-1000-000110E20000")},
{InArchiveFormat.Hfs, new Guid("23170f69-40c1-278a-1000-000110E30000")},
{InArchiveFormat.Dmg, new Guid("23170f69-40c1-278a-1000-000110E40000")},
{InArchiveFormat.XZ, new Guid("23170f69-40c1-278a-1000-0001100C0000")},
{InArchiveFormat.Mslz, new Guid("23170f69-40c1-278a-1000-000110D50000")},
{InArchiveFormat.PE, new Guid("23170f69-40c1-278a-1000-000110DD0000")},
{InArchiveFormat.Elf, new Guid("23170f69-40c1-278a-1000-000110DE0000")},
{InArchiveFormat.Swf, new Guid("23170f69-40c1-278a-1000-000110D70000")},
{InArchiveFormat.Vhd, new Guid("23170f69-40c1-278a-1000-000110DC0000")}
};
#endregion
#if COMPRESS
/// <summary>
/// List of writable archive format interface guids for 7-zip COM interop.
/// </summary>
internal static readonly Dictionary<OutArchiveFormat, Guid> OutFormatGuids =
new Dictionary<OutArchiveFormat, Guid>(2)
#region OutFormatGuids initialization
{
{OutArchiveFormat.SevenZip, new Guid("23170f69-40c1-278a-1000-000110070000")},
{OutArchiveFormat.Zip, new Guid("23170f69-40c1-278a-1000-000110010000")},
{OutArchiveFormat.BZip2, new Guid("23170f69-40c1-278a-1000-000110020000")},
{OutArchiveFormat.GZip, new Guid("23170f69-40c1-278a-1000-000110ef0000")},
{OutArchiveFormat.Tar, new Guid("23170f69-40c1-278a-1000-000110ee0000")},
{OutArchiveFormat.XZ, new Guid("23170f69-40c1-278a-1000-0001100C0000")},
};
#endregion
internal static readonly Dictionary<CompressionMethod, string> MethodNames =
new Dictionary<CompressionMethod, string>(6)
#region MethodNames initialization
{
{CompressionMethod.Copy, "Copy"},
{CompressionMethod.Deflate, "Deflate"},
{CompressionMethod.Deflate64, "Deflate64"},
{CompressionMethod.Lzma, "LZMA"},
{CompressionMethod.Lzma2, "LZMA2"},
{CompressionMethod.Ppmd, "PPMd"},
{CompressionMethod.BZip2, "BZip2"}
};
#endregion
internal static readonly Dictionary<OutArchiveFormat, InArchiveFormat> InForOutFormats =
new Dictionary<OutArchiveFormat, InArchiveFormat>(6)
#region InForOutFormats initialization
{
{OutArchiveFormat.SevenZip, InArchiveFormat.SevenZip},
{OutArchiveFormat.GZip, InArchiveFormat.GZip},
{OutArchiveFormat.BZip2, InArchiveFormat.BZip2},
{OutArchiveFormat.Tar, InArchiveFormat.Tar},
{OutArchiveFormat.XZ, InArchiveFormat.XZ},
{OutArchiveFormat.Zip, InArchiveFormat.Zip}
};
#endregion
#endif
/// <summary>
/// List of archive formats corresponding to specific extensions
/// </summary>
private static readonly Dictionary<string, InArchiveFormat> InExtensionFormats =
new Dictionary<string, InArchiveFormat>
#region InExtensionFormats initialization
{{"7z", InArchiveFormat.SevenZip},
{"gz", InArchiveFormat.GZip},
{"tar", InArchiveFormat.Tar},
{"rar", InArchiveFormat.Rar},
{"zip", InArchiveFormat.Zip},
{"lzma", InArchiveFormat.Lzma},
{"lzh", InArchiveFormat.Lzh},
{"arj", InArchiveFormat.Arj},
{"bz2", InArchiveFormat.BZip2},
{"cab", InArchiveFormat.Cab},
{"chm", InArchiveFormat.Chm},
{"deb", InArchiveFormat.Deb},
{"iso", InArchiveFormat.Iso},
{"rpm", InArchiveFormat.Rpm},
{"wim", InArchiveFormat.Wim},
{"udf", InArchiveFormat.Udf},
{"mub", InArchiveFormat.Mub},
{"xar", InArchiveFormat.Xar},
{"hfs", InArchiveFormat.Hfs},
{"dmg", InArchiveFormat.Dmg},
{"Z", InArchiveFormat.Lzw},
{"xz", InArchiveFormat.XZ},
{"flv", InArchiveFormat.Flv},
{"swf", InArchiveFormat.Swf},
{"exe", InArchiveFormat.PE},
{"dll", InArchiveFormat.PE},
{"vhd", InArchiveFormat.Vhd}
};
#endregion
/// <summary>
/// List of archive formats corresponding to specific signatures
/// </summary>
/// <remarks>Based on the information at <a href="http://www.garykessler.net/library/file_sigs.html">this site.</a></remarks>
internal static readonly Dictionary<string, InArchiveFormat> InSignatureFormats =
new Dictionary<string, InArchiveFormat>
#region InSignatureFormats initialization
{{"37-7A-BC-AF-27-1C", InArchiveFormat.SevenZip},
{"1F-8B-08", InArchiveFormat.GZip},
{"75-73-74-61-72", InArchiveFormat.Tar},
//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<InArchiveFormat, string> InSignatureFormatsReversed;
static Formats()
{
InSignatureFormatsReversed = new Dictionary<InArchiveFormat, string>(InSignatureFormats.Count);
foreach (var pair in InSignatureFormats)
{
InSignatureFormatsReversed.Add(pair.Value, pair.Key);
}
}
/// <summary>
/// Gets InArchiveFormat for specified archive file name
/// </summary>
/// <param name="fileName">Archive file name</param>
/// <param name="reportErrors">Indicates whether to throw exceptions</param>
/// <returns>InArchiveFormat recognized by the file name extension</returns>
/// <exception cref="System.ArgumentException"/>
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
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
using System;
namespace SevenZip
{
/// <summary>
/// The set of features supported by the library.
/// </summary>
[Flags]
public enum LibraryFeature : uint
{
/// <summary>
/// Default feature.
/// </summary>
None = 0,
/// <summary>
/// The library can extract 7zip archives compressed with LZMA method.
/// </summary>
Extract7z = 0x1,
/// <summary>
/// The library can extract 7zip archives compressed with LZMA2 method.
/// </summary>
Extract7zLZMA2 = 0x2,
/// <summary>
/// The library can extract 7z archives compressed with all known methods.
/// </summary>
Extract7zAll = Extract7z|Extract7zLZMA2|0x4,
/// <summary>
/// The library can extract zip archives.
/// </summary>
ExtractZip = 0x8,
/// <summary>
/// The library can extract rar archives.
/// </summary>
ExtractRar = 0x10,
/// <summary>
/// The library can extract gzip archives.
/// </summary>
ExtractGzip = 0x20,
/// <summary>
/// The library can extract bzip2 archives.
/// </summary>
ExtractBzip2 = 0x40,
/// <summary>
/// The library can extract tar archives.
/// </summary>
ExtractTar = 0x80,
/// <summary>
/// The library can extract xz archives.
/// </summary>
ExtractXz = 0x100,
/// <summary>
/// The library can extract all types of archives supported.
/// </summary>
ExtractAll = Extract7zAll|ExtractZip|ExtractRar|ExtractGzip|ExtractBzip2|ExtractTar|ExtractXz,
/// <summary>
/// The library can compress data to 7zip archives with LZMA method.
/// </summary>
Compress7z = 0x200,
/// <summary>
/// The library can compress data to 7zip archives with LZMA2 method.
/// </summary>
Compress7zLZMA2 = 0x400,
/// <summary>
/// The library can compress data to 7zip archives with all methods known.
/// </summary>
Compress7zAll = Compress7z|Compress7zLZMA2|0x800,
/// <summary>
/// The library can compress data to tar archives.
/// </summary>
CompressTar = 0x1000,
/// <summary>
/// The library can compress data to gzip archives.
/// </summary>
CompressGzip = 0x2000,
/// <summary>
/// The library can compress data to bzip2 archives.
/// </summary>
CompressBzip2 = 0x4000,
/// <summary>
/// The library can compress data to xz archives.
/// </summary>
CompressXz = 0x8000,
/// <summary>
/// The library can compress data to zip archives.
/// </summary>
CompressZip = 0x10000,
/// <summary>
/// The library can compress data to all types of archives supported.
/// </summary>
CompressAll = Compress7zAll|CompressTar|CompressGzip|CompressBzip2|CompressXz|CompressZip,
/// <summary>
/// The library can modify archives.
/// </summary>
Modify = 0x20000
}
}

View File

@ -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 <http://www.gnu.org/licenses/>.
*/
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
/// <summary>
/// 7-zip library low-level wrapper.
/// </summary>
internal static class SevenZipLibraryManager
{
#if !WINCE && !MONO
/// <summary>
/// Path to the 7-zip dll.
/// </summary>
/// <remarks>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.
/// </remarks>
//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
/// <summary>
/// 7-zip library handle.
/// </summary>
private static IntPtr _modulePtr;
/// <summary>
/// 7-zip library features.
/// </summary>
private static LibraryFeature? _features;
private static Dictionary<object, Dictionary<InArchiveFormat, IInArchive>> _inArchives;
#if COMPRESS
private static Dictionary<object, Dictionary<OutArchiveFormat, IOutArchive>> _outArchives;
#endif
private static int _totalUsers;
// private static string _LibraryVersion;
private static bool? _modifyCapabale;
private static void InitUserInFormat(object user, InArchiveFormat format)
{
if (!_inArchives.ContainsKey(user))
{
_inArchives.Add(user, new Dictionary<InArchiveFormat, IInArchive>());
}
if (!_inArchives[user].ContainsKey(format))
{
_inArchives[user].Add(format, null);
_totalUsers++;
}
}
#if COMPRESS
private static void InitUserOutFormat(object user, OutArchiveFormat format)
{
if (!_outArchives.ContainsKey(user))
{
_outArchives.Add(user, new Dictionary<OutArchiveFormat, IOutArchive>());
}
if (!_outArchives[user].ContainsKey(format))
{
_outArchives[user].Add(format, null);
_totalUsers++;
}
}
#endif
private static void Init()
{
_inArchives = new Dictionary<object, Dictionary<InArchiveFormat, IInArchive>>();
#if COMPRESS
_outArchives = new Dictionary<object, Dictionary<OutArchiveFormat, IOutArchive>>();
#endif
}
/// <summary>
/// Loads the 7-zip library if necessary and adds user to the reference list
/// </summary>
/// <param name="user">Caller of the function</param>
/// <param name="format">Archive format</param>
public static void LoadLibrary(object user, Enum format)
{
if (_inArchives == null
#if COMPRESS
|| _outArchives == null
#endif
)
{
Init();
}
#if !WINCE && !MONO
if (_modulePtr == IntPtr.Zero)
{
//zero 29-oct-2012 - this check isnt useful since LoadLibrary can pretty much check for the same thing. and it wrecks our dll relocation scheme
//if (!File.Exists(_libraryFileName))
//{
// throw new SevenZipLibraryException("DLL file does not exist.");
//}
if ((_modulePtr = NativeMethods.LoadLibrary(_libraryFileName)) == IntPtr.Zero)
{
//try a different directory
string alternateFilename = Path.Combine(Path.Combine(Path.GetDirectoryName(_libraryFileName),"dll"),"7z.dll");
if ((_modulePtr = NativeMethods.LoadLibrary(alternateFilename)) == IntPtr.Zero)
throw new SevenZipLibraryException("failed to load library.");
}
if (NativeMethods.GetProcAddress(_modulePtr, "GetHandlerProperty") == IntPtr.Zero)
{
NativeMethods.FreeLibrary(_modulePtr);
throw new SevenZipLibraryException("library is invalid.");
}
}
#endif
if (format is InArchiveFormat)
{
InitUserInFormat(user, (InArchiveFormat) format);
return;
}
#if COMPRESS
if (format is OutArchiveFormat)
{
InitUserOutFormat(user, (OutArchiveFormat) format);
return;
}
#endif
throw new ArgumentException(
"Enum " + format + " is not a valid archive format attribute!");
}
/*/// <summary>
/// Gets the native 7zip library version string.
/// </summary>
public static string LibraryVersion
{
get
{
if (String.IsNullOrEmpty(_LibraryVersion))
{
FileVersionInfo dllVersionInfo = FileVersionInfo.GetVersionInfo(_libraryFileName);
_LibraryVersion = String.Format(
System.Globalization.CultureInfo.CurrentCulture,
"{0}.{1}",
dllVersionInfo.FileMajorPart, dllVersionInfo.FileMinorPart);
}
return _LibraryVersion;
}
}*/
/// <summary>
/// Gets the value indicating whether the library supports modifying archives.
/// </summary>
public static bool ModifyCapable
{
get
{
if (!_modifyCapabale.HasValue)
{
#if !WINCE && !MONO
FileVersionInfo dllVersionInfo = FileVersionInfo.GetVersionInfo(_libraryFileName);
_modifyCapabale = dllVersionInfo.FileMajorPart >= 9;
#else
_modifyCapabale = true;
#endif
}
return _modifyCapabale.Value;
}
}
static readonly string Namespace = Assembly.GetExecutingAssembly().GetManifestResourceNames()[0].Split('.')[0];
private static string GetResourceString(string str)
{
return Namespace + ".arch." + str;
}
private static bool ExtractionBenchmark(string archiveFileName, Stream outStream,
ref LibraryFeature? features, LibraryFeature testedFeature)
{
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(
GetResourceString(archiveFileName));
try
{
using (var extr = new SevenZipExtractor(stream))
{
extr.ExtractFile(0, outStream);
}
}
catch(Exception)
{
return false;
}
features |= testedFeature;
return true;
}
private static bool CompressionBenchmark(Stream inStream, Stream outStream,
OutArchiveFormat format, CompressionMethod method,
ref LibraryFeature? features, LibraryFeature testedFeature)
{
try
{
var compr = new SevenZipCompressor {ArchiveFormat = format, CompressionMethod = method};
compr.CompressStream(inStream, outStream);
}
catch (Exception)
{
return false;
}
features |= testedFeature;
return true;
}
public static LibraryFeature CurrentLibraryFeatures
{
get
{
if (_features != null && _features.HasValue)
{
return _features.Value;
}
_features = LibraryFeature.None;
#region Benchmark
#region Extraction features
using (var outStream = new MemoryStream())
{
ExtractionBenchmark("Test.lzma.7z", outStream, ref _features, LibraryFeature.Extract7z);
ExtractionBenchmark("Test.lzma2.7z", outStream, ref _features, LibraryFeature.Extract7zLZMA2);
int i = 0;
if (ExtractionBenchmark("Test.bzip2.7z", outStream, ref _features, _features.Value))
{
i++;
}
if (ExtractionBenchmark("Test.ppmd.7z", outStream, ref _features, _features.Value))
{
i++;
if (i == 2 && (_features & LibraryFeature.Extract7z) != 0 &&
(_features & LibraryFeature.Extract7zLZMA2) != 0)
{
_features |= LibraryFeature.Extract7zAll;
}
}
ExtractionBenchmark("Test.rar", outStream, ref _features, LibraryFeature.ExtractRar);
ExtractionBenchmark("Test.tar", outStream, ref _features, LibraryFeature.ExtractTar);
ExtractionBenchmark("Test.txt.bz2", outStream, ref _features, LibraryFeature.ExtractBzip2);
ExtractionBenchmark("Test.txt.gz", outStream, ref _features, LibraryFeature.ExtractGzip);
ExtractionBenchmark("Test.txt.xz", outStream, ref _features, LibraryFeature.ExtractXz);
ExtractionBenchmark("Test.zip", outStream, ref _features, LibraryFeature.ExtractZip);
}
#endregion
#region Compression features
using (var inStream = new MemoryStream())
{
inStream.Write(Encoding.UTF8.GetBytes("Test"), 0, 4);
using (var outStream = new MemoryStream())
{
CompressionBenchmark(inStream, outStream,
OutArchiveFormat.SevenZip, CompressionMethod.Lzma,
ref _features, LibraryFeature.Compress7z);
CompressionBenchmark(inStream, outStream,
OutArchiveFormat.SevenZip, CompressionMethod.Lzma2,
ref _features, LibraryFeature.Compress7zLZMA2);
int i = 0;
if (CompressionBenchmark(inStream, outStream,
OutArchiveFormat.SevenZip, CompressionMethod.BZip2,
ref _features, _features.Value))
{
i++;
}
if (CompressionBenchmark(inStream, outStream,
OutArchiveFormat.SevenZip, CompressionMethod.Ppmd,
ref _features, _features.Value))
{
i++;
if (i == 2 && (_features & LibraryFeature.Compress7z) != 0 &&
(_features & LibraryFeature.Compress7zLZMA2) != 0)
{
_features |= LibraryFeature.Compress7zAll;
}
}
CompressionBenchmark(inStream, outStream,
OutArchiveFormat.Zip, CompressionMethod.Default,
ref _features, LibraryFeature.CompressZip);
CompressionBenchmark(inStream, outStream,
OutArchiveFormat.BZip2, CompressionMethod.Default,
ref _features, LibraryFeature.CompressBzip2);
CompressionBenchmark(inStream, outStream,
OutArchiveFormat.GZip, CompressionMethod.Default,
ref _features, LibraryFeature.CompressGzip);
CompressionBenchmark(inStream, outStream,
OutArchiveFormat.Tar, CompressionMethod.Default,
ref _features, LibraryFeature.CompressTar);
CompressionBenchmark(inStream, outStream,
OutArchiveFormat.XZ, CompressionMethod.Default,
ref _features, LibraryFeature.CompressXz);
}
}
#endregion
#endregion
if (ModifyCapable && (_features.Value & LibraryFeature.Compress7z) != 0)
{
_features |= LibraryFeature.Modify;
}
return _features.Value;
}
}
/// <summary>
/// Removes user from reference list and frees the 7-zip library if it becomes empty
/// </summary>
/// <param name="user">Caller of the function</param>
/// <param name="format">Archive format</param>
public static void FreeLibrary(object user, Enum format)
{
#if !WINCE && !MONO
var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
#endif
if (_modulePtr != IntPtr.Zero)
{
if (format is InArchiveFormat)
{
if (_inArchives != null && _inArchives.ContainsKey(user) &&
_inArchives[user].ContainsKey((InArchiveFormat) format) &&
_inArchives[user][(InArchiveFormat) format] != null)
{
try
{
Marshal.ReleaseComObject(_inArchives[user][(InArchiveFormat) format]);
}
catch (InvalidComObjectException) {}
_inArchives[user].Remove((InArchiveFormat) format);
_totalUsers--;
if (_inArchives[user].Count == 0)
{
_inArchives.Remove(user);
}
}
}
#if COMPRESS
if (format is OutArchiveFormat)
{
if (_outArchives != null && _outArchives.ContainsKey(user) &&
_outArchives[user].ContainsKey((OutArchiveFormat) format) &&
_outArchives[user][(OutArchiveFormat) format] != null)
{
try
{
Marshal.ReleaseComObject(_outArchives[user][(OutArchiveFormat) format]);
}
catch (InvalidComObjectException) {}
_outArchives[user].Remove((OutArchiveFormat) format);
_totalUsers--;
if (_outArchives[user].Count == 0)
{
_outArchives.Remove(user);
}
}
}
#endif
if ((_inArchives == null || _inArchives.Count == 0)
#if COMPRESS
&& (_outArchives == null || _outArchives.Count == 0)
#endif
)
{
_inArchives = null;
#if COMPRESS
_outArchives = null;
#endif
if (_totalUsers == 0)
{
#if !WINCE && !MONO
NativeMethods.FreeLibrary(_modulePtr);
#endif
_modulePtr = IntPtr.Zero;
}
}
}
}
/// <summary>
/// Gets IInArchive interface to extract 7-zip archives.
/// </summary>
/// <param name="format">Archive format.</param>
/// <param name="user">Archive format user.</param>
public static IInArchive InArchive(InArchiveFormat format, object user)
{
#if !WINCE && !MONO
lock (_libraryFileName)
{
#endif
if (_inArchives[user][format] == null)
{
#if !WINCE && !MONO
var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
if (_modulePtr == IntPtr.Zero)
{
LoadLibrary(user, format);
if (_modulePtr == IntPtr.Zero)
{
throw new SevenZipLibraryException();
}
}
var createObject = (NativeMethods.CreateObjectDelegate)
Marshal.GetDelegateForFunctionPointer(
NativeMethods.GetProcAddress(_modulePtr, "CreateObject"),
typeof(NativeMethods.CreateObjectDelegate));
if (createObject == null)
{
throw new SevenZipLibraryException();
}
#endif
object result;
Guid interfaceId =
#if !WINCE && !MONO
typeof(IInArchive).GUID;
#else
new Guid(((GuidAttribute)typeof(IInArchive).GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value);
#endif
Guid classID = Formats.InFormatGuids[format];
try
{
#if !WINCE && !MONO
createObject(ref classID, ref interfaceId, out result);
#elif !MONO
NativeMethods.CreateCOMObject(ref classID, ref interfaceId, out result);
#else
result = SevenZip.Mono.Factory.CreateInterface<IInArchive>(user, classID, interfaceId);
#endif
}
catch (Exception)
{
throw new SevenZipLibraryException("Your 7-zip library does not support this archive type.");
}
InitUserInFormat(user, format);
_inArchives[user][format] = result as IInArchive;
}
#if !WINCE && !MONO
}
#endif
return _inArchives[user][format];
}
#if COMPRESS
/// <summary>
/// Gets IOutArchive interface to pack 7-zip archives.
/// </summary>
/// <param name="format">Archive format.</param>
/// <param name="user">Archive format user.</param>
public static IOutArchive OutArchive(OutArchiveFormat format, object user)
{
#if !WINCE && !MONO
lock (_libraryFileName)
{
#endif
if (_outArchives[user][format] == null)
{
#if !WINCE && !MONO
var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
if (_modulePtr == IntPtr.Zero)
{
throw new SevenZipLibraryException();
}
var createObject = (NativeMethods.CreateObjectDelegate)
Marshal.GetDelegateForFunctionPointer(
NativeMethods.GetProcAddress(_modulePtr, "CreateObject"),
typeof(NativeMethods.CreateObjectDelegate));
if (createObject == null)
{
throw new SevenZipLibraryException();
}
#endif
object result;
Guid interfaceId =
#if !WINCE && !MONO
typeof(IOutArchive).GUID;
#else
new Guid(((GuidAttribute)typeof(IOutArchive).GetCustomAttributes(typeof(GuidAttribute), false)[0]).Value);
#endif
Guid classID = Formats.OutFormatGuids[format];
try
{
#if !WINCE && !MONO
createObject(ref classID, ref interfaceId, out result);
#elif !MONO
NativeMethods.CreateCOMObject(ref classID, ref interfaceId, out result);
#else
result = SevenZip.Mono.Factory.CreateInterface<IOutArchive>(classID, interfaceId, user);
#endif
}
catch (Exception)
{
throw new SevenZipLibraryException("Your 7-zip library does not support this archive type.");
}
InitUserOutFormat(user, format);
_outArchives[user][format] = result as IOutArchive;
}
#if !WINCE && !MONO
}
#endif
return _outArchives[user][format];
}
#endif
#if !WINCE && !MONO
public static void SetLibraryPath(string libraryPath)
{
if (_modulePtr != IntPtr.Zero && !Path.GetFullPath(libraryPath).Equals(
Path.GetFullPath(_libraryFileName), StringComparison.OrdinalIgnoreCase))
{
throw new SevenZipLibraryException(
"can not change the library path while the library \"" + _libraryFileName + "\" is being used.");
}
if (!File.Exists(libraryPath))
{
throw new SevenZipLibraryException(
"can not change the library path because the file \"" + libraryPath + "\" does not exist.");
}
_libraryFileName = libraryPath;
_features = null;
}
#endif
}
#endif
}

View File

@ -1,240 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using SevenZip.Sdk.Compression.Lzma;
namespace SevenZip
{
#if LZMA_STREAM
/// <summary>
/// The stream which decompresses data with LZMA on the fly.
/// </summary>
public class LzmaDecodeStream : Stream
{
private readonly MemoryStream _buffer = new MemoryStream();
private readonly Decoder _decoder = new Decoder();
private readonly Stream _input;
private byte[] _commonProperties;
private bool _error;
private bool _firstChunkRead;
/// <summary>
/// Initializes a new instance of the LzmaDecodeStream class.
/// </summary>
/// <param name="encodedStream">A compressed stream.</param>
public LzmaDecodeStream(Stream encodedStream)
{
if (!encodedStream.CanRead)
{
throw new ArgumentException("The specified stream can not read.", "encodedStream");
}
_input = encodedStream;
}
/// <summary>
/// Gets the chunk size.
/// </summary>
public int ChunkSize
{
get
{
return (int) _buffer.Length;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports reading.
/// </summary>
public override bool CanRead
{
get
{
return true;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports seeking.
/// </summary>
public override bool CanSeek
{
get
{
return false;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports writing.
/// </summary>
public override bool CanWrite
{
get
{
return false;
}
}
/// <summary>
/// Gets the length in bytes of the output stream.
/// </summary>
public override long Length
{
get
{
if (_input.CanSeek)
{
return _input.Length;
}
return _buffer.Length;
}
}
/// <summary>
/// Gets or sets the position within the output stream.
/// </summary>
public override long Position
{
get
{
if (_input.CanSeek)
{
return _input.Position;
}
return _buffer.Position;
}
set
{
throw new NotSupportedException();
}
}
private void ReadChunk()
{
long size;
byte[] properties;
try
{
properties = SevenZipExtractor.GetLzmaProperties(_input, out size);
}
catch (LzmaException)
{
_error = true;
return;
}
if (!_firstChunkRead)
{
_commonProperties = properties;
}
if (_commonProperties[0] != properties[0] ||
_commonProperties[1] != properties[1] ||
_commonProperties[2] != properties[2] ||
_commonProperties[3] != properties[3] ||
_commonProperties[4] != properties[4])
{
_error = true;
return;
}
if (_buffer.Capacity < (int) size)
{
_buffer.Capacity = (int) size;
}
_buffer.SetLength(size);
_decoder.SetDecoderProperties(properties);
_buffer.Position = 0;
_decoder.Code(
_input, _buffer, 0, size, null);
_buffer.Position = 0;
}
/// <summary>
/// Does nothing.
/// </summary>
public override void Flush() {}
/// <summary>
/// Reads a sequence of bytes from the current stream and decompresses data if necessary.
/// </summary>
/// <param name="buffer">An array of bytes.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
/// <returns>The total number of bytes read into the buffer.</returns>
public override int Read(byte[] buffer, int offset, int count)
{
if (_error)
{
return 0;
}
if (!_firstChunkRead)
{
ReadChunk();
_firstChunkRead = true;
}
int readCount = 0;
while (count > _buffer.Length - _buffer.Position && !_error)
{
var buf = new byte[_buffer.Length - _buffer.Position];
_buffer.Read(buf, 0, buf.Length);
buf.CopyTo(buffer, offset);
offset += buf.Length;
count -= buf.Length;
readCount += buf.Length;
ReadChunk();
}
if (!_error)
{
_buffer.Read(buffer, offset, count);
readCount += count;
}
return readCount;
}
/// <summary>
/// Sets the position within the current stream.
/// </summary>
/// <param name="offset">A byte offset relative to the origin parameter.</param>
/// <param name="origin">A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.</param>
/// <returns>The new position within the current stream.</returns>
public override long Seek(long offset, SeekOrigin origin)
{
throw new NotSupportedException();
}
/// <summary>
/// Sets the length of the current stream.
/// </summary>
/// <param name="value">The desired length of the current stream in bytes.</param>
public override void SetLength(long value)
{
throw new NotSupportedException();
}
/// <summary>
/// Writes a sequence of bytes to the current stream.
/// </summary>
/// <param name="buffer">An array of bytes.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
public override void Write(byte[] buffer, int offset, int count)
{
throw new NotSupportedException();
}
}
#endif
}

View File

@ -1,304 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using SevenZip.Sdk.Compression.Lzma;
namespace SevenZip
{
#if LZMA_STREAM
#if COMPRESS
/// <summary>
/// The stream which compresses data with LZMA on the fly.
/// </summary>
public class LzmaEncodeStream : Stream
{
private const int MAX_BUFFER_CAPACITY = 1 << 30; //1 Gb
private readonly MemoryStream _buffer = new MemoryStream();
private readonly int _bufferCapacity = 1 << 18; //256 kb
private readonly bool _ownOutput;
private bool _disposed;
private Encoder _lzmaEncoder;
private Stream _output;
/// <summary>
/// Initializes a new instance of the LzmaEncodeStream class.
/// </summary>
public LzmaEncodeStream()
{
_output = new MemoryStream();
_ownOutput = true;
Init();
}
/// <summary>
/// Initializes a new instance of the LzmaEncodeStream class.
/// </summary>
/// <param name="bufferCapacity">The buffer size. The bigger size, the better compression.</param>
public LzmaEncodeStream(int bufferCapacity)
{
_output = new MemoryStream();
_ownOutput = true;
if (bufferCapacity > MAX_BUFFER_CAPACITY)
{
throw new ArgumentException("Too large capacity.", "bufferCapacity");
}
_bufferCapacity = bufferCapacity;
Init();
}
/// <summary>
/// Initializes a new instance of the LzmaEncodeStream class.
/// </summary>
/// <param name="outputStream">An output stream which supports writing.</param>
public LzmaEncodeStream(Stream outputStream)
{
if (!outputStream.CanWrite)
{
throw new ArgumentException("The specified stream can not write.", "outputStream");
}
_output = outputStream;
Init();
}
/// <summary>
/// Initializes a new instance of the LzmaEncodeStream class.
/// </summary>
/// <param name="outputStream">An output stream which supports writing.</param>
/// <param name="bufferCapacity">A buffer size. The bigger size, the better compression.</param>
public LzmaEncodeStream(Stream outputStream, int bufferCapacity)
{
if (!outputStream.CanWrite)
{
throw new ArgumentException("The specified stream can not write.", "outputStream");
}
_output = outputStream;
if (bufferCapacity > 1 << 30)
{
throw new ArgumentException("Too large capacity.", "bufferCapacity");
}
_bufferCapacity = bufferCapacity;
Init();
}
/// <summary>
/// Gets a value indicating whether the current stream supports reading.
/// </summary>
public override bool CanRead
{
get
{
return false;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports seeking.
/// </summary>
public override bool CanSeek
{
get
{
return false;
}
}
/// <summary>
/// Gets a value indicating whether the current stream supports writing.
/// </summary>
public override bool CanWrite
{
get
{
DisposedCheck();
return _buffer.CanWrite;
}
}
/// <summary>
/// Gets the length in bytes of the output stream.
/// </summary>
public override long Length
{
get
{
DisposedCheck();
if (_output.CanSeek)
{
return _output.Length;
}
return _buffer.Position;
}
}
/// <summary>
/// Gets or sets the position within the output stream.
/// </summary>
public override long Position
{
get
{
DisposedCheck();
if (_output.CanSeek)
{
return _output.Position;
}
return _buffer.Position;
}
set
{
throw new NotSupportedException();
}
}
private void Init()
{
_buffer.Capacity = _bufferCapacity;
SevenZipCompressor.LzmaDictionarySize = _bufferCapacity;
_lzmaEncoder = new Encoder();
SevenZipCompressor.WriteLzmaProperties(_lzmaEncoder);
}
/// <summary>
/// Checked whether the class was disposed.
/// </summary>
/// <exception cref="System.ObjectDisposedException" />
private void DisposedCheck()
{
if (_disposed)
{
throw new ObjectDisposedException("SevenZipExtractor");
}
}
private void WriteChunk()
{
_lzmaEncoder.WriteCoderProperties(_output);
long streamSize = _buffer.Position;
if (_buffer.Length != _buffer.Position)
{
_buffer.SetLength(_buffer.Position);
}
_buffer.Position = 0;
for (int i = 0; i < 8; i++)
{
_output.WriteByte((byte) (streamSize >> (8*i)));
}
_lzmaEncoder.Code(_buffer, _output, -1, -1, null);
_buffer.Position = 0;
}
/// <summary>
/// Converts the LzmaEncodeStream to the LzmaDecodeStream to read data.
/// </summary>
/// <returns></returns>
public LzmaDecodeStream ToDecodeStream()
{
DisposedCheck();
Flush();
return new LzmaDecodeStream(_output);
}
/// <summary>
/// Clears all buffers for this stream and causes any buffered data to be compressed and written.
/// </summary>
public override void Flush()
{
DisposedCheck();
WriteChunk();
}
/// <summary>
/// Releases all unmanaged resources used by LzmaEncodeStream.
/// </summary>
protected override void Dispose(bool disposing)
{
if (!_disposed)
{
if (disposing)
{
Flush();
_buffer.Close();
if (_ownOutput)
{
_output.Dispose();
}
_output = null;
}
_disposed = true;
}
}
/// <summary>
/// Reads a sequence of bytes from the current stream and advances the position within the stream by the number of bytes read.
/// </summary>
/// <param name="buffer">An array of bytes.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
/// <returns>The total number of bytes read into the buffer.</returns>
public override int Read(byte[] buffer, int offset, int count)
{
DisposedCheck();
throw new NotSupportedException();
}
/// <summary>
/// Sets the position within the current stream.
/// </summary>
/// <param name="offset">A byte offset relative to the origin parameter.</param>
/// <param name="origin">A value of type System.IO.SeekOrigin indicating the reference point used to obtain the new position.</param>
/// <returns>The new position within the current stream.</returns>
public override long Seek(long offset, SeekOrigin origin)
{
DisposedCheck();
throw new NotSupportedException();
}
/// <summary>
/// Sets the length of the current stream.
/// </summary>
/// <param name="value">The desired length of the current stream in bytes.</param>
public override void SetLength(long value)
{
DisposedCheck();
throw new NotSupportedException();
}
/// <summary>
/// Writes a sequence of bytes to the current stream and compresses it if necessary.
/// </summary>
/// <param name="buffer">An array of bytes.</param>
/// <param name="offset">The zero-based byte offset in buffer at which to begin storing the data read from the current stream.</param>
/// <param name="count">The maximum number of bytes to be read from the current stream.</param>
public override void Write(byte[] buffer, int offset, int count)
{
DisposedCheck();
int dataLength = Math.Min(buffer.Length - offset, count);
while (_buffer.Position + dataLength >= _bufferCapacity)
{
int length = _bufferCapacity - (int) _buffer.Position;
_buffer.Write(buffer, offset, length);
offset = length + offset;
dataLength -= length;
WriteChunk();
}
_buffer.Write(buffer, offset, dataLength);
}
}
#endif
#endif
}

View File

@ -1,72 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using SevenZip.Sdk;
namespace SevenZip
{
/// <summary>
/// Callback to implement the ICodeProgress interface
/// </summary>
internal sealed class LzmaProgressCallback : ICodeProgress
{
private readonly long _inSize;
private float _oldPercentDone;
/// <summary>
/// Initializes a new instance of the LzmaProgressCallback class
/// </summary>
/// <param name="inSize">The input size</param>
/// <param name="working">Progress event handler</param>
public LzmaProgressCallback(long inSize, EventHandler<ProgressEventArgs> working)
{
_inSize = inSize;
Working += working;
}
#region ICodeProgress Members
/// <summary>
/// Sets the progress
/// </summary>
/// <param name="inSize">The processed input size</param>
/// <param name="outSize">The processed output size</param>
public void SetProgress(long inSize, long outSize)
{
if (Working != null)
{
float newPercentDone = (inSize + 0.0f) / _inSize;
float delta = newPercentDone - _oldPercentDone;
if (delta * 100 < 1.0)
{
delta = 0;
}
else
{
_oldPercentDone = newPercentDone;
}
Working(this, new ProgressEventArgs(
PercentDoneEventArgs.ProducePercentDone(newPercentDone),
delta > 0 ? PercentDoneEventArgs.ProducePercentDone(delta) : (byte)0));
}
}
#endregion
public event EventHandler<ProgressEventArgs> Working;
}
}

View File

@ -1,77 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Runtime.InteropServices;
#if MONO
using SevenZip.Mono.COM;
#endif
namespace SevenZip
{
#if UNMANAGED
internal static class NativeMethods
{
#if !WINCE && !MONO
#region Delegates
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
public delegate int CreateObjectDelegate(
[In] ref Guid classID,
[In] ref Guid interfaceID,
[MarshalAs(UnmanagedType.Interface)] out object outObject);
#endregion
[DllImport("kernel32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern IntPtr LoadLibrary([MarshalAs(UnmanagedType.LPStr)] string fileName);
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool FreeLibrary(IntPtr hModule);
[DllImport("kernel32.dll", BestFitMapping = false, ThrowOnUnmappableChar = true)]
public static extern IntPtr GetProcAddress(IntPtr hModule, [MarshalAs(UnmanagedType.LPStr)] string procName);
#endif
#if WINCE
[DllImport("7z.dll", EntryPoint="CreateObject")]
public static extern int CreateCOMObject(
[In] ref Guid classID,
[In] ref Guid interfaceID,
[MarshalAs(UnmanagedType.Interface)] out object outObject);
#endif
public static T SafeCast<T>(PropVariant var, T def)
{
object obj;
try
{
obj = var.Object;
}
catch (Exception)
{
return def;
}
if (obj != null && obj is T)
{
return (T) obj;
}
return def;
}
}
#endif
}

File diff suppressed because it is too large Load Diff

View File

@ -1,689 +0,0 @@
namespace SevenZip
{
using System.Collections.Generic;
using System.IO;
#if DOTNET20
using System.Threading;
#else
using System.Windows.Threading;
#endif
partial class SevenZipCompressor
{
#region Delegates
private delegate void CompressFiles1Delegate(string archiveName, string[] fileFullNames);
private delegate void CompressFiles2Delegate(Stream archiveStream, string[] fileFullNames);
private delegate void CompressFiles3Delegate(string archiveName, int commonRootLength, string[] fileFullNames);
private delegate void CompressFiles4Delegate(Stream archiveStream, int commonRootLength, string[] fileFullNames);
private delegate void CompressFilesEncrypted1Delegate(string archiveName, string password, string[] fileFullNames);
private delegate void CompressFilesEncrypted2Delegate(Stream archiveStream, string password, string[] fileFullNames);
private delegate void CompressFilesEncrypted3Delegate(string archiveName, int commonRootLength, string password, string[] fileFullNames);
private delegate void CompressFilesEncrypted4Delegate(Stream archiveStream, int commonRootLength, string password, string[] fileFullNames);
private delegate void CompressDirectory1Delegate(string directory, string archiveName);
private delegate void CompressDirectory2Delegate(string directory, Stream archiveStream);
private delegate void CompressDirectory3Delegate(string directory, string archiveName, string password);
private delegate void CompressDirectory4Delegate(string directory, Stream archiveStream, string password);
private delegate void CompressDirectory5Delegate(string directory, string archiveName,
string password, string searchPattern, bool recursion);
private delegate void CompressDirectory6Delegate(string directory, Stream archiveStream,
string password, string searchPattern, bool recursion);
private delegate void CompressStream1Delegate(Stream inStream, Stream outStream);
private delegate void CompressStream2Delegate(Stream inStream, Stream outStream, string password);
private delegate void ModifyArchive1Delegate(string archiveName, Dictionary<int, string> newFileNames);
private delegate void ModifyArchive2Delegate(string archiveName, Dictionary<int, string> newFileNames,
string password);
#endregion
#region CompressFiles overloads
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveName">The archive file name.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveName">The archive file name.</param>
#endif
public void BeginCompressFiles(
string archiveName
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFiles1Delegate(CompressFiles)).BeginInvoke(archiveName, fileFullNames,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles(string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles(string archiveName ... ) overloads for archiving to disk.</param>
#endif
public void BeginCompressFiles(
Stream archiveStream
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFiles2Delegate(CompressFiles)).BeginInvoke(archiveStream, fileFullNames,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
/// <param name="archiveName">The archive file name.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
/// <param name="archiveName">The archive file name.</param>
#endif
public void BeginCompressFiles(
string archiveName, int commonRootLength
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFiles3Delegate(CompressFiles)).BeginInvoke(archiveName, commonRootLength, fileFullNames,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles(string archiveName, ... ) overloads for archiving to disk.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles(string archiveName, ... ) overloads for archiving to disk.</param>
#endif
public void BeginCompressFiles(
Stream archiveStream, int commonRootLength
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFiles4Delegate(CompressFiles)).BeginInvoke(archiveStream, commonRootLength, fileFullNames,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveName">The archive file name</param>
/// <param name="password">The archive password.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveName">The archive file name</param>
/// <param name="password">The archive password.</param>
#endif
public void BeginCompressFilesEncrypted(
string archiveName, string password
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFilesEncrypted1Delegate(CompressFilesEncrypted)).BeginInvoke(archiveName, password, fileFullNames,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
#endif
public void BeginCompressFilesEncrypted(
Stream archiveStream, string password
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFilesEncrypted2Delegate(CompressFilesEncrypted)).BeginInvoke(archiveStream, password, fileFullNames,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveName">The archive file name</param>
/// <param name="password">The archive password.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveName">The archive file name</param>
/// <param name="password">The archive password.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
#endif
public void BeginCompressFilesEncrypted(
string archiveName, int commonRootLength, string password
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFilesEncrypted3Delegate(CompressFilesEncrypted)).BeginInvoke(archiveName, commonRootLength, password,
fileFullNames, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs files into the archive asynchronously.
/// </summary>
/// <param name="fileFullNames">Array of file names to pack.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressFiles( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
/// <param name="commonRootLength">The length of the common root of the file names.</param>
#endif
public void BeginCompressFilesEncrypted(
Stream archiveStream, int commonRootLength, string password
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
, params string[] fileFullNames
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressFilesEncrypted4Delegate(CompressFilesEncrypted)).BeginInvoke(archiveStream, commonRootLength, password,
fileFullNames, AsyncCallbackImplementation, this);
}
#endregion
#region BeginCompressDirectory overloads
#if !CS4
#if !DOTNET20
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveName">The archive file name.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveName">The archive file name.</param>
#endif
public void BeginCompressDirectory(
string directory, string archiveName
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressDirectory1Delegate(CompressDirectory)).BeginInvoke(directory, archiveName,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
#endif
public void BeginCompressDirectory(
string directory, Stream archiveStream
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressDirectory2Delegate(CompressDirectory)).BeginInvoke(directory, archiveStream,
AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveName">The archive file name.</param>
/// <param name="password">The archive password.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveName">The archive file name.</param>
/// <param name="password">The archive password.</param>
#endif
public void BeginCompressDirectory(
string directory, string archiveName, string password
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressDirectory3Delegate(CompressDirectory)).BeginInvoke(directory, archiveName,
password, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Recursively packs all files in the specified directory.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
#endif
public void BeginCompressDirectory(
string directory, Stream archiveStream, string password
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressDirectory4Delegate(CompressDirectory)).BeginInvoke(directory, archiveStream,
password, AsyncCallbackImplementation, this);
}
#endif
#if !DOTNET20
/// <summary>
/// Packs all files in the specified directory asynchronously.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveName">The archive file name.</param>
/// <param name="password">The archive password.</param>
/// <param name="searchPattern">Search string, such as "*.txt".</param>
/// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs all files in the specified directory asynchronously.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveName">The archive file name.</param>
/// <param name="password">The archive password.</param>
/// <param name="searchPattern">Search string, such as "*.txt".</param>
/// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
#endif
public void BeginCompressDirectory(string directory, string archiveName,
string password
#if CS4
= ""
#endif
, string searchPattern
#if CS4
= "*"
#endif
, bool recursion
#if CS4
= true
#endif
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressDirectory5Delegate(CompressDirectory)).BeginInvoke(directory, archiveName,
password, searchPattern, recursion, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Packs all files in the specified directory asynchronously.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
/// <param name="searchPattern">Search string, such as "*.txt".</param>
/// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Packs all files in the specified directory asynchronously.
/// </summary>
/// <param name="directory">The directory to compress.</param>
/// <param name="archiveStream">The archive output stream.
/// Use CompressDirectory( ... string archiveName ... ) overloads for archiving to disk.</param>
/// <param name="password">The archive password.</param>
/// <param name="searchPattern">Search string, such as "*.txt".</param>
/// <param name="recursion">If true, files will be searched for recursively; otherwise, not.</param>
#endif
public void BeginCompressDirectory(string directory, Stream archiveStream,
string password
#if CS4
= ""
#endif
, string searchPattern
#if CS4
= "*"
#endif
, bool recursion
#if CS4
= true
#endif
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressDirectory6Delegate(CompressDirectory)).BeginInvoke(directory, archiveStream,
password, searchPattern, recursion, AsyncCallbackImplementation, this);
}
#endregion
#region BeginCompressStream overloads
#if !CS4
#if !DOTNET20
/// <summary>
/// Compresses the specified stream.
/// </summary>
/// <param name="inStream">The source uncompressed stream.</param>
/// <param name="outStream">The destination compressed stream.</param>
/// <exception cref="ArgumentException">ArgumentException: at least one of the specified streams is invalid.</exception>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Compresses the specified stream.
/// </summary>
/// <param name="inStream">The source uncompressed stream.</param>
/// <param name="outStream">The destination compressed stream.</param>
/// <exception cref="System.ArgumentException">ArgumentException: at least one of the specified streams is invalid.</exception>
#endif
public void BeginCompressStream(Stream inStream, Stream outStream
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressStream1Delegate(CompressStream)).BeginInvoke(inStream, outStream, AsyncCallbackImplementation, this);
}
#endif
#if !DOTNET20
/// <summary>
/// Compresses the specified stream.
/// </summary>
/// <param name="inStream">The source uncompressed stream.</param>
/// <param name="outStream">The destination compressed stream.</param>
/// <param name="password">The archive password.</param>
/// <exception cref="System.ArgumentException">ArgumentException: at least one of the specified streams is invalid.</exception>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Compresses the specified stream.
/// </summary>
/// <param name="inStream">The source uncompressed stream.</param>
/// <param name="outStream">The destination compressed stream.</param>
/// <param name="password">The archive password.</param>
/// <exception cref="System.ArgumentException">ArgumentException: at least one of the specified streams is invalid.</exception>
#endif
public void BeginCompressStream(Stream inStream, Stream outStream, string password
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new CompressStream2Delegate(CompressStream)).BeginInvoke(inStream, outStream, password, AsyncCallbackImplementation, this);
}
#endregion
#region BeginModifyArchive overloads
#if !CS4
#if !DOTNET20
/// <summary>
/// Modifies the existing archive asynchronously (renames files or deletes them).
/// </summary>
/// <param name="archiveName">The archive file name.</param>
/// <param name="newFileNames">New file names. Null value to delete the corresponding index.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Modifies the existing archive asynchronously (renames files or deletes them).
/// </summary>
/// <param name="archiveName">The archive file name.</param>
/// <param name="newFileNames">New file names. Null value to delete the corresponding index.</param>
#endif
public void BeginModifyArchive(string archiveName, Dictionary<int, string> newFileNames
#if !DOTNET20
, DispatcherPriority eventPriority
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ModifyArchive1Delegate(ModifyArchive)).BeginInvoke(archiveName, newFileNames, AsyncCallbackImplementation, this);
}
#endif
#if !DOTNET20
/// <summary>
/// Modifies the existing archive asynchronously (renames files or deletes them).
/// </summary>
/// <param name="archiveName">The archive file name.</param>
/// <param name="newFileNames">New file names. Null value to delete the corresponding index.</param>
/// <param name="password">The archive password.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Modifies the existing archive asynchronously (renames files or deletes them).
/// </summary>
/// <param name="archiveName">The archive file name.</param>
/// <param name="newFileNames">New file names. Null value to delete the corresponding index.</param>
/// <param name="password">The archive password.</param>
#endif
public void BeginModifyArchive(string archiveName, Dictionary<int, string> newFileNames,
string password
#if CS4
= ""
#endif
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ModifyArchive2Delegate(ModifyArchive)).BeginInvoke(archiveName, newFileNames, password, AsyncCallbackImplementation, this);
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,294 +0,0 @@
namespace SevenZip
{
using System;
using System.IO;
#if DOTNET20
using System.Threading;
#else
using System.Windows.Threading;
#endif
partial class SevenZipExtractor
{
#region Asynchronous core methods
/// <summary>
/// Recreates the instance of the SevenZipExtractor class.
/// Used in asynchronous methods.
/// </summary>
private void RecreateInstanceIfNeeded()
{
if (NeedsToBeRecreated)
{
NeedsToBeRecreated = false;
Stream backupStream = null;
string backupFileName = null;
if (String.IsNullOrEmpty(_fileName))
{
backupStream = _inStream;
}
else
{
backupFileName = _fileName;
}
CommonDispose();
if (backupStream == null)
{
Init(backupFileName);
}
else
{
Init(backupStream);
}
}
}
internal override void SaveContext(
#if !DOTNET20
DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
DisposedCheck();
base.SaveContext(
#if !DOTNET20
eventPriority
#endif
);
}
#endregion
#region Delegates
/// <summary>
/// The delegate to use in BeginExtractArchive.
/// </summary>
/// <param name="directory">The directory where the files are to be unpacked.</param>
private delegate void ExtractArchiveDelegate(string directory);
/// <summary>
/// The delegate to use in BeginExtractFile (by file name).
/// </summary>
/// <param name="fileName">The file full name in the archive file table.</param>
/// <param name="stream">The stream where the file is to be unpacked.</param>
private delegate void ExtractFileByFileNameDelegate(string fileName, Stream stream);
/// <summary>
/// The delegate to use in BeginExtractFile (by index).
/// </summary>
/// <param name="index">Index in the archive file table.</param>
/// <param name="stream">The stream where the file is to be unpacked.</param>
private delegate void ExtractFileByIndexDelegate(int index, Stream stream);
/// <summary>
/// The delegate to use in BeginExtractFiles(string directory, params int[] indexes).
/// </summary>
/// <param name="indexes">indexes of the files in the archive file table.</param>
/// <param name="directory">Directory where the files are to be unpacked.</param>
private delegate void ExtractFiles1Delegate(string directory, int[] indexes);
/// <summary>
/// The delegate to use in BeginExtractFiles(string directory, params string[] fileNames).
/// </summary>
/// <param name="fileNames">Full file names in the archive file table.</param>
/// <param name="directory">Directory where the files are to be unpacked.</param>
private delegate void ExtractFiles2Delegate(string directory, string[] fileNames);
/// <summary>
/// The delegate to use in BeginExtractFiles(ExtractFileCallback extractFileCallback).
/// </summary>
/// <param name="extractFileCallback">The callback to call for each file in the archive.</param>
private delegate void ExtractFiles3Delegate(ExtractFileCallback extractFileCallback);
#endregion
#if !DOTNET20
/// <summary>
/// Unpacks the whole archive asynchronously to the specified directory name at the specified priority.
/// </summary>
/// <param name="directory">The directory where the files are to be unpacked.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Unpacks the whole archive asynchronously to the specified directory name at the specified priority.
/// </summary>
/// <param name="directory">The directory where the files are to be unpacked.</param>
#endif
public void BeginExtractArchive(string directory
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ExtractArchiveDelegate(ExtractArchive)).BeginInvoke(directory, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Unpacks the file asynchronously by its name to the specified stream.
/// </summary>
/// <param name="fileName">The file full name in the archive file table.</param>
/// <param name="stream">The stream where the file is to be unpacked.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Unpacks the file asynchronously by its name to the specified stream.
/// </summary>
/// <param name="fileName">The file full name in the archive file table.</param>
/// <param name="stream">The stream where the file is to be unpacked.</param>
#endif
public void BeginExtractFile(string fileName, Stream stream
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ExtractFileByFileNameDelegate(ExtractFile)).BeginInvoke(fileName, stream, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Unpacks the file asynchronously by its index to the specified stream.
/// </summary>
/// <param name="index">Index in the archive file table.</param>
/// <param name="stream">The stream where the file is to be unpacked.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Unpacks the file asynchronously by its index to the specified stream.
/// </summary>
/// <param name="index">Index in the archive file table.</param>
/// <param name="stream">The stream where the file is to be unpacked.</param>
#endif
public void BeginExtractFile(int index, Stream stream
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ExtractFileByIndexDelegate(ExtractFile)).BeginInvoke(index, stream, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Unpacks files asynchronously by their indices to the specified directory.
/// </summary>
/// <param name="indexes">indexes of the files in the archive file table.</param>
/// <param name="directory">Directory where the files are to be unpacked.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Unpacks files asynchronously by their indices to the specified directory.
/// </summary>
/// <param name="indexes">indexes of the files in the archive file table.</param>
/// <param name="directory">Directory where the files are to be unpacked.</param>
#endif
public void BeginExtractFiles(string directory
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
, params int[] indexes)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ExtractFiles1Delegate(ExtractFiles)).BeginInvoke(directory, indexes, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Unpacks files asynchronously by their full names to the specified directory.
/// </summary>
/// <param name="fileNames">Full file names in the archive file table.</param>
/// <param name="directory">Directory where the files are to be unpacked.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Unpacks files asynchronously by their full names to the specified directory.
/// </summary>
/// <param name="fileNames">Full file names in the archive file table.</param>
/// <param name="directory">Directory where the files are to be unpacked.</param>
#endif
public void BeginExtractFiles(string directory
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
, params string[] fileNames)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ExtractFiles2Delegate(ExtractFiles)).BeginInvoke(directory, fileNames, AsyncCallbackImplementation, this);
}
#if !DOTNET20
/// <summary>
/// Extracts files from the archive asynchronously, giving a callback the choice what
/// to do with each file. The order of the files is given by the archive.
/// 7-Zip (and any other solid) archives are NOT supported.
/// </summary>
/// <param name="extractFileCallback">The callback to call for each file in the archive.</param>
/// <param name="eventPriority">The priority of events, relative to the other pending operations in the System.Windows.Threading.Dispatcher event queue, the specified method is invoked.</param>
#else
/// <summary>
/// Extracts files from the archive asynchronously, giving a callback the choice what
/// to do with each file. The order of the files is given by the archive.
/// 7-Zip (and any other solid) archives are NOT supported.
/// </summary>
/// <param name="extractFileCallback">The callback to call for each file in the archive.</param>
#endif
public void BeginExtractFiles(ExtractFileCallback extractFileCallback
#if !DOTNET20
, DispatcherPriority eventPriority
#if CS4
= DispatcherPriority.Normal
#endif
#endif
)
{
SaveContext(
#if !DOTNET20
eventPriority
#endif
);
(new ExtractFiles3Delegate(ExtractFiles)).BeginInvoke(extractFileCallback, AsyncCallbackImplementation, this);
}
}
}

View File

@ -1,499 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Text;
using System.Xml;
using System.Xml.Schema;
namespace SevenZip
{
#if SFX
using SfxSettings = Dictionary<string, string>;
/// <summary>
/// Sfx module choice enumeration
/// </summary>
public enum SfxModule
{
/// <summary>
/// Default module (leave this if unsure)
/// </summary>
Default,
/// <summary>
/// The simple sfx module by Igor Pavlov with no adjustable parameters
/// </summary>
Simple,
/// <summary>
/// The installer sfx module by Igor Pavlov
/// </summary>
Installer,
/// <summary>
/// The extended installer sfx module by Oleg Scherbakov
/// </summary>
Extended,
/// <summary>
/// The custom sfx module. First you must specify the module file name.
/// </summary>
Custom
}
/// <summary>
/// The class for making 7-zip based self-extracting archives.
/// </summary>
public class SevenZipSfx
{
private static readonly Dictionary<SfxModule, List<string>> SfxSupportedModuleNames =
new Dictionary<SfxModule, List<string>>(3)
{
{SfxModule.Default, new List<string>(1) {"7zxSD_All.sfx"}},
{SfxModule.Simple, new List<string>(2) {"7z.sfx", "7zCon.sfx"}},
{SfxModule.Installer, new List<string>(2) {"7zS.sfx", "7zSD.sfx"}},
{
SfxModule.Extended,
new List<string>(4) {"7zxSD_All.sfx", "7zxSD_Deflate", "7zxSD_LZMA", "7zxSD_PPMd"}
}
};
private SfxModule _module = SfxModule.Default;
private string _moduleFileName;
private Dictionary<SfxModule, List<string>> _sfxCommands;
/// <summary>
/// Initializes a new instance of the SevenZipSfx class.
/// </summary>
public SevenZipSfx()
{
_module = SfxModule.Default;
CommonInit();
}
/// <summary>
/// Initializes a new instance of the SevenZipSfx class.
/// </summary>
/// <param name="module">The sfx module to use as a front-end.</param>
public SevenZipSfx(SfxModule module)
{
if (module == SfxModule.Custom)
{
throw new ArgumentException("You must specify the custom module executable.", "module");
}
_module = module;
CommonInit();
}
/// <summary>
/// Initializes a new instance of the SevenZipSfx class.
/// </summary>
/// <param name="moduleFileName"></param>
public SevenZipSfx(string moduleFileName)
{
_module = SfxModule.Custom;
ModuleFileName = moduleFileName;
CommonInit();
}
/// <summary>
/// Gets the sfx module type.
/// </summary>
public SfxModule SfxModule
{
get
{
return _module;
}
}
/// <summary>
/// Gets or sets the custom sfx module file name
/// </summary>
public string ModuleFileName
{
get
{
return _moduleFileName;
}
set
{
if (!File.Exists(value))
{
throw new ArgumentException("The specified file does not exist.");
}
_moduleFileName = value;
_module = SfxModule.Custom;
string sfxName = Path.GetFileName(value);
foreach (SfxModule mod in SfxSupportedModuleNames.Keys)
{
if (SfxSupportedModuleNames[mod].Contains(sfxName))
{
_module = mod;
}
}
}
}
private void CommonInit()
{
LoadCommandsFromResource("Configs");
}
private static string GetResourceString(string str)
{
#if !WINCE
return "SevenZip.sfx." + str;
#else
return "SevenZipSharpMobile.sfx." + str;
#endif
}
/// <summary>
/// Gets the sfx module enum by the list of supported modules
/// </summary>
/// <param name="name"></param>
/// <returns></returns>
private static SfxModule GetModuleByName(string name)
{
if (name.IndexOf("7z.sfx", StringComparison.Ordinal) > -1)
{
return SfxModule.Simple;
}
if (name.IndexOf("7zS.sfx", StringComparison.Ordinal) > -1)
{
return SfxModule.Installer;
}
if (name.IndexOf("7zxSD_All.sfx", StringComparison.Ordinal) > -1)
{
return SfxModule.Extended;
}
throw new SevenZipSfxValidationException("The specified configuration is unsupported.");
}
/// <summary>
/// Loads the commands for each supported sfx module configuration
/// </summary>
/// <param name="xmlDefinitions">The resource name for xml definitions</param>
private void LoadCommandsFromResource(string xmlDefinitions)
{
using (Stream cfg = Assembly.GetExecutingAssembly().GetManifestResourceStream(
GetResourceString(xmlDefinitions + ".xml")))
{
if (cfg == null)
{
throw new SevenZipSfxValidationException("The configuration \"" + xmlDefinitions +
"\" does not exist.");
}
using (Stream schm = Assembly.GetExecutingAssembly().GetManifestResourceStream(
GetResourceString(xmlDefinitions + ".xsd")))
{
if (schm == null)
{
throw new SevenZipSfxValidationException("The configuration schema \"" + xmlDefinitions +
"\" does not exist.");
}
var sc = new XmlSchemaSet();
using (XmlReader scr = XmlReader.Create(schm))
{
sc.Add(null, scr);
var settings = new XmlReaderSettings {ValidationType = ValidationType.Schema, Schemas = sc};
string validationErrors = "";
settings.ValidationEventHandler +=
((s, t) =>
{
validationErrors += String.Format(CultureInfo.InvariantCulture, "[{0}]: {1}\n",
t.Severity.ToString(), t.Message);
});
using (XmlReader rdr = XmlReader.Create(cfg, settings))
{
_sfxCommands = new Dictionary<SfxModule, List<string>>();
rdr.Read();
rdr.Read();
rdr.Read();
rdr.Read();
rdr.Read();
rdr.ReadStartElement("sfxConfigs");
rdr.Read();
do
{
SfxModule mod = GetModuleByName(rdr["modules"]);
rdr.ReadStartElement("config");
rdr.Read();
if (rdr.Name == "id")
{
var cmds = new List<string>();
_sfxCommands.Add(mod, cmds);
do
{
cmds.Add(rdr["command"]);
rdr.Read();
rdr.Read();
} while (rdr.Name == "id");
rdr.ReadEndElement();
rdr.Read();
}
else
{
_sfxCommands.Add(mod, null);
}
} while (rdr.Name == "config");
}
if (!String.IsNullOrEmpty(validationErrors))
{
throw new SevenZipSfxValidationException(
"\n" + validationErrors.Substring(0, validationErrors.Length - 1));
}
_sfxCommands.Add(SfxModule.Default, _sfxCommands[SfxModule.Extended]);
}
}
}
}
/// <summary>
/// Validates the sfx scenario commands.
/// </summary>
/// <param name="settings">The sfx settings dictionary to validate.</param>
private void ValidateSettings(SfxSettings settings)
{
if (_module == SfxModule.Custom)
{
return;
}
List<string> commands = _sfxCommands[_module];
if (commands == null)
{
return;
}
var invalidCommands = new List<string>();
foreach (string command in settings.Keys)
{
if (!commands.Contains(command))
{
invalidCommands.Add(command);
}
}
if (invalidCommands.Count > 0)
{
var invalidText = new StringBuilder("\nInvalid commands:\n");
foreach (string str in invalidCommands)
{
invalidText.Append(str);
}
throw new SevenZipSfxValidationException(invalidText.ToString());
}
}
/// <summary>
/// Gets the stream containing the sfx settings.
/// </summary>
/// <param name="settings">The sfx settings dictionary.</param>
/// <returns></returns>
private static Stream GetSettingsStream(SfxSettings settings)
{
var ms = new MemoryStream();
byte[] buf = Encoding.UTF8.GetBytes(@";!@Install@!UTF-8!" + '\n');
ms.Write(buf, 0, buf.Length);
foreach (string command in settings.Keys)
{
buf =
Encoding.UTF8.GetBytes(String.Format(CultureInfo.InvariantCulture, "{0}=\"{1}\"\n", command,
settings[command]));
ms.Write(buf, 0, buf.Length);
}
buf = Encoding.UTF8.GetBytes(@";!@InstallEnd@!");
ms.Write(buf, 0, buf.Length);
return ms;
}
private SfxSettings GetDefaultSettings()
{
switch (_module)
{
default:
return null;
case SfxModule.Installer:
var settings = new Dictionary<string, string> {{"Title", "7-Zip self-extracting archive"}};
return settings;
case SfxModule.Default:
case SfxModule.Extended:
settings = new Dictionary<string, string>
{
{"GUIMode", "0"},
{"InstallPath", "."},
{"GUIFlags", "128+8"},
{"ExtractPathTitle", "7-Zip self-extracting archive"},
{"ExtractPathText", "Specify the path where to extract the files:"}
};
return settings;
}
}
/// <summary>
/// Writes the whole to the other one.
/// </summary>
/// <param name="src">The source stream to read from.</param>
/// <param name="dest">The destination stream to wrie to.</param>
private static void WriteStream(Stream src, Stream dest)
{
src.Seek(0, SeekOrigin.Begin);
var buf = new byte[32768];
int bytesRead;
while ((bytesRead = src.Read(buf, 0, buf.Length)) > 0)
{
dest.Write(buf, 0, bytesRead);
}
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archive">The archive stream.</param>
/// <param name="sfxFileName">The name of the self-extracting executable.</param>
public void MakeSfx(Stream archive, string sfxFileName)
{
using (Stream sfxStream = File.Create(sfxFileName))
{
MakeSfx(archive, GetDefaultSettings(), sfxStream);
}
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archive">The archive stream.</param>
/// <param name="sfxStream">The stream to write the self-extracting executable to.</param>
public void MakeSfx(Stream archive, Stream sfxStream)
{
MakeSfx(archive, GetDefaultSettings(), sfxStream);
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archive">The archive stream.</param>
/// <param name="settings">The sfx settings.</param>
/// <param name="sfxFileName">The name of the self-extracting executable.</param>
public void MakeSfx(Stream archive, SfxSettings settings, string sfxFileName)
{
using (Stream sfxStream = File.Create(sfxFileName))
{
MakeSfx(archive, settings, sfxStream);
}
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archive">The archive stream.</param>
/// <param name="settings">The sfx settings.</param>
/// <param name="sfxStream">The stream to write the self-extracting executable to.</param>
public void MakeSfx(Stream archive, SfxSettings settings, Stream sfxStream)
{
if (!sfxStream.CanWrite)
{
throw new ArgumentException("The specified output stream can not write.", "sfxStream");
}
ValidateSettings(settings);
using (Stream sfx = _module == SfxModule.Default
? Assembly.GetExecutingAssembly().GetManifestResourceStream(
GetResourceString(SfxSupportedModuleNames[_module][0]))
: new FileStream(_moduleFileName, FileMode.Open, FileAccess.Read,
FileShare.ReadWrite))
{
WriteStream(sfx, sfxStream);
}
if (_module == SfxModule.Custom || _sfxCommands[_module] != null)
{
using (Stream set = GetSettingsStream(settings))
{
WriteStream(set, sfxStream);
}
}
WriteStream(archive, sfxStream);
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archiveFileName">The archive file name.</param>
/// <param name="sfxFileName">The name of the self-extracting executable.</param>
public void MakeSfx(string archiveFileName, string sfxFileName)
{
using (Stream sfxStream = File.Create(sfxFileName))
{
using (
Stream archive = new FileStream(archiveFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
)
{
MakeSfx(archive, GetDefaultSettings(), sfxStream);
}
}
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archiveFileName">The archive file name.</param>
/// <param name="sfxStream">The stream to write the self-extracting executable to.</param>
public void MakeSfx(string archiveFileName, Stream sfxStream)
{
using (Stream archive = new FileStream(archiveFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
)
{
MakeSfx(archive, GetDefaultSettings(), sfxStream);
}
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archiveFileName">The archive file name.</param>
/// <param name="settings">The sfx settings.</param>
/// <param name="sfxFileName">The name of the self-extracting executable.</param>
public void MakeSfx(string archiveFileName, SfxSettings settings, string sfxFileName)
{
using (Stream sfxStream = File.Create(sfxFileName))
{
using (
Stream archive = new FileStream(archiveFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
)
{
MakeSfx(archive, settings, sfxStream);
}
}
}
/// <summary>
/// Makes the self-extracting archive.
/// </summary>
/// <param name="archiveFileName">The archive file name.</param>
/// <param name="settings">The sfx settings.</param>
/// <param name="sfxStream">The stream to write the self-extracting executable to.</param>
public void MakeSfx(string archiveFileName, SfxSettings settings, Stream sfxStream)
{
using (Stream archive = new FileStream(archiveFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
)
{
MakeSfx(archive, settings, sfxStream);
}
}
}
#endif
}

View File

@ -1,545 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
#if MONO
using SevenZip.Mono.COM;
#endif
namespace SevenZip
{
#if UNMANAGED
/// <summary>
/// A class that has DisposeStream property.
/// </summary>
internal class DisposeVariableWrapper
{
public bool DisposeStream { protected get; set; }
protected DisposeVariableWrapper(bool disposeStream) { DisposeStream = disposeStream; }
}
/// <summary>
/// Stream wrapper used in InStreamWrapper
/// </summary>
internal class StreamWrapper : DisposeVariableWrapper, IDisposable
{
/// <summary>
/// File name associated with the stream (for date fix)
/// </summary>
private readonly string _fileName;
private readonly DateTime _fileTime;
/// <summary>
/// Worker stream for reading, writing and seeking.
/// </summary>
private Stream _baseStream;
/// <summary>
/// Initializes a new instance of the StreamWrapper class
/// </summary>
/// <param name="baseStream">Worker stream for reading, writing and seeking</param>
/// <param name="fileName">File name associated with the stream (for attributes fix)</param>
/// <param name="time">File last write time (for attributes fix)</param>
/// <param name="disposeStream">Indicates whether to dispose the baseStream</param>
protected StreamWrapper(Stream baseStream, string fileName, DateTime time, bool disposeStream)
: base(disposeStream)
{
_baseStream = baseStream;
_fileName = fileName;
_fileTime = time;
}
/// <summary>
/// Initializes a new instance of the StreamWrapper class
/// </summary>
/// <param name="baseStream">Worker stream for reading, writing and seeking</param>
/// <param name="disposeStream">Indicates whether to dispose the baseStream</param>
protected StreamWrapper(Stream baseStream, bool disposeStream)
: base(disposeStream)
{
_baseStream = baseStream;
}
/// <summary>
/// Gets the worker stream for reading, writing and seeking.
/// </summary>
protected Stream BaseStream
{
get
{
return _baseStream;
}
}
#region IDisposable Members
/// <summary>
/// Cleans up any resources used and fixes file attributes.
/// </summary>
public void Dispose()
{
if (_baseStream != null && DisposeStream)
{
try
{
_baseStream.Dispose();
}
catch (ObjectDisposedException) { }
_baseStream = null;
}
if (!String.IsNullOrEmpty(_fileName) && File.Exists(_fileName))
{
try
{
#if !WINCE
File.SetLastWriteTime(_fileName, _fileTime);
File.SetLastAccessTime(_fileName, _fileTime);
File.SetCreationTime(_fileName, _fileTime);
#elif WINCE
OpenNETCF.IO.FileHelper.SetLastWriteTime(_fileName, _fileTime);
OpenNETCF.IO.FileHelper.SetLastAccessTime(_fileName, _fileTime);
OpenNETCF.IO.FileHelper.SetCreationTime(_fileName, _fileTime);
#endif
//TODO: time support for Windows Phone
}
catch (ArgumentOutOfRangeException) {}
}
GC.SuppressFinalize(this);
}
#endregion
public virtual void Seek(long offset, SeekOrigin seekOrigin, IntPtr newPosition)
{
if (BaseStream != null)
{
long position = BaseStream.Seek(offset, seekOrigin);
if (newPosition != IntPtr.Zero)
{
Marshal.WriteInt64(newPosition, position);
}
}
}
}
/// <summary>
/// IInStream wrapper used in stream read operations.
/// </summary>
internal sealed class InStreamWrapper : StreamWrapper, ISequentialInStream, IInStream
{
/// <summary>
/// Initializes a new instance of the InStreamWrapper class.
/// </summary>
/// <param name="baseStream">Stream for writing data</param>
/// <param name="disposeStream">Indicates whether to dispose the baseStream</param>
public InStreamWrapper(Stream baseStream, bool disposeStream) : base(baseStream, disposeStream) { }
#region ISequentialInStream Members
/// <summary>
/// Reads data from the stream.
/// </summary>
/// <param name="data">A data array.</param>
/// <param name="size">The array size.</param>
/// <returns>The read bytes count.</returns>
public int Read(byte[] data, uint size)
{
int readCount = 0;
if (BaseStream != null)
{
readCount = BaseStream.Read(data, 0, (int) size);
if (readCount > 0)
{
OnBytesRead(new IntEventArgs(readCount));
}
}
return readCount;
}
#endregion
/// <summary>
/// Occurs when IntEventArgs.Value bytes were read from the source.
/// </summary>
public event EventHandler<IntEventArgs> BytesRead;
private void OnBytesRead(IntEventArgs e)
{
if (BytesRead != null)
{
BytesRead(this, e);
}
}
}
/// <summary>
/// IOutStream wrapper used in stream write operations.
/// </summary>
internal sealed class OutStreamWrapper : StreamWrapper, ISequentialOutStream, IOutStream
{
/// <summary>
/// Initializes a new instance of the OutStreamWrapper class
/// </summary>
/// <param name="baseStream">Stream for writing data</param>
/// <param name="fileName">File name (for attributes fix)</param>
/// <param name="time">Time of the file creation (for attributes fix)</param>
/// <param name="disposeStream">Indicates whether to dispose the baseStream</param>
public OutStreamWrapper(Stream baseStream, string fileName, DateTime time, bool disposeStream) :
base(baseStream, fileName, time, disposeStream) {}
/// <summary>
/// Initializes a new instance of the OutStreamWrapper class
/// </summary>
/// <param name="baseStream">Stream for writing data</param>
/// <param name="disposeStream">Indicates whether to dispose the baseStream</param>
public OutStreamWrapper(Stream baseStream, bool disposeStream) :
base(baseStream, disposeStream) {}
#region IOutStream Members
public int SetSize(long newSize)
{
BaseStream.SetLength(newSize);
return 0;
}
#endregion
#region ISequentialOutStream Members
/// <summary>
/// Writes data to the stream
/// </summary>
/// <param name="data">Data array</param>
/// <param name="size">Array size</param>
/// <param name="processedSize">Count of written bytes</param>
/// <returns>Zero if Ok</returns>
public int Write(byte[] data, uint size, IntPtr processedSize)
{
BaseStream.Write(data, 0, (int) size);
if (processedSize != IntPtr.Zero)
{
Marshal.WriteInt32(processedSize, (int) size);
}
OnBytesWritten(new IntEventArgs((int) size));
return 0;
}
#endregion
/// <summary>
/// Occurs when IntEventArgs.Value bytes were written.
/// </summary>
public event EventHandler<IntEventArgs> BytesWritten;
private void OnBytesWritten(IntEventArgs e)
{
if (BytesWritten != null)
{
BytesWritten(this, e);
}
}
}
/// <summary>
/// Base multi volume stream wrapper class.
/// </summary>
internal class MultiStreamWrapper : DisposeVariableWrapper, IDisposable
{
protected readonly Dictionary<int, KeyValuePair<long, long>> StreamOffsets =
new Dictionary<int, KeyValuePair<long, long>>();
protected readonly List<Stream> Streams = new List<Stream>();
protected int CurrentStream;
protected long Position;
protected long StreamLength;
/// <summary>
/// Initializes a new instance of the MultiStreamWrapper class.
/// </summary>
/// <param name="dispose">Perform Dispose() if requested to.</param>
protected MultiStreamWrapper(bool dispose) : base(dispose) {}
/// <summary>
/// Gets the total length of input data.
/// </summary>
public long Length
{
get
{
return StreamLength;
}
}
#region IDisposable Members
/// <summary>
/// Cleans up any resources used and fixes file attributes.
/// </summary>
public virtual void Dispose()
{
if (DisposeStream)
{
foreach (Stream stream in Streams)
{
try
{
stream.Dispose();
}
catch (ObjectDisposedException) {}
}
Streams.Clear();
}
GC.SuppressFinalize(this);
}
#endregion
protected static string VolumeNumber(int num)
{
if (num < 10)
{
return ".00" + num.ToString(CultureInfo.InvariantCulture);
}
if (num > 9 && num < 100)
{
return ".0" + num.ToString(CultureInfo.InvariantCulture);
}
if (num > 99 && num < 1000)
{
return "." + num.ToString(CultureInfo.InvariantCulture);
}
return String.Empty;
}
private int StreamNumberByOffset(long offset)
{
foreach (int number in StreamOffsets.Keys)
{
if (StreamOffsets[number].Key <= offset &&
StreamOffsets[number].Value >= offset)
{
return number;
}
}
return -1;
}
public void Seek(long offset, SeekOrigin seekOrigin, IntPtr newPosition)
{
long absolutePosition = (seekOrigin == SeekOrigin.Current)
? Position + offset
: offset;
CurrentStream = StreamNumberByOffset(absolutePosition);
long delta = Streams[CurrentStream].Seek(
absolutePosition - StreamOffsets[CurrentStream].Key, SeekOrigin.Begin);
Position = StreamOffsets[CurrentStream].Key + delta;
if (newPosition != IntPtr.Zero)
{
Marshal.WriteInt64(newPosition, Position);
}
}
}
/// <summary>
/// IInStream wrapper used in stream multi volume read operations.
/// </summary>
internal sealed class InMultiStreamWrapper : MultiStreamWrapper, ISequentialInStream, IInStream
{
/// <summary>
/// Initializes a new instance of the InMultiStreamWrapper class.
/// </summary>
/// <param name="fileName">The archive file name.</param>
/// <param name="dispose">Perform Dispose() if requested to.</param>
public InMultiStreamWrapper(string fileName, bool dispose) :
base(dispose)
{
string baseName = fileName.Substring(0, fileName.Length - 4);
int i = 0;
while (File.Exists(fileName))
{
Streams.Add(new FileStream(fileName, FileMode.Open));
long length = Streams[i].Length;
StreamOffsets.Add(i++, new KeyValuePair<long, long>(StreamLength, StreamLength + length));
StreamLength += length;
fileName = baseName + VolumeNumber(i + 1);
}
}
#region ISequentialInStream Members
/// <summary>
/// Reads data from the stream.
/// </summary>
/// <param name="data">A data array.</param>
/// <param name="size">The array size.</param>
/// <returns>The read bytes count.</returns>
public int Read(byte[] data, uint size)
{
var readSize = (int) size;
int readCount = Streams[CurrentStream].Read(data, 0, readSize);
readSize -= readCount;
Position += readCount;
while (readCount < (int) size)
{
if (CurrentStream == Streams.Count - 1)
{
return readCount;
}
CurrentStream++;
Streams[CurrentStream].Seek(0, SeekOrigin.Begin);
int count = Streams[CurrentStream].Read(data, readCount, readSize);
readCount += count;
readSize -= count;
Position += count;
}
return readCount;
}
#endregion
}
#if COMPRESS
/// <summary>
/// IOutStream wrapper used in multi volume stream write operations.
/// </summary>
internal sealed class OutMultiStreamWrapper : MultiStreamWrapper, ISequentialOutStream, IOutStream
{
private readonly string _archiveName;
private readonly int _volumeSize;
private long _overallLength;
/// <summary>
/// Initializes a new instance of the OutMultiStreamWrapper class.
/// </summary>
/// <param name="archiveName">The archive name.</param>
/// <param name="volumeSize">The volume size.</param>
public OutMultiStreamWrapper(string archiveName, int volumeSize) :
base(true)
{
_archiveName = archiveName;
_volumeSize = volumeSize;
CurrentStream = -1;
NewVolumeStream();
}
#region IOutStream Members
public int SetSize(long newSize)
{
return 0;
}
#endregion
#region ISequentialOutStream Members
public int Write(byte[] data, uint size, IntPtr processedSize)
{
int offset = 0;
var originalSize = (int) size;
Position += size;
_overallLength = Math.Max(Position + 1, _overallLength);
while (size > _volumeSize - Streams[CurrentStream].Position)
{
var count = (int) (_volumeSize - Streams[CurrentStream].Position);
Streams[CurrentStream].Write(data, offset, count);
size -= (uint) count;
offset += count;
NewVolumeStream();
}
Streams[CurrentStream].Write(data, offset, (int) size);
if (processedSize != IntPtr.Zero)
{
Marshal.WriteInt32(processedSize, originalSize);
}
return 0;
}
#endregion
public override void Dispose()
{
int lastIndex = Streams.Count - 1;
Streams[lastIndex].SetLength(lastIndex > 0? Streams[lastIndex].Position : _overallLength);
base.Dispose();
}
private void NewVolumeStream()
{
CurrentStream++;
Streams.Add(File.Create(_archiveName + VolumeNumber(CurrentStream + 1)));
Streams[CurrentStream].SetLength(_volumeSize);
StreamOffsets.Add(CurrentStream, new KeyValuePair<long, long>(0, _volumeSize - 1));
}
}
#endif
internal sealed class FakeOutStreamWrapper : ISequentialOutStream, IDisposable
{
#region IDisposable Members
public void Dispose()
{
GC.SuppressFinalize(this);
}
#endregion
#region ISequentialOutStream Members
/// <summary>
/// Does nothing except calling the BytesWritten event
/// </summary>
/// <param name="data">Data array</param>
/// <param name="size">Array size</param>
/// <param name="processedSize">Count of written bytes</param>
/// <returns>Zero if Ok</returns>
public int Write(byte[] data, uint size, IntPtr processedSize)
{
OnBytesWritten(new IntEventArgs((int) size));
if (processedSize != IntPtr.Zero)
{
Marshal.WriteInt32(processedSize, (int) size);
}
return 0;
}
#endregion
/// <summary>
/// Occurs when IntEventArgs.Value bytes were written
/// </summary>
public event EventHandler<IntEventArgs> BytesWritten;
private void OnBytesWritten(IntEventArgs e)
{
if (BytesWritten != null)
{
BytesWritten(this, e);
}
}
}
#endif
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1 +0,0 @@
Test

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,75 +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 <http://www.gnu.org/licenses/>.
*/
namespace SevenZip.Sdk
{
internal class CRC
{
public static readonly uint[] Table;
private uint _value = 0xFFFFFFFF;
static CRC()
{
Table = new uint[256];
const uint kPoly = 0xEDB88320;
for (uint i = 0; i < 256; i++)
{
uint r = i;
for (int j = 0; j < 8; j++)
if ((r & 1) != 0)
r = (r >> 1) ^ kPoly;
else
r >>= 1;
Table[i] = r;
}
}
public void Init()
{
_value = 0xFFFFFFFF;
}
public void UpdateByte(byte b)
{
_value = Table[(((byte) (_value)) ^ b)] ^ (_value >> 8);
}
public void Update(byte[] data, uint offset, uint size)
{
for (uint i = 0; i < size; i++)
_value = Table[(((byte) (_value)) ^ data[offset + i])] ^ (_value >> 8);
}
public uint GetDigest()
{
return _value ^ 0xFFFFFFFF;
}
private static uint CalculateDigest(byte[] data, uint offset, uint size)
{
var crc = new CRC();
// crc.Init();
crc.Update(data, offset, size);
return crc.GetDigest();
}
private static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size)
{
return (CalculateDigest(data, offset, size) == digest);
}
}
}

View File

@ -1,119 +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 <http://www.gnu.org/licenses/>.
*/
using System.IO;
namespace SevenZip.Sdk.Buffer
{
/// <summary>
/// Implements the input buffer work
/// </summary>
internal class InBuffer
{
private readonly byte[] m_Buffer;
private readonly uint m_BufferSize;
private uint m_Limit;
private uint m_Pos;
private ulong m_ProcessedSize;
private Stream m_Stream;
private bool m_StreamWasExhausted;
/// <summary>
/// Initializes the input buffer
/// </summary>
/// <param name="bufferSize"></param>
private InBuffer(uint bufferSize)
{
m_Buffer = new byte[bufferSize];
m_BufferSize = bufferSize;
}
/// <summary>
/// Initializes the class
/// </summary>
/// <param name="stream"></param>
private void Init(Stream stream)
{
m_Stream = stream;
m_ProcessedSize = 0;
m_Limit = 0;
m_Pos = 0;
m_StreamWasExhausted = false;
}
/// <summary>
/// Reads the whole block
/// </summary>
/// <returns></returns>
private bool ReadBlock()
{
if (m_StreamWasExhausted)
return false;
m_ProcessedSize += m_Pos;
int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int) m_BufferSize);
m_Pos = 0;
m_Limit = (uint) aNumProcessedBytes;
m_StreamWasExhausted = (aNumProcessedBytes == 0);
return (!m_StreamWasExhausted);
}
/// <summary>
/// Releases the stream
/// </summary>
private void ReleaseStream()
{
// m_Stream.Close();
m_Stream = null;
}
/// <summary>
/// Reads the byte to check it
/// </summary>
/// <param name="b"></param>
/// <returns></returns>
private bool ReadByte(out byte b)
{
b = 0;
if (m_Pos >= m_Limit)
if (!ReadBlock())
return false;
b = m_Buffer[m_Pos++];
return true;
}
/// <summary>
/// Reads the next byte
/// </summary>
/// <returns></returns>
private byte ReadByte()
{
// return (byte)m_Stream.ReadByte();
if (m_Pos >= m_Limit)
if (!ReadBlock())
return 0xFF;
return m_Buffer[m_Pos++];
}
/// <summary>
/// Gets processed size
/// </summary>
/// <returns></returns>
private ulong GetProcessedSize()
{
return m_ProcessedSize + m_Pos;
}
}
}

View File

@ -1,85 +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 <http://www.gnu.org/licenses/>.
*/
using System.IO;
namespace SevenZip.Sdk.Buffer
{
internal class OutBuffer
{
private readonly byte[] m_Buffer;
private readonly uint m_BufferSize;
private uint m_Pos;
private ulong m_ProcessedSize;
private Stream m_Stream;
/// <summary>
/// Initializes a new instance of the OutBuffer class
/// </summary>
/// <param name="bufferSize"></param>
public OutBuffer(uint bufferSize)
{
m_Buffer = new byte[bufferSize];
m_BufferSize = bufferSize;
}
public void SetStream(Stream stream)
{
m_Stream = stream;
}
public void FlushStream()
{
m_Stream.Flush();
}
public void CloseStream()
{
m_Stream.Close();
}
public void ReleaseStream()
{
m_Stream = null;
}
public void Init()
{
m_ProcessedSize = 0;
m_Pos = 0;
}
public void WriteByte(byte b)
{
m_Buffer[m_Pos++] = b;
if (m_Pos >= m_BufferSize)
FlushData();
}
public void FlushData()
{
if (m_Pos == 0)
return;
m_Stream.Write(m_Buffer, 0, (int) m_Pos);
m_Pos = 0;
}
public ulong GetProcessedSize()
{
return m_ProcessedSize + m_Pos;
}
}
}

View File

@ -1,40 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
namespace SevenZip.Sdk.Compression.LZ
{
internal interface IInWindowStream
{
void SetStream(Stream inStream);
void Init();
void ReleaseStream();
Byte GetIndexByte(Int32 index);
UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit);
UInt32 GetNumAvailableBytes();
}
internal interface IMatchFinder : IInWindowStream
{
void Create(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter);
UInt32 GetMatches(UInt32[] distances);
void Skip(UInt32 num);
}
}

View File

@ -1,405 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
namespace SevenZip.Sdk.Compression.LZ
{
internal class BinTree : InWindow, IMatchFinder
{
private const UInt32 kBT2HashSize = 1 << 16;
private const UInt32 kEmptyHashValue = 0;
private const UInt32 kHash2Size = 1 << 10;
private const UInt32 kHash3Offset = kHash2Size;
private const UInt32 kHash3Size = 1 << 16;
private const UInt32 kMaxValForNormalize = ((UInt32) 1 << 31) - 1;
private const UInt32 kStartMaxLen = 1;
private UInt32 _cutValue = 0xFF;
private UInt32 _cyclicBufferPos;
private UInt32 _cyclicBufferSize;
private UInt32[] _hash;
private UInt32 _hashMask;
private UInt32 _hashSizeSum;
private UInt32 _matchMaxLen;
private UInt32[] _son;
private bool HASH_ARRAY = true;
private UInt32 kFixHashSize = kHash2Size + kHash3Size;
private UInt32 kMinMatchCheck = 4;
private UInt32 kNumHashDirectBytes;
#region IMatchFinder Members
public new void SetStream(Stream stream)
{
base.SetStream(stream);
}
public new void ReleaseStream()
{
base.ReleaseStream();
}
public new void Init()
{
base.Init();
for (UInt32 i = 0; i < _hashSizeSum; i++)
_hash[i] = kEmptyHashValue;
_cyclicBufferPos = 0;
ReduceOffsets(-1);
}
public new Byte GetIndexByte(Int32 index)
{
return base.GetIndexByte(index);
}
public new UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)
{
return base.GetMatchLen(index, distance, limit);
}
public new UInt32 GetNumAvailableBytes()
{
return base.GetNumAvailableBytes();
}
public void Create(UInt32 historySize, UInt32 keepAddBufferBefore,
UInt32 matchMaxLen, UInt32 keepAddBufferAfter)
{
if (historySize + 256 > kMaxValForNormalize)
{
throw new ArgumentException("historySize + 256 > kMaxValForNormalize", "historySize");
}
_cutValue = 16 + (matchMaxLen >> 1);
UInt32 windowReservSize = (historySize + keepAddBufferBefore +
matchMaxLen + keepAddBufferAfter)/2 + 256;
base.Create(historySize + keepAddBufferBefore, matchMaxLen + keepAddBufferAfter, windowReservSize);
_matchMaxLen = matchMaxLen;
UInt32 cyclicBufferSize = historySize + 1;
if (_cyclicBufferSize != cyclicBufferSize)
_son = new UInt32[(_cyclicBufferSize = cyclicBufferSize)*2];
UInt32 hs = kBT2HashSize;
if (HASH_ARRAY)
{
hs = historySize - 1;
hs |= (hs >> 1);
hs |= (hs >> 2);
hs |= (hs >> 4);
hs |= (hs >> 8);
hs >>= 1;
hs |= 0xFFFF;
if (hs > (1 << 24))
hs >>= 1;
_hashMask = hs;
hs++;
hs += kFixHashSize;
}
if (hs != _hashSizeSum)
_hash = new UInt32[_hashSizeSum = hs];
}
public UInt32 GetMatches(UInt32[] distances)
{
UInt32 lenLimit;
if (_pos + _matchMaxLen <= _streamPos)
lenLimit = _matchMaxLen;
else
{
lenLimit = _streamPos - _pos;
if (lenLimit < kMinMatchCheck)
{
MovePos();
return 0;
}
}
UInt32 offset = 0;
UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
UInt32 cur = _bufferOffset + _pos;
UInt32 maxLen = kStartMaxLen; // to avoid items for len < hashSize;
UInt32 hashValue, hash2Value = 0, hash3Value = 0;
if (HASH_ARRAY)
{
UInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];
hash2Value = (temp & (((int) kHash2Size) - 1));
temp ^= (uint) ((_bufferBase[cur + 2]) << 8);
hash3Value = (temp & (((int) kHash3Size) - 1));
hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
}
else
hashValue = _bufferBase[cur] ^ ((UInt32) (_bufferBase[cur + 1]) << 8);
UInt32 curMatch = _hash[kFixHashSize + hashValue];
if (HASH_ARRAY)
{
UInt32 curMatch2 = _hash[hash2Value];
UInt32 curMatch3 = _hash[kHash3Offset + hash3Value];
_hash[hash2Value] = _pos;
_hash[kHash3Offset + hash3Value] = _pos;
if (curMatch2 > matchMinPos)
if (_bufferBase[_bufferOffset + curMatch2] == _bufferBase[cur])
{
distances[offset++] = maxLen = 2;
distances[offset++] = _pos - curMatch2 - 1;
}
if (curMatch3 > matchMinPos)
if (_bufferBase[_bufferOffset + curMatch3] == _bufferBase[cur])
{
if (curMatch3 == curMatch2)
offset -= 2;
distances[offset++] = maxLen = 3;
distances[offset++] = _pos - curMatch3 - 1;
curMatch2 = curMatch3;
}
if (offset != 0 && curMatch2 == curMatch)
{
offset -= 2;
maxLen = kStartMaxLen;
}
}
_hash[kFixHashSize + hashValue] = _pos;
UInt32 ptr0 = (_cyclicBufferPos << 1) + 1;
UInt32 ptr1 = (_cyclicBufferPos << 1);
UInt32 len0, len1;
len0 = len1 = kNumHashDirectBytes;
if (kNumHashDirectBytes != 0)
{
if (curMatch > matchMinPos)
{
if (_bufferBase[_bufferOffset + curMatch + kNumHashDirectBytes] !=
_bufferBase[cur + kNumHashDirectBytes])
{
distances[offset++] = maxLen = kNumHashDirectBytes;
distances[offset++] = _pos - curMatch - 1;
}
}
}
UInt32 count = _cutValue;
while (true)
{
if (curMatch <= matchMinPos || count-- == 0)
{
_son[ptr0] = _son[ptr1] = kEmptyHashValue;
break;
}
UInt32 delta = _pos - curMatch;
UInt32 cyclicPos = ((delta <= _cyclicBufferPos)
?
(_cyclicBufferPos - delta)
:
(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;
UInt32 pby1 = _bufferOffset + curMatch;
UInt32 len = Math.Min(len0, len1);
if (_bufferBase[pby1 + len] == _bufferBase[cur + len])
{
while (++len != lenLimit)
if (_bufferBase[pby1 + len] != _bufferBase[cur + len])
break;
if (maxLen < len)
{
distances[offset++] = maxLen = len;
distances[offset++] = delta - 1;
if (len == lenLimit)
{
_son[ptr1] = _son[cyclicPos];
_son[ptr0] = _son[cyclicPos + 1];
break;
}
}
}
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
{
_son[ptr1] = curMatch;
ptr1 = cyclicPos + 1;
curMatch = _son[ptr1];
len1 = len;
}
else
{
_son[ptr0] = curMatch;
ptr0 = cyclicPos;
curMatch = _son[ptr0];
len0 = len;
}
}
MovePos();
return offset;
}
public void Skip(UInt32 num)
{
do
{
UInt32 lenLimit;
if (_pos + _matchMaxLen <= _streamPos)
lenLimit = _matchMaxLen;
else
{
lenLimit = _streamPos - _pos;
if (lenLimit < kMinMatchCheck)
{
MovePos();
continue;
}
}
UInt32 matchMinPos = (_pos > _cyclicBufferSize) ? (_pos - _cyclicBufferSize) : 0;
UInt32 cur = _bufferOffset + _pos;
UInt32 hashValue;
if (HASH_ARRAY)
{
UInt32 temp = CRC.Table[_bufferBase[cur]] ^ _bufferBase[cur + 1];
UInt32 hash2Value = (temp & (((int) kHash2Size) - 1));
_hash[hash2Value] = _pos;
temp ^= ((UInt32) (_bufferBase[cur + 2]) << 8);
UInt32 hash3Value = (temp & (((int) kHash3Size) - 1));
_hash[kHash3Offset + hash3Value] = _pos;
hashValue = (temp ^ (CRC.Table[_bufferBase[cur + 3]] << 5)) & _hashMask;
}
else
hashValue = _bufferBase[cur] ^ ((UInt32) (_bufferBase[cur + 1]) << 8);
UInt32 curMatch = _hash[kFixHashSize + hashValue];
_hash[kFixHashSize + hashValue] = _pos;
UInt32 ptr0 = (_cyclicBufferPos << 1) + 1;
UInt32 ptr1 = (_cyclicBufferPos << 1);
UInt32 len0, len1;
len0 = len1 = kNumHashDirectBytes;
UInt32 count = _cutValue;
while (true)
{
if (curMatch <= matchMinPos || count-- == 0)
{
_son[ptr0] = _son[ptr1] = kEmptyHashValue;
break;
}
UInt32 delta = _pos - curMatch;
UInt32 cyclicPos = ((delta <= _cyclicBufferPos)
?
(_cyclicBufferPos - delta)
:
(_cyclicBufferPos - delta + _cyclicBufferSize)) << 1;
UInt32 pby1 = _bufferOffset + curMatch;
UInt32 len = Math.Min(len0, len1);
if (_bufferBase[pby1 + len] == _bufferBase[cur + len])
{
while (++len != lenLimit)
if (_bufferBase[pby1 + len] != _bufferBase[cur + len])
break;
if (len == lenLimit)
{
_son[ptr1] = _son[cyclicPos];
_son[ptr0] = _son[cyclicPos + 1];
break;
}
}
if (_bufferBase[pby1 + len] < _bufferBase[cur + len])
{
_son[ptr1] = curMatch;
ptr1 = cyclicPos + 1;
curMatch = _son[ptr1];
len1 = len;
}
else
{
_son[ptr0] = curMatch;
ptr0 = cyclicPos;
curMatch = _son[ptr0];
len0 = len;
}
}
MovePos();
} while (--num != 0);
}
#endregion
public void SetType(int numHashBytes)
{
HASH_ARRAY = (numHashBytes > 2);
if (HASH_ARRAY)
{
kNumHashDirectBytes = 0;
kMinMatchCheck = 4;
kFixHashSize = kHash2Size + kHash3Size;
}
else
{
kNumHashDirectBytes = 2;
kMinMatchCheck = 2 + 1;
kFixHashSize = 0;
}
}
public new void MovePos()
{
if (++_cyclicBufferPos >= _cyclicBufferSize)
_cyclicBufferPos = 0;
base.MovePos();
if (_pos == kMaxValForNormalize)
Normalize();
}
private static void NormalizeLinks(UInt32[] items, UInt32 numItems, UInt32 subValue)
{
for (UInt32 i = 0; i < numItems; i++)
{
UInt32 value = items[i];
if (value <= subValue)
value = kEmptyHashValue;
else
value -= subValue;
items[i] = value;
}
}
private void Normalize()
{
UInt32 subValue = _pos - _cyclicBufferSize;
NormalizeLinks(_son, _cyclicBufferSize*2, subValue);
NormalizeLinks(_hash, _hashSizeSum, subValue);
ReduceOffsets((Int32) subValue);
}
//public void SetCutValue(UInt32 cutValue) { _cutValue = cutValue; }
}
}

View File

@ -1,197 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
namespace SevenZip.Sdk.Compression.LZ
{
/// <summary>
/// Input window class
/// </summary>
internal class InWindow
{
/// <summary>
/// Size of Allocated memory block
/// </summary>
public UInt32 _blockSize;
/// <summary>
/// The pointer to buffer with data
/// </summary>
public Byte[] _bufferBase;
/// <summary>
/// Buffer offset value
/// </summary>
public UInt32 _bufferOffset;
/// <summary>
/// How many BYTEs must be kept buffer after _pos
/// </summary>
private UInt32 _keepSizeAfter;
/// <summary>
/// How many BYTEs must be kept in buffer before _pos
/// </summary>
private UInt32 _keepSizeBefore;
private UInt32 _pointerToLastSafePosition;
/// <summary>
/// Offset (from _buffer) of curent byte
/// </summary>
public UInt32 _pos;
private UInt32 _posLimit; // offset (from _buffer) of first byte when new block reading must be done
private Stream _stream;
private bool _streamEndWasReached; // if (true) then _streamPos shows real end of stream
/// <summary>
/// Offset (from _buffer) of first not read byte from Stream
/// </summary>
public UInt32 _streamPos;
public void MoveBlock()
{
UInt32 offset = (_bufferOffset) + _pos - _keepSizeBefore;
// we need one additional byte, since MovePos moves on 1 byte.
if (offset > 0)
offset--;
UInt32 numBytes = (_bufferOffset) + _streamPos - offset;
// check negative offset ????
for (UInt32 i = 0; i < numBytes; i++)
_bufferBase[i] = _bufferBase[offset + i];
_bufferOffset -= offset;
}
public virtual void ReadBlock()
{
if (_streamEndWasReached)
return;
while (true)
{
var size = (int) ((0 - _bufferOffset) + _blockSize - _streamPos);
if (size == 0)
return;
int numReadBytes = _stream.Read(_bufferBase, (int) (_bufferOffset + _streamPos), size);
if (numReadBytes == 0)
{
_posLimit = _streamPos;
UInt32 pointerToPostion = _bufferOffset + _posLimit;
if (pointerToPostion > _pointerToLastSafePosition)
_posLimit = (_pointerToLastSafePosition - _bufferOffset);
_streamEndWasReached = true;
return;
}
_streamPos += (UInt32) numReadBytes;
if (_streamPos >= _pos + _keepSizeAfter)
_posLimit = _streamPos - _keepSizeAfter;
}
}
private void Free()
{
_bufferBase = null;
}
public void Create(UInt32 keepSizeBefore, UInt32 keepSizeAfter, UInt32 keepSizeReserv)
{
_keepSizeBefore = keepSizeBefore;
_keepSizeAfter = keepSizeAfter;
UInt32 blockSize = keepSizeBefore + keepSizeAfter + keepSizeReserv;
if (_bufferBase == null || _blockSize != blockSize)
{
Free();
_blockSize = blockSize;
_bufferBase = new Byte[_blockSize];
}
_pointerToLastSafePosition = _blockSize - keepSizeAfter;
}
public void SetStream(Stream stream)
{
_stream = stream;
}
public void ReleaseStream()
{
_stream = null;
}
public void Init()
{
_bufferOffset = 0;
_pos = 0;
_streamPos = 0;
_streamEndWasReached = false;
ReadBlock();
}
public void MovePos()
{
_pos++;
if (_pos > _posLimit)
{
UInt32 pointerToPostion = _bufferOffset + _pos;
if (pointerToPostion > _pointerToLastSafePosition)
MoveBlock();
ReadBlock();
}
}
public Byte GetIndexByte(Int32 index)
{
return _bufferBase[_bufferOffset + _pos + index];
}
/// <summary>
/// index + limit have not to exceed _keepSizeAfter
/// </summary>
/// <param name="index"></param>
/// <param name="distance"></param>
/// <param name="limit"></param>
/// <returns></returns>
public UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit)
{
if (_streamEndWasReached)
if ((_pos + index) + limit > _streamPos)
limit = _streamPos - (UInt32) (_pos + index);
distance++;
// Byte *pby = _buffer + (size_t)_pos + index;
UInt32 pby = _bufferOffset + _pos + (UInt32) index;
UInt32 i;
for (i = 0; i < limit && _bufferBase[pby + i] == _bufferBase[pby + i - distance]; i++) ;
return i;
}
public UInt32 GetNumAvailableBytes()
{
return _streamPos - _pos;
}
public void ReduceOffsets(Int32 subValue)
{
_bufferOffset += (UInt32) subValue;
_posLimit -= (UInt32) subValue;
_pos -= (UInt32) subValue;
_streamPos -= (UInt32) subValue;
}
}
}

View File

@ -1,125 +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 <http://www.gnu.org/licenses/>.
*/
using System.IO;
namespace SevenZip.Sdk.Compression.LZ
{
internal class OutWindow
{
private byte[] _buffer;
private uint _pos;
private Stream _stream;
private uint _streamPos;
private uint _windowSize;
public uint TrainSize;
public void Create(uint windowSize)
{
if (_windowSize != windowSize)
{
// System.GC.Collect();
_buffer = new byte[windowSize];
}
_windowSize = windowSize;
_pos = 0;
_streamPos = 0;
}
public void Init(Stream stream, bool solid)
{
ReleaseStream();
_stream = stream;
if (!solid)
{
_streamPos = 0;
_pos = 0;
TrainSize = 0;
}
}
public bool Train(Stream stream)
{
long len = stream.Length;
uint size = (len < _windowSize) ? (uint) len : _windowSize;
TrainSize = size;
stream.Position = len - size;
_streamPos = _pos = 0;
while (size > 0)
{
uint curSize = _windowSize - _pos;
if (size < curSize)
curSize = size;
int numReadBytes = stream.Read(_buffer, (int) _pos, (int) curSize);
if (numReadBytes == 0)
return false;
size -= (uint) numReadBytes;
_pos += (uint) numReadBytes;
_streamPos += (uint) numReadBytes;
if (_pos == _windowSize)
_streamPos = _pos = 0;
}
return true;
}
public void ReleaseStream()
{
Flush();
_stream = null;
}
public void Flush()
{
uint size = _pos - _streamPos;
if (size == 0)
return;
_stream.Write(_buffer, (int) _streamPos, (int) size);
if (_pos >= _windowSize)
_pos = 0;
_streamPos = _pos;
}
public void CopyBlock(uint distance, uint len)
{
uint pos = _pos - distance - 1;
if (pos >= _windowSize)
pos += _windowSize;
for (; len > 0; len--)
{
if (pos >= _windowSize)
pos = 0;
_buffer[_pos++] = _buffer[pos++];
if (_pos >= _windowSize)
Flush();
}
}
public void PutByte(byte b)
{
_buffer[_pos++] = b;
if (_pos >= _windowSize)
Flush();
}
public byte GetByte(uint distance)
{
uint pos = _pos - distance - 1;
if (pos >= _windowSize)
pos += _windowSize;
return _buffer[pos];
}
}
}

View File

@ -1,108 +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 <http://www.gnu.org/licenses/>.
*/
namespace SevenZip.Sdk.Compression.Lzma
{
internal abstract class Base
{
public const uint kAlignMask = (kAlignTableSize - 1);
public const uint kAlignTableSize = 1 << kNumAlignBits;
public const int kDicLogSizeMin = 0;
public const uint kEndPosModelIndex = 14;
public const uint kMatchMaxLen = kMatchMinLen + kNumLenSymbols - 1;
// public const int kDicLogSizeMax = 30;
// public const uint kDistTableSizeMax = kDicLogSizeMax * 2;
public const uint kMatchMinLen = 2;
public const int kNumAlignBits = 4;
public const uint kNumFullDistances = 1 << ((int) kEndPosModelIndex/2);
public const int kNumHighLenBits = 8;
public const uint kNumLenSymbols = kNumLowLenSymbols + kNumMidLenSymbols +
(1 << kNumHighLenBits);
public const uint kNumLenToPosStates = 1 << kNumLenToPosStatesBits;
public const int kNumLenToPosStatesBits = 2; // it's for speed optimization
public const uint kNumLitContextBitsMax = 8;
public const uint kNumLitPosStatesBitsEncodingMax = 4;
public const int kNumLowLenBits = 3;
public const uint kNumLowLenSymbols = 1 << kNumLowLenBits;
public const int kNumMidLenBits = 3;
public const uint kNumMidLenSymbols = 1 << kNumMidLenBits;
public const uint kNumPosModels = kEndPosModelIndex - kStartPosModelIndex;
public const int kNumPosSlotBits = 6;
public const int kNumPosStatesBitsEncodingMax = 4;
public const int kNumPosStatesBitsMax = 4;
public const uint kNumPosStatesEncodingMax = (1 << kNumPosStatesBitsEncodingMax);
public const uint kNumPosStatesMax = (1 << kNumPosStatesBitsMax);
public const uint kNumRepDistances = 4;
public const uint kNumStates = 12;
public const uint kStartPosModelIndex = 4;
public static uint GetLenToPosState(uint len)
{
len -= kMatchMinLen;
if (len < kNumLenToPosStates)
return len;
return (kNumLenToPosStates - 1);
}
#region Nested type: State
public struct State
{
public uint Index;
public void Init()
{
Index = 0;
}
public void UpdateChar()
{
if (Index < 4) Index = 0;
else if (Index < 10) Index -= 3;
else Index -= 6;
}
public void UpdateMatch()
{
Index = (uint) (Index < 7 ? 7 : 10);
}
public void UpdateRep()
{
Index = (uint) (Index < 7 ? 8 : 11);
}
public void UpdateShortRep()
{
Index = (uint) (Index < 7 ? 9 : 11);
}
public bool IsCharState()
{
return Index < 7;
}
}
#endregion
}
}

View File

@ -1,480 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using SevenZip.Sdk.Compression.LZ;
using SevenZip.Sdk.Compression.RangeCoder;
namespace SevenZip.Sdk.Compression.Lzma
{
/// <summary>
/// The LZMA decoder class
/// </summary>
public class Decoder : ICoder, ISetDecoderProperties // ,System.IO.Stream
{
private readonly BitDecoder[] m_IsMatchDecoders = new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];
private readonly BitDecoder[] m_IsRep0LongDecoders =
new BitDecoder[Base.kNumStates << Base.kNumPosStatesBitsMax];
private readonly BitDecoder[] m_IsRepDecoders = new BitDecoder[Base.kNumStates];
private readonly BitDecoder[] m_IsRepG0Decoders = new BitDecoder[Base.kNumStates];
private readonly BitDecoder[] m_IsRepG1Decoders = new BitDecoder[Base.kNumStates];
private readonly BitDecoder[] m_IsRepG2Decoders = new BitDecoder[Base.kNumStates];
private readonly LenDecoder m_LenDecoder = new LenDecoder();
private readonly LiteralDecoder m_LiteralDecoder = new LiteralDecoder();
private readonly OutWindow m_OutWindow = new OutWindow();
private readonly BitDecoder[] m_PosDecoders = new BitDecoder[Base.kNumFullDistances - Base.kEndPosModelIndex];
private readonly BitTreeDecoder[] m_PosSlotDecoder = new BitTreeDecoder[Base.kNumLenToPosStates];
private readonly RangeCoder.Decoder m_RangeDecoder = new RangeCoder.Decoder();
private readonly LenDecoder m_RepLenDecoder = new LenDecoder();
private bool _solid;
private uint m_DictionarySize;
private uint m_DictionarySizeCheck;
private BitTreeDecoder m_PosAlignDecoder = new BitTreeDecoder(Base.kNumAlignBits);
private uint m_PosStateMask;
/// <summary>
/// Initializes the Lzma Decoder class.
/// </summary>
public Decoder()
{
m_DictionarySize = 0xFFFFFFFF;
for (int i = 0; i < Base.kNumLenToPosStates; i++)
m_PosSlotDecoder[i] = new BitTreeDecoder(Base.kNumPosSlotBits);
}
#region ICoder Members
/// <summary>
/// Codes a stream with LZMA algorithm to an output stream
/// </summary>
/// <param name="inStream">The input stream</param>
/// <param name="inSize">The input size</param>
/// <param name="outSize">The output size</param>
/// <param name="outStream">The output stream</param>
/// <param name="progress">Progress interface</param>
public void Code(Stream inStream, Stream outStream,
Int64 inSize, Int64 outSize, ICodeProgress progress)
{
Init(inStream, outStream);
var state = new Base.State();
state.Init();
uint rep0 = 0, rep1 = 0, rep2 = 0, rep3 = 0;
UInt64 nowPos64 = 0;
var outSize64 = (UInt64) outSize;
if (nowPos64 < outSize64)
{
if (m_IsMatchDecoders[state.Index << Base.kNumPosStatesBitsMax].Decode(m_RangeDecoder) != 0)
throw new DataErrorException();
state.UpdateChar();
byte b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, 0, 0);
m_OutWindow.PutByte(b);
nowPos64++;
}
while (nowPos64 < outSize64)
{
// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);
// while(nowPos64 < next)
{
uint posState = (uint) nowPos64 & m_PosStateMask;
if (
m_IsMatchDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(m_RangeDecoder) ==
0)
{
byte b;
byte prevByte = m_OutWindow.GetByte(0);
if (!state.IsCharState())
b = m_LiteralDecoder.DecodeWithMatchByte(m_RangeDecoder,
(uint) nowPos64, prevByte,
m_OutWindow.GetByte(rep0));
else
b = m_LiteralDecoder.DecodeNormal(m_RangeDecoder, (uint) nowPos64, prevByte);
m_OutWindow.PutByte(b);
state.UpdateChar();
nowPos64++;
}
else
{
uint len;
if (m_IsRepDecoders[state.Index].Decode(m_RangeDecoder) == 1)
{
if (m_IsRepG0Decoders[state.Index].Decode(m_RangeDecoder) == 0)
{
if (
m_IsRep0LongDecoders[(state.Index << Base.kNumPosStatesBitsMax) + posState].Decode(
m_RangeDecoder) == 0)
{
state.UpdateShortRep();
m_OutWindow.PutByte(m_OutWindow.GetByte(rep0));
nowPos64++;
continue;
}
}
else
{
UInt32 distance;
if (m_IsRepG1Decoders[state.Index].Decode(m_RangeDecoder) == 0)
{
distance = rep1;
}
else
{
if (m_IsRepG2Decoders[state.Index].Decode(m_RangeDecoder) == 0)
distance = rep2;
else
{
distance = rep3;
rep3 = rep2;
}
rep2 = rep1;
}
rep1 = rep0;
rep0 = distance;
}
len = m_RepLenDecoder.Decode(m_RangeDecoder, posState) + Base.kMatchMinLen;
state.UpdateRep();
}
else
{
rep3 = rep2;
rep2 = rep1;
rep1 = rep0;
len = Base.kMatchMinLen + m_LenDecoder.Decode(m_RangeDecoder, posState);
state.UpdateMatch();
uint posSlot = m_PosSlotDecoder[Base.GetLenToPosState(len)].Decode(m_RangeDecoder);
if (posSlot >= Base.kStartPosModelIndex)
{
var numDirectBits = (int) ((posSlot >> 1) - 1);
rep0 = ((2 | (posSlot & 1)) << numDirectBits);
if (posSlot < Base.kEndPosModelIndex)
rep0 += BitTreeDecoder.ReverseDecode(m_PosDecoders,
rep0 - posSlot - 1, m_RangeDecoder,
numDirectBits);
else
{
rep0 += (m_RangeDecoder.DecodeDirectBits(
numDirectBits - Base.kNumAlignBits) << Base.kNumAlignBits);
rep0 += m_PosAlignDecoder.ReverseDecode(m_RangeDecoder);
}
}
else
rep0 = posSlot;
}
if (rep0 >= m_OutWindow.TrainSize + nowPos64 || rep0 >= m_DictionarySizeCheck)
{
if (rep0 == 0xFFFFFFFF)
break;
throw new DataErrorException();
}
m_OutWindow.CopyBlock(rep0, len);
nowPos64 += len;
}
}
}
m_OutWindow.Flush();
m_OutWindow.ReleaseStream();
m_RangeDecoder.ReleaseStream();
}
#endregion
#region ISetDecoderProperties Members
/// <summary>
/// Sets decoder properties
/// </summary>
/// <param name="properties">Array of byte properties</param>
public void SetDecoderProperties(byte[] properties)
{
if (properties.Length < 5)
throw new InvalidParamException();
int lc = properties[0]%9;
int remainder = properties[0]/9;
int lp = remainder%5;
int pb = remainder/5;
if (pb > Base.kNumPosStatesBitsMax)
throw new InvalidParamException();
UInt32 dictionarySize = 0;
for (int i = 0; i < 4; i++)
dictionarySize += ((UInt32) (properties[1 + i])) << (i*8);
SetDictionarySize(dictionarySize);
SetLiteralProperties(lp, lc);
SetPosBitsProperties(pb);
}
#endregion
private void SetDictionarySize(uint dictionarySize)
{
if (m_DictionarySize != dictionarySize)
{
m_DictionarySize = dictionarySize;
m_DictionarySizeCheck = Math.Max(m_DictionarySize, 1);
uint blockSize = Math.Max(m_DictionarySizeCheck, (1 << 12));
m_OutWindow.Create(blockSize);
}
}
private void SetLiteralProperties(int lp, int lc)
{
if (lp > 8)
throw new InvalidParamException();
if (lc > 8)
throw new InvalidParamException();
m_LiteralDecoder.Create(lp, lc);
}
private void SetPosBitsProperties(int pb)
{
if (pb > Base.kNumPosStatesBitsMax)
throw new InvalidParamException();
uint numPosStates = (uint) 1 << pb;
m_LenDecoder.Create(numPosStates);
m_RepLenDecoder.Create(numPosStates);
m_PosStateMask = numPosStates - 1;
}
private void Init(Stream inStream, Stream outStream)
{
m_RangeDecoder.Init(inStream);
m_OutWindow.Init(outStream, _solid);
uint i;
for (i = 0; i < Base.kNumStates; i++)
{
for (uint j = 0; j <= m_PosStateMask; j++)
{
uint index = (i << Base.kNumPosStatesBitsMax) + j;
m_IsMatchDecoders[index].Init();
m_IsRep0LongDecoders[index].Init();
}
m_IsRepDecoders[i].Init();
m_IsRepG0Decoders[i].Init();
m_IsRepG1Decoders[i].Init();
m_IsRepG2Decoders[i].Init();
}
m_LiteralDecoder.Init();
for (i = 0; i < Base.kNumLenToPosStates; i++)
m_PosSlotDecoder[i].Init();
// m_PosSpecDecoder.Init();
for (i = 0; i < Base.kNumFullDistances - Base.kEndPosModelIndex; i++)
m_PosDecoders[i].Init();
m_LenDecoder.Init();
m_RepLenDecoder.Init();
m_PosAlignDecoder.Init();
}
/// <summary>
/// Trains a stream
/// </summary>
/// <param name="stream">The stream to train.</param>
/// <returns>true if Ok; otherwise, false.</returns>
public bool Train(Stream stream)
{
_solid = true;
return m_OutWindow.Train(stream);
}
#region Nested type: LenDecoder
private class LenDecoder
{
private readonly BitTreeDecoder[] m_LowCoder = new BitTreeDecoder[Base.kNumPosStatesMax];
private readonly BitTreeDecoder[] m_MidCoder = new BitTreeDecoder[Base.kNumPosStatesMax];
private BitDecoder m_Choice;
private BitDecoder m_Choice2;
private BitTreeDecoder m_HighCoder = new BitTreeDecoder(Base.kNumHighLenBits);
private uint m_NumPosStates;
internal void Create(uint numPosStates)
{
for (uint posState = m_NumPosStates; posState < numPosStates; posState++)
{
m_LowCoder[posState] = new BitTreeDecoder(Base.kNumLowLenBits);
m_MidCoder[posState] = new BitTreeDecoder(Base.kNumMidLenBits);
}
m_NumPosStates = numPosStates;
}
internal void Init()
{
m_Choice.Init();
for (uint posState = 0; posState < m_NumPosStates; posState++)
{
m_LowCoder[posState].Init();
m_MidCoder[posState].Init();
}
m_Choice2.Init();
m_HighCoder.Init();
}
/// <summary>
/// Decodes the stream
/// </summary>
/// <param name="rangeDecoder">The specified RangeCoder</param>
/// <param name="posState">The position state</param>
/// <returns></returns>
public uint Decode(RangeCoder.Decoder rangeDecoder, uint posState)
{
if (m_Choice.Decode(rangeDecoder) == 0)
return m_LowCoder[posState].Decode(rangeDecoder);
else
{
uint symbol = Base.kNumLowLenSymbols;
if (m_Choice2.Decode(rangeDecoder) == 0)
symbol += m_MidCoder[posState].Decode(rangeDecoder);
else
{
symbol += Base.kNumMidLenSymbols;
symbol += m_HighCoder.Decode(rangeDecoder);
}
return symbol;
}
}
}
#endregion
#region Nested type: LiteralDecoder
private class LiteralDecoder
{
private Decoder2[] m_Coders;
private int m_NumPosBits;
private int m_NumPrevBits;
private uint m_PosMask;
public void Create(int numPosBits, int numPrevBits)
{
if (m_Coders != null && m_NumPrevBits == numPrevBits &&
m_NumPosBits == numPosBits)
return;
m_NumPosBits = numPosBits;
m_PosMask = ((uint) 1 << numPosBits) - 1;
m_NumPrevBits = numPrevBits;
uint numStates = (uint) 1 << (m_NumPrevBits + m_NumPosBits);
m_Coders = new Decoder2[numStates];
for (uint i = 0; i < numStates; i++)
m_Coders[i].Create();
}
public void Init()
{
uint numStates = (uint) 1 << (m_NumPrevBits + m_NumPosBits);
for (uint i = 0; i < numStates; i++)
m_Coders[i].Init();
}
private uint GetState(uint pos, byte prevByte)
{
return ((pos & m_PosMask) << m_NumPrevBits) + (uint) (prevByte >> (8 - m_NumPrevBits));
}
public byte DecodeNormal(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte)
{
return m_Coders[GetState(pos, prevByte)].DecodeNormal(rangeDecoder);
}
public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, uint pos, byte prevByte, byte matchByte)
{
return m_Coders[GetState(pos, prevByte)].DecodeWithMatchByte(rangeDecoder, matchByte);
}
#region Nested type: Decoder2
private struct Decoder2
{
private BitDecoder[] m_Decoders;
public void Create()
{
m_Decoders = new BitDecoder[0x300];
}
public void Init()
{
for (int i = 0; i < 0x300; i++) m_Decoders[i].Init();
}
public byte DecodeNormal(RangeCoder.Decoder rangeDecoder)
{
uint symbol = 1;
do
symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder); while (symbol < 0x100);
return (byte) symbol;
}
public byte DecodeWithMatchByte(RangeCoder.Decoder rangeDecoder, byte matchByte)
{
uint symbol = 1;
do
{
uint matchBit = (uint) (matchByte >> 7) & 1;
matchByte <<= 1;
uint bit = m_Decoders[((1 + matchBit) << 8) + symbol].Decode(rangeDecoder);
symbol = (symbol << 1) | bit;
if (matchBit != bit)
{
while (symbol < 0x100)
symbol = (symbol << 1) | m_Decoders[symbol].Decode(rangeDecoder);
break;
}
} while (symbol < 0x100);
return (byte) symbol;
}
}
#endregion
} ;
#endregion
/*
public override bool CanRead { get { return true; }}
public override bool CanWrite { get { return true; }}
public override bool CanSeek { get { return true; }}
public override long Length { get { return 0; }}
public override long Position
{
get { return 0; }
set { }
}
public override void Flush() { }
public override int Read(byte[] buffer, int offset, int count)
{
return 0;
}
public override void Write(byte[] buffer, int offset, int count)
{
}
public override long Seek(long offset, System.IO.SeekOrigin origin)
{
return 0;
}
public override void SetLength(long value) {}
*/
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,249 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
namespace SevenZip.Sdk.Compression.RangeCoder
{
internal class Encoder
{
public const uint kTopValue = (1 << 24);
private byte _cache;
private uint _cacheSize;
public UInt64 Low;
public uint Range;
private long StartPosition;
private Stream Stream;
public void SetStream(Stream stream)
{
Stream = stream;
}
public void ReleaseStream()
{
Stream = null;
}
public void Init()
{
StartPosition = Stream.Position;
Low = 0;
Range = 0xFFFFFFFF;
_cacheSize = 1;
_cache = 0;
}
public void FlushData()
{
for (int i = 0; i < 5; i++)
ShiftLow();
}
public void FlushStream()
{
Stream.Flush();
}
/*public void CloseStream()
{
Stream.Close();
}*/
/*public void Encode(uint start, uint size, uint total)
{
Low += start * (Range /= total);
Range *= size;
while (Range < kTopValue)
{
Range <<= 8;
ShiftLow();
}
}*/
public void ShiftLow()
{
if ((uint) Low < 0xFF000000 || (uint) (Low >> 32) == 1)
{
byte temp = _cache;
do
{
Stream.WriteByte((byte) (temp + (Low >> 32)));
temp = 0xFF;
} while (--_cacheSize != 0);
_cache = (byte) (((uint) Low) >> 24);
}
_cacheSize++;
Low = ((uint) Low) << 8;
}
public void EncodeDirectBits(uint v, int numTotalBits)
{
for (int i = numTotalBits - 1; i >= 0; i--)
{
Range >>= 1;
if (((v >> i) & 1) == 1)
Low += Range;
if (Range < kTopValue)
{
Range <<= 8;
ShiftLow();
}
}
}
/*public void EncodeBit(uint size0, int numTotalBits, uint symbol)
{
uint newBound = (Range >> numTotalBits) * size0;
if (symbol == 0)
Range = newBound;
else
{
Low += newBound;
Range -= newBound;
}
while (Range < kTopValue)
{
Range <<= 8;
ShiftLow();
}
}*/
public long GetProcessedSizeAdd()
{
return _cacheSize +
Stream.Position - StartPosition + 4;
// (long)Stream.GetProcessedSize();
}
}
internal class Decoder
{
public const uint kTopValue = (1 << 24);
public uint Code;
public uint Range;
// public Buffer.InBuffer Stream = new Buffer.InBuffer(1 << 16);
public Stream Stream;
public void Init(Stream stream)
{
// Stream.Init(stream);
Stream = stream;
Code = 0;
Range = 0xFFFFFFFF;
for (int i = 0; i < 5; i++)
Code = (Code << 8) | (byte) Stream.ReadByte();
}
public void ReleaseStream()
{
// Stream.ReleaseStream();
Stream = null;
}
/*public void CloseStream()
{
Stream.Close();
}*/
/*public void Normalize()
{
while (Range < kTopValue)
{
Code = (Code << 8) | (byte)Stream.ReadByte();
Range <<= 8;
}
}*/
/*public void Normalize2()
{
if (Range < kTopValue)
{
Code = (Code << 8) | (byte)Stream.ReadByte();
Range <<= 8;
}
}*/
/*public uint GetThreshold(uint total)
{
return Code / (Range /= total);
}*/
/*public void Decode(uint start, uint size, uint total)
{
Code -= start * Range;
Range *= size;
Normalize();
}*/
public uint DecodeDirectBits(int numTotalBits)
{
uint range = Range;
uint code = Code;
uint result = 0;
for (int i = numTotalBits; i > 0; i--)
{
range >>= 1;
/*
result <<= 1;
if (code >= range)
{
code -= range;
result |= 1;
}
*/
uint t = (code - range) >> 31;
code -= range & (t - 1);
result = (result << 1) | (1 - t);
if (range < kTopValue)
{
code = (code << 8) | (byte) Stream.ReadByte();
range <<= 8;
}
}
Range = range;
Code = code;
return result;
}
/*public uint DecodeBit(uint size0, int numTotalBits)
{
uint newBound = (Range >> numTotalBits) * size0;
uint symbol;
if (Code < newBound)
{
symbol = 0;
Range = newBound;
}
else
{
symbol = 1;
Code -= newBound;
Range -= newBound;
}
Normalize();
return symbol;
}*/
// ulong GetProcessedSize() {return Stream.GetProcessedSize(); }
}
}

View File

@ -1,146 +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 <http://www.gnu.org/licenses/>.
*/
using System;
namespace SevenZip.Sdk.Compression.RangeCoder
{
internal struct BitEncoder
{
public const uint kBitModelTotal = (1 << kNumBitModelTotalBits);
public const int kNumBitModelTotalBits = 11;
public const int kNumBitPriceShiftBits = 6;
private const int kNumMoveBits = 5;
private const int kNumMoveReducingBits = 2;
private static readonly UInt32[] ProbPrices = new UInt32[kBitModelTotal >> kNumMoveReducingBits];
private uint Prob;
static BitEncoder()
{
const int kNumBits = (kNumBitModelTotalBits - kNumMoveReducingBits);
for (int i = kNumBits - 1; i >= 0; i--)
{
UInt32 start = (UInt32) 1 << (kNumBits - i - 1);
UInt32 end = (UInt32) 1 << (kNumBits - i);
for (UInt32 j = start; j < end; j++)
ProbPrices[j] = ((UInt32) i << kNumBitPriceShiftBits) +
(((end - j) << kNumBitPriceShiftBits) >> (kNumBits - i - 1));
}
}
public void Init()
{
Prob = kBitModelTotal >> 1;
}
/*public void UpdateModel(uint symbol)
{
if (symbol == 0)
Prob += (kBitModelTotal - Prob) >> kNumMoveBits;
else
Prob -= (Prob) >> kNumMoveBits;
}*/
public void Encode(Encoder encoder, uint symbol)
{
// encoder.EncodeBit(Prob, kNumBitModelTotalBits, symbol);
// UpdateModel(symbol);
uint newBound = (encoder.Range >> kNumBitModelTotalBits)*Prob;
if (symbol == 0)
{
encoder.Range = newBound;
Prob += (kBitModelTotal - Prob) >> kNumMoveBits;
}
else
{
encoder.Low += newBound;
encoder.Range -= newBound;
Prob -= (Prob) >> kNumMoveBits;
}
if (encoder.Range < Encoder.kTopValue)
{
encoder.Range <<= 8;
encoder.ShiftLow();
}
}
public uint GetPrice(uint symbol)
{
return ProbPrices[(((Prob - symbol) ^ ((-(int) symbol))) & (kBitModelTotal - 1)) >> kNumMoveReducingBits];
}
public uint GetPrice0()
{
return ProbPrices[Prob >> kNumMoveReducingBits];
}
public uint GetPrice1()
{
return ProbPrices[(kBitModelTotal - Prob) >> kNumMoveReducingBits];
}
}
internal struct BitDecoder
{
public const uint kBitModelTotal = (1 << kNumBitModelTotalBits);
public const int kNumBitModelTotalBits = 11;
private const int kNumMoveBits = 5;
private uint Prob;
/*public void UpdateModel(int numMoveBits, uint symbol)
{
if (symbol == 0)
Prob += (kBitModelTotal - Prob) >> numMoveBits;
else
Prob -= (Prob) >> numMoveBits;
}*/
public void Init()
{
Prob = kBitModelTotal >> 1;
}
public uint Decode(Decoder rangeDecoder)
{
uint newBound = (rangeDecoder.Range >> kNumBitModelTotalBits)*Prob;
if (rangeDecoder.Code < newBound)
{
rangeDecoder.Range = newBound;
Prob += (kBitModelTotal - Prob) >> kNumMoveBits;
if (rangeDecoder.Range < Decoder.kTopValue)
{
rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte) rangeDecoder.Stream.ReadByte();
rangeDecoder.Range <<= 8;
}
return 0;
}
else
{
rangeDecoder.Range -= newBound;
rangeDecoder.Code -= newBound;
Prob -= (Prob) >> kNumMoveBits;
if (rangeDecoder.Range < Decoder.kTopValue)
{
rangeDecoder.Code = (rangeDecoder.Code << 8) | (byte) rangeDecoder.Stream.ReadByte();
rangeDecoder.Range <<= 8;
}
return 1;
}
}
}
}

View File

@ -1,173 +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 <http://www.gnu.org/licenses/>.
*/
using System;
namespace SevenZip.Sdk.Compression.RangeCoder
{
internal struct BitTreeEncoder
{
private readonly BitEncoder[] Models;
private readonly int NumBitLevels;
public BitTreeEncoder(int numBitLevels)
{
NumBitLevels = numBitLevels;
Models = new BitEncoder[1 << numBitLevels];
}
public void Init()
{
for (uint i = 1; i < (1 << NumBitLevels); i++)
Models[i].Init();
}
public void Encode(Encoder rangeEncoder, UInt32 symbol)
{
UInt32 m = 1;
for (int bitIndex = NumBitLevels; bitIndex > 0;)
{
bitIndex--;
UInt32 bit = (symbol >> bitIndex) & 1;
Models[m].Encode(rangeEncoder, bit);
m = (m << 1) | bit;
}
}
public void ReverseEncode(Encoder rangeEncoder, UInt32 symbol)
{
UInt32 m = 1;
for (UInt32 i = 0; i < NumBitLevels; i++)
{
UInt32 bit = symbol & 1;
Models[m].Encode(rangeEncoder, bit);
m = (m << 1) | bit;
symbol >>= 1;
}
}
public UInt32 GetPrice(UInt32 symbol)
{
UInt32 price = 0;
UInt32 m = 1;
for (int bitIndex = NumBitLevels; bitIndex > 0;)
{
bitIndex--;
UInt32 bit = (symbol >> bitIndex) & 1;
price += Models[m].GetPrice(bit);
m = (m << 1) + bit;
}
return price;
}
public UInt32 ReverseGetPrice(UInt32 symbol)
{
UInt32 price = 0;
UInt32 m = 1;
for (int i = NumBitLevels; i > 0; i--)
{
UInt32 bit = symbol & 1;
symbol >>= 1;
price += Models[m].GetPrice(bit);
m = (m << 1) | bit;
}
return price;
}
public static UInt32 ReverseGetPrice(BitEncoder[] Models, UInt32 startIndex,
int NumBitLevels, UInt32 symbol)
{
UInt32 price = 0;
UInt32 m = 1;
for (int i = NumBitLevels; i > 0; i--)
{
UInt32 bit = symbol & 1;
symbol >>= 1;
price += Models[startIndex + m].GetPrice(bit);
m = (m << 1) | bit;
}
return price;
}
public static void ReverseEncode(BitEncoder[] Models, UInt32 startIndex,
Encoder rangeEncoder, int NumBitLevels, UInt32 symbol)
{
UInt32 m = 1;
for (int i = 0; i < NumBitLevels; i++)
{
UInt32 bit = symbol & 1;
Models[startIndex + m].Encode(rangeEncoder, bit);
m = (m << 1) | bit;
symbol >>= 1;
}
}
}
internal struct BitTreeDecoder
{
private readonly BitDecoder[] Models;
private readonly int NumBitLevels;
public BitTreeDecoder(int numBitLevels)
{
NumBitLevels = numBitLevels;
Models = new BitDecoder[1 << numBitLevels];
}
public void Init()
{
for (uint i = 1; i < (1 << NumBitLevels); i++)
Models[i].Init();
}
public uint Decode(Decoder rangeDecoder)
{
uint m = 1;
for (int bitIndex = NumBitLevels; bitIndex > 0; bitIndex--)
m = (m << 1) + Models[m].Decode(rangeDecoder);
return m - ((uint) 1 << NumBitLevels);
}
public uint ReverseDecode(Decoder rangeDecoder)
{
uint m = 1;
uint symbol = 0;
for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
{
uint bit = Models[m].Decode(rangeDecoder);
m <<= 1;
m += bit;
symbol |= (bit << bitIndex);
}
return symbol;
}
public static uint ReverseDecode(BitDecoder[] Models, UInt32 startIndex,
Decoder rangeDecoder, int NumBitLevels)
{
uint m = 1;
uint symbol = 0;
for (int bitIndex = 0; bitIndex < NumBitLevels; bitIndex++)
{
uint bit = Models[startIndex + m].Decode(rangeDecoder);
m <<= 1;
m += bit;
symbol |= (bit << bitIndex);
}
return symbol;
}
}
}

View File

@ -1,191 +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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
namespace SevenZip.Sdk
{
/// <summary>
/// The exception that is thrown when an error in input stream occurs during decoding.
/// </summary>
[Serializable]
internal class DataErrorException : ApplicationException
{
public DataErrorException() : base("Data Error") {}
}
/// <summary>
/// The exception that is thrown when the value of an argument is outside the allowable range.
/// </summary>
internal class InvalidParamException : ApplicationException
{
public InvalidParamException() : base("Invalid Parameter") {}
}
/// <summary>
/// Callback progress interface.
/// </summary>
public interface ICodeProgress
{
/// <summary>
/// Callback progress.
/// </summary>
/// <param name="inSize">
/// Processed input size. -1 if unknown.
/// </param>
/// <param name="outSize">
/// Processed output size. -1 if unknown.
/// </param>
void SetProgress(Int64 inSize, Int64 outSize);
} ;
/// <summary>
/// Stream coder interface
/// </summary>
public interface ICoder
{
/// <summary>
/// Codes streams.
/// </summary>
/// <param name="inStream">
/// input Stream.
/// </param>
/// <param name="outStream">
/// output Stream.
/// </param>
/// <param name="inSize">
/// input Size. -1 if unknown.
/// </param>
/// <param name="outSize">
/// output Size. -1 if unknown.
/// </param>
/// <param name="progress">
/// callback progress reference.
/// </param>
/// <exception cref="SevenZip.Sdk.DataErrorException">
/// if input stream is not valid
/// </exception>
void Code(Stream inStream, Stream outStream,
Int64 inSize, Int64 outSize, ICodeProgress progress);
} ;
/*
public interface ICoder2
{
void Code(ISequentialInStream []inStreams,
const UInt64 []inSizes,
ISequentialOutStream []outStreams,
UInt64 []outSizes,
ICodeProgress progress);
};
*/
/// <summary>
/// Provides the fields that represent properties idenitifiers for compressing.
/// </summary>
public enum CoderPropId
{
/// <summary>
/// Specifies default property.
/// </summary>
DefaultProp = 0,
/// <summary>
/// Specifies size of dictionary.
/// </summary>
DictionarySize,
/// <summary>
/// Specifies size of memory for PPM*.
/// </summary>
UsedMemorySize,
/// <summary>
/// Specifies order for PPM methods.
/// </summary>
Order,
/// <summary>
/// Specifies Block Size.
/// </summary>
BlockSize,
/// <summary>
/// Specifies number of postion state bits for LZMA (0 &lt;= x &lt;= 4).
/// </summary>
PosStateBits,
/// <summary>
/// Specifies number of literal context bits for LZMA (0 &lt;= x &lt;= 8).
/// </summary>
LitContextBits,
/// <summary>
/// Specifies number of literal position bits for LZMA (0 &lt;= x &lt;= 4).
/// </summary>
LitPosBits,
/// <summary>
/// Specifies number of fast bytes for LZ*.
/// </summary>
NumFastBytes,
/// <summary>
/// Specifies match finder. LZMA: "BT2", "BT4" or "BT4B".
/// </summary>
MatchFinder,
/// <summary>
/// Specifies the number of match finder cyckes.
/// </summary>
MatchFinderCycles,
/// <summary>
/// Specifies number of passes.
/// </summary>
NumPasses,
/// <summary>
/// Specifies number of algorithm.
/// </summary>
Algorithm,
/// <summary>
/// Specifies the number of threads.
/// </summary>
NumThreads,
/// <summary>
/// Specifies mode with end marker.
/// </summary>
EndMarker = 0x490
} ;
/// <summary>
/// The ISetCoderProperties interface
/// </summary>
internal interface ISetCoderProperties
{
void SetCoderProperties(CoderPropId[] propIDs, object[] properties);
} ;
/// <summary>
/// The IWriteCoderProperties interface
/// </summary>
internal interface IWriteCoderProperties
{
void WriteCoderProperties(Stream outStream);
}
/// <summary>
/// The ISetDecoderPropertiesinterface
/// </summary>
internal interface ISetDecoderProperties
{
/// <summary>
/// Sets decoder properties
/// </summary>
/// <param name="properties">Array of byte properties</param>
void SetDecoderProperties(byte[] properties);
}
}

View File

@ -1,307 +0,0 @@
using System.Runtime.InteropServices;
using System.Text;
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Security.Permissions;
namespace BizHawk
{
/// <summary>
/// Component wrapping access to the Browse For Folder common dialog box.
/// Call the ShowDialog() method to bring the dialog box up.
/// </summary>
public sealed class FolderBrowserEx : Component
{
private const int MAX_PATH = 260;
// Root node of the tree view.
private FolderID startLocation = FolderID.Desktop;
// Browse info options.
private int publicOptions = (int) Win32API.Shell32.BffStyles.RestrictToFilesystem |
(int) Win32API.Shell32.BffStyles.RestrictToDomain;
private const int privateOptions = (int) (Win32API.Shell32.BffStyles.NewDialogStyle | Win32API.Shell32.BffStyles.ShowTextBox);
// Description text to show.
public string Description = "Please select a folder below:";
/// <summary>
/// Enum of CSIDLs identifying standard shell folders.
/// </summary>
public enum FolderID
{
Desktop = 0x0000,
Printers = 0x0004,
MyDocuments = 0x0005,
Favorites = 0x0006,
Recent = 0x0008,
SendTo = 0x0009,
StartMenu = 0x000b,
MyComputer = 0x0011,
NetworkNeighborhood = 0x0012,
Templates = 0x0015,
MyPictures = 0x0027,
NetAndDialUpConnections = 0x0031,
}
/// <summary>
/// Helper function that returns the IMalloc interface used by the shell.
/// </summary>
private static Win32API.IMalloc GetSHMalloc()
{
Win32API.IMalloc malloc;
Win32API.Shell32.SHGetMalloc(out malloc);
return malloc;
}
/// <summary>
/// Shows the folder browser dialog box.
/// </summary>
public DialogResult ShowDialog()
{
return ShowDialog(null);
}
private int callback(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData)
{
switch (uMsg)
{
case 1:
{
IntPtr str = Marshal.StringToHGlobalUni(SelectedPath);
Win32.SendMessage(hwnd, (0x400 + 103), 1, str.ToInt32());
Marshal.FreeHGlobal(str);
break;
}
}
return 0;
}
/// <summary>
/// Shows the folder browser dialog box with the specified owner window.
/// </summary>
public DialogResult ShowDialog(IWin32Window owner)
{
IntPtr pidlRoot = IntPtr.Zero;
// Get/find an owner HWND for this dialog.
IntPtr hWndOwner;
if (owner != null)
{
hWndOwner = owner.Handle;
}
else
{
hWndOwner = Win32API.GetActiveWindow();
}
// Get the IDL for the specific startLocation.
Win32API.Shell32.SHGetSpecialFolderLocation(hWndOwner, (int) startLocation, out pidlRoot);
if (pidlRoot == IntPtr.Zero)
{
return DialogResult.Cancel;
}
int mergedOptions = (int) publicOptions | (int) privateOptions;
if ((mergedOptions & (int) Win32API.Shell32.BffStyles.NewDialogStyle) != 0)
{
if (System.Threading.ApartmentState.MTA == Application.OleRequired())
mergedOptions = mergedOptions & (~(int) Win32API.Shell32.BffStyles.NewDialogStyle);
}
IntPtr pidlRet = IntPtr.Zero;
try
{
// Construct a BROWSEINFO.
Win32API.Shell32.BROWSEINFO bi = new Win32API.Shell32.BROWSEINFO();
IntPtr buffer = Marshal.AllocHGlobal(MAX_PATH);
bi.pidlRoot = pidlRoot;
bi.hwndOwner = hWndOwner;
bi.pszDisplayName = buffer;
bi.lpszTitle = Description;
bi.ulFlags = mergedOptions;
bi.lpfn = new Win32API.Shell32.BFFCALLBACK(callback);
// The rest of the fields are initialized to zero by the constructor.
// bi.lParam = IntPtr.Zero; bi.iImage = 0;
// Show the dialog.
pidlRet = Win32API.Shell32.SHBrowseForFolder(ref bi);
// Free the buffer you've allocated on the global heap.
Marshal.FreeHGlobal(buffer);
if (pidlRet == IntPtr.Zero)
{
// User clicked Cancel.
return DialogResult.Cancel;
}
// Then retrieve the path from the IDList.
StringBuilder sb = new StringBuilder(MAX_PATH);
if (0 == Win32API.Shell32.SHGetPathFromIDList(pidlRet, sb))
{
return DialogResult.Cancel;
}
// Convert to a string.
}
finally
{
Win32API.IMalloc malloc = GetSHMalloc();
malloc.Free(pidlRoot);
if (pidlRet != IntPtr.Zero)
{
malloc.Free(pidlRet);
}
}
return DialogResult.OK;
}
/// <summary>
/// Helper function used to set and reset bits in the publicOptions bitfield.
/// </summary>
private void SetOptionField(int mask, bool turnOn)
{
if (turnOn)
publicOptions |= mask;
else
publicOptions &= ~mask;
}
/// <summary>
/// Only return file system directories. If the user selects folders
/// that are not part of the file system, the OK button is unavailable.
/// </summary>
[Category("Navigation")]
[Description("Only return file system directories. If the user selects folders " +
"that are not part of the file system, the OK button is unavailable.")]
[DefaultValue(true)]
public bool OnlyFilesystem
{
get { return (publicOptions & (int) Win32API.Shell32.BffStyles.RestrictToFilesystem) != 0; }
set { SetOptionField((int) Win32API.Shell32.BffStyles.RestrictToFilesystem, value); }
}
/// <summary>
/// Location of the root folder from which to start browsing. Only the specified
/// folder and any folders beneath it in the namespace hierarchy appear
/// in the dialog box.
/// </summary>
[Category("Navigation")]
[Description("Location of the root folder from which to start browsing. Only the specified " +
"folder and any folders beneath it in the namespace hierarchy appear " +
"in the dialog box.")]
[DefaultValue(typeof (FolderID), "0")]
public FolderID StartLocation
{
get { return startLocation; }
set
{
new UIPermission(UIPermissionWindow.AllWindows).Demand();
startLocation = value;
}
}
public string SelectedPath;
}
internal class Win32API
{
// C# representation of the IMalloc interface.
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown),
Guid("00000002-0000-0000-C000-000000000046")]
public interface IMalloc
{
[PreserveSig]
IntPtr Alloc([In] int cb);
[PreserveSig]
IntPtr Realloc([In] IntPtr pv, [In] int cb);
[PreserveSig]
void Free([In] IntPtr pv);
[PreserveSig]
int GetSize([In] IntPtr pv);
[PreserveSig]
int DidAlloc(IntPtr pv);
[PreserveSig]
void HeapMinimize();
}
[DllImport("User32.DLL")]
public static extern IntPtr GetActiveWindow();
public class Shell32
{
// Styles used in the BROWSEINFO.ulFlags field.
[Flags]
public enum BffStyles
{
RestrictToFilesystem = 0x0001, // BIF_RETURNONLYFSDIRS
RestrictToDomain = 0x0002, // BIF_DONTGOBELOWDOMAIN
RestrictToSubfolders = 0x0008, // BIF_RETURNFSANCESTORS
ShowTextBox = 0x0010, // BIF_EDITBOX
ValidateSelection = 0x0020, // BIF_VALIDATE
NewDialogStyle = 0x0040, // BIF_NEWDIALOGSTYLE
BrowseForComputer = 0x1000, // BIF_BROWSEFORCOMPUTER
BrowseForPrinter = 0x2000, // BIF_BROWSEFORPRINTER
BrowseForEverything = 0x4000, // BIF_BROWSEINCLUDEFILES
}
// Delegate type used in BROWSEINFO.lpfn field.
public delegate int BFFCALLBACK(IntPtr hwnd, uint uMsg, IntPtr lParam, IntPtr lpData);
[StructLayout(LayoutKind.Sequential, Pack = 8)]
public struct BROWSEINFO
{
public IntPtr hwndOwner;
public IntPtr pidlRoot;
public IntPtr pszDisplayName;
[MarshalAs(UnmanagedType.LPTStr)] public string lpszTitle;
public int ulFlags;
[MarshalAs(UnmanagedType.FunctionPtr)] public BFFCALLBACK lpfn;
public IntPtr lParam;
public int iImage;
}
[DllImport("Shell32.DLL")]
public static extern int SHGetMalloc(out IMalloc ppMalloc);
[DllImport("Shell32.DLL")]
public static extern int SHGetSpecialFolderLocation(
IntPtr hwndOwner, int nFolder, out IntPtr ppidl);
[DllImport("Shell32.DLL")]
public static extern int SHGetPathFromIDList(
IntPtr pidl, StringBuilder Path);
[DllImport("Shell32.DLL", CharSet = CharSet.Auto)]
public static extern IntPtr SHBrowseForFolder(ref BROWSEINFO bi);
}
}
}

View File

@ -1,243 +0,0 @@
using System;
using System.Globalization;
using System.Windows.Forms;
namespace BizHawk
{
public interface INumberBox
{
int ToRawInt();
void SetFromRawInt(int rawint);
bool Nullable { get; }
}
public class HexTextBox : TextBox, INumberBox
{
private string _addressFormatStr = "{0:X4}";
private int? _maxSize = null;
private bool _nullable = true;
public bool Nullable { get { return _nullable; } set { _nullable = value; } }
public void SetHexProperties(int domainSize)
{
_maxSize = domainSize - 1;
MaxLength = IntHelpers.GetNumDigits(_maxSize.Value);
_addressFormatStr = "{0:X" + MaxLength.ToString() + "}";
ResetText();
}
private uint GetMax()
{
if (_maxSize.HasValue)
{
return (uint)_maxSize.Value;
}
else
{
return IntHelpers.MaxHexValueFromMaxDigits(MaxLength);
}
}
public override void ResetText()
{
if (_nullable)
{
Text = String.Empty;
}
else
{
Text = String.Format(_addressFormatStr, 0);
}
}
public HexTextBox()
{
CharacterCasing = CharacterCasing.Upper;
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
{
return;
}
else if (!InputValidate.IsValidHexNumber(e.KeyChar))
{
e.Handled = true;
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
if (InputValidate.IsValidHexNumber(Text))
{
uint val = (uint)ToRawInt();
if (val == GetMax())
{
val = 0;
}
else
{
val++;
}
Text = String.Format(_addressFormatStr, val);
}
}
else if (e.KeyCode == Keys.Down)
{
if (InputValidate.IsValidHexNumber(Text))
{
uint val = (uint)ToRawInt();
if (val == 0)
{
val = GetMax();
}
else
{
val--;
}
Text = String.Format(_addressFormatStr, val);
}
}
else
{
base.OnKeyDown(e);
}
}
protected override void OnTextChanged(EventArgs e)
{
if (String.IsNullOrWhiteSpace(Text))
{
ResetText();
}
}
public int ToRawInt()
{
if (String.IsNullOrWhiteSpace(Text))
{
return 0;
}
else
{
return int.Parse(Text, NumberStyles.HexNumber);
}
}
public void SetFromRawInt(int val)
{
Text = String.Format(_addressFormatStr, val);
}
}
public class UnsignedIntegerBox : TextBox, INumberBox
{
public UnsignedIntegerBox()
{
CharacterCasing = CharacterCasing.Upper;
}
private bool _nullable = true;
public bool Nullable { get { return _nullable; } set { _nullable = value; } }
protected override void OnKeyPress(KeyPressEventArgs e)
{
if (e.KeyChar == '\b' || e.KeyChar == 22 || e.KeyChar == 1 || e.KeyChar == 3)
{
return;
}
else if (!InputValidate.IsValidUnsignedNumber(e.KeyChar))
{
e.Handled = true;
}
}
public override void ResetText()
{
if (_nullable)
{
Text = String.Empty;
}
else
{
Text = "0";
}
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Up)
{
if (InputValidate.IsValidUnsignedNumber(Text))
{
uint val = (uint)ToRawInt();
if (val == uint.MaxValue)
{
val = 0;
}
else
{
val++;
}
Text = val.ToString();
}
}
else if (e.KeyCode == Keys.Down)
{
if (InputValidate.IsValidUnsignedNumber(Text))
{
uint val = (uint)ToRawInt();
if (val == 0)
{
val = uint.MaxValue;
}
else
{
val--;
}
Text = val.ToString();
}
}
else
{
base.OnKeyDown(e);
}
}
protected override void OnTextChanged(EventArgs e)
{
if (String.IsNullOrWhiteSpace(Text))
{
ResetText();
}
}
public int ToRawInt()
{
if (String.IsNullOrWhiteSpace(Text))
{
return 0;
}
else
{
return (int)uint.Parse(Text);
}
}
public void SetFromRawInt(int val)
{
Text = val.ToString();
}
}
}

View File

@ -1,25 +0,0 @@
using System.Collections.Generic;
using System.Windows.Forms;
namespace BizHawk
{
public class InputConfigBase : Form
{
public void CheckDups()
{
Dictionary<string,bool> dups = new Dictionary<string,bool>();
foreach (Control c in Controls)
{
SmartTextBoxControl stbc = c as SmartTextBoxControl;
if (stbc == null) continue;
if (dups.ContainsKey(stbc.Text))
{
MessageBox.Show("DUP!");
return;
}
dups[stbc.Text] = true;
}
}
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,277 +0,0 @@
using System.Text;
namespace BizHawk
{
/// <summary>
/// Includes helper functions to validate user input
/// </summary>
public static class InputValidate
{
public static bool IsValidUnsignedNumber(string Str)
{
char[] input = (Str.ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] < 47 || bc[0] > 58)
return false;
}
return true;
}
public static bool IsValidUnsignedNumber(char c)
{
if (c < 47 || c > 58)
return false;
return true;
}
/// <summary>
/// Validates all chars are 0-9 or a dash as the first value
/// </summary>
/// <param name="Str"></param>
/// <returns></returns>
public static bool IsValidSignedNumber(string Str)
{
char[] input = (Str.Trim().ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] > 58)
return false;
if (bc[0] < 47)
{
if (bc[0] == 45 && x == 0)
continue;
else
return false;
}
}
return true;
}
public static bool IsValidSignedNumber(char c)
{
if (c == 45) return true;
if (c < 47 || c > 58)
return false;
return true;
}
/// <summary>
/// validates is a Hex number 0-9, A-F (must be capital letters)
/// </summary>
/// <returns></returns>
public static bool IsValidHexNumber(string Str)
{
char[] input = (Str.ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] < 47) //0
return false;
if (bc[0] > 58) //9
{
if (bc[0] < 65) //A
return false;
if (bc[0] > 70) //F
{
if (bc[0] < 97 || bc[0] > 102) //a-f
return false;
}
}
}
return true;
}
public static bool IsValidHexNumber(char c)
{
if (c < 47) return false; //0
if (c > 58) //9
{
if (c < 65) //A
return false;
if (c > 70) //F
{
if (c < 97 || c > 102) //a-f
return false;
}
}
return true;
}
/// <summary>
/// Takes any string and removes any value that is not a valid hex value (0-9, a-f, A-F), returns the remaining characters in uppercase
/// </summary>
/// <param name="raw"></param>
/// <returns></returns>
public static string DoHexString(string raw)
{
raw = raw.ToUpper();
StringBuilder output = new StringBuilder();
foreach (char x in raw)
{
if (x >= 'A' && x <= 'F')
{
output.Append(x);
}
else if (x >= '0' && x <= '9')
{
output.Append(x);
}
}
return output.ToString();
}
public static bool IsValidBinaryNumber(string s)
{
char[] input = (s.ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] != 48 && bc[0] != 49) //0 or 1
{
return false;
}
}
return true;
}
public static bool IsValidBinaryNumber(char c)
{
return (c == 48 || c == 49);
}
/// <summary>
/// Validates all chars are 0-9 or decimal
/// </summary>
/// <param name="Str"></param>
/// <returns></returns>
public static bool IsValidFixedPointNumber(string Str)
{
if (StringHelpers.HowMany(Str, '.') > 1)
{
return false;
}
char[] input = (Str.Trim().ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] > 58)
return false;
if (bc[0] == 46)
continue;
if (bc[0] < 48)
{
if (bc[0] == 45 && x == 0)
continue;
else
return false;
}
}
return true;
}
public static bool IsValidFixedPointNumber(char c)
{
if (c == 46 || c == 45) return true;
if (c < 48 || c > 58)
return false;
return true;
}
/// <summary>
/// Validates all chars are 0-9 or decimal or dash as the first character
/// </summary>
/// <param name="Str"></param>
/// <returns></returns>
public static bool IsValidDecimalNumber(string Str)
{
if (StringHelpers.HowMany(Str, '.') > 1)
{
return false;
}
char[] input = (Str.Trim().ToCharArray());
ASCIIEncoding AE = new ASCIIEncoding();
// Check each character in the new label to determine if it is a number.
for (int x = 0; x < input.Length; x++)
{
// Encode the character from the character array to its ASCII code.
byte[] bc = AE.GetBytes(input[x].ToString());
// Determine if the ASCII code is within the valid range of numerical values.
if (bc[0] > 58)
return false;
if (bc[0] == 46)
continue;
if (bc[0] < 48)
{
if (bc[0] == 45 && x == 0)
continue;
else
return false;
}
}
return true;
}
public static bool IsValidDecimalNumber(char c)
{
if (c == 45 || c == 46) //45 = dash, 46 = dot
{
return true;
}
else if (c < 48 || c > 58)
{
return false;
}
return true;
}
}
}

View File

@ -1,36 +0,0 @@
namespace BizHawk
{
public class TurboKey
{
public void Reset(int downTime, int upTime)
{
Value = false;
_timer = 0;
_upTime = upTime;
_downTime = downTime;
}
public void Tick(bool down)
{
if (!down)
{
Reset(_downTime, _upTime);
return;
}
_timer++;
Value = true;
if (_timer > _downTime)
Value = false;
if(_timer > (_upTime+_downTime))
{
_timer = 0;
Value = true;
}
}
public bool Value;
private int _upTime, _downTime, _timer;
}
}

View File

@ -1,72 +0,0 @@
using System.Drawing;
using System.Windows.Forms;
namespace BizHawk.Core
{
public class HorizontalLine : Control
{
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, 2, specified);
}
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder3D(e.Graphics, 0, 0, Width, 2, Border3DStyle.Etched);
}
}
public class CustomCheckBox : CheckBox
{
Color _CheckBackColor = SystemColors.Control;
public Color CheckBackColor
{
get { return _CheckBackColor; }
set { _CheckBackColor = value; Refresh(); }
}
bool? _ForceChecked;
public bool? ForceChecked
{
get { return _ForceChecked; }
set { _ForceChecked = value; Refresh(); }
}
protected override void OnPaint(PaintEventArgs pevent)
{
//draw text-label part of the control with something so that it isn't hallofmirrorsy
using(var brush = new SolidBrush(Parent.BackColor))
pevent.Graphics.FillRectangle(brush, ClientRectangle);
var r = new Rectangle(ClientRectangle.Location, SystemInformation.MenuCheckSize);
var glyphLoc = ClientRectangle;
glyphLoc.Size = SystemInformation.MenuCheckSize;
//draw the selectedbackdrop color roughly where the glyph belongs
using (var brush = new SolidBrush(_CheckBackColor))
pevent.Graphics.FillRectangle(brush, glyphLoc);
//draw a checkbox menu glyph (we could do this more elegantly with DrawFrameControl)
bool c = CheckState == CheckState.Checked;
if (ForceChecked.HasValue)
{
c = ForceChecked.Value;
}
if (c)
{
glyphLoc.Y--;
glyphLoc.X++;
ControlPaint.DrawMenuGlyph(pevent.Graphics, glyphLoc, MenuGlyph.Checkmark, Color.Black, Color.Transparent);
}
//draw a border on top of it all
ControlPaint.DrawBorder3D(pevent.Graphics, r, Border3DStyle.Sunken);
//stuff that didnt work
//CheckBoxRenderer.DrawParentBackground(pevent.Graphics, ClientRectangle, this);
//CheckBoxRenderer.DrawCheckBox(pevent.Graphics, ClientRectangle.Location, System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal);
//glyphLoc.Size = new System.Drawing.Size(SystemInformation.MenuCheckSize.Width-1,SystemInformation.MenuCheckSize.Height-1);
}
}
}

View File

@ -1,77 +0,0 @@
namespace BizHawk
{
partial class QuickProgressPopup
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.progressBar = new System.Windows.Forms.ProgressBar();
this.lblProgress = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// progressBar
//
this.progressBar.Location = new System.Drawing.Point(12, 12);
this.progressBar.Name = "progressBar";
this.progressBar.Size = new System.Drawing.Size(194, 23);
this.progressBar.TabIndex = 0;
//
// lblProgress
//
this.lblProgress.AutoSize = true;
this.lblProgress.Location = new System.Drawing.Point(12, 41);
this.lblProgress.Margin = new System.Windows.Forms.Padding(3);
this.lblProgress.Name = "lblProgress";
this.lblProgress.Size = new System.Drawing.Size(35, 13);
this.lblProgress.TabIndex = 1;
this.lblProgress.Text = "label1";
//
// QuickProgressPopup
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.AutoSize = true;
this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
this.ClientSize = new System.Drawing.Size(229, 63);
this.ControlBox = false;
this.Controls.Add(this.lblProgress);
this.Controls.Add(this.progressBar);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "QuickProgressPopup";
this.Text = "Please wait...";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ProgressBar progressBar;
private System.Windows.Forms.Label lblProgress;
}
}

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace BizHawk
{
public partial class QuickProgressPopup : Form
{
public QuickProgressPopup()
{
InitializeComponent();
}
}
}

View File

@ -1,120 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -1,34 +0,0 @@
using System;
using System.Windows.Forms;
namespace BizHawk
{
public class SmartTextBoxControl : TextBox
{
public SmartTextBoxControl()
{
ReadOnly = true;
}
protected override void OnKeyDown(KeyEventArgs e)
{
base.Text = e.KeyCode.ToString();
OnTextChanged(new EventArgs());
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
}
protected override void OnKeyUp(KeyEventArgs e)
{
}
public override string Text
{
get { return base.Text; }
set { }
}
}
}

View File

@ -1,73 +0,0 @@
using System;
using System.Linq;
namespace BizHawk
{
public static class StringHelpers
{
public static int HowMany(string str, char c)
{
if (!String.IsNullOrEmpty(str))
{
return str.Count(t => t == c);
}
else
{
return 0;
}
}
public static int HowMany(string str, string s)
{
int count = 0;
for (int x = 0; x < (str.Length - s.Length); x++)
{
if (str.Substring(x, s.Length) == s)
count++;
}
return count;
}
}
//TODO: put it in its own file
public static class IntHelpers //TODO: a less lame name
{
public static int GetNumDigits(Int32 i)
{
//if (i == 0) return 0;
//if (i < 0x10) return 1;
if (i < 0x100) return 2;
//if (i < 0x1000) return 3; //adelikat: let's only do even numbers
if (i < 0x10000) return 4;
if (i < 0x1000000) return 6;
else return 8;
}
public static uint MaxHexValueFromMaxDigits(Int32 i)
{
switch (i)
{
case 0:
return 0;
case 1:
return 0xF;
case 2:
return 0xFF;
case 3:
return 0xFFF;
case 4:
return 0xFFFF;
case 5:
return 0xFFFFF;
case 6:
return 0xFFFFFF;
case 7:
return 0xFFFFFFF;
case 8:
return 0xFFFFFFFF;
}
return int.MaxValue;
}
}
}

View File

@ -1,58 +0,0 @@
using System.Drawing;
using System.Windows.Forms;
namespace BizHawk
{
public class TextDebugView : Control
{
public TextDebugView()
{
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.Clear(SystemColors.Control);
Font font = new Font(new FontFamily("Courier New"), 8);
e.Graphics.DrawString(Text, font, Brushes.Black,0,0);
font.Dispose();
}
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
Invalidate();
}
}
}
public class TextDebugForm : Form
{
public TextDebugView view = new TextDebugView();
public TextDebugForm()
{
view.Dock = DockStyle.Fill;
Controls.Add(view);
}
public override string Text
{
get
{
return view.Text;
}
set
{
view.Text = value;
}
}
}
}

View File

@ -1,84 +0,0 @@
//credit: http://blogs.msdn.com/b/rickbrew/archive/2006/01/09/511003.aspx
using System;
using System.Windows.Forms;
/// <summary>
/// This class adds on to the functionality provided in System.Windows.Forms.ToolStrip.
/// </summary>
public class ToolStripEx : ToolStrip
{
private bool clickThrough = true;
/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does
/// not have input focus.
/// </summary>
public bool ClickThrough
{
get
{
return clickThrough;
}
set
{
clickThrough = value;
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (clickThrough &&
m.Msg == NativeConstants.WM_MOUSEACTIVATE &&
m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT)
{
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
}
/// <summary>
/// This class adds on to the functionality provided in System.Windows.Forms.MenuStrip.
/// </summary>
public class MenuStripEx : MenuStrip
{
private bool clickThrough = true;
/// <summary>
/// Gets or sets whether the ToolStripEx honors item clicks when its containing form does
/// not have input focus.
/// </summary>
public bool ClickThrough
{
get
{
return clickThrough;
}
set
{
clickThrough = value;
}
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (clickThrough &&
m.Msg == NativeConstants.WM_MOUSEACTIVATE &&
m.Result == (IntPtr)NativeConstants.MA_ACTIVATEANDEAT)
{
m.Result = (IntPtr)NativeConstants.MA_ACTIVATE;
}
}
}
internal sealed class NativeConstants
{
private NativeConstants(){}
internal const uint WM_MOUSEACTIVATE = 0x21;
internal const uint MA_ACTIVATE = 1;
internal const uint MA_ACTIVATEANDEAT = 2;
internal const uint MA_NOACTIVATE = 3;
internal const uint MA_NOACTIVATEANDEAT = 4;
}

View File

@ -1,139 +0,0 @@
using System;
using System.Text;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace BizHawk
{
public static class Extensions
{
//extension method to make Control.Invoke easier to use
public static void Invoke(this Control control, Action action)
{
control.Invoke((Delegate)action);
}
}
public static class ListViewExtensions
{
[StructLayout(LayoutKind.Sequential)]
public struct HDITEM
{
public Mask mask;
public int cxy;
[MarshalAs(UnmanagedType.LPTStr)]
public string pszText;
public IntPtr hbm;
public int cchTextMax;
public Format fmt;
public IntPtr lParam;
// _WIN32_IE >= 0x0300
public int iImage;
public int iOrder;
// _WIN32_IE >= 0x0500
public uint type;
public IntPtr pvFilter;
// _WIN32_WINNT >= 0x0600
public uint state;
[Flags]
public enum Mask
{
Format = 0x4, // HDI_FORMAT
};
[Flags]
public enum Format
{
SortDown = 0x200, // HDF_SORTDOWN
SortUp = 0x400, // HDF_SORTUP
};
};
public const int LVM_FIRST = 0x1000;
public const int LVM_GETHEADER = LVM_FIRST + 31;
public const int HDM_FIRST = 0x1200;
public const int HDM_GETITEM = HDM_FIRST + 11;
public const int HDM_SETITEM = HDM_FIRST + 12;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref HDITEM lParam);
public static string CopyItemsAsText(this ListView listViewControl)
{
ListView.SelectedIndexCollection indexes = listViewControl.SelectedIndices;
if (indexes.Count <= 0)
return "";
StringBuilder sb = new StringBuilder();
//walk over each selected item and subitem within it to generate a string from it
foreach (int index in indexes)
{
foreach (ListViewItem.ListViewSubItem item in listViewControl.Items[index].SubItems)
{
if (!String.IsNullOrWhiteSpace(item.Text))
sb.Append(item.Text).Append('\t');
}
//remove the last tab
sb.Remove(sb.Length - 1, 1);
sb.Append("\r\n");
}
//remove last newline
sb.Length -= 2;
return sb.ToString();
}
public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)
{
IntPtr columnHeader = SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++)
{
var columnPtr = new IntPtr(columnNumber);
var item = new HDITEM
{
mask = HDITEM.Mask.Format
};
if (SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
if (order != SortOrder.None && columnNumber == columnIndex)
{
switch (order)
{
case SortOrder.Ascending:
item.fmt &= ~HDITEM.Format.SortDown;
item.fmt |= HDITEM.Format.SortUp;
break;
case SortOrder.Descending:
item.fmt &= ~HDITEM.Format.SortUp;
item.fmt |= HDITEM.Format.SortDown;
break;
}
}
else
{
item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;
}
if (SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero)
{
throw new Win32Exception();
}
}
}
}
}

View File

@ -1,239 +0,0 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace BizHawk.Core
{
/// <summary>
/// A programmatic PictureBox, really, which will paint itself using the last bitmap that was provided
/// </summary>
public class RetainedViewportPanel : Control
{
Thread threadPaint;
EventWaitHandle ewh;
volatile bool killSignal;
public Func<Bitmap,bool> ReleaseCallback;
/// <summary>
/// Turns this panel into multi-threaded mode.
/// This will sort of glitch out other gdi things on the system, but at least its fast...
/// </summary>
public void ActivateThreaded()
{
ewh = new EventWaitHandle(false, EventResetMode.AutoReset);
threadPaint = new Thread(PaintProc);
threadPaint.IsBackground = true;
threadPaint.Start();
}
public RetainedViewportPanel(bool doubleBuffer = false)
{
CreateHandle();
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, doubleBuffer);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.UserMouse, true);
SetBitmap(new Bitmap(2, 2));
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (threadPaint != null)
{
killSignal = true;
ewh.Set();
ewh.WaitOne();
}
CleanupDisposeQueue();
}
public bool ScaleImage = true;
void DoPaint()
{
if (bmp != null)
{
using (Graphics g = CreateGraphics())
{
g.PixelOffsetMode = PixelOffsetMode.HighSpeed;
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.CompositingMode = CompositingMode.SourceCopy;
g.CompositingQuality = CompositingQuality.HighSpeed;
if (ScaleImage)
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.Half;
g.DrawImage(bmp, 0, 0, Width, Height);
}
else
{
using (var sb = new SolidBrush(Color.Black))
{
g.FillRectangle(sb, bmp.Width, 0, Width - bmp.Width, Height);
g.FillRectangle(sb, 0, bmp.Height, bmp.Width, Height - bmp.Height);
}
g.DrawImageUnscaled(bmp, 0, 0);
}
}
}
CleanupDisposeQueue();
}
void PaintProc()
{
for (; ; )
{
ewh.WaitOne();
if (killSignal)
{
ewh.Set();
return;
}
DoPaint();
}
}
void CleanupDisposeQueue()
{
lock (this)
{
while (DisposeQueue.Count > 0)
{
var bmp = DisposeQueue.Dequeue();
bool dispose = true;
if(ReleaseCallback != null)
dispose = ReleaseCallback(bmp);
if(dispose) bmp.Dispose();
}
}
}
Queue<Bitmap> DisposeQueue = new Queue<Bitmap>();
void SignalPaint()
{
if (threadPaint == null)
DoPaint();
else
ewh.Set();
}
//Size logicalSize;
////int pitch;
//public void SetLogicalSize(int w, int h)
//{
// if (bmp != null) bmp.Dispose();
// bmp = new Bitmap(w, h, PixelFormat.Format32bppArgb);
// logicalSize = new Size(w, h);
//}
/// <summary>
/// Takes ownership of the provided bitmap and will use it for future painting
/// </summary>
public void SetBitmap(Bitmap newbmp)
{
lock (this)
{
if(bmp != null) DisposeQueue.Enqueue(bmp);
bmp = newbmp;
}
SignalPaint();
}
Bitmap bmp;
/// <summary>bit of a hack; use at your own risk</summary>
/// <returns>you probably shouldn't modify this?</returns>
public Bitmap GetBitmap()
{
return bmp;
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
}
protected override void OnPaint(PaintEventArgs e)
{
SignalPaint();
base.OnPaint(e);
}
}
/// <summary>
/// A dumb panel which functions as a placeholder for framebuffer painting
/// </summary>
public class ViewportPanel : Control
{
public ViewportPanel()
{
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.DoubleBuffer, true);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.UserMouse, true);
}
}
/// <summary>
/// A ViewportPanel with a vertical scroll bar
/// </summary>
public class ScrollableViewportPanel : UserControl
{
TableLayoutPanel table;
ViewportPanel view;
VScrollBar scroll;
public ViewportPanel View { get { return view; } }
public VScrollBar Scrollbar { get { return scroll; } }
public int ScrollMax { get { return Scrollbar.Maximum; } set { Scrollbar.Maximum = value; } }
public int ScrollLargeChange { get { return Scrollbar.LargeChange; } set { Scrollbar.LargeChange = value; } }
public ScrollableViewportPanel()
{
InitializeComponent();
}
public void InitializeComponent()
{
table = new TableLayoutPanel();
view = new ViewportPanel();
scroll = new VScrollBar();
scroll.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom;
view.Dock = DockStyle.Fill;
table.Dock = DockStyle.Fill;
table.RowStyles.Add(new RowStyle(SizeType.Percent, 100));
table.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100));
table.ColumnStyles.Add(new ColumnStyle(SizeType.AutoSize, 0));
table.RowCount = 1;
table.ColumnCount = 2;
table.Controls.Add(view);
table.Controls.Add(scroll);
table.SetColumn(view, 0);
table.SetColumn(scroll, 1);
scroll.Scroll += (sender, e) => OnScroll(e);
view.Paint += (sender, e) => OnPaint(e);
Controls.Add(table);
}
}
}

View File

@ -1,695 +0,0 @@
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Drawing;
namespace BizHawk
{
#region win32interop
[StructLayout(LayoutKind.Sequential)]
internal struct LVDISPINFO {
public NMHDR hdr;
public LVITEM item;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NMHDR {
public int hwndFrom;
public int idFrom;
public int code;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NMITEMACTIVATE {
NMHDR hdr;
int iItem;
int iSubItem;
uint uNewState;
uint uOldState;
uint uChanged;
POINT ptAction;
uint lParam;
uint uKeyFlags;
}
[StructLayout(LayoutKind.Sequential)]
internal struct RECT {
public int left, top, right, bottom;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NMCUSTOMDRAWINFO {
public NMHDR hdr;
public uint dwDrawStage;
public IntPtr hdc;
public RECT rc;
public int dwItemSpec;
public uint uItemState;
public int lItemlParam;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NMLVCUSTOMDRAW {
public NMCUSTOMDRAWINFO nmcd;
public int clrText;
public int clrTextBk;
public int iSubItem;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
internal struct LVITEM {
public uint mask;
public int iItem;
public int iSubItem;
public uint state;
public uint stateMask;
public IntPtr pszText;
public int cchTextMax;
public int iImage;
public IntPtr lParam;
//#if (_WIN32_IE >= 0x0300)
public int iIndent;
//#endif
//#if (_WIN32_WINNT >= 0x501)
//public int iGroupId;
//public uint cColumns;
//public IntPtr puColumns;
//#endif
}
[FlagsAttribute]
enum CUSTOMDRAWRETURNFLAGS {
CDRF_DODEFAULT = 0x00000000,
CDRF_NEWFONT = 0x00000002,
CDRF_SKIPDEFAULT = 0x00000004,
CDRF_NOTIFYPOSTPAINT = 0x00000010,
CDRF_NOTIFYITEMDRAW = 0x00000020,
//#if (_WIN32_IE >= 0x0400)
CDRF_NOTIFYSUBITEMDRAW = 0x00000020,//[sic]
//#endif
CDRF_NOTIFYPOSTERASE = 0x00000040,
}
[FlagsAttribute]
enum CUSTOMDRAWDRAWSTAGEFLAGS {
CDDS_PREPAINT = 0x00000001,
CDDS_POSTPAINT = 0x00000002,
CDDS_PREERASE = 0x00000003,
CDDS_POSTERASE = 0x00000004,
// the 0x000010000 bit means it's individual item specific
CDDS_ITEM = 0x00010000,
CDDS_ITEMPREPAINT = (CDDS_ITEM | CDDS_PREPAINT),
CDDS_ITEMPOSTPAINT = (CDDS_ITEM | CDDS_POSTPAINT),
CDDS_ITEMPREERASE = (CDDS_ITEM | CDDS_PREERASE),
CDDS_ITEMPOSTERASE = (CDDS_ITEM | CDDS_POSTERASE),
//#if (_WIN32_IE >= 0x0400)
CDDS_SUBITEM = 0x00020000,
CDDS_SUBITEMPREPAINT = (CDDS_SUBITEM | CDDS_ITEMPREPAINT),
CDDS_SUBITEMPOSTPAINT = (CDDS_SUBITEM | CDDS_ITEMPOSTPAINT),
CDDS_SUBITEMPREERASE = (CDDS_SUBITEM | CDDS_ITEMPREERASE),
CDDS_SUBITEMPOSTERASE = (CDDS_SUBITEM | CDDS_ITEMPOSTERASE),
//#endif
}
[FlagsAttribute]
enum LVHITTESTFLAGS {
LVHT_NOWHERE = 0x0001,
LVHT_ONITEMICON = 0x0002,
LVHT_ONITEMLABEL = 0x0004,
LVHT_ONITEMSTATEICON = 0x0008,
LVHT_ONITEM = (LVHT_ONITEMICON | LVHT_ONITEMLABEL | LVHT_ONITEMSTATEICON),
LVHT_ABOVE = 0x0008,
LVHT_BELOW = 0x0010,
LVHT_TORIGHT = 0x0020,
LVHT_TOLEFT = 0x0040
}
[StructLayout(LayoutKind.Sequential)]
internal struct POINT {
public int x;
public int y;
}
[StructLayout(LayoutKind.Sequential)]
internal class LVHITTESTINFO {
public POINT pt;
public uint flags;
public int iItem;
public int iSubItem;
}
[StructLayout(LayoutKind.Sequential)]
internal struct NMLISTVIEW {
public NMHDR hdr;
public int iItem;
public int iSubItem;
public uint uNewState;
public uint uOldState;
public uint uChanged;
public POINT ptAction;
public IntPtr lParam;
}
internal enum ListViewItemMask : short {
LVIF_TEXT = 0x0001,
LVIF_IMAGE = 0x0002,
LVIF_PARAM = 0x0004,
LVIF_STATE = 0x0008,
LVIF_INDENT = 0x0010,
LVIF_NORECOMPUTE = 0x0800,
LVIF_GROUPID = 0x0100,
LVIF_COLUMNS = 0x0200
}
internal enum LVNI {
ALL = 0x0000,
FOCUSED = 0x0001,
SELECTED = 0x0002,
CUT = 0x0004,
DROPHILITED = 0x0008,
ABOVE = 0x0100,
BELOW = 0x0200,
TOLEFT = 0x0400,
TORIGHT = 0x0800
}
internal enum ListViewMessages {
LVM_FIRST = 0x1000,
LVM_GETITEMCOUNT = (LVM_FIRST + 4),
LVM_SETCALLBACKMASK = (LVM_FIRST + 11),
LVM_GETNEXTITEM = (LVM_FIRST + 12),
LVM_HITTEST = (LVM_FIRST + 18),
LVM_ENSUREVISIBLE = (LVM_FIRST + 19),
LVM_SETITEMSTATE = (LVM_FIRST + 43),
LVM_GETITEMSTATE = (LVM_FIRST + 44),
LVM_SETITEMCOUNT = (LVM_FIRST + 47),
LVM_GETSUBITEMRECT = (LVM_FIRST + 56)
}
internal enum ListViewStyles : short {
LVS_OWNERDATA = 0x1000,
LVS_SORTASCENDING = 0x0010,
LVS_SORTDESCENDING = 0x0020,
LVS_SHAREIMAGELISTS = 0x0040,
LVS_NOLABELWRAP = 0x0080,
LVS_AUTOARRANGE = 0x0100
}
internal enum ListViewStylesICF : uint {
LVSICF_NOINVALIDATEALL = 0x00000001,
LVSICF_NOSCROLL = 0x00000002
}
internal enum WindowsMessage : uint {
WM_ERASEBKGND = 0x0014,
WM_SCROLL = 0x115,
WM_LBUTTONDOWN = 0x0201,
WM_LBUTTONUP = 0x0202,
WM_LBUTTONDBLCLK = 0x0203,
WM_RBUTTONDOWN = 0x0204,
WM_RBUTTONUP = 0x0205,
WM_RBUTTONDBLCLK = 0x0206,
WM_SETFOCUS = 0x0007,
WM_NOTIFY = 0x004E,
WM_USER = 0x0400,
WM_REFLECT = WM_USER + 0x1c00
}
internal enum Notices : int {
NM_FIRST = 0,
NM_CUSTOMDRAW = NM_FIRST - 12,
NM_CLICK = NM_FIRST - 2,
NM_DBLCLICK = NM_FIRST - 3,
}
internal enum ListViewNotices : int {
LVN_FIRST = (0 - 100),
LVN_LAST = (0 - 199),
LVN_BEGINDRAG = (int)LVN_FIRST - 9,
LVN_BEGINRDRAG = (int)LVN_FIRST - 11,
LVN_GETDISPINFOA = (int)LVN_FIRST - 50,
LVN_GETDISPINFOW = (int)LVN_FIRST - 77,
LVN_SETDISPINFOA = (int)LVN_FIRST - 51,
LVN_SETDISPINFOW = (int)LVN_FIRST - 78,
LVN_ODCACHEHINT = (int)LVN_FIRST - 13,
LVN_ODFINDITEMW = (int)LVN_FIRST - 79
}
[Flags]
internal enum ListViewCallBackMask : uint {
LVIS_FOCUSED = 0x0001,
LVIS_SELECTED = 0x0002,
LVIS_CUT = 0x0004,
LVIS_DROPHILITED = 0x0008,
LVIS_GLOW = 0x0010,
LVIS_ACTIVATING = 0x0020,
LVIS_OVERLAYMASK = 0x0F00,
LVIS_STATEIMAGEMASK = 0xF000,
}
#endregion
#region VirtualListView Delegates
/// <summary>
/// Retrieve the background color for a Listview cell (item and subitem).
/// </summary>
/// <param name="item">Listview item (row).</param>
/// <param name="subItem">Listview subitem (column).</param>
/// <param name="color">Background color to use</param>
public delegate void QueryItemBkColorHandler(int item, int subItem, ref Color color);
/// <summary>
/// Retrieve the text for a Listview cell (item and subitem).
/// </summary>
/// <param name="item">Listview item (row).</param>
/// <param name="subItem">Listview subitem (column).</param>
/// <param name="text">Text to display.</param>
public delegate void QueryItemTextHandler(int item, int subItem, out string text);
/// <summary>
/// Retrieve the image index for a Listview item.
/// </summary>
/// <param name="item">Listview item (row).</param>
/// <param name="subItem">Listview subitem (column) - should always be zero.</param>
/// <param name="imageIndex">Index of associated ImageList.</param>
public delegate void QueryItemImageHandler(int item, int subItem, out int imageIndex);
/// <summary>
/// Retrieve the indent for a Listview item. The indent is always width of an image.
/// For example, 1 indents the Listview item one image width.
/// </summary>
/// <param name="item">Listview item (row).</param>
/// <param name="itemIndent">The amount to indent the Listview item.</param>
public delegate void QueryItemIndentHandler(int item, out int itemIndent);
public delegate void QueryItemHandler(int idx, out ListViewItem item);
#endregion
/// <summary>
/// VirtualListView is a virtual Listview which allows for a large number of items(rows)
/// to be displayed. The virtual Listview contains very little actual information -
/// mainly item selection and focus information.
/// </summary>
public class VirtualListView : ListView {
// store the item count to prevent the call to SendMessage(LVM_GETITEMCOUNT)
private int itemCount = 0;
#region Display query callbacks
/// <summary>
/// Fire the QueryItemBkColor event which requests the background color for the passed Listview cell
/// </summary>
public event QueryItemBkColorHandler QueryItemBkColor;
/// <summary>
/// Fire the QueryItemText event which requests the text for the passed Listview cell.
/// </summary>
[Category("Data")]
public event QueryItemTextHandler QueryItemText;
/// <summary>
/// Fire the QueryItemImage event which requests the ImageIndex for the passed Listview item.
/// </summary>
[Category("Data")]
public event QueryItemImageHandler QueryItemImage;
/// <summary>
/// Fire the QueryItemIndent event which requests the indent for the passed Listview item.
/// </summary>
[Category("Data")]
public event QueryItemIndentHandler QueryItemIndent;
[Category("Data")]
public event QueryItemHandler QueryItem;
#endregion
#region Properties
/// <summary>
/// Gets/sets the sets the virtual number of items to be displayed.
/// </summary>
[Category("Behavior")]
public int ItemCount {
get {
return itemCount;
}
set {
itemCount = value;
// if the virtual item count is set before the handle is created
// then the image lists don't get loaded properly
if(!this.IsHandleCreated)
return;
SetVirtualItemCount();
}
}
/// <summary>
/// Gets/sets how list items are to be displayed.
///
/// Hide the ListView.View property.
/// Virtual Listviews only allow Details or List.
/// </summary>
public new System.Windows.Forms.View View {
get {
return base.View;
}
set {
if(value == View.LargeIcon ||
value == View.SmallIcon) {
throw new ArgumentException("Icon views are invalid for virtual ListViews", "View");
}
base.View = value;
}
}
/// <summary>
/// Gets the required creation parameters when the control handle is created.
///
/// Use LVS_OWNERDATA to set this as a virtual Listview.
/// </summary>
protected override System.Windows.Forms.CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
// LVS_OWNERDATA style must be set when the control is created
cp.Style |= (int)ListViewStyles.LVS_OWNERDATA;
return cp;
}
}
#endregion
#region Constructors
/// <summary>
/// Create a new instance of this control.
/// </summary>
public VirtualListView() {
// virtual listviews must be Details or List view with no sorting
View = View.Details;
Sorting = SortOrder.None;
ptrlvhti = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(LVHITTESTINFO)));
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
SetStyle(ControlStyles.Opaque, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
~VirtualListView() {
Marshal.FreeHGlobal(ptrlvhti);
}
#endregion
#region Methods
/// <summary>
/// Set the state of the passed Listview item's index.
/// </summary>
/// <param name="index">Listview item's index.</param>
/// <param name="selected">Select the passed item?</param>
public void SelectItem(int index, bool selected) {
IntPtr ptrItem = IntPtr.Zero;
try {
// Determine whether selecting or unselecting.
uint select = selected ? (uint)ListViewCallBackMask.LVIS_SELECTED : 0;
// Fill in the LVITEM structure with state fields.
LVITEM stateItem = new LVITEM();
stateItem.mask = (uint)ListViewItemMask.LVIF_STATE;
stateItem.iItem = index;
stateItem.iSubItem = 0;
stateItem.state = select;
stateItem.stateMask = (uint)ListViewCallBackMask.LVIS_SELECTED;
// Copy the structure to unmanaged memory.
ptrItem = Marshal.AllocHGlobal(Marshal.SizeOf(stateItem.GetType()));
Marshal.StructureToPtr(stateItem, ptrItem, true);
// Send the message to the control window.
int result = Win32.SendMessage(
this.Handle,
(int)ListViewMessages.LVM_SETITEMSTATE,
index,
ptrItem.ToInt32());
} catch(Exception ex) {
System.Diagnostics.Trace.WriteLine("VirtualListView.SetItemState error=" + ex.Message);
// TODO: should this eat any exceptions?
throw ex;
} finally {
// Always release the unmanaged memory.
if(ptrItem != IntPtr.Zero) {
Marshal.FreeHGlobal(ptrItem);
}
}
}
private void SetVirtualItemCount() {
int result;
result = Win32.SendMessage(
this.Handle,
(int)ListViewMessages.LVM_SETITEMCOUNT,
itemCount,
0);
}
protected void OnDispInfoNotice(ref Message m, bool useAnsi) {
LVDISPINFO info = (LVDISPINFO)m.GetLParam(typeof(LVDISPINFO));
string lvtext = null;
if((info.item.mask & (uint)ListViewItemMask.LVIF_TEXT) > 0) {
if(QueryItemText != null) {
QueryItemText(info.item.iItem, info.item.iSubItem, out lvtext);
if(lvtext != null) {
try {
int maxIndex = Math.Min(info.item.cchTextMax - 1, lvtext.Length);
char[] data = new char[maxIndex + 1];
lvtext.CopyTo(0, data, 0, lvtext.Length);
data[maxIndex] = '\0';
System.Runtime.InteropServices.Marshal.Copy(data, 0, info.item.pszText, data.Length);
} catch(Exception e) {
Debug.WriteLine("Failed to copy text name from client: " + e.ToString(), "VirtualListView.OnDispInfoNotice");
}
}
}
}
if((info.item.mask & (uint)ListViewItemMask.LVIF_IMAGE) > 0) {
int imageIndex = 0;
if(QueryItemImage != null) {
QueryItemImage(info.item.iItem, info.item.iSubItem, out imageIndex);
}
info.item.iImage = imageIndex;
System.Runtime.InteropServices.Marshal.StructureToPtr(info, m.LParam, false);
}
if((info.item.mask & (uint)ListViewItemMask.LVIF_INDENT) > 0) {
int itemIndent = 0;
if(QueryItemIndent != null) {
QueryItemIndent(info.item.iItem, out itemIndent);
}
info.item.iIndent = itemIndent;
System.Runtime.InteropServices.Marshal.StructureToPtr(info, m.LParam, false);
}
m.Result = new IntPtr(0);
}
protected void OnCustomDrawNotice(ref System.Windows.Forms.Message m) {
NMLVCUSTOMDRAW cd = (NMLVCUSTOMDRAW)m.GetLParam(typeof(NMLVCUSTOMDRAW));
switch(cd.nmcd.dwDrawStage) {
case (int)CUSTOMDRAWDRAWSTAGEFLAGS.CDDS_ITEMPREPAINT:
case (int)CUSTOMDRAWDRAWSTAGEFLAGS.CDDS_PREPAINT:
m.Result = new IntPtr((int)CUSTOMDRAWRETURNFLAGS.CDRF_NOTIFYSUBITEMDRAW);
break;
case (int)CUSTOMDRAWDRAWSTAGEFLAGS.CDDS_SUBITEMPREPAINT:
Color color;
if(QueryItemBkColor != null) {
color = Color.FromArgb(cd.clrTextBk & 0xFF, (cd.clrTextBk >> 8) & 0xFF, (cd.clrTextBk >> 16) & 0xFF);
QueryItemBkColor(cd.nmcd.dwItemSpec, cd.iSubItem, ref color);
cd.clrTextBk = (color.B << 16) | (color.G << 8) | (color.R);
System.Runtime.InteropServices.Marshal.StructureToPtr(cd, m.LParam, false);
}
m.Result = new IntPtr((int)CUSTOMDRAWRETURNFLAGS.CDRF_DODEFAULT);
break;
}
}
/// <summary>
/// Event to be fired whenever the control scrolls
/// </summary>
public event ScrollEventHandler Scroll;
protected virtual void OnScroll(ScrollEventArgs e)
{
ScrollEventHandler handler = this.Scroll;
if (handler != null) handler(this, e);
}
protected override void WndProc(ref System.Windows.Forms.Message m) {
NMHDR nm1;
bool messageProcessed = false;
switch(m.Msg) {
case (int)WindowsMessage.WM_REFLECT + (int)WindowsMessage.WM_NOTIFY:
nm1 = (NMHDR)m.GetLParam(typeof(NMHDR));
switch(nm1.code) {
case (int)Notices.NM_CUSTOMDRAW:
OnCustomDrawNotice(ref m);
messageProcessed = true;
break;
case (int)ListViewNotices.LVN_GETDISPINFOW:
OnDispInfoNotice(ref m, false);
messageProcessed = true;
break;
case (int)ListViewNotices.LVN_BEGINDRAG:
OnBeginItemDrag(MouseButtons.Left, ref m);
messageProcessed = true;
break;
case (int)ListViewNotices.LVN_BEGINRDRAG:
OnBeginItemDrag(MouseButtons.Right, ref m);
messageProcessed = true;
break;
//case (int)Notices.NM_CLICK:
//case (int)Notices.NM_DBLCLICK:
// {
// NMITEMACTIVATE test = (NMITEMACTIVATE)m.GetLParam(typeof(NMITEMACTIVATE));
// messageProcessed = true;
// break;
// }
default:
break;
}
break;
case (int)WindowsMessage.WM_SCROLL:
//http://stackoverflow.com/questions/1851620/handling-scroll-event-on-listview-in-c-sharp
OnScroll(new ScrollEventArgs((ScrollEventType)(m.WParam.ToInt32() & 0xffff), 0));
break;
//obscure message loop flakiness when exceptions are thrown from the message loop...
//THIS BREAKS PROPER LISTVIEW FOCUS SELECTION (blue)
//next time we run into this, debug it better.
//case (int)WindowsMessage.WM_SETFOCUS:
// if (SelectedIndices.Count > 0 && SelectedIndices[0] >= VirtualListSize)
// messageProcessed = true;
// break;
//TRY THIS HACK INSTEAD TO FIX THE EXCEPTION
// (( NOPE, THEY ALL BREAK ONE THING OR ANOTHER. WINFORMS LISTVIEW JUST THROWS EXCEPTIONS, WHAT CAN WE DO? ))
//case 0x100C:
// {
// base.WndProc(ref m);
// int num = m.Result.ToInt32();
// messageProcessed = true;
// m.Result = new IntPtr(-1);
// break;
// }
//case 0x1012:
// {
// base.WndProc(ref m);
// int num = m.Result.ToInt32();
// messageProcessed = true;
// m.Result = new IntPtr(-1);
// break;
// }
case (int)WindowsMessage.WM_ERASEBKGND:
if (BlazingFast)
{
messageProcessed = true;
m.Result = new IntPtr(1);
}
break;
default:
break;
}
if(!messageProcessed) {
try {
base.WndProc(ref m);
} catch(Exception ex) {
Trace.WriteLine(string.Format("Message {0} caused an exception: {1}", m, ex.Message));
}
}
}
public bool BlazingFast = false;
protected ListViewItem GetItem(int idx) {
ListViewItem item = null;
if(QueryItem != null) {
QueryItem(idx, out item);
}
if(item == null) {
throw new ArgumentException("cannot find item " + idx.ToString() + " via QueryItem event");
}
return item;
}
protected void OnBeginItemDrag(MouseButtons mouseButton, ref System.Windows.Forms.Message m) {
NMLISTVIEW info = (NMLISTVIEW)m.GetLParam(typeof(NMLISTVIEW));
ListViewItem item = null;
if(QueryItem != null) {
QueryItem(info.iItem, out item);
}
OnItemDrag(new ItemDragEventArgs(mouseButton, item));
}
protected override void OnHandleCreated(System.EventArgs e) {
base.OnHandleCreated(e);
// ensure the value for ItemCount is sent to the control properly if the user set it
// before the handle was created
SetVirtualItemCount();
}
protected override void OnHandleDestroyed(System.EventArgs e) {
// the ListView OnHandleDestroyed accesses the Items list for all selected items
ItemCount = 0;
base.OnHandleDestroyed(e);
}
#endregion
LVHITTESTINFO lvhti = new LVHITTESTINFO();
IntPtr ptrlvhti;
int selection = -1;
public int hitTest(int x, int y) {
lvhti.pt.x = x;
lvhti.pt.y = y;
Marshal.StructureToPtr(lvhti, ptrlvhti, true);
int z = Win32.SendMessage(this.Handle, (int)ListViewMessages.LVM_HITTEST, 0, ptrlvhti.ToInt32());
Marshal.PtrToStructure(ptrlvhti, lvhti);
return z;
}
public void ensureVisible(int index) {
Win32.SendMessage(Handle, (int)ListViewMessages.LVM_ENSUREVISIBLE, index, 1);
}
public void ensureVisible() {
ensureVisible(selectedItem);
}
public void setSelection(int index) {
clearSelection();
selection = index;
SelectItem(selection, true);
}
public int selectedItem { get { if(SelectedIndices.Count == 0) return -1; else return SelectedIndices[0]; } set { setSelection(value); } }
public void clearSelection() {
if(selection != -1)
SelectItem(selection, false);
selection = -1;
}
}
}

View File

@ -1,574 +0,0 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Drawing;
using System.Runtime.InteropServices;
using Microsoft.Win32.SafeHandles;
namespace BizHawk
{
public static class Win32
{
public static bool Is64BitProcess { get { return (IntPtr.Size == 8); } }
public static bool Is64BitOperatingSystem { get { return Is64BitProcess || InternalCheckIsWow64(); } }
[DllImport("kernel32.dll", SetLastError = true, CallingConvention = CallingConvention.Winapi)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWow64Process(
[In] IntPtr hProcess,
[Out] out bool wow64Process
);
static bool InternalCheckIsWow64()
{
if ((Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor >= 1) ||
Environment.OSVersion.Version.Major >= 6)
{
using (var p = System.Diagnostics.Process.GetCurrentProcess())
{
bool retVal;
if (!IsWow64Process(p.Handle, out retVal))
{
return false;
}
return retVal;
}
}
else
{
return false;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct RECT
{
private int _Left;
private int _Top;
private int _Right;
private int _Bottom;
public RECT(RECT Rectangle)
: this(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom)
{
}
public RECT(int Left, int Top, int Right, int Bottom)
{
_Left = Left;
_Top = Top;
_Right = Right;
_Bottom = Bottom;
}
public int X
{
get { return _Left; }
set { _Left = value; }
}
public int Y
{
get { return _Top; }
set { _Top = value; }
}
public int Left
{
get { return _Left; }
set { _Left = value; }
}
public int Top
{
get { return _Top; }
set { _Top = value; }
}
public int Right
{
get { return _Right; }
set { _Right = value; }
}
public int Bottom
{
get { return _Bottom; }
set { _Bottom = value; }
}
public int Height
{
get { return _Bottom - _Top; }
set { _Bottom = value - _Top; }
}
public int Width
{
get { return _Right - _Left; }
set { _Right = value + _Left; }
}
public Point Location
{
get { return new Point(Left, Top); }
set
{
_Left = value.X;
_Top = value.Y;
}
}
public Size Size
{
get { return new Size(Width, Height); }
set
{
_Right = value.Width + _Left;
_Bottom = value.Height + _Top;
}
}
public static implicit operator Rectangle(RECT Rectangle)
{
return new Rectangle(Rectangle.Left, Rectangle.Top, Rectangle.Width, Rectangle.Height);
}
public static implicit operator RECT(Rectangle Rectangle)
{
return new RECT(Rectangle.Left, Rectangle.Top, Rectangle.Right, Rectangle.Bottom);
}
public static bool operator ==(RECT Rectangle1, RECT Rectangle2)
{
return Rectangle1.Equals(Rectangle2);
}
public static bool operator !=(RECT Rectangle1, RECT Rectangle2)
{
return !Rectangle1.Equals(Rectangle2);
}
public override string ToString()
{
return "{Left: " + _Left + "; " + "Top: " + _Top + "; Right: " + _Right + "; Bottom: " + _Bottom + "}";
}
public override int GetHashCode()
{
return ToString().GetHashCode();
}
public bool Equals(RECT Rectangle)
{
return Rectangle.Left == _Left && Rectangle.Top == _Top && Rectangle.Right == _Right && Rectangle.Bottom == _Bottom;
}
public override bool Equals(object Object)
{
if (Object is RECT)
{
return Equals((RECT)Object);
}
else if (Object is Rectangle)
{
return Equals(new RECT((Rectangle)Object));
}
return false;
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct AVISTREAMINFOW
{
public Int32 fccType;
public Int32 fccHandler;
public Int32 dwFlags;
public Int32 dwCaps;
public Int16 wPriority;
public Int16 wLanguage;
public Int32 dwScale;
public Int32 dwRate;
public Int32 dwStart;
public Int32 dwLength;
public Int32 dwInitialFrames;
public Int32 dwSuggestedBufferSize;
public Int32 dwQuality;
public Int32 dwSampleSize;
public RECT rcFrame;
public Int32 dwEditCount;
public Int32 dwFormatChangeCount;
[MarshalAs(UnmanagedType.LPWStr, SizeConst=64)]
public string szName;
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct BITMAPINFOHEADER
{
public uint biSize;
public int biWidth;
public int biHeight;
public ushort biPlanes;
public ushort biBitCount;
public uint biCompression;
public uint biSizeImage;
public int biXPelsPerMeter;
public int biYPelsPerMeter;
public uint biClrUsed;
public uint biClrImportant;
public void Init()
{
biSize = (uint)Marshal.SizeOf(this);
}
}
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct WAVEFORMATEX
{
public ushort wFormatTag;
public ushort nChannels;
public uint nSamplesPerSec;
public uint nAvgBytesPerSec;
public ushort nBlockAlign;
public ushort wBitsPerSample;
public ushort cbSize;
public void Init()
{
cbSize = (ushort)Marshal.SizeOf(this);
}
}
public const int WAVE_FORMAT_PCM = 1;
public const int AVIIF_KEYFRAME = 0x00000010;
[Flags]
public enum OpenFileStyle : uint
{
OF_CANCEL = 0x00000800, // Ignored. For a dialog box with a Cancel button, use OF_PROMPT.
OF_CREATE = 0x00001000, // Creates a new file. If file exists, it is truncated to zero (0) length.
OF_DELETE = 0x00000200, // Deletes a file.
OF_EXIST = 0x00004000, // Opens a file and then closes it. Used to test that a file exists
OF_PARSE = 0x00000100, // Fills the OFSTRUCT structure, but does not do anything else.
OF_PROMPT = 0x00002000, // Displays a dialog box if a requested file does not exist
OF_READ = 0x00000000, // Opens a file for reading only.
OF_READWRITE = 0x00000002, // Opens a file with read/write permissions.
OF_REOPEN = 0x00008000, // Opens a file by using information in the reopen buffer.
// For MS-DOSbased file systems, opens a file with compatibility mode, allows any process on a
// specified computer to open the file any number of times.
// Other efforts to open a file with other sharing modes fail. This flag is mapped to the
// FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function.
OF_SHARE_COMPAT = 0x00000000,
// Opens a file without denying read or write access to other processes.
// On MS-DOS-based file systems, if the file has been opened in compatibility mode
// by any other process, the function fails.
// This flag is mapped to the FILE_SHARE_READ|FILE_SHARE_WRITE flags of the CreateFile function.
OF_SHARE_DENY_NONE = 0x00000040,
// Opens a file and denies read access to other processes.
// On MS-DOS-based file systems, if the file has been opened in compatibility mode,
// or for read access by any other process, the function fails.
// This flag is mapped to the FILE_SHARE_WRITE flag of the CreateFile function.
OF_SHARE_DENY_READ = 0x00000030,
// Opens a file and denies write access to other processes.
// On MS-DOS-based file systems, if a file has been opened in compatibility mode,
// or for write access by any other process, the function fails.
// This flag is mapped to the FILE_SHARE_READ flag of the CreateFile function.
OF_SHARE_DENY_WRITE = 0x00000020,
// Opens a file with exclusive mode, and denies both read/write access to other processes.
// If a file has been opened in any other mode for read/write access, even by the current process,
// the function fails.
OF_SHARE_EXCLUSIVE = 0x00000010,
// Verifies that the date and time of a file are the same as when it was opened previously.
// This is useful as an extra check for read-only files.
OF_VERIFY = 0x00000400,
// Opens a file for write access only.
OF_WRITE = 0x00000001
}
[DllImport("avifil32.dll", SetLastError = true)]
public static extern int AVIFileOpenW(ref IntPtr pAviFile, [MarshalAs(UnmanagedType.LPWStr)] string szFile, OpenFileStyle uMode, int lpHandler);
[DllImport("avifil32.dll", SetLastError = true)]
public static extern void AVIFileInit();
// Create a new stream in an existing file and creates an interface to the new stream
[DllImport("avifil32.dll")]
public static extern int AVIFileCreateStreamW(
IntPtr pfile,
out IntPtr ppavi,
ref AVISTREAMINFOW psi);
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct AVICOMPRESSOPTIONS
{
public int fccType;
public int fccHandler;
public int dwKeyFrameEvery;
public int dwQuality;
public int dwBytesPerSecond;
public int dwFlags;
public int lpFormat;
public int cbFormat;
public int lpParms;
public int cbParms;
public int dwInterleaveEvery;
}
[DllImport("kernel32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall, SetLastError = true)]
public static extern SafeFileHandle CreateFile(
string lpFileName,
uint dwDesiredAccess,
uint dwShareMode,
IntPtr SecurityAttributes,
uint dwCreationDisposition,
uint dwFlagsAndAttributes,
IntPtr hTemplateFile
);
[DllImport("kernel32.dll")]
public static extern FileType GetFileType(IntPtr hFile);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern System.IntPtr GetCommandLine();
public enum FileType : uint
{
FileTypeChar = 0x0002,
FileTypeDisk = 0x0001,
FileTypePipe = 0x0003,
FileTypeRemote = 0x8000,
FileTypeUnknown = 0x0000,
}
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll", SetLastError = true)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr SetActiveWindow(IntPtr hWnd);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool AttachConsole(int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool AllocConsole();
[DllImport("kernel32.dll", SetLastError = false)]
public static extern bool FreeConsole();
[DllImport("kernel32.dll", SetLastError = true)]
public static extern IntPtr GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool SetStdHandle(int nStdHandle, IntPtr hConsoleOutput);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern IntPtr CreateFile(
string fileName,
int desiredAccess,
int shareMode,
IntPtr securityAttributes,
int creationDisposition,
int flagsAndAttributes,
IntPtr templateFile);
[DllImport("kernel32.dll", ExactSpelling = true, SetLastError = true)]
public static extern bool CloseHandle(IntPtr handle);
[DllImport("user32.dll", SetLastError = false)]
public static extern IntPtr GetDesktopWindow();
// Retrieve the save options for a file and returns them in a buffer
[DllImport("avifil32.dll")]
public static extern int AVISaveOptions(
IntPtr hwnd,
int flags,
int streams,
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] IntPtr[] ppavi,
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] IntPtr[] plpOptions);
// Free the resources allocated by the AVISaveOptions function
[DllImport("avifil32.dll")]
public static extern int AVISaveOptionsFree(
int streams,
[In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] plpOptions);
// Create a compressed stream from an uncompressed stream and a
// compression filter, and returns the address of a pointer to
// the compressed stream
[DllImport("avifil32.dll")]
public static extern int AVIMakeCompressedStream(
out IntPtr ppsCompressed,
IntPtr psSource,
ref AVICOMPRESSOPTIONS lpOptions,
IntPtr pclsidHandler);
// Set the format of a stream at the specified position
[DllImport("avifil32.dll")]
public static extern int AVIStreamSetFormat(
IntPtr pavi,
int lPos,
ref BITMAPINFOHEADER lpFormat,
int cbFormat);
// Set the format of a stream at the specified position
[DllImport("avifil32.dll")]
public static extern int AVIStreamSetFormat(
IntPtr pavi,
int lPos,
ref WAVEFORMATEX lpFormat,
int cbFormat);
// Write data to a stream
[DllImport("avifil32.dll")]
public static extern int AVIStreamWrite(
IntPtr pavi,
int lStart,
int lSamples,
IntPtr lpBuffer,
int cbBuffer,
int dwFlags,
IntPtr plSampWritten,
out int plBytesWritten);
// Release an open AVI stream
[DllImport("avifil32.dll")]
public static extern int AVIStreamRelease(
IntPtr pavi);
// Release an open AVI stream
[DllImport("avifil32.dll")]
public static extern int AVIFileRelease(
IntPtr pfile);
// Replacement of mmioFOURCC macros
public static int mmioFOURCC(string str)
{
return (
((int)(byte)(str[0])) |
((int)(byte)(str[1]) << 8) |
((int)(byte)(str[2]) << 16) |
((int)(byte)(str[3]) << 24));
}
public static bool FAILED(int hr) { return hr < 0; }
// Inverse of mmioFOURCC
public static string decode_mmioFOURCC(int code)
{
char[] chs = new char[4];
for (int i = 0; i < 4; i++)
{
chs[i] = (char)(byte)((code >> (i << 3)) & 0xFF);
if (!char.IsLetterOrDigit(chs[i]))
chs[i] = ' ';
}
return new string(chs);
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
[DllImport("Kernel32.dll", EntryPoint = "RtlZeroMemory", SetLastError = false)]
public static extern void ZeroMemory(IntPtr dest, uint size);
[DllImport("msvcrt.dll", EntryPoint = "memset", CallingConvention = CallingConvention.Cdecl, SetLastError = false)]
public static extern IntPtr MemSet(IntPtr dest, int c, uint count);
[DllImport("shlwapi.dll", CharSet = CharSet.Auto)]
public static extern bool PathRelativePathTo(
[Out] System.Text.StringBuilder pszPath,
[In] string pszFrom,
[In] FileAttributes dwAttrFrom,
[In] string pszTo,
[In] FileAttributes dwAttrTo
);
/// <summary>
/// File attributes are metadata values stored by the file system on disk and are used by the system and are available to developers via various file I/O APIs.
/// </summary>
[Flags]
[CLSCompliant(false)]
public enum FileAttributes : uint
{
/// <summary>
/// A file that is read-only. Applications can read the file, but cannot write to it or delete it. This attribute is not honored on directories. For more information, see "You cannot view or change the Read-only or the System attributes of folders in Windows Server 2003, in Windows XP, or in Windows Vista".
/// </summary>
Readonly = 0x00000001,
/// <summary>
/// The file or directory is hidden. It is not included in an ordinary directory listing.
/// </summary>
Hidden = 0x00000002,
/// <summary>
/// A file or directory that the operating system uses a part of, or uses exclusively.
/// </summary>
System = 0x00000004,
/// <summary>
/// The handle that identifies a directory.
/// </summary>
Directory = 0x00000010,
/// <summary>
/// A file or directory that is an archive file or directory. Applications typically use this attribute to mark files for backup or removal.
/// </summary>
Archive = 0x00000020,
/// <summary>
/// This value is reserved for system use.
/// </summary>
Device = 0x00000040,
/// <summary>
/// A file that does not have other attributes set. This attribute is valid only when used alone.
/// </summary>
Normal = 0x00000080,
/// <summary>
/// A file that is being used for temporary storage. File systems avoid writing data back to mass storage if sufficient cache memory is available, because typically, an application deletes a temporary file after the handle is closed. In that scenario, the system can entirely avoid writing the data. Otherwise, the data is written after the handle is closed.
/// </summary>
Temporary = 0x00000100,
/// <summary>
/// A file that is a sparse file.
/// </summary>
SparseFile = 0x00000200,
/// <summary>
/// A file or directory that has an associated reparse point, or a file that is a symbolic link.
/// </summary>
ReparsePoint = 0x00000400,
/// <summary>
/// A file or directory that is compressed. For a file, all of the data in the file is compressed. For a directory, compression is the default for newly created files and subdirectories.
/// </summary>
Compressed = 0x00000800,
/// <summary>
/// The data of a file is not available immediately. This attribute indicates that the file data is physically moved to offline storage. This attribute is used by Remote Storage, which is the hierarchical storage management software. Applications should not arbitrarily change this attribute.
/// </summary>
Offline = 0x00001000,
/// <summary>
/// The file or directory is not to be indexed by the content indexing service.
/// </summary>
NotContentIndexed = 0x00002000,
/// <summary>
/// A file or directory that is encrypted. For a file, all data streams in the file are encrypted. For a directory, encryption is the default for newly created files and subdirectories.
/// </summary>
Encrypted = 0x00004000,
/// <summary>
/// This value is reserved for system use.
/// </summary>
Virtual = 0x00010000
}
}
}

View File

@ -3,15 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Emulation", "BizHawk.Emulation\BizHawk.Emulation.csproj", "{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Util", "BizHawk.Util\BizHawk.Util.csproj", "{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.MultiClient", "BizHawk.MultiClient\BizHawk.MultiClient.csproj", "{DD448B37-BA3F-4544-9754-5406E8094723}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscoHawk", "DiscoHawk\DiscoHawk.csproj", "{C4366030-6D03-424B-AE53-F4F43BB217C3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.PCE_Debugger", "BizHawk.PCE_Debugger\BizHawk.PCE_Debugger.csproj", "{2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LuaHawk", "LuaHawk\LuaHawk.csproj", "{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Client.Common", "BizHawk.Client.Common\BizHawk.Client.Common.csproj", "{24A0AA3C-B25F-4197-B23D-476D6462DBA0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,20 +37,6 @@ Global
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Win32.ActiveCfg = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Win32.Build.0 = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|x86.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Win32.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Win32.Build.0 = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|x86.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Any CPU.Build.0 = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Win32.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Win32.Build.0 = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|x86.ActiveCfg = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -93,18 +77,18 @@ Global
{2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|Win32.ActiveCfg = Release|x86
{2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|x86.ActiveCfg = Release|x86
{2D7F5A4A-C3C4-41CD-839C-C35F3DD58725}.Release|x86.Build.0 = Release|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Debug|Any CPU.ActiveCfg = Debug|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Debug|Mixed Platforms.ActiveCfg = Debug|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Debug|Mixed Platforms.Build.0 = Debug|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Debug|Win32.ActiveCfg = Debug|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Debug|x86.ActiveCfg = Debug|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Debug|x86.Build.0 = Debug|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Release|Any CPU.ActiveCfg = Release|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Release|Mixed Platforms.ActiveCfg = Release|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Release|Mixed Platforms.Build.0 = Release|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Release|Win32.ActiveCfg = Release|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Release|x86.ActiveCfg = Release|x86
{B7FA7300-52DF-4A3F-84EF-D69E40CF60AF}.Release|x86.Build.0 = Release|x86
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|Win32.ActiveCfg = Debug|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Debug|x86.ActiveCfg = Debug|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Release|Any CPU.Build.0 = Release|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Release|Win32.ActiveCfg = Release|Any CPU
{24A0AA3C-B25F-4197-B23D-476D6462DBA0}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -1,87 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Emulation_v4.5", "BizHawk.Emulation\BizHawk.Emulation_v4.5.csproj", "{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.Util_v4.5", "BizHawk.Util\BizHawk.Util_v4.5.csproj", "{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BizHawk.MultiClient_v4.5", "BizHawk.MultiClient\BizHawk.MultiClient_v4.5.csproj", "{DD448B37-BA3F-4544-9754-5406E8094723}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscoHawk_4.5", "DiscoHawk\DiscoHawk_4.5.csproj", "{C4366030-6D03-424B-AE53-F4F43BB217C3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|Mixed Platforms = Debug|Mixed Platforms
Debug|Win32 = Debug|Win32
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|Mixed Platforms = Release|Mixed Platforms
Release|Win32 = Release|Win32
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Debug|Win32.ActiveCfg = Debug|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Debug|Win32.Build.0 = Debug|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Debug|x86.ActiveCfg = Debug|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Any CPU.Build.0 = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Win32.ActiveCfg = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|Win32.Build.0 = Release|Any CPU
{197D4314-8A9F-49BA-977D-54ACEFAEB6BA}.Release|x86.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Win32.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|Win32.Build.0 = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Debug|x86.ActiveCfg = Debug|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Any CPU.Build.0 = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Win32.ActiveCfg = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|Win32.Build.0 = Release|Any CPU
{EE135301-08B3-4EFC-A61C-1C53E1C65CB9}.Release|x86.ActiveCfg = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Win32.ActiveCfg = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|Win32.Build.0 = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Debug|x86.ActiveCfg = Debug|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Release|Any CPU.Build.0 = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Release|Win32.ActiveCfg = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Release|Win32.Build.0 = Release|Any CPU
{DD448B37-BA3F-4544-9754-5406E8094723}.Release|x86.ActiveCfg = Release|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Debug|Win32.ActiveCfg = Debug|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Debug|Win32.Build.0 = Debug|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Debug|x86.ActiveCfg = Debug|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Any CPU.Build.0 = Release|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Win32.ActiveCfg = Release|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|Win32.Build.0 = Release|Any CPU
{C4366030-6D03-424B-AE53-F4F43BB217C3}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = BizHawk.MultiClient\BizHawk.MultiClient.csproj
EndGlobalSection
EndGlobal