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
5 changes: 5 additions & 0 deletions Core/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.IO;
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
using System.Threading.Tasks;

namespace LocalAdmin.V2.Core;
Expand All @@ -14,6 +15,10 @@ private static async Task Main(string[] args)
while (true)
{
using var la = new LocalAdmin();

iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
if (File.Exists("laargs.txt"))
StartupArgManager.MigrateArgsFile();

await la.Start(StartupArgManager.MergeStartupArgs(args));
}
// ReSharper disable once FunctionNeverReturns
Expand Down
25 changes: 23 additions & 2 deletions Core/StartupArgManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +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"/>
/// </summary>
Expand All @@ -37,5 +36,27 @@ public static string[] MergeStartupArgs(IEnumerable<string> cmdArgs)
return startupArgs.ToArray();
}
}

public static void MigrateArgsFile()
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
{
try
{
string OldFileLocation = "laargs.txt";
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved

if (!File.Exists(StartupArgsPath)) { return; }
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
if (string.IsNullOrEmpty(File.ReadAllText(OldFileLocation)) || string.IsNullOrWhiteSpace(File.ReadAllText(OldFileLocation)))
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
File.Delete(OldFileLocation);

File.Delete(StartupArgsPath);
File.WriteAllText(StartupArgsPath, File.ReadAllText(OldFileLocation));
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
File.Delete(OldFileLocation);

return;
iamalexrouse marked this conversation as resolved.
Show resolved Hide resolved
}
catch (Exception ex)
{
ConsoleUtil.WriteLine($"An error occured while trying to migrate laargs.txt: {ex}", ConsoleColor.Red);
}
}
}
}
Loading