static void Main(string[] args) { var stopwatch = Stopwatch.StartNew(); var appParams = new ApplicationParams.ApplicationParams(); try { appParams.ParseCommandLineParams(args); CheckFileParams(appParams); switch (appParams.OperationType) { case OperationType.Compress: Compress(appParams.SourceFilePath, appParams.TargetFilePath); break; case OperationType.Decompress: Decompress(appParams.SourceFilePath, appParams.TargetFilePath); break; default: Compress(appParams.SourceFilePath, appParams.TargetFilePath); break; } } catch (Exception e) { if (e is IndexOutOfRangeException || e is OutOfMemoryException) { Console.WriteLine("Недостаточно места на диске."); } else { Console.WriteLine(e); } } Console.WriteLine($"Elapsed time: {stopwatch.ElapsedMilliseconds} ms."); Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
/// <summary> /// Проверить переданные файлы на доступность. /// </summary> private static void CheckFileParams(ApplicationParams.ApplicationParams appParams) { if (!File.Exists(appParams.SourceFilePath)) { throw new FileNotFoundException("Source file not found or not accessible"); } var path = Path.GetDirectoryName(appParams.TargetFilePath); if (string.IsNullOrEmpty(path) || !Directory.Exists(path)) { throw new DirectoryNotFoundException("Target directory not exists or not accessible"); } if (File.Exists(appParams.TargetFilePath)) { try { File.Delete(appParams.TargetFilePath); } catch (Exception e) { throw new Exception("Can`t delete existing target file", e); } } }