Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Commit

Permalink
added a confirm option for risky options, better FileMenuOptions hand…
Browse files Browse the repository at this point in the history
…ling
  • Loading branch information
Creationsss committed Oct 21, 2023
1 parent 5fd0865 commit 4c62ef2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 37 deletions.
6 changes: 5 additions & 1 deletion Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Program
{
{"disclaimer", "true"},
{"autoInject", "false"},
{"confirmOptions", "true"},
{"autoInjectDelay", "45000"}
};

Expand Down Expand Up @@ -271,9 +272,12 @@ public static void ReloadFileOptions()
string autoInject = Settings["autoInject"] .Equals("true") ? "Auto inject: enabled" : "Auto inject: disabled";
StandFileOptions = StandFileOptions.Append(autoInject).ToArray();

string? ShowDisclaimer = (IniFile?.ReadValue("Settings", "disclaimer")?.Equals("true") ?? false) ? "Show disclaimer: enabled\n" : "Show disclaimer: disabled\n";
string? ShowDisclaimer = (IniFile?.ReadValue("Settings", "disclaimer")?.Equals("true") ?? false) ? "Show disclaimer: enabled" : "Show disclaimer: disabled";
StandFileOptions = StandFileOptions.Append(ShowDisclaimer).ToArray();

string? ConfirmOptions = (IniFile?.ReadValue("Settings", "confirmOptions")?.Equals("true") ?? false) ? "Confirm options: enabled\n" : "Confirm options: disabled\n";
StandFileOptions = StandFileOptions.Append(ConfirmOptions).ToArray();

string? autoInjectDelay = IniFile?.ReadValue("Settings", "autoInjectDelay") ?? null;
if (autoInjectDelay != null)
{
Expand Down
100 changes: 64 additions & 36 deletions handlers/OptionsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace StandCLI.Handlers
public partial class MenuOptionsHandler
{
private static int selectedOption = 0;
public static string CurrentMenu = String.Empty;
public static string CurrentMenu = string.Empty;

public static void MenuOptions(string Option)
{
Expand Down Expand Up @@ -168,6 +168,15 @@ public static void HandleMainMenuOptions(int optionIndex)
}
}

private static bool ToggleIniSetting(string section, string key)
{
string currentValue = Program.IniFile?.ReadValue(section, key) ?? "true";
bool isTrue = currentValue == "true";
bool toggledValue = !isTrue;
Program.IniFile?.SetValue(section, key, toggledValue ? "true" : "false");
return toggledValue;
}

public static void HandleStandFileMenuOptions(int optionIndex)
{
Console.Clear();
Expand All @@ -178,33 +187,38 @@ public static void HandleStandFileMenuOptions(int optionIndex)
if (optionIndex >= 0 && optionIndex < sv_length.Length)
{
string[] sv_split = sv_length[optionIndex].Split(" ");
if (sv_length[optionIndex] == "Auto inject: disabled")
string CurrentOption = sv_length[optionIndex].Replace("\n", String.Empty);

if (CurrentOption.Contains("Back"))
{
selectedOption = 0;
MenuOptions("MainMenu");
return;
}
else if(CurrentOption.StartsWith("Auto inject:"))
{
Program.Settings["autoInject"] = "true";
Program.IniFile?.SetValue("Settings", "autoInject", "true");
Task.Run(() => AutoInjection.AutoInject());
bool toggle = ToggleIniSetting("Settings", "autoInject");
if(toggle) Task.Run(() => AutoInjection.AutoInject());
Program.Settings["autoInject"] = toggle.ToString().ToLower();
skipReadKey = true;
}
else if (sv_length[optionIndex] == "Auto inject: enabled")
else if (CurrentOption.StartsWith("Show disclaimer:"))
{
Program.Settings["autoInject"] = "false";
Program.IniFile?.SetValue("Settings", "autoInject", "false");
ToggleIniSetting("Settings", "disclaimer");
skipReadKey = true;
}
else if (sv_length[optionIndex].Contains("Back"))
else if (CurrentOption.StartsWith("Confirm options:"))
{
selectedOption = 0;
MenuOptions("MainMenu");
return;
ToggleIniSetting("Settings", "confirmOptions");
skipReadKey = true;
}

else if(sv_length[optionIndex].StartsWith("Auto inject delay:"))
else if(CurrentOption.StartsWith("Auto inject delay:"))
{
string[] local_split = sv_length[optionIndex].Split(":");
string[] local_split = CurrentOption.Split(":");
int delay = int.Parse(local_split[1].Replace("ms", String.Empty).Trim());

Console.Clear();
Console.WriteLine("Please enter the new delay in milliseconds:\n");
Console.WriteLine("Please enter the new delay in milliseconds:");

string? newDelay = Console.ReadLine();
if (string.IsNullOrWhiteSpace(newDelay) || !int.TryParse(newDelay, out int newDelayInt))
Expand All @@ -224,10 +238,10 @@ public static void HandleStandFileMenuOptions(int optionIndex)
Program.ReloadFileOptions();
skipReadKey = true;
}
else if(sv_length[optionIndex].StartsWith("GTA Path:"))
else if(CurrentOption.StartsWith("GTA Path:"))
{
Console.Clear();
Console.WriteLine("Please enter the Grand Theft Auto V path:\n");
Console.WriteLine("Please enter the Grand Theft Auto V path:");
string? gtaPath = Console.ReadLine();
if (string.IsNullOrWhiteSpace(gtaPath))
{
Expand All @@ -242,48 +256,41 @@ public static void HandleStandFileMenuOptions(int optionIndex)
}
else
{
Console.WriteLine("\nThe path you entered does not exist.");
Console.WriteLine("The path you entered does not exist.");
}
}
}
else if (sv_length[optionIndex].StartsWith("StandCLI Logs and Settings:"))
else if (CurrentOption.StartsWith("StandCLI Logs and Settings:"))
{
Process.Start("explorer.exe", Program.StandCLIFolder);
skipReadKey = true;
}
else if(sv_length[optionIndex].StartsWith("Stand Folder:"))
else if(CurrentOption.StartsWith("Stand Folder:"))
{
Process.Start("explorer.exe", Program.StandFolder);
skipReadKey = true;
}
else if (sv_length[optionIndex] == "Show disclaimer: enabled\n")
{
Program.IniFile?.SetValue("Settings", "disclaimer", "false");
skipReadKey = true;
}
else if (sv_length[optionIndex] == "Show disclaimer: disabled\n")
{
Program.IniFile?.SetValue("Settings", "disclaimer", "true");
skipReadKey = true;
}
else if(sv_length[optionIndex] == "Delete Stand Temp Folder")
else if(CurrentOption == "Delete Stand Temp Folder")
{
if(!ConfirmOption("delete the stand temp folder")) return;
if (FolderExists.CheckFolderExists(Path.Combine(Program.StandBinFolder, "Temp"), false) != "null")
{
Directory.Delete(Path.Combine(Program.StandBinFolder, "Temp"), true);
Console.WriteLine("Deleted Stand Temp Folder");
}
}
else if(sv_length[optionIndex] == "Delete Stand Folder")
else if(CurrentOption == "Delete Stand Folder")
{
if(!ConfirmOption("delete the stand folder")) return;
if (FolderExists.CheckFolderExists(Program.StandFolder, false) != "null")
{
Directory.Delete(Program.StandFolder, true);
Console.WriteLine("Deleted Stand Folder");
}
}
else if(sv_length[optionIndex] == "Delete All stand versions\n")
else if(CurrentOption == "Delete All stand versions")
{
if(!ConfirmOption("delete all stand versions")) return;
if (FolderExists.CheckFolderExists(Program.StandBinFolder, false) != "null")
{
foreach (string file in Directory.GetFiles(Program.StandBinFolder, "Stand_*.dll"))
Expand All @@ -294,9 +301,10 @@ public static void HandleStandFileMenuOptions(int optionIndex)
Console.WriteLine("Deleted All stand versions");
}
}
else if(sv_length[optionIndex].StartsWith("Delete Stand DLL"))
else if(CurrentOption.StartsWith("Delete Stand DLL"))
{
string ToDelete = Regex.Replace(sv_split[3], @"\(([^)]*)\)", "$1").Trim();
if(!ConfirmOption($"delete Stand {ToDelete}")) return;
if (File.Exists(Path.Combine(Program.StandBinFolder, $"Stand_{ToDelete}.dll")))
{
File.Delete(Path.Combine(Program.StandBinFolder, $"Stand_{ToDelete}.dll"));
Expand All @@ -321,6 +329,24 @@ public static void HandleStandFileMenuOptions(int optionIndex)
}
}

public static bool ConfirmOption(string Option)
{
string ConfirmOptions = Program.IniFile?.ReadValue("Settings", "confirmOptions") ?? "true";
if(ConfirmOptions == "false") return true;

Console.Clear();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine($"Are you sure you want to {Option}?");
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Press y to confirm or any other key to cancel\n");
Console.ResetColor();
Console.CursorVisible = true;
ConsoleKey key = Console.ReadKey(true).Key;
Console.Clear();
Console.CursorVisible = false;
return key.ToString().ToLower() == "y";
}

public static int ReturnLength(string Option)
{
Dictionary<string, object> menus = Program.ReturnMenus();
Expand Down Expand Up @@ -396,7 +422,7 @@ public static void HandleLauncherOptions(int optionIndex)
Console.Clear();
if(gtaPath == null || !Directory.Exists(gtaPath))
{
Console.WriteLine("Please enter the Grand Theft Auto V path:\n");
Console.WriteLine("Please enter the Grand Theft Auto V path:");
gtaPath = Console.ReadLine();
}

Expand Down Expand Up @@ -431,6 +457,7 @@ public static void HandleLauncherOptions(int optionIndex)
}
else if(option.Equals("Reinstall Launcher"))
{
if(!ConfirmOption("reinstall the launcher")) return;
string ReinstallLauncher = LauncherCreation.ReinstallLauncher();

Console.Clear();
Expand All @@ -440,6 +467,7 @@ public static void HandleLauncherOptions(int optionIndex)
}
else if(option.Equals("Delete Launcher"))
{
if(!ConfirmOption("delete the launcher")) return;
string DeleteLauncher = LauncherCreation.DeleteLauncher();
Program.IniFile?.DeleteValue("Settings", "launcherPath");

Expand Down

0 comments on commit 4c62ef2

Please sign in to comment.