private static bool ProcessFile(RunParameters runParameters, int fileCount, string formatString, ConvertFileData file, ref int errors) { if (fileCount > 1) { if (Console.KeyAvailable) { //read key available to skip Console.ReadKey(true); Print(WarningColor, "Key pressed, press Escape to stop or any other key to continue..."); var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Escape) { return(false); } } if (runParameters.LogErrorsOnly) { Print(WarningColor, $"Processing file {file.Index.ToString(formatString)}/{fileCount}", true); } else { Print(WarningColor, file.GetDescription(fileCount, formatString)); } } try { var result = file.Mode switch { ProcessMode.Unpack => Unpack(file), ProcessMode.Pack => Pack(file), ProcessMode.UnpackAndPack => UnpackAndPack(file), _ => throw new ArgumentOutOfRangeException() }; if (!result) { errors++; } } catch (Exception ex) { errors++; Print(ErrorColor, $"\t{file.GetDescription(fileCount, formatString)} - Failed: {ex}"); } return(true); }
private static void ProcessFileParallel(ConvertFileData file, bool logErrorsOnly) { try { var success = file.Mode switch { ProcessMode.Unpack => Unpack(file), ProcessMode.Pack => Pack(file), ProcessMode.UnpackAndPack => UnpackAndPack(file), _ => throw new ArgumentOutOfRangeException() }; if (!success || !logErrorsOnly) { Print(success ? SuccessColor : ErrorColor, $"\t{file.GetDescription(null, null)}"); } } catch (Exception ex) { Print(ErrorColor, $"\t{file.GetDescription(null,null)} - Failed: {ex}"); } }