66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
global using System;
|
|
global using DTLib.Console;
|
|
global using DTLib.Demystifier;
|
|
global using DTLib.Filesystem;
|
|
global using Directory = DTLib.Filesystem.Directory;
|
|
global using File = DTLib.Filesystem.File;
|
|
using ParadoxSaveParser.CLI;
|
|
|
|
try
|
|
{
|
|
Mode mode = Mode.Unset;
|
|
IOPath? inputPath = null;
|
|
IOPath? outputPath = null;
|
|
string? searchQuery = null;
|
|
|
|
new LaunchArgumentParser(
|
|
new LaunchArgument(["-i", "--input"],
|
|
"Set input file path",
|
|
s => inputPath = s,
|
|
"gamestate or zip file"),
|
|
|
|
new LaunchArgument(["-o", "--output"],
|
|
"Set output file path",
|
|
s => outputPath = s,
|
|
"json file [default=stdout]"),
|
|
|
|
new LaunchArgument(["-s", "--search"],
|
|
"Search in input file",
|
|
s =>
|
|
{
|
|
searchQuery = s;
|
|
mode = Mode.Search;
|
|
},
|
|
"search expression")
|
|
)
|
|
.WithNoExit()
|
|
.ParseAndHandle(args);
|
|
|
|
if (args.Length == 0)
|
|
mode = Mode.Interactive;
|
|
|
|
switch (mode)
|
|
{
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(mode));
|
|
case Mode.Unset:
|
|
throw new Exception("No action specified");
|
|
case Mode.Search:
|
|
if (string.IsNullOrEmpty(searchQuery))
|
|
throw new ArgumentException("Search expression is required");
|
|
if (inputPath is null)
|
|
throw new ArgumentException("Input file path is required");
|
|
Modes.Search(searchQuery, inputPath.Value, outputPath);
|
|
break;
|
|
case Mode.Interactive:
|
|
Modes.Interactive();
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
ColoredConsole.WriteLine(ex.ToStringDemystified(), ConsoleColor.Red);
|
|
Console.ResetColor();
|
|
Environment.Exit(1);
|
|
}
|
|
Console.ResetColor(); |