Esempio n. 1
0
        protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pGzipExtractorStruct, DoWorkEventArgs e)
        {
            GzipExtractorStruct gzipExtractorStruct = (GzipExtractorStruct)pGzipExtractorStruct;

            this.progressStruct.Clear();

            if (gzipExtractorStruct.DoDecompress)
            {
                progressStruct.GenericMessage = String.Format("Decompressing <{0}>{1}", pPath, Environment.NewLine);
            }
            else
            {
                progressStruct.GenericMessage = String.Format("Compressing <{0}>{1}", pPath, Environment.NewLine);
            }
            ReportProgress(this.Progress, progressStruct);

            try
            {
                string outputFileName;

                if (gzipExtractorStruct.DoDecompress)
                {
                    outputFileName = Path.ChangeExtension(pPath, CompressionUtil.GzipDecompressOutputExtension);
                }
                else
                {
                    outputFileName = Path.ChangeExtension(pPath, CompressionUtil.GzipCompressOutputExtension);
                }

                using (FileStream fs = File.OpenRead(pPath))
                {
                    if (gzipExtractorStruct.StartingOffset > fs.Length)
                    {
                        throw new ArgumentOutOfRangeException("Starting Offset", "Offset cannot be greater than the file size.");
                    }

                    if (gzipExtractorStruct.DoDecompress)
                    {
                        CompressionUtil.DecompressGzipStreamToFile(fs, outputFileName, gzipExtractorStruct.StartingOffset);
                    }
                    else
                    {
                        CompressionUtil.CompressStreamToGzipFile(fs, outputFileName, gzipExtractorStruct.StartingOffset);
                    }
                }

                this.progressStruct.Clear();
                if (gzipExtractorStruct.DoDecompress)
                {
                    progressStruct.GenericMessage = String.Format("    {0} decompressed.{1}", Path.GetFileName(outputFileName), Environment.NewLine);
                }
                else
                {
                    progressStruct.GenericMessage = String.Format("    {0} compressed.{1}", Path.GetFileName(outputFileName), Environment.NewLine);
                }

                ReportProgress(this.Progress, progressStruct);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string inFilename;
            string outFilename;
            string startOffset;

            string fullInputPath;
            string fullOutputPath;

            long longStartOffset;

            if (args.Length < 2)
            {
                Console.WriteLine("Usage: gzipext.exe <infile> <outfile> <start offset>");
                Console.WriteLine("   or: gzipext.exe <infile> <outfile>");
                Console.WriteLine();
                Console.WriteLine("The 2 parameter option will set <start offset> to 0.");
            }
            else
            {
                inFilename  = args[0];
                outFilename = args[1];

                if (args.Length < 3)
                {
                    startOffset = "0";
                }
                else
                {
                    startOffset = args[2];
                }

                fullInputPath  = Path.GetFullPath(inFilename);
                fullOutputPath = Path.GetFullPath(outFilename);

                if (File.Exists(fullInputPath))
                {
                    using (FileStream fs = File.OpenRead(fullInputPath))
                    {
                        if (startOffset.StartsWith("0x"))
                        {
                            startOffset     = startOffset.Substring(2);
                            longStartOffset = long.Parse(startOffset, System.Globalization.NumberStyles.HexNumber, null);
                        }
                        else
                        {
                            longStartOffset = long.Parse(startOffset, System.Globalization.NumberStyles.Integer, null);
                        }

                        if (longStartOffset > fs.Length)
                        {
                            Console.WriteLine(String.Format("Sorry that start offset is larger than the entire file: {0}", fs.Length.ToString()));
                        }
                        else
                        {
                            try
                            {
                                CompressionUtil.DecompressGzipStreamToFile(fs, fullOutputPath, longStartOffset);
                            }
                            catch (Exception)
                            {
                                Console.WriteLine(String.Format("Cannot decompress <{0}>.", fullInputPath));
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("File Not Found: " + fullInputPath);
                }
            }
        }