Exemplo n.º 1
0
        /// <summary>
        /// Use this function to debug and test work.
        /// It compresses and decomresses file and then compares results by md5 hash
        /// </summary>
        /// <returns></returns>
        private static int Test(string inputFilePath, string compressedFilePath, string decompressedFilePath)
        {
            IFileArchiver archiver = new FileArchiver();

            try
            {
                var startTime = DateTime.Now;
                Console.WriteLine($"File {inputFilePath} is compressing, please wait...");
                archiver.Compress(inputFilePath, compressedFilePath);
                Console.WriteLine("Compressing time: " + DateTime.Now.Subtract(startTime).TotalMilliseconds);
                startTime = DateTime.Now;
                Console.WriteLine($"File {compressedFilePath} is decompressing, please wait...");
                archiver.Decompress(compressedFilePath, decompressedFilePath);
                Console.WriteLine("Decompressing time: " + DateTime.Now.Subtract(startTime).TotalMilliseconds);

                Console.WriteLine($"File {inputFilePath} was processed successfully. Result files located in {compressedFilePath} and {decompressedFilePath}");

                Console.WriteLine("Files equality check: " + CheckFilesEqual(inputFilePath, decompressedFilePath));
                File.Delete(compressedFilePath);
                File.Delete(decompressedFilePath);
                return(0);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Unexpected error during processing file: " + ex.Message);
                Console.WriteLine(ex.StackTrace);
                Console.WriteLine("Execution aborted");

                return(1);
            }
        }
Exemplo n.º 2
0
        private static int Decompress(string inputPath, string outputPath)
        {
            IFileArchiver archiver = new FileArchiver();

            try
            {
                Console.WriteLine("File {0} is decompressing, please wait...", inputPath);
                if (!ValidateFiles(inputPath, outputPath))
                {
                    return(1);
                }
                archiver.Decompress(inputPath, outputPath);
                Console.WriteLine("File {0} was decompressed successfully. Result file located in {1}", inputPath, outputPath);
                Console.ReadLine();
                return(0);
            }
            catch (Exception ex)
            {
                CancelOperation(outputPath, ex.Message);
                return(1);
            }
        }