Пример #1
0
        static int Main(string[] args)
        {
            waitHandle = new AutoResetEvent(false);
            GZipCompressor compressor = new GZipCompressor(waitHandle);

            token = CustomCancellationTokenSource.GetToken();
            compressor.OnCompressionComplete        += compressor_OnCompressionComplete;
            compressor.OnCompressionProgressChanged += compressor_OnProgressChanged;
            Console.CancelKeyPress += Console_CancelKeyPress;
            jobResult = 0;
            try
            {
                SourceFileName = args[1];
                EndFileName    = args[2];
                switch (args[0].ToLower())
                {
                case "compress":
                    compressor.Compress(SourceFileName, EndFileName);
                    break;

                case "decompress":
                    compressor.Decompress(SourceFileName, EndFileName);
                    break;

                default:
                    throw new NotSupportedException();
                }
            }
            catch (NotSupportedException)
            {
                Console.WriteLine("Unknown method!");
                ShowHelp();
                waitHandle.Set();
                jobResult = 1;
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("Not enought parameters!");
                ShowHelp();
                waitHandle.Set();
                jobResult = 1;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ShowHelp();
                waitHandle.Set();
                jobResult = 1;
            }
            waitHandle.WaitOne();
            return(jobResult);
        }
Пример #2
0
 public int Decompress(string sourceFile, string destFile)
 {
     return(this.Decompress(sourceFile, destFile, CustomCancellationTokenSource.GetToken()));
 }