コード例 #1
0
ファイル: Viewer.cs プロジェクト: memerdot/puyotools
        private Bitmap LoadImage(string filename)
        {
            try
            {
                /* Open the file */
                Images imageClass;
                Stream file;
                using (file = new FileStream(filename, FileMode.Open, FileAccess.Read))
                {
                    imageClass = new Images(file, filename);

                    /* Get the image */
                    if (imageClass.Format == GraphicFormat.NULL)
                    {
                        /* Decompress the file and see if we can get anything */
                        Compression compression = new Compression(file, filename);
                        if (compression.Format == CompressionFormat.NULL)
                            throw new GraphicFormatNotSupported();
                        file = compression.Decompress();

                        imageClass = new Images(file, filename);

                        if (imageClass.Format == GraphicFormat.NULL)
                            throw new GraphicFormatNotSupported();
                    }

                    try
                    {
                        return imageClass.Unpack();
                    }
                    catch (GraphicFormatNeedsPalette)
                    {
                        // Load palette data and then unpack again
                        if (Path.GetDirectoryName(filename) != String.Empty)
                            imageClass.Decoder.PaletteData = LoadPaletteFile(Path.GetDirectoryName(filename) + Path.DirectorySeparatorChar + imageClass.PaletteFilename, imageClass);
                        else
                            imageClass.Decoder.PaletteData = LoadPaletteFile(imageClass.PaletteFilename, imageClass);

                        return imageClass.Unpack();
                    }
                }
            }
            catch
            {
                return null;
            }
        }
コード例 #2
0
ファイル: ImageEncoder.cs プロジェクト: memerdot/puyotools
        // Import PVR settings
        private void ImportPvrSettings(object sender, EventArgs e)
        {
            /* Select Pvr */
            string pvrFile = FileSelectionDialog.OpenFile("Select PVR file",
                "PVR Files (*.pvr;*.pvz)|*.pvr;*.pvz|" +
                "All Files (*.*)|*.*");

            if (pvrFile == null || pvrFile == String.Empty)
                return;

            /* Load pvr file */
            using (Stream file = new FileStream(pvrFile, FileMode.Open, FileAccess.Read))
            {
                Stream fileData = file;

                /* Is the file compressed? */
                Compression compression = new Compression(fileData, pvrFile);
                if (compression.Format != CompressionFormat.NULL)
                {
                    MemoryStream decompressedData = compression.Decompress();
                    if (decompressedData != null)
                        fileData = decompressedData;
                }

                /* Is this a PVR? */
                Images images = new Images(fileData, pvrFile);
                if (images.Format == GraphicFormat.PVR)
                {
                    /* Get file offset */
                    int fileOffset = (fileData.ReadString(0x0, 4) == GraphicHeader.GBIX ? 0x10 : 0x0);

                    /* Get Palette Format, Data Format, and Global Index */
                    byte pvrPaletteFormat = fileData.ReadByte(fileOffset + 0x8);
                    byte pvrDataFormat    = fileData.ReadByte(fileOffset + 0x9);

                    uint pvrGlobalIndex = 0;
                    if (fileData.ReadString(0x0, 4) == GraphicHeader.GBIX)
                        pvrGlobalIndex = fileData.ReadUInt(0x8);

                    /* Set palette format */
                    switch (pvrPaletteFormat)
                    {
                        case 0x0: paletteFormat.SelectedIndex = 0; break;
                        case 0x1: paletteFormat.SelectedIndex = 1; break;
                        case 0x2: paletteFormat.SelectedIndex = 2; break;
                    }

                    /* Set data format */
                    switch (pvrDataFormat)
                    {
                        case 0x1: dataFormat.SelectedIndex = 0; break;
                        case 0x9: dataFormat.SelectedIndex = 1; break;
                        case 0xD: dataFormat.SelectedIndex = 2; break;
                    }

                    /* Set global index */
                    addGbix.Checked  = (fileData.ReadString(0x0, 4) == "GBIX");
                    globalIndex.Text = pvrGlobalIndex.ToString();
                }
            }
        }
コード例 #3
0
ファイル: Decompress.cs プロジェクト: memerdot/puyotools
        /* Decompress the files */
        private void run(object sender, DoWorkEventArgs e)
        {
            /* Create the file list */
            List<string> fileList = new List<string>();
            foreach (string i in files)
                fileList.Add(i);

            for (int i = 0; i < files.Length; i++)
            {
                /* Set the current file */
                status.CurrentFile = i;

                try
                {
                    /* Open up the file */
                    MemoryStream data;
                    string outputDirectory, outputFilename;
                    using (FileStream inputStream = new FileStream(fileList[i], FileMode.Open, FileAccess.Read))
                    {
                        /* Set up the decompressor */
                        Compression compression = new Compression(inputStream, Path.GetFileName(fileList[i]));
                        if (compression.Format == CompressionFormat.NULL)
                            continue;

                        /* Set up the output directories and file names */
                        outputDirectory = Path.GetDirectoryName(fileList[i]) + (decompressSameDir.Checked ? String.Empty : Path.DirectorySeparatorChar + compression.OutputDirectory);
                        outputFilename  = (useStoredFilename.Checked ? compression.DecompressFilename : Path.GetFileName(fileList[i]));

                        /* Decompress data */
                        MemoryStream decompressedData = compression.Decompress();

                        /* Check to make sure the decompression was successful */
                        if (decompressedData == null)
                            continue;
                        else
                            data = decompressedData;
                    }

                    /* Create the output directory if it does not exist */
                    if (!Directory.Exists(outputDirectory))
                        Directory.CreateDirectory(outputDirectory);

                    /* Write file data */
                    using (FileStream outputStream = new FileStream(outputDirectory + Path.DirectorySeparatorChar + outputFilename, FileMode.Create, FileAccess.Write))
                        outputStream.Write(data);

                    /* Delete source file? */
                    if (deleteSourceFile.Checked && File.Exists(fileList[i]))
                        File.Delete(fileList[i]);

                    /* Unpack image? */
                    if (unpackImage.Checked)
                    {
                        /* Create Image object and make sure the format is supported */
                        Images images = new Images(data, outputFilename);
                        if (images.Format != GraphicFormat.NULL)
                        {
                            /* Set up our input and output image */
                            string inputImage  = outputDirectory + Path.DirectorySeparatorChar + outputFilename;
                            string outputImage = outputDirectory + Path.DirectorySeparatorChar + (convertSameDir.Checked ? String.Empty : images.OutputDirectory + Path.DirectorySeparatorChar) + Path.GetFileNameWithoutExtension(outputFilename) + ".png";

                            // Convert image
                            Bitmap imageData = null;
                            try
                            {
                                imageData = images.Unpack();
                            }
                            catch (GraphicFormatNeedsPalette)
                            {
                                // See if the palette file exists
                                if (File.Exists(outputDirectory + Path.DirectorySeparatorChar + images.PaletteFilename))
                                {
                                    using (FileStream paletteData = new FileStream(outputDirectory + Path.DirectorySeparatorChar + images.PaletteFilename, FileMode.Open, FileAccess.Read))
                                    {
                                        images.Decoder.PaletteData = paletteData;
                                        imageData = images.Unpack();
                                    }
                                }
                            }

                            /* Make sure an image was written */
                            if (imageData != null)
                            {
                                data = new MemoryStream();
                                imageData.Save(data, ImageFormat.Png);

                                /* Create the output directory if it does not exist */
                                if (!Directory.Exists(Path.GetDirectoryName(outputImage)))
                                    Directory.CreateDirectory(Path.GetDirectoryName(outputImage));

                                /* Output the image */
                                using (FileStream outputStream = new FileStream(outputImage, FileMode.Create, FileAccess.Write))
                                    outputStream.Write(data);

                                /* Delete the source image if we want to */
                                if (deleteSourceImage.Checked && File.Exists(inputImage) && File.Exists(outputImage))
                                    File.Delete(inputImage);
                            }
                        }
                    }
                }
                catch
                {
                    /* Something went wrong. Continue please. */
                    continue;
                }
            }

            /* Close the status box now */
            status.Close();
            this.Close();
        }
コード例 #4
0
ファイル: Explorer.cs プロジェクト: memerdot/puyotools
        private void loadEmbeddedImage()
        {
            try
            {
                // Get the selected item and the data and filename
                int item = fileListView.SelectedIndices[0] - (level == 0 ? 0 : 1);
                MemoryStream imageData = ArchiveData[level].Copy(FileList[level].Entries[item].Offset, FileList[level].Entries[item].Length);
                string filename = FileList[level].Entries[item].Filename;

                // Check to see if the image is compressed
                Compression compression = new Compression(imageData, filename);
                if (compression.Format != CompressionFormat.NULL)
                {
                    // Decompress
                    MemoryStream decompressedData = compression.Decompress();
                    if (decompressedData != null)
                        imageData = decompressedData;
                }

                // Check to see if this is an image
                Images image = new Images(imageData, filename);
                if (image.Format == GraphicFormat.NULL)
                    throw new GraphicFormatNotSupported();

                // Try to open this image if we can
                try
                {
                    new Image_Viewer(imageData, filename);
                }
                catch (GraphicFormatNeedsPalette)
                {
                    int index = indexOfFile(image.PaletteFilename);
                    if (index == -1)
                        throw new Exception();
                    else
                        new Image_Viewer(imageData, filename, ArchiveData[level].Copy(FileList[level].Entries[index].Offset, FileList[level].Entries[index].Length));
                }
            }
            catch
            {
            }
        }
コード例 #5
0
ファイル: ImageEncoder.cs プロジェクト: memerdot/puyotools
        /* Convert the images */
        private void run(object sender, DoWorkEventArgs e)
        {
            /* Create the file list */
            List<string> fileList = new List<string>();
            foreach (string i in files)
                fileList.Add(i);

            for (int i = 0; i < files.Length; i++)
            {
                /* Set the current file */
                status.CurrentFile = i;

                try
                {
                    /* Open up the file */
                    Stream data = null;
                    string outputFilename  = Path.GetFileName(fileList[i]);
                    string outputDirectory = Path.GetDirectoryName(fileList[i]);
                    using (Stream inputStream = new FileStream(fileList[i], FileMode.Open, FileAccess.Read))
                    {
                        /* Set up the PVR creator */
                        data = inputStream;
                        PVR encoder = new PVR();

                        switch (paletteFormat.SelectedIndex)
                        {
                            case 0: encoder.PixelFormat = PvrPixelFormat.Argb1555; break;
                            case 1: encoder.PixelFormat = PvrPixelFormat.Rgb565; break;
                            case 2: encoder.PixelFormat = PvrPixelFormat.Argb4444; break;
                        }
                        switch (dataFormat.SelectedIndex)
                        {
                            case 0: encoder.DataFormat = PvrDataFormat.SquareTwiddled; break;
                            case 1: encoder.DataFormat = PvrDataFormat.Rectangle; break;
                            case 2: encoder.DataFormat = PvrDataFormat.RectangleTwiddled; break;
                        }

                        // Set the global index and gbix header
                        // There shouldn't be an error when parsing anymore, so we won't do checks
                        encoder.GbixHeader = addGbix.Checked;
                        if (addGbix.Checked && globalIndex.Text.Length > 0)
                            encoder.GlobalIndex = uint.Parse(globalIndex.Text);
                        else
                            encoder.GlobalIndex = 0;

                        /* Set up our input and output image */
                        string inputImage  = outputDirectory + Path.DirectorySeparatorChar + outputFilename;
                        string outputImage = outputDirectory + Path.DirectorySeparatorChar + (convertSameDir.Checked ? String.Empty : "PVR Created" + Path.DirectorySeparatorChar) + Path.GetFileNameWithoutExtension(outputFilename) + (compressFile.Checked && compressionFormat.SelectedIndex == 0 ? ".pvz" : ".pvr");
                        outputFilename     = outputImage;

                        /* Create image */
                        MemoryStream imageData = (MemoryStream)encoder.Pack(ref data);

                        /* Don't continue if an image wasn't created */
                        if (imageData == null)
                            continue;

                        // Compress image?
                        if (compressFile.Checked)
                        {
                            Compression compression = new Compression(imageData, outputFilename, CompressionFormats[compressionFormat.SelectedIndex]);

                            MemoryStream compressedData = compression.Compress();
                            if (compressedData != null)
                            {
                                imageData = compressedData;
                                outputImage = Path.GetDirectoryName(outputImage) + Path.DirectorySeparatorChar + compression.CompressFilename;
                            }
                        }

                        /* Create the output directory if it does not exist */
                        if (!Directory.Exists(Path.GetDirectoryName(outputImage)))
                            Directory.CreateDirectory(Path.GetDirectoryName(outputImage));

                        /* Output the image */
                        using (FileStream outputStream = new FileStream(outputImage, FileMode.Create, FileAccess.Write))
                            outputStream.Write(imageData);
                    }

                    /* Delete the source image if we want to */
                    if (deleteSourceImage.Checked && File.Exists(fileList[i]) && File.Exists(outputFilename))
                        File.Delete(fileList[i]);
                }
                catch
                {
                    /* Something went wrong. Continue please. */
                    continue;
                }
            }

            /* Close the status box now */
            status.Close();
            this.Close();
        }
コード例 #6
0
ファイル: Explorer.cs プロジェクト: memerdot/puyotools
        private ArchiveFileList GetFileList(ref Stream data, string filename, out string type)
        {
            type = null;

            try
            {
                /* Check to see if the archive is compressed */
                Compression compression = new Compression(data, filename);
                if (compression.Format != CompressionFormat.NULL)
                {
                    /* Decompress */
                    MemoryStream decompressedData = compression.Decompress();
                    if (decompressedData != null)
                        data = decompressedData;
                }

                /* Check to see if this is an archive */
                Archive archive = new Archive(data, filename);
                if (archive.Format == ArchiveFormat.NULL)
                    throw new ArchiveFormatNotSupported();

                /* Check to see if the data was translated */
                if (data != archive.GetData())
                    data = archive.GetData();

                /* Get the file list and archive type */
                type = archive.Name;
                return archive.GetFileList();
            }
            catch
            {
                return null;
            }
        }
コード例 #7
0
ファイル: Explorer.cs プロジェクト: memerdot/puyotools
        /* Extract files */
        private void extract(object sender, EventArgs e)
        {
            /* Set the files to extract */
            List<int> files = new List<int>();
            if (sender == extractSelectedFiles) // Select only the files chosen
            {
                for (int i = 0; i < fileListView.SelectedIndices.Count; i++)
                {
                    if (level == 0 || fileListView.SelectedIndices[i] > 0)
                        files.Add(fileListView.SelectedIndices[i]);
                }
            }
            else // Select all the files
            {
                for (int i = (level == 0 ? 0 : 1); i < fileListView.Items.Count; i++)
                    files.Add(i);
            }

            /* Don't continue if no files were selected */
            if (files.Count == 0)
                return;

            /* Display the save file dialog or folder dialog */
            string output_directory = String.Empty;
            string output_filename  = String.Empty;

            /* Directory selection if there are more than one file */
            if (files.Count > 1)
            {
                output_directory = FileSelectionDialog.SaveDirectory("Select a directory to output the files to");

                /* Make sure a directory was selected */
                if (output_directory == null || output_directory == String.Empty)
                    return;
            }

            for (int i = 0; i < files.Count; i++)
            {
                try
                {
                    string filename = FileList[level].Entries[files[i] - (level > 0 ? 1 : 0)].Filename;
                    int num         = files[i] - (level > 0 ? 1 : 0);

                    output_filename = (filename == String.Empty ? num.ToString().PadLeft(FileList.Count.Digits(), '0') :
                        (addFileNumberExtracted.Checked ? Path.GetFileNameWithoutExtension(filename) + '_' + num.ToString().PadLeft(FileList.Count.Digits(), '0') + Path.GetExtension(filename) :
                        filename));

                    /* Which selection dialog do we want? */
                    if (files.Count == 1)
                    {
                        output_filename = FileSelectionDialog.SaveFile("Extract File", output_filename,
                            (Path.GetExtension(filename) == String.Empty ? "All Files (*.*)|*.*" : Path.GetExtension(filename).Substring(1).ToUpper() + " File (*" + Path.GetExtension(filename) + ")|*" + Path.GetExtension(filename)));

                        /* Make sure we selected a file */
                        if (output_filename == null || output_filename == String.Empty)
                            return;

                        output_directory = Path.GetDirectoryName(output_filename);
                        output_filename  = Path.GetFileName(output_filename);
                    }

                    /* If for some reason the output directory doesn't exist, create it */
                    if (!Directory.Exists(output_directory))
                        Directory.CreateDirectory(output_directory);

                    /* Copy the data to a new stream */
                    MemoryStream outputData = ArchiveData[level].Copy(FileList[level].Entries[num].Offset, FileList[level].Entries[num].Length);

                    /* Do we want to decompress the file? */
                    if (decompressExtracted.Checked)
                    {
                        Compression compression = new Compression(outputData, output_filename);
                        if (compression.Format != CompressionFormat.NULL)
                        {
                            MemoryStream decompressedData = compression.Decompress();
                            if (decompressedData != null)
                            {
                                outputData      = decompressedData;
                                output_filename = compression.DecompressFilename;
                            }
                        }
                    }

                    // Convert the file to a PNG?
                    if (extractImageAsPng.Checked)
                    {
                        Images images = new Images(outputData, output_filename);
                        if (images.Format != GraphicFormat.NULL)
                        {
                            Bitmap imageData;
                            try
                            {
                                imageData = images.Unpack();
                            }
                            catch (GraphicFormatNeedsPalette)
                            {
                                // See if the file exists in the archive
                                int index = indexOfFile(images.PaletteFilename);
                                if (index != -1)
                                    images.Decoder.PaletteData = ArchiveData[level].Copy(FileList[level].Entries[index].Offset, FileList[level].Entries[index].Length);

                                imageData = images.Unpack();
                            }

                            // Now output the image if it was written
                            if (imageData != null)
                            {
                                outputData = new MemoryStream();
                                imageData.Save(outputData, ImageFormat.Png);
                                output_filename = Path.GetFileNameWithoutExtension(output_filename) + ".png";
                            }
                        }
                    }

                    /* Write the file */
                    using (FileStream outputStream = new FileStream(output_directory + Path.DirectorySeparatorChar + output_filename, FileMode.Create, FileAccess.Write))
                        outputStream.Write(outputData);
                }
                catch
                {
                    continue;
                }
            }
        }
コード例 #8
0
ファイル: Create.cs プロジェクト: memerdot/puyotools
        /* Create the archive */
        //private void run(object sender, DoWorkEventArgs e)
        private void run(string output_filename)
        {
            try
            {
                // Get archive and compression format
                int ArchiveFormatIndex = archiveFormatList.SelectedIndex;
                int CompressionFormatIndex = compressionFormatList.SelectedIndex;

                // Get output filename
                //string output_filename = FileSelectionDialog.SaveFile("Create Archive", String.Empty, String.Format("{0} ({1})|{1}", ArchiveFilters[archiveFormatList.SelectedIndex][0], ArchiveFilters[archiveFormatList.SelectedIndex][1]));
                //if (output_filename == null || output_filename == String.Empty)
                //    return;

                // Disable the window and show the status box
                PanelContent.Enabled = false;
                //status.Visible = true;

                /* Start creating the archive */
                Archive archive = new Archive(ArchiveFormats[archiveFormatList.SelectedIndex], Path.GetFileName(output_filename));

                using (FileStream outputStream = new FileStream(output_filename, FileMode.Create, FileAccess.ReadWrite))
                {
                    // Get the block size
                    int blockSize;
                    if (blockSizes[ArchiveFormatIndex].Enabled && blockSizes[ArchiveFormatIndex].Text.Length > 0)
                        blockSize = int.Parse(blockSizes[ArchiveFormatIndex].Text);
                    else
                        blockSize = ArchiveBlockSizes[ArchiveFormatIndex][0];

                    /* Create and write the header */
                    bool[] settings = GetSettings(ArchiveFormatIndex);
                    uint[] offsetList;
                    MemoryStream header = archive.CreateHeader(fileList.ToArray(), archiveFilenames.ToArray(), blockSize, settings, out offsetList);
                    outputStream.Write(header);

                    /* Add the files */
                    for (int i = 0; i < fileList.Count; i++)
                    {
                        // Set the current file
                        status.CurrentFile = i;

                        /* Pad file so we can have the correct block offset */
                        while (outputStream.Position < offsetList[i])
                            outputStream.WriteByte(archive.PaddingByte);

                        using (Stream inputStream = new FileStream(fileList[i], FileMode.Open, FileAccess.Read))
                        {
                            /* Format the file so we can add it */
                            Stream inputFile = inputStream;
                            inputFile = archive.FormatFileToAdd(ref inputFile);
                            if (inputFile == null)
                                throw new Exception();

                            /* Write the data to the file */
                            outputStream.Write(inputFile);
                        }
                    }

                    /* Pad file so we can have the correct block offset */
                    while (outputStream.Position % blockSize != 0)
                        outputStream.WriteByte(archive.PaddingByte);

                    /* Write the footer */
                    MemoryStream footer = archive.CreateFooter(fileList.ToArray(), archiveFilenames.ToArray(), blockSize, settings, ref header);
                    if (footer != null)
                    {
                        outputStream.Write(footer);

                        /* Pad file so we can have the correct block offset */
                        while (outputStream.Position % blockSize != 0)
                            outputStream.WriteByte(archive.PaddingByte);
                    }

                    /* Compress the data if we want to */
                    if (compressionFormatList.SelectedIndex != 0)
                    {
                        Compression compression = new Compression(outputStream, output_filename, CompressionFormats[CompressionFormatIndex - 1]);
                        MemoryStream compressedData = compression.Compress();
                        if (compressedData != null)
                        {
                            /* Clear the output stream and write the compressed data */
                            outputStream.Position = 0;
                            outputStream.SetLength(compressedData.Length);
                            outputStream.Write(compressedData);
                        }
                    }
                }

                this.Close();
            }
            catch
            {
                this.Close();
            }
            finally
            {
                status.Close();
            }
        }
コード例 #9
0
ファイル: Compress.cs プロジェクト: memerdot/puyotools
        /* Decompress the files */
        private void run(object sender, DoWorkEventArgs e)
        {
            /* Create the file list */
            List<string> fileList = new List<string>();
            foreach (string i in files)
                fileList.Add(i);

            // Get file size restriction size
            uint restrictSize = 0;
            if (filesizeRestriction.Checked && !uint.TryParse(filesizeRestrictionSize.Text, out restrictSize)) // For some reason if this happens
                restrictSize = 0;

            for (int i = 0; i < files.Length; i++)
            {
                /* Set the current file */
                status.CurrentFile = i;

                try
                {
                    /* Open up the file */
                    MemoryStream data;
                    string outputDirectory, outputFilename;
                    using (FileStream inputStream = new FileStream(fileList[i], FileMode.Open, FileAccess.Read))
                    {
                        // Check to see if we want to compress this file (filesize restriction)
                        if (filesizeRestriction.Checked && inputStream.Length < restrictSize)
                            continue;

                        // Setup the decompressor
                        Compression compression = new Compression(inputStream, Path.GetFileName(fileList[i]), CompressionFormats[compressionFormat.SelectedIndex]);

                        /* Set up the output directories and file names */
                        outputDirectory = Path.GetDirectoryName(fileList[i]) + (compressSameDir.Checked ? String.Empty : Path.DirectorySeparatorChar + "Compressed");
                        outputFilename  = Path.GetFileName(fileList[i]);

                        // Decompress data and get decompressed filename
                        MemoryStream compressedData = compression.Compress();
                        outputFilename = compression.CompressFilename;

                        /* Check to make sure the decompression was successful */
                        if (compressedData == null)
                            continue;
                        else
                            data = compressedData;
                    }

                    /* Create the output directory if it does not exist */
                    if (!Directory.Exists(outputDirectory))
                        Directory.CreateDirectory(outputDirectory);

                    /* Write file data */
                    using (FileStream outputStream = new FileStream(outputDirectory + Path.DirectorySeparatorChar + outputFilename, FileMode.Create, FileAccess.Write))
                        outputStream.Write(data);
                }
                catch
                {
                    /* Something went wrong. Continue please. */
                    continue;
                }
            }

            /* Close the status box now */
            status.Close();
            this.Close();
        }
コード例 #10
0
ファイル: Extract.cs プロジェクト: memerdot/puyotools
        // Extract the files
        private void run(object sender, DoWorkEventArgs e)
        {
            // Create the file list
            List<string> fileList = new List<string>();
            foreach (string i in files)
                fileList.Add(i);

            for (int i = 0; i < fileList.Count; i++)
            {
                // Set the current file in the status
                status.CurrentFile      = i;
                status.CurrentFileLocal = 0;

                // Set up the image file list for conversion
                List<string> imageFileList = new List<string>();

                try
                {
                    // Set up the file paths and open up the file
                    string InFile       = Path.GetFileName(fileList[i]);
                    string InDirectory  = Path.GetDirectoryName(fileList[i]);
                    string OutFile      = InFile;
                    string OutDirectory = InDirectory;

                    using (FileStream InputStream = new FileStream(fileList[i], FileMode.Open, FileAccess.Read))
                    {
                        Stream InputData = InputStream;

                        // Decompress the file
                        if (decompressSourceFile.Checked)
                        {
                            Compression compression = new Compression(InputData, InFile);
                            if (compression.Format != CompressionFormat.NULL)
                            {
                                MemoryStream DecompressedData = compression.Decompress();
                                if (DecompressedData != null)
                                {
                                    InputData = DecompressedData;
                                    if (useStoredFilename.Checked)
                                        InFile = compression.DecompressFilename;
                                }
                            }
                        }

                        // Open up the archive
                        Archive archive = new Archive(InputData, InFile);
                        if (archive.Format == ArchiveFormat.NULL)
                            continue;
                        ArchiveFileList ArchiveFileList = archive.GetFileList();
                        if (ArchiveFileList == null || ArchiveFileList.Entries.Length == 0)
                            continue;
                        status.TotalFilesLocal = ArchiveFileList.Entries.Length;

                        // Create the directory where we will extract the files to
                        if (extractDirSameFilename.Checked && deleteSourceArchive.Checked)
                            OutDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); // Create a temporary place to store the files for now
                        else if (extractSameDir.Checked)
                            OutDirectory = InDirectory;
                        else
                            OutDirectory = InDirectory + Path.DirectorySeparatorChar + archive.OutputDirectory + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(InFile);
                        if (!Directory.Exists(OutDirectory))
                            Directory.CreateDirectory(OutDirectory);

                        // Extract the data from the archive
                        for (int j = 0; j < ArchiveFileList.Entries.Length; j++)
                        {
                            // Set the current file and get the data
                            status.CurrentFileLocal = j;
                            MemoryStream OutData = archive.GetData().Copy(ArchiveFileList.Entries[j].Offset, ArchiveFileList.Entries[j].Length);

                            // Get the filename that the file will be extracted to
                            if (extractFilenames.Checked && ArchiveFileList.Entries[j].Filename != String.Empty)
                                OutFile = ArchiveFileList.Entries[j].Filename;
                            else
                                OutFile = j.ToString().PadLeft(ArchiveFileList.Entries.Length.Digits(), '0') + FileTypeInfo.GetFileExtension(OutData);

                            // Decompress the data
                            if (decompressExtractedFile.Checked)
                            {
                                Compression compression = new Compression(OutData, OutFile);
                                if (compression.Format != CompressionFormat.NULL)
                                {
                                    MemoryStream DecompressedData = compression.Decompress();

                                    if (decompressExtractedDir.Checked)
                                    {
                                        // Write this to a different directory
                                        string TempOutFile = OutFile; // We will change it temporarily
                                        if (useStoredFilename.Checked)
                                            OutFile = compression.DecompressFilename;

                                        if (!Directory.Exists(OutDirectory + Path.DirectorySeparatorChar + compression.OutputDirectory))
                                            Directory.CreateDirectory(OutDirectory + Path.DirectorySeparatorChar + compression.OutputDirectory);
                                        using (FileStream OutputStream = new FileStream(OutDirectory + Path.DirectorySeparatorChar + compression.OutputDirectory + Path.DirectorySeparatorChar + OutFile, FileMode.Create, FileAccess.Write))
                                            OutputStream.Write(DecompressedData);

                                        OutFile = TempOutFile; // Reset the output file now
                                    }
                                    else
                                        OutData = DecompressedData;
                                }
                            }

                            // See if we want to extract subarchives
                            if (extractExtracted.Checked)
                            {
                                Archive archiveTemp = new Archive(OutData, OutFile);
                                if (archiveTemp.Format != ArchiveFormat.NULL)
                                {
                                    string AddFile = String.Empty;
                                    if (extractDirSameFilename.Checked && deleteSourceArchive.Checked)
                                        AddFile = fileList[i] + Path.DirectorySeparatorChar + OutFile;
                                    else
                                        AddFile = OutDirectory + Path.DirectorySeparatorChar + OutFile;

                                    fileList.Add(AddFile);
                                    status.AddFile(AddFile);
                                }
                            }

                            // Output an image
                            if (unpackImage.Checked)
                            {
                                Images images = new Images(OutData, OutFile);
                                if (images.Format != GraphicFormat.NULL)
                                    imageFileList.Add(OutDirectory + Path.DirectorySeparatorChar + OutFile); // Add this to the image conversion list (in case we need a palette file)
                            }

                            // Write the file
                            using (FileStream OutputStream = new FileStream(OutDirectory + Path.DirectorySeparatorChar + OutFile, FileMode.Create, FileAccess.Write))
                                OutputStream.Write(OutData);
                        }
                    }

                    // Process image conversion now
                    if (unpackImage.Checked && imageFileList.Count > 0)
                    {
                        // Reset the local file count
                        status.CurrentFileLocal = 0;
                        status.TotalFilesLocal = imageFileList.Count;

                        for (int j = 0; j < imageFileList.Count; j++)
                        {
                            status.CurrentFileLocal = j;

                            string InFileBitmap       = Path.GetFileName(imageFileList[j]);
                            string InDirectoryBitmap  = Path.GetDirectoryName(imageFileList[j]);
                            string OutFileBitmap      = Path.GetFileNameWithoutExtension(InFileBitmap) + ".png";
                            string OutDirectoryBitmap = InDirectoryBitmap;

                            // Load the file
                            using (FileStream InputStream = new FileStream(imageFileList[j], FileMode.Open, FileAccess.Read))
                            {
                                Images images = new Images(InputStream, Path.GetFileName(imageFileList[j]));
                                if (images.Format != GraphicFormat.NULL)
                                {
                                    if (!convertSameDir.Checked)
                                        OutDirectoryBitmap = InDirectoryBitmap + Path.DirectorySeparatorChar + images.OutputDirectory;

                                    // Start the conversion
                                    Bitmap ImageData = null;
                                    try
                                    {
                                        ImageData = images.Unpack();
                                    }
                                    catch (GraphicFormatNeedsPalette)
                                    {
                                        // We need a palette file
                                        if (File.Exists(InDirectoryBitmap + Path.DirectorySeparatorChar + images.PaletteFilename))
                                        {
                                            using (FileStream InStreamPalette = new FileStream(InDirectoryBitmap + Path.DirectorySeparatorChar + images.PaletteFilename, FileMode.Open, FileAccess.Read))
                                            {
                                                images.Decoder.PaletteData = InStreamPalette;
                                                ImageData = images.Unpack();
                                            }
                                        }
                                    }
                                    catch
                                    {
                                        continue;
                                    }

                                    // Output the image
                                    if (ImageData != null)
                                    {
                                        if (!Directory.Exists(OutDirectoryBitmap))
                                            Directory.CreateDirectory(OutDirectoryBitmap);

                                        ImageData.Save(OutDirectoryBitmap + Path.DirectorySeparatorChar + OutFileBitmap, ImageFormat.Png);
                                    }
                                }
                            }

                            if (deleteSourceImage.Checked &&
                                File.Exists(InDirectoryBitmap + Path.DirectorySeparatorChar + InFileBitmap) &&
                                File.Exists(OutDirectoryBitmap + Path.DirectorySeparatorChar + OutFileBitmap))
                                File.Delete(InDirectoryBitmap + Path.DirectorySeparatorChar + InFileBitmap);
                        }
                    }

                    // Delete the source archive now
                    if (deleteSourceArchive.Checked && File.Exists(fileList[i]))
                    {
                        File.Delete(fileList[i]);
                        if (extractDirSameFilename.Checked)
                        {
                            // If the source and destination directory are on the same volume we can just move the directory
                            if (Directory.GetDirectoryRoot(OutDirectory) == Directory.GetDirectoryRoot(fileList[i]))
                                Directory.Move(OutDirectory, fileList[i]);
                            // Otherwise we have to do a series of complicated file moves
                            else
                                MoveDirectory(new DirectoryInfo(OutDirectory), new DirectoryInfo(fileList[i]));
                        }
                    }
                }
                catch
                {
                    // Something went wrong. Continue please.
                    continue;
                }
            }

            // Close the status box now
            status.Close();
            this.Close();
        }