Exemple #1
0
        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);
        }
Exemple #2
0
 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}");
     }
 }
Exemple #3
0
 private static bool Unpack(ConvertFileData file)
 {
     var(inputFile, outputFile, _, _) = file;
     return(Algorithm.Unpack(inputFile, outputFile, file.ProcessData));
 }
Exemple #4
0
 private static bool Pack(ConvertFileData file)
 {
     var(inputFile, outputFile, agfFile, _) = file;
     return(Algorithm.Unpack(agfFile, null, file.ProcessData) && Algorithm.Pack(inputFile, outputFile, file.ProcessData));
 }
Exemple #5
0
 private static bool UnpackAndPack(ConvertFileData file)
 {
     var(inputFile, outputFile, _, intermediateBmp) = file;
     return(Algorithm.Unpack(inputFile, intermediateBmp, file.ProcessData) && Algorithm.Pack(intermediateBmp, outputFile, file.ProcessData));
 }