Ejemplo n.º 1
0
Archivo: Main.cs Proyecto: MetLob/tinke
        public static void Decompress(string input, string output, FormatCompress format)
        {
            byte[] inData;
            using (FileStream inStream = File.OpenRead(input))
            {
                inData = new byte[inStream.Length];
                inStream.Read(inData, 0, inData.Length);
            }

            MemoryStream decompressedData = new MemoryStream();
            long decSize = -1;
            // just try all formats, and stop once one has been found that can decompress it.
            using (MemoryStream inStream = new MemoryStream(inData))
            {
                decSize = Decompress(inStream, decompressedData, format);
            }
            if (decSize < 0)
            {
                Console.WriteLine(String.Format(Main.Get_Traduction("S1B"), input));
                return;
            }

            byte[] outData = decompressedData.ToArray();
            using (FileStream outStream = File.Create(output))
            {
                outStream.Write(outData, 0, outData.Length);
                Console.WriteLine(String.Format(Main.Get_Traduction("S1C"), format.ToString(), input, output));
            }
        }
Ejemplo n.º 2
0
        public static void Decompress(string input, string output, FormatCompress format)
        {
            byte[] inData;
            using (FileStream inStream = File.OpenRead(input))
            {
                inData = new byte[inStream.Length];
                inStream.Read(inData, 0, inData.Length);
            }

            MemoryStream decompressedData = new MemoryStream();
            long         decSize          = -1;

            // just try all formats, and stop once one has been found that can decompress it.
            using (MemoryStream inStream = new MemoryStream(inData))
            {
                decSize = Decompress(inStream, decompressedData, format);
            }
            if (decSize < 0)
            {
                Console.WriteLine(String.Format(Main.Get_Traduction("S1B"), input));
                return;
            }

            byte[] outData = decompressedData.ToArray();
            using (FileStream outStream = File.Create(output))
            {
                outStream.Write(outData, 0, outData.Length);
                Console.WriteLine(String.Format(Main.Get_Traduction("S1C"), format.ToString(), input, output));
            }
        }
        public CompressionControl(int id, FormatCompress format, IPluginHost pluginHost)
        {
            InitializeComponent();

            this.pluginHost = pluginHost;
            this.id         = id;
            this.format     = format;
            ReadLanguage();

            txtBoxOlderCompress.Text = Enum.GetName(typeof(FormatCompress), format);
            comboFormat.Text         = txtBoxOlderCompress.Text;
            txtBoxNewCompress.Text   = nullString;
        }
        private void comboFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            format = (FormatCompress)Enum.Parse(typeof(FormatCompress), comboFormat.Text);

            if (format == FormatCompress.LZ10 || format == FormatCompress.LZ11 || format == FormatCompress.LZOVL)
            {
                checkLookAhead.Enabled = true;
            }
            else
            {
                checkLookAhead.Enabled = false;
            }
        }
Ejemplo n.º 5
0
        public CompressionControl(int id, FormatCompress format, IPluginHost pluginHost)
        {
            InitializeComponent();

            this.pluginHost = pluginHost;
            this.id = id;
            this.format = format;
            ReadLanguage();

            txtBoxOlderCompress.Text = Enum.GetName(typeof(FormatCompress), format);
            comboFormat.Text = txtBoxOlderCompress.Text;
            txtBoxNewCompress.Text = nullString;
        }
Ejemplo n.º 6
0
Archivo: Main.cs Proyecto: MetLob/tinke
        public static void Compress(string input, string output, FormatCompress format)
        {
            // compress the input
            MemoryStream compressedData = new MemoryStream();
            FormatCompress compressedFormat;
            int outsize = DoCompress(input, compressedData, format, out compressedFormat);
            if (outsize < 0)
                return;

            using (FileStream outStream = File.Create(output))
            {
                compressedData.WriteTo(outStream);
                Console.WriteLine(String.Format(Main.Get_Traduction("S19"), compressedFormat.ToString(), input, output));
            }
        }
Ejemplo n.º 7
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);
                }
            }
        }
Ejemplo n.º 8
0
        public static void Compress(string input, string output, FormatCompress format)
        {
            // compress the input
            MemoryStream   compressedData = new MemoryStream();
            FormatCompress compressedFormat;
            int            outsize = DoCompress(input, compressedData, format, out compressedFormat);

            if (outsize < 0)
            {
                return;
            }

            using (FileStream outStream = File.Create(output))
            {
                compressedData.WriteTo(outStream);
                Console.WriteLine(String.Format(Main.Get_Traduction("S19"), compressedFormat.ToString(), input, output));
            }
        }
Ejemplo n.º 9
0
Archivo: Main.cs Proyecto: MetLob/tinke
        private static int CompressBest(string infile, MemoryStream output, out FormatCompress actualFormat, params FormatCompress[] formats)
        {
            // only read the input data once from the file.
            byte[] inputData;
            using (FileStream inStream = File.OpenRead(infile))
            {
                inputData = new byte[inStream.Length];
                inStream.Read(inputData, 0, inputData.Length);
            }

            MemoryStream bestOutput = null;
            int minCompSize = int.MaxValue;
            actualFormat = FormatCompress.GBA;
            foreach (FormatCompress format in formats)
            {
                #region compress the file in each format, and save the best one

                MemoryStream currentOutput = new MemoryStream();
                CompressionFormat realFormat = null;
                switch (format)
                {
                    case FormatCompress.HUFF4: Huffman.CompressBlockSize = Huffman.BlockSize.FOURBIT; realFormat = new Huffman(); break;
                    case FormatCompress.HUFF8: Huffman.CompressBlockSize = Huffman.BlockSize.EIGHTBIT; realFormat = new Huffman(); break;
                    case FormatCompress.LZ10: realFormat = new LZ10(); break;
                    case FormatCompress.LZ11: realFormat = new LZ11(); break;
                    case FormatCompress.LZOVL: realFormat = new LZOvl(); break;
                    case FormatCompress.RLE: realFormat = new RLE(); break;
                }

                int currentOutSize;
                try
                {
                    using (MemoryStream inStream = new MemoryStream(inputData))
                    {
                        currentOutSize = realFormat.Compress(inStream, inStream.Length, currentOutput);
                    }
                }
                catch (InputTooLargeException i)
                {
                    Console.WriteLine(i.Message);
                    actualFormat = format;
                    return -1;
                }
                catch (Exception)
                {
                    continue;
                }
                if (currentOutSize < minCompSize)
                {
                    bestOutput = currentOutput;
                    minCompSize = currentOutSize;
                    actualFormat = format;
                }

                #endregion
            }

            if (bestOutput == null)
            {
                Console.WriteLine(Main.Get_Traduction("S1A"));
                return -1;
            }
            bestOutput.WriteTo(output);
            return minCompSize;
        }
Ejemplo n.º 10
0
        private void comboFormat_SelectedIndexChanged(object sender, EventArgs e)
        {
            format = (FormatCompress)Enum.Parse(typeof(FormatCompress), comboFormat.Text);

            if (format == FormatCompress.LZ10 || format == FormatCompress.LZ11 || format == FormatCompress.LZOVL)
                checkLookAhead.Enabled = true;
            else
                checkLookAhead.Enabled = false;
        }
Ejemplo n.º 11
0
 public void Compress(string filein, string fileout, FormatCompress format)
 {
     DSDecmp.Main.Compress(filein, fileout, format);
 }
Ejemplo n.º 12
0
 private static int CompressNDS(string infile, MemoryStream output, out FormatCompress actualFormat)
 {
     return(CompressBest(infile, output, out actualFormat, FormatCompress.HUFF4, FormatCompress.HUFF8, FormatCompress.LZ10, FormatCompress.LZ11, FormatCompress.RLE));
 }
Ejemplo n.º 13
0
        private static int CompressBest(string infile, MemoryStream output, out FormatCompress actualFormat, params FormatCompress[] formats)
        {
            // only read the input data once from the file.
            byte[] inputData;
            using (FileStream inStream = File.OpenRead(infile))
            {
                inputData = new byte[inStream.Length];
                inStream.Read(inputData, 0, inputData.Length);
            }

            MemoryStream bestOutput  = null;
            int          minCompSize = int.MaxValue;

            actualFormat = FormatCompress.GBA;
            foreach (FormatCompress format in formats)
            {
                #region compress the file in each format, and save the best one

                MemoryStream      currentOutput = new MemoryStream();
                CompressionFormat realFormat    = null;
                switch (format)
                {
                case FormatCompress.HUFF4: Huffman.CompressBlockSize = Huffman.BlockSize.FOURBIT; realFormat = new Huffman(); break;

                case FormatCompress.HUFF8: Huffman.CompressBlockSize = Huffman.BlockSize.EIGHTBIT; realFormat = new Huffman(); break;

                case FormatCompress.LZ10: realFormat = new LZ10(); break;

                case FormatCompress.LZ11: realFormat = new LZ11(); break;

                case FormatCompress.LZOVL: realFormat = new LZOvl(); break;

                case FormatCompress.RLE: realFormat = new RLE(); break;
                }

                int currentOutSize;
                try
                {
                    using (MemoryStream inStream = new MemoryStream(inputData))
                    {
                        currentOutSize = realFormat.Compress(inStream, inStream.Length, currentOutput);
                    }
                }
                catch (InputTooLargeException i)
                {
                    Console.WriteLine(i.Message);
                    actualFormat = format;
                    return(-1);
                }
                catch (Exception)
                {
                    continue;
                }
                if (currentOutSize < minCompSize)
                {
                    bestOutput   = currentOutput;
                    minCompSize  = currentOutSize;
                    actualFormat = format;
                }

                #endregion
            }

            if (bestOutput == null)
            {
                Console.WriteLine(Main.Get_Traduction("S1A"));
                return(-1);
            }
            bestOutput.WriteTo(output);
            return(minCompSize);
        }
Ejemplo n.º 14
0
        private static long Decompress(MemoryStream inputStream, MemoryStream output, FormatCompress format)
        {
            CompressionFormat realFormat = null;

            switch (format)
            {
            case FormatCompress.HUFF:
                realFormat = new Huffman(); break;

            case FormatCompress.LZ10:
                realFormat = new LZ10(); break;

            case FormatCompress.LZ11:
                realFormat = new LZ11(); break;

            case FormatCompress.LZOVL:
                realFormat = new LZOvl(); break;

            case FormatCompress.RLE:
                realFormat = new RLE(); break;

            default:
                return(-1);
            }
            if (!realFormat.Supports(inputStream, inputStream.Length))
            {
                return(-1);
            }
            try
            {
                return(realFormat.Decompress(inputStream, inputStream.Length, output));
            }
            catch (TooMuchInputException e)
            {
                Console.WriteLine(e.Message);
                return(output.Length);
            }
            catch (Exception e)
            {
                Console.WriteLine(String.Format(Main.Get_Traduction("S1D"), format.ToString(), e.Message));
                return(-1);
            }
        }
Ejemplo n.º 15
0
Archivo: Main.cs Proyecto: MetLob/tinke
 private static long Decompress(MemoryStream inputStream, MemoryStream output, FormatCompress format)
 {
     CompressionFormat realFormat = null;
     switch (format)
     {
         case FormatCompress.HUFF:
             realFormat = new Huffman(); break;
         case FormatCompress.LZ10:
             realFormat = new LZ10(); break;
         case FormatCompress.LZ11:
             realFormat = new LZ11(); break;
         case FormatCompress.LZOVL:
             realFormat = new LZOvl(); break;
         case FormatCompress.RLE:
             realFormat = new RLE(); break;
         default:
             return -1;
     }
     if (!realFormat.Supports(inputStream, inputStream.Length))
         return -1;
     try
     {
         return realFormat.Decompress(inputStream, inputStream.Length, output);
     }
     catch (TooMuchInputException e)
     {
         Console.WriteLine(e.Message);
         return output.Length;
     }
     catch (Exception e)
     {
         Console.WriteLine(String.Format(Main.Get_Traduction("S1D"), format.ToString(), e.Message));
         return -1;
     }
 }
Ejemplo n.º 16
0
Archivo: Main.cs Proyecto: MetLob/tinke
 private static int CompressNDS(string infile, MemoryStream output, out FormatCompress actualFormat)
 {
     return CompressBest(infile, output, out actualFormat, FormatCompress.HUFF4, FormatCompress.HUFF8, FormatCompress.LZ10, FormatCompress.LZ11, FormatCompress.RLE);
 }
Ejemplo n.º 17
0
Archivo: Main.cs Proyecto: MetLob/tinke
 private static int CompressHuff(string infile, MemoryStream output, out FormatCompress actualFormat)
 {
     return CompressBest(infile, output, out actualFormat, FormatCompress.HUFF4, FormatCompress.HUFF8);
 }
Ejemplo n.º 18
0
 private static int CompressHuff(string infile, MemoryStream output, out FormatCompress actualFormat)
 {
     return(CompressBest(infile, output, out actualFormat, FormatCompress.HUFF4, FormatCompress.HUFF8));
 }
Ejemplo n.º 19
0
Archivo: Main.cs Proyecto: MetLob/tinke
        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;
                }
            }
        }
Ejemplo n.º 20
0
 public void Compress(string filein, string fileout, FormatCompress format)
 {
     DSDecmp.Main.Compress(filein, fileout, format);
 }