Adding it to an app¶
An app needs the C# side and the DLL beside default.xex:
Silverlight360.UnRAR.dll,RarExtractor, withSilverlight360.UnRAR.xmlbeside it for IntelliSense: a reference to the release's DLL, or aProjectReferenceto the repository'scsharp/Silverlight360.UnRAR.csproj.unrar360.xex, asContent.
The C# side uses NativeBuffer from Silverlight360's common library, Silverlight360.Common, for the progress the DLL writes. An app built with Silverlight360 references that library already, and its build puts Silverlight360.Common.dll in the package.
In the app's project, as sample/UnRarSample.csproj has them:
<ItemGroup>
<ProjectReference Include="..\Silverlight360.UnRAR\csharp\Silverlight360.UnRAR.csproj" />
<!-- or, from a release: <Reference Include="Silverlight360.UnRAR"><HintPath>..\Silverlight360.UnRAR\Silverlight360.UnRAR.dll</HintPath></Reference> -->
</ItemGroup>
<ItemGroup>
<Content Include="..\Silverlight360.UnRAR\unrar360.xex"><Link>unrar360.xex</Link></Content>
</ItemGroup>
Ship the release's licenses/unrar.txt and THIRD-PARTY-NOTICES.md with them: unrar360.xex is built from UnRAR's source, under its own license. Silverlight360.UnRAR's own license asks for a visible reference to https://github.com/Digiex/Silverlight360.UnRAR in the app's documentation, credits or "about" information (see Licenses).
Extracting¶
Extract blocks until the archive is done, so call it on a thread of its own, never the UI's, and read the progress from the UI's:
var rar = new RarExtractor();
ThreadPool.QueueUserWorkItem(delegate
{
int result = rar.Extract(@"usb:\Downloads\movie.rar", @"hdd:\Videos\Movie", null);
Deployment.Current.Dispatcher.BeginInvoke(() =>
Show(result == RarExtractor.Success ? "Done" : RarExtractor.Describe(result) + ": " + rar.Message));
rar.Dispose();
});
// On a timer on the UI thread:
Status.Text = rar.FilesDone + " files, " + rar.BytesDone / (1 << 20) + " MB: " + rar.CurrentFile;
- One extraction at a time per extractor.
Cancel,FilesDone,BytesDoneandCurrentFileare for other threads. - Folders are kept as the archive has them, and those missing are made. A split archive's other volumes must be beside the first.
- A password goes to
Extract; a wrong one returnsBadPassword, and none for an encrypted archiveMissingPassword. - The first extraction starts the DLL with a heap of
DefaultHeapBytes(128 MB, reserved and committed as it's used): RAR5's 32 MB dictionary and more. CallRarExtractor.Start(bytes)before the first one for another size;HeapPeaksays what an extraction needed (8.4 MB for the test archives). - The DLL loads at
0x8F000000. In a Silverlight app's process on the console,0x8A000000,0x8C000000and0x8E000000are taken and Silverlight360.Https has0x8D000000, so another DLL of the app's own needs a base of its own. A DllImport of a module that can't load turns into a call through null, which can power the console off, so check a new build loads first (see Testing).
See API for everything an extractor has.