Skip to content

Commit

Permalink
add: add guided run if no arguments are provided
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsShamed committed Jun 14, 2022
1 parent bb8bea4 commit 9eb2799
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
### What's new?

* __If you run the executable without arguments (e.g: from the file explorer), you'll be guided on providing
the arguments it needs via prompts.__
* The program now checks for duplicate collections and will ask you if you want to continue if it finds one.
You can also disable this behaviour by passing the `--skip-duplicate-check` flag.
* Backups now include the date in the filename to not overwrite the old ones.
Expand Down
3 changes: 2 additions & 1 deletion OsuPackImporter/Collections/Collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public virtual byte[] Serialize(ProgressContext? context = null)
/// </summary>
public virtual void Rename()
{
var newName = AnsiConsole.Ask<string>($"Rename collection {Name} (leave empty for default): ");
var newName = AnsiConsole.Ask($"Rename collection {Name} [gray](leave empty for default)[/]",
Name!);
if (!string.IsNullOrWhiteSpace(newName)) Name = newName;
}
}
67 changes: 66 additions & 1 deletion OsuPackImporter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,78 @@ public static class Program

public static void Main(string[] args)
{
if (args.Length == 0 && AnsiConsole.Confirm("Did you meant to run the program without arguments? " +
"(e.g: you opened the program from the file explorer)"))
{
GuidedRun(ref args);
}

_parserResult = Parser.Default.ParseArguments<Options>(args);

_parserResult
.WithParsed(o => Environment.Exit(Run(o)))
.WithNotParsed(e => Environment.Exit(FailRun(e, _parserResult)));
}

private static void GuidedRun(ref string[] args)
{
List<string> tempArgs = new List<string>();
string inputPath = AnsiConsole.Ask<string>("Enter the path to the beatmap pack " +
"[gray](you can also drag the file in the console)[/]:");
if (String.IsNullOrWhiteSpace(inputPath))
return;
tempArgs.Add(inputPath);

if (AnsiConsole.Confirm("Do you want to export it as a .osdb file?", false))
{
string osdbFolderPath = AnsiConsole.Ask(
"Enter the path of the folder where the .osdb " +
"file will be saved [gray](you can also drag the folder in the console)[/]",
Directory.GetCurrentDirectory());
while (!Directory.Exists(osdbFolderPath))
{
Logging.Log("Could not find the specified folder.", LogLevel.Error);
osdbFolderPath = AnsiConsole.Ask(
"Enter the path of the folder where the .osdb " +
"file will be saved [gray](you can also drag the folder in the console)[/]",
Directory.GetCurrentDirectory());
}

string osdbFileName = AnsiConsole.Ask("Enter the name of the file", "collection.osdb");
if (!osdbFileName.EndsWith(".osdb")) osdbFileName += ".osdb";
string osdbPath = osdbFolderPath + "\\" + osdbFileName;
while (File.Exists(osdbPath))
{
Logging.Log("This file already exists.");
if (!AnsiConsole.Confirm("Do you want to overwrite this file?", false))
{
osdbFileName = AnsiConsole.Ask("Enter the name of the file", "collection.osdb");
if (!osdbFileName.EndsWith(".osdb")) osdbFileName += ".osdb";
osdbPath = osdbFolderPath + "\\" + osdbFileName;
}
}

tempArgs.Add("--osdb");
tempArgs.Add(osdbPath);
}
else
{
if (!AnsiConsole.Confirm("Do you want to automatically import the beatmaps in osu!?"))
{
tempArgs.Add("--no-import");
}
}

args = tempArgs.ToArray();
Logging.Log("The program will now start with the following arguments:");
Logging.Log("OsuPackImporter " + String.Join(' ', args));
if (!AnsiConsole.Confirm("Are you okay with this?"))
{
Logging.Log("Aborting...", LogLevel.Error);
Environment.Exit(1);
}
}

private static int Run(Options options)
{
if (options.InputPath == null)
Expand Down Expand Up @@ -147,7 +212,7 @@ private static int RunLegacyConversion(ExtendedCollection inputCollection, strin

Logging.Log("Backing up existing collection.db...");

File.Copy("collection.db", "collection.db.OLD_"
File.Copy("collection.db", "collection.db.OLD_"
+ DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"));
using (var stream = File.Create(@"collection.db"))
{
Expand Down

0 comments on commit 9eb2799

Please sign in to comment.