static void GetParameters( string[] args, out FileInfo flacExec, out FileInfo sourceFile, out int compressionLevel) { var argumentDictionary = ArgumentSplitter.GetArguments(args); var @params = ParameterReader.GetParameters(argumentDictionary); if (string.IsNullOrEmpty(@params.SourceFile)) { throw new Exception("Source file not provided"); } sourceFile = new FileInfo(@params.SourceFile); flacExec = new FileInfo(@params.FlacExec); compressionLevel = @params.CompressionLevel ?? maxCompressionLevel; }
static int Main(string[] args) { Settings settings; try { var settingsFile = new FileInfo(settingsFileName); settings = SettingsProvider.GetSettings(settingsFile); } catch (Exception e) { Console.WriteLine($"Failure reading a settings file. {e.Message}"); return((int)ReturnValue.SettingsReadingFailure); } Parameters parameters; try { var argumentDictionary = ArgumentSplitter.GetArguments(args); parameters = ParameterReader.GetParameters(argumentDictionary); } catch (CmdLineArgNotFoundException e) { Console.Error.WriteLine(e.Message); return((int)ReturnValue.ArgumentNotFound); } catch (Exception e) { Console.Error.WriteLine(e.Message); return((int)ReturnValue.ArgumentError); } try { FileInfo decoderFile = ExecutionParameterResolver.GetDecoder(settings, parameters); string outputFomat = ExecutionParameterResolver.ResolveOutputFormat(settings, parameters); int processTimeoutSec = ExecutionParameterResolver.GetProcessTimeoutInSeconds(settings, parameters, processTimeoutSecDefault); IList <FileInfo> inputFiles = ExecutionParameterResolver.GetInputFiles(parameters); var decoder = new IO.Audio.Flac.CmdLine.FileDecoder( decoderFile, new ExternalProcess.ProcessRunner(processTimeoutSec)); var hasher = new FileHasher(decoder, new Sha256HashComputer()); var multiHasher = new MultipleFileHasher(hasher); IEnumerable <FileHashResult> hashes = multiHasher .ComputeHashes(inputFiles); // The hashes should be computed on this enumeration, and therefore will be output as they're computed foreach (var entry in hashes) { OutputHash(entry.Hash, outputFomat, entry.File); } ; } catch (ConfigurationException e) { Console.WriteLine(e.Message); return((int)ReturnValue.ConfigurationError); } catch (IO.IOException e) { Console.WriteLine(e.Message); return((int)ReturnValue.InputReadingFailure); } catch (Exception e) { Console.WriteLine(e.Message); return((int)ReturnValue.ExecutionFailure); } Console.Error.WriteLine("Done!"); return((int)ReturnValue.Success); }