Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move laargs.txt to more suitable location. #83

Merged
merged 15 commits into from
Dec 12, 2023
32 changes: 31 additions & 1 deletion Core/StartupArgManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public static class StartupArgManager
/// <summary>
/// Path to startup arguments file.
/// </summary>
private const string StartupArgsPath = "laargs.txt";
private static readonly string StartupArgsPath = Path.Combine(PathManager.ConfigPath, "laargs.txt");
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Merges Command-line arguments and arguments in <paramref name="cmdArgs"/>
Expand All @@ -20,6 +20,8 @@ public static class StartupArgManager
/// <returns>Merged Arguments</returns>
public static string[] MergeStartupArgs(IEnumerable<string> cmdArgs)
{
MigrateArgsFile();

List<string> startupArgs = new List<string>();
startupArgs.AddRange(cmdArgs);

Expand All @@ -37,5 +39,33 @@ public static string[] MergeStartupArgs(IEnumerable<string> cmdArgs)
return startupArgs.ToArray();
}
}

private static void MigrateArgsFile()
{
const string ObsoleteFile = "laargs.txt";

try
{
if (File.Exists(ObsoleteFile) && string.IsNullOrWhiteSpace(File.ReadAllText(ObsoleteFile)))
{
File.Delete(ObsoleteFile);
ConsoleUtil.WriteLine("Obsolete configuration file 'laargs.txt' is empty and has been deleted.");
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if (File.Exists(StartupArgsPath))
{
ConsoleUtil.WriteLine("Unable to migrate your old 'laargs' configuration. The destination file already exists.");
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
return;
}

File.Move(ObsoleteFile, StartupArgsPath);
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
ConsoleUtil.WriteLine("Successfully migrated your old 'laargs' configuration.");
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
}
catch (Exception ex)
{
ConsoleUtil.WriteLine($"An error occurred during migration: {ex}");
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
Loading