Mounting a package

Requirements: An Arphoon Package, An application wich references ArpsEngine.dll library

To mount a package in your application, you first need to add a reference to ArpsEngine.dll library to your solution in Visual Studio. Then you will get full access to the Arps namespace.

First create a new instance of the Arps.Engine object, wich is the main engine of the library. It mounts and access files stored inside Arphoon packages.

Syntax
Arps.Engine engine = new Arps.Engine();

The initialization method takes no parameters, and creates a new fully featured Engine ready to mount packages.

After creating the object, you can call the Mount() method, passing the package filename as the first parameter.
Syntax
engine.Mount("C:\\Users\\Razorback\\Desktop\\myPackage.arphon");

The method will block and return after the Mount operation ends (regardless if its succeeds or not). It will not throw any exceptions, and will return an status code with the result of the mount operation.

If the result is Arps.Engine.PackageMountReturnCode.MountSuccess you can use the method GetFile() to get information about an existing file in the package.
Syntax
Arps.Utilities.PackagedFileInformationCollection info = engine.GetFile("sample.txt");

This method takes a single parameter wich is the filename and returns an PackagedFileInformationCollection structure wich holds all the relevant information about the packed file, like its full Name, its parent directory and its size. This structure can be used to create an stream to the packed file, use the method GetStream() from the PackagedFileInformationCollection structure, wich takes no parameters and returns an Arps.PackagedFileStream stream object wich inherits from System.IO.Stream (and thereby can be casted to it).
Syntax
System.IO.Stream str = info.GetStream();

Once the stream is created, you can use it like a normal stream object, similar to System.IO.FileStream object.

Remember to dispose the stream and call Unmount() method on the engine after you done using it, to avoid any possible memory leaks.

If the mount process fails for some reason, its usefull to also handle the "LogChanged(string text)" event of the Engine object, to get realtime verbose output on all engine operations.

The full code for this example is
    class Program
    {
        static void Main(string[] args)
        {
            Arps.Engine engine = new Arps.Engine();
            engine.LogChanged += engine_LogChanged;
            if (engine.Mount("sample-v1010D.arphoon") == Arps.Engine.PackageMountReturnCode.MountSuccess)
            {
                Arps.Utilities.PackagedFileInformationCollection info = engine.GetFile("sample.txt");
                System.IO.Stream str = info.GetStream();

                // use stream

                str.Dispose();
                engine.Unmount();
                engine.Dispose();
            }
        }

        static void engine_LogChanged(string text)
        {
            Console.WriteLine("Engine: " + text);
        }
    }

Last edited Feb 13, 2014 at 2:35 AM by kderazorback, version 2