private static Hg3Args RequestConvertHg3Args(Game game, IntArgs?intArgs = null)
        {
            Hg3Args args = new Hg3Args()
            {
                Game = game,
            };

            if (game != null)
            {
                Console.WriteLine($"Convert {game.Name()} Hg3s to Pngs:");
            }
            else
            {
                Console.WriteLine($"Convert Hg3s to Pngs:");
            }

            bool parseSuccess;

            string defInputDir  = settings.Directories.IntDirectory;
            string defOutputDir = settings.Directories.Hg3Directory;

            if (game == Game.All)
            {
                defInputDir = ".";
            }
            else if (game != null)
            {
                defInputDir  = Path.Combine(game.Name(), defInputDir);
                defOutputDir = Path.Combine(game.Name(), defOutputDir);
            }
            if (!intArgs.HasValue)
            {
                do
                {
                    if (game == Game.All)
                    {
                        defInputDir = ".";
                        Console.Write("Input Directory (Before game name): ");
                        WriteWatermark("<current directory>");
                    }
                    else
                    {
                        Console.Write("Input Directory: ");
                        WriteWatermark(defInputDir);
                    }
                    args.InputDir = ReadDirectory(defInputDir, out parseSuccess);
                } while (!parseSuccess);

                if (game == Game.All)
                {
                    defInputDir = settings.Directories.IntDirectory;
                    do
                    {
                        Console.Write("Input Directory (After game name): ");
                        WriteWatermark(defInputDir);
                        args.InputDirAfter = ReadRelativePath(defInputDir, out parseSuccess);
                    } while (!parseSuccess);
                }
            }
            else
            {
                args.InputDir      = intArgs.Value.OutputDir;
                args.InputDirAfter = intArgs.Value.OutputDirAfter;
            }

            /*do {
             *      Console.Write("Output Directory: ");
             *      WriteWatermark(defOutputDir);
             *      args.OutputDir = ReadDirectory(defOutputDir, out parseSuccess);
             * } while (!parseSuccess);*/

            do
            {
                if (game == Game.All)
                {
                    defOutputDir = ".";
                    Console.Write("Output Directory (Before game name): ");
                    WriteWatermark("<current directory>");
                }
                else
                {
                    Console.Write("Output Directory: ");
                    WriteWatermark(defOutputDir);
                }
                args.OutputDir = ReadDirectory(defOutputDir, out parseSuccess);
            } while (!parseSuccess);

            if (game == Game.All)
            {
                defOutputDir = settings.Directories.Hg3Directory;
                do
                {
                    Console.Write("Output Directory (After game name): ");
                    WriteWatermark(defOutputDir);
                    args.OutputDirAfter = ReadRelativePath(defOutputDir, out parseSuccess);
                } while (!parseSuccess);
            }

            do
            {
                Console.Write("Search Pattern: ");
                WriteWatermark("(none)");
                args.Pattern = ReadPattern("", out parseSuccess);
            } while (!parseSuccess);

            do
            {
                Console.Write("Sorting (sorted/unsorted/both): ");
                WriteWatermark("sorted");
                args.Sorting = ReadSorting(Hg3Sorting.Sorted, out parseSuccess);
            } while (!parseSuccess);

            do
            {
                Console.Write("Stop on Error (y/n): ");
                WriteWatermark("no");
                args.StopOnError = ReadYesNo(false, out parseSuccess);
            } while (!parseSuccess);


            return(args);
        }
Ejemplo n.º 2
0
        private static bool ConvertHg3s(Hg3Args args, LogInfo log)
        {
            Console.Clear();
            DrawLogo();
            WriteLog(log, false);
            if (args.Game != null)
            {
                Console.WriteLine($"Converting {args.Game.Name()} Hg3s to Pngs:");
            }
            else
            {
                Console.WriteLine("Converting Hg3s to Pngs:");
            }
            LogMessage(log, "Converting Hg3s to Pngs", args.Game);

            string inputDir = args.InputDir;

            if (!string.IsNullOrEmpty(args.InputDirAfter))
            {
                inputDir = Path.Combine(args.InputDir,
                                        args.Game.Name(), args.InputDirAfter);
            }
            string outputDir = args.OutputDir;

            if (!string.IsNullOrEmpty(args.OutputDirAfter))
            {
                outputDir = Path.Combine(args.OutputDir,
                                         args.Game.Name(), args.OutputDirAfter);
            }

            int  line           = Console.CursorTop;
            int  lastLineLength = 0;
            bool error          = false;

            Extracting.ExtractHg3s(inputDir, outputDir, args.Sorting,
                                   args.Pattern,
                                   (a) => {
                WriteProgress(line, ref lastLineLength, a);
                return(false);
            },
                                   (ex, a) => {
                if (!error)
                {
                    LogMessage(log, $"Error on {a.FileName}: {ex.Message}", args.Game);
                    log.WriteLine(ex.ToString());
                    if (args.StopOnError)
                    {
                        a.TotalErrors = 0;
                        WriteProgress(line, ref lastLineLength, a);
                        Console.WriteLine();
                        WriteError(ex);
                        Beep(300, 750);
                        Thread.Sleep(1500);
                        log.GamesFailed.Add(args.Game);
                        LogMessage(log, "Stopping due to error!");
                        return(true);
                    }
                    else
                    {
                        log.GamesWithErrors.Add(args.Game);
                    }
                }
                error = true;
                WriteProgress(line, ref lastLineLength, a);
                return(false);
            });

            if (!error && !args.StopOnError)
            {
                LogMessage(log, "Finished!");
                Beep();
            }

            return(!error);
        }
Ejemplo n.º 3
0
        private static void Run(string[] args)
        {
            Console.Clear();
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Gray;
            Console.Title           = "Grisaia Extract (Ripping written by asmodean)";
            DrawLogo();
            settings = new UserSettings();
            settings.Load();
            if (!string.IsNullOrWhiteSpace(settings.Directories.CurrentDirectory) &&
                !PathHelper.IsValidDirectory(settings.Directories.CurrentDirectory))
            {
                WriteError("CurrentDirectory ini setting is not valid!");
                settings.Directories.CurrentDirectory = "";
            }
            if (!PathHelper.IsValidRelativePath(settings.Directories.IntDirectory))
            {
                WriteError("IntDirectory ini setting is not valid!");
                settings.Directories.IntDirectory = "Raw";
            }
            if (!PathHelper.IsValidRelativePath(settings.Directories.Hg3Directory))
            {
                WriteError("IntDirectory ini setting is not valid!");
                settings.Directories.Hg3Directory = "Hg3";
            }
            foreach (var pair in settings.GameLocations.Paths)
            {
                if (pair.Value == null)
                {
                    continue;
                }
                if (!PathHelper.IsValidDirectory(pair.Value))
                {
                    WriteError($"{pair.Key} ini setting is not valid!");
                    Locator.SetPath(null, pair.Key);
                }
            }
            if (!string.IsNullOrWhiteSpace(settings.Directories.CurrentDirectory))
            {
                Directory.CreateDirectory(settings.Directories.CurrentDirectory);
                Directory.SetCurrentDirectory(settings.Directories.CurrentDirectory);
            }
            bool parseSuccess;

            bool hg3    = false;
            bool resort = false;

            do
            {
                Console.Write("What to Extract (int/hg3/resort): ");
                string input = ReadLine();
                parseSuccess = true;
                if (input.Equals2("int", true))
                {
                    hg3 = false;
                }
                else if (input.Equals2("hg3", true))
                {
                    hg3 = true;
                }
                else if (input.Equals2("resort", true))
                {
                    resort = true;
                }
                else
                {
                    WriteError("Invalid choice!");
                    parseSuccess = false;
                }
            } while (!parseSuccess);
            Game    game    = ReadGame(hg3 || resort);
            IntArgs intArgs = new IntArgs();
            Hg3Args hg3Args = new Hg3Args();
            PngArgs pngArgs = new PngArgs();
            bool    alsoHg3 = false;

            if (resort)
            {
                pngArgs = RequestResortPngArgs(game);
            }
            else if (!hg3)
            {
                intArgs = RequestExtractIntArgs(game);

                if (intArgs.IsImage)
                {
                    do
                    {
                        Console.Write("Convert hg3s afterwords (y/n): ");
                        alsoHg3 = ReadYesNo(null, out parseSuccess);
                    } while (!parseSuccess);
                }
            }
            if (hg3 || alsoHg3)
            {
                if (alsoHg3)
                {
                    hg3Args = RequestConvertHg3Args(game, intArgs);
                }
                else
                {
                    hg3Args = RequestConvertHg3Args(game);
                }
            }
            using (LogInfo log = new LogInfo()) {
                if (game != Game.All)
                {
                    RipGame(game, hg3, alsoHg3, resort, intArgs, hg3Args, pngArgs, log);
                }
                else
                {
                    foreach (Game located in Locator.LocateGames(out _))
                    {
                        RipGame(located, hg3, alsoHg3, resort, intArgs, hg3Args, pngArgs, log);
                    }
                }

                if (log.OperationsComplete > 1)
                {
                    Console.Clear();
                    DrawLogo();
                    WriteLog(log, true);
                }
            }
        }
Ejemplo n.º 4
0
 private static void RipGame(Game game, bool hg3, bool alsoHg3, bool resort,
                             IntArgs intArgs, Hg3Args hg3Args, PngArgs pngArgs, LogInfo log)
 {
     if (resort)
     {
         pngArgs.Game = game;
         ResortPngs(pngArgs, log);
         log.OperationsComplete++;
         log.GamesComplete++;
     }
     else if (!hg3)
     {
         intArgs.Game = game;
         // Continue to the next process on success
         string inputDir = intArgs.InputDir;
         if (string.IsNullOrEmpty(intArgs.InputDir))
         {
             inputDir = intArgs.Game?.Path;
         }
         string[] intFiles = Directory.GetFiles(inputDir, intArgs.IntFile);
         if (intFiles.Length == 0)
         {
             LogMessage(log, $"No int files found matching `{intArgs.IntFile}`!", game);
             WriteError($"No int files found matching `{intArgs.IntFile}`!");
             Beep(300, 750);
             Thread.Sleep(1500);
             log.GamesFailed.Add(game);
             log.OperationsComplete++;
         }
         else
         {
             bool error = false;
             for (int i = 0; i < intFiles.Length; i++)
             {
                 string intFile = Path.GetFileName(intFiles[i]);
                 intArgs.IntFile = intFile;
                 if (!ExtractIntFile(intArgs, log))
                 {
                     error = true;
                 }
                 log.OperationsComplete++;
             }
             if (!error)
             {
                 if (alsoHg3)
                 {
                     hg3 = true;
                 }
                 else
                 {
                     log.GamesComplete++;
                 }
             }
         }
     }
     if (hg3)
     {
         hg3Args.Game = game;
         if (ConvertHg3s(hg3Args, log))
         {
             log.GamesComplete++;
         }
         log.OperationsComplete++;
     }
 }