private static int Decompress(DecompressConfiguration configuration) { if (!File.Exists(configuration.Input)) { Console.WriteLine("Входной файл не существует"); return(1); } var decompressor = new Decompressor(); decompressor.Decompress(configuration.Input, configuration.Output, ChunkSize); return(0); }
/// <summary> /// Choose necessary mode and start process /// </summary> private static void LaunchZip() { if (mode == CompressionMode.Compress) { using (var compressor = new Compressor()) { compressor.Compress(pathFileOriginal, pathFileResult); } } else { using (var decompressor = new Decompressor()) { decompressor.Decompress(pathFileOriginal, pathFileResult); } } }
static int Main(string[] args) { if (args.Length != 3) { Console.WriteLine("Invalid argument count."); Console.WriteLine(Usage); return(1); } var inputFilePath = args[1]; if (!File.Exists(inputFilePath)) { Console.WriteLine("Input file does not exist."); return(1); } var outFilePath = args[2]; try { Path.GetFileName(outFilePath); } catch { Console.WriteLine("Invalid output file name."); return(1); } if (File.Exists(outFilePath)) { Console.WriteLine("Output file already exists. Specify a new file name."); return(1); } switch (args[0]) { case "compress": var compressor = new Compressor(inputFilePath, FilePartitioner.GetRecommendedChunkSize(inputFilePath), outFilePath); try { compressor.Compress(); } catch (Exception e) { Debug.WriteLine(e); Console.WriteLine($"Unexpected error occured: {e.Message}."); return(1); } break; case "decompress": var decompressor = new Decompressor(inputFilePath, outFilePath); try { decompressor.Decompress(); } catch (Exception e) { Debug.WriteLine(e); Console.WriteLine($"Unexpected error occured: {e.Message}."); return(1); } break; default: Console.WriteLine("Cannot parse arguments."); Console.WriteLine(Usage); return(1); } return(0); }