private static PngArgs RequestResortPngArgs(Game game)
        {
            PngArgs args = new PngArgs()
            {
                Game = game,
            };

            if (game != null)
            {
                Console.WriteLine($"Resort {game.Name()} Pngs:");
            }
            else
            {
                Console.WriteLine($"Resort Pngs:");
            }
            WriteWarning("This will attempt to resort EVERY png found in the specified directory. " +
                         "Make extra sure that you do not input the wrong directory.");
            Console.WriteLine();

            bool parseSuccess;

            string defOutputDir = settings.Directories.Hg3Directory;

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

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

            return(args);
        }
Exemplo n.º 2
0
        private static bool ResortPngs(PngArgs args, LogInfo log)
        {
            Console.Clear();
            DrawLogo();
            WriteLog(log, false);
            if (args.Game != null)
            {
                Console.WriteLine($"Resorting {args.Game.Name()} Pngs:");
            }
            else
            {
                Console.WriteLine("Resorting Pngs:");
            }
            LogMessage(log, "Resorting Pngs", args.Game);

            string resortDir = args.ResortDir;

            if (!string.IsNullOrEmpty(args.ResortDirAfter))
            {
                resortDir = Path.Combine(args.ResortDir,
                                         args.Game.Name(), args.ResortDirAfter);
            }

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

            Extracting.ResortPngs(resortDir,
                                  (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);
        }
Exemplo 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);
                }
            }
        }
Exemplo 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++;
     }
 }