public static ArchivingSettings GetSettingsFromArguments(string[] args) { if (args == null || args.Length < 3) throw new ArgumentException("Wrong arguments count"); ArchivingSettings result; switch (args[0]) { case TypeCompress: result = new ArchivingSettings { Mode = CompressionMode.Compress, File = args[1], Archive = args[2] }; break; case TypeDecompress: result = new ArchivingSettings { Mode = CompressionMode.Decompress, File = args[2], Archive = args[1] }; break; default: throw new ArgumentException("Wrong action argument"); } CheckFiles(result); return result; }
private static void CheckFiles(ArchivingSettings settings) { if ((settings.Mode == CompressionMode.Compress && !File.Exists(settings.File)) || (settings.Mode == CompressionMode.Decompress && !File.Exists(settings.Archive))) throw new FileNotFoundException("Input file does not exist"); if ((settings.Mode == CompressionMode.Compress && File.Exists(settings.Archive)) || (settings.Mode == CompressionMode.Decompress && File.Exists(settings.File))) throw new Exception("Output file already exist"); }