Exemple #1
0
        public static int DoCompress(string infile, MemoryStream output, FormatCompress format, out FormatCompress actualFormat)
        {
            CompressionFormat fmt = null;
            switch (format)
            {
                case FormatCompress.LZ10: fmt = new LZ10(); break;
                case FormatCompress.LZ11: fmt = new LZ11(); break;
                case FormatCompress.LZOVL: fmt = new LZOvl(); break;
                case FormatCompress.RLE: fmt = new RLE(); break;
                case FormatCompress.HUFF4: Huffman.CompressBlockSize = Huffman.BlockSize.FOURBIT; fmt = new Huffman(); break;
                case FormatCompress.HUFF8: Huffman.CompressBlockSize = Huffman.BlockSize.EIGHTBIT; fmt = new Huffman(); break;
                case FormatCompress.HUFF:
                    return CompressHuff(infile, output, out actualFormat);
                case FormatCompress.GBA:
                    return CompressGBA(infile, output, out actualFormat);
                case FormatCompress.NDS:
                    return CompressNDS(infile, output, out actualFormat);
                default:
                    actualFormat = FormatCompress.Invalid;
                    return -1;
            }
            actualFormat = format;

            using (FileStream inStream = File.OpenRead(infile))
            {
                try
                {
                    return fmt.Compress(inStream, inStream.Length, output);
                }
                catch (Exception s)
                {
                    // any exception generated by compression is a fatal exception
                    Console.WriteLine(s.Message);
                    return -1;
                }
            }
        }