From 15b0c44f1c7160d407e6c298a24031f597a2be43 Mon Sep 17 00:00:00 2001 From: Scrim <105956702+scrim-dev@users.noreply.github.com> Date: Thu, 6 Jun 2024 12:12:49 -0400 Subject: [PATCH] Update and New functions Added network reset and stuff, also more regedit stuff. Won't be making a GUI edition because it is pointless. --- VRC-Deep-Clean/GlobalSuppressions.cs | 1 + VRC-Deep-Clean/Program.cs | 22 ++++-------- VRC-Deep-Clean/Utils/Batch.cs | 41 ++++++++++++++++------- VRC-Deep-Clean/Utils/CleanerUtils.cs | 4 +-- VRC-Deep-Clean/Utils/CustomLog.cs | 4 --- VRC-Deep-Clean/Utils/NetworkUtils.cs | 50 ++++++++++++++++++++++++++++ VRC-Deep-Clean/Utils/UpdateUtils.cs | 24 +++++++++++++ VRC-Deep-Clean/Utils/VRC.cs | 29 ++++++++++++++++ VRC-Deep-Clean/VRC-Deep-Clean.csproj | 8 +++++ 9 files changed, 148 insertions(+), 35 deletions(-) create mode 100644 VRC-Deep-Clean/Utils/NetworkUtils.cs create mode 100644 VRC-Deep-Clean/Utils/UpdateUtils.cs diff --git a/VRC-Deep-Clean/GlobalSuppressions.cs b/VRC-Deep-Clean/GlobalSuppressions.cs index 978b81c..daed3d3 100644 --- a/VRC-Deep-Clean/GlobalSuppressions.cs +++ b/VRC-Deep-Clean/GlobalSuppressions.cs @@ -8,3 +8,4 @@ [assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "", Scope = "member", Target = "~M:VRC_Deep_Clean.Program.Main(System.String[])")] [assembly: SuppressMessage("Style", "IDE0060:Remove unused parameter", Justification = "", Scope = "member", Target = "~M:VRC_Deep_Clean.Program.Main(System.String[])")] [assembly: SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "", Scope = "member", Target = "~M:VRC_Deep_Clean.Utils.CleanerUtils.RegDelete(System.String)")] +[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "", Scope = "member", Target = "~M:VRC_Deep_Clean.Utils.CustomLog._Thread(System.Boolean)")] diff --git a/VRC-Deep-Clean/Program.cs b/VRC-Deep-Clean/Program.cs index 16b33ba..c1798bd 100644 --- a/VRC-Deep-Clean/Program.cs +++ b/VRC-Deep-Clean/Program.cs @@ -8,11 +8,11 @@ internal class Program { private static void Main(string[] args) { + //Entry Console.Title = string.Empty; Console.OutputEncoding = Encoding.UTF8; -#pragma warning disable CS8622 + AppDomain.CurrentDomain.ProcessExit += OnProcessExit; -#pragma warning restore CS8622 Console.SetWindowSize(120, 35); @@ -21,7 +21,7 @@ private static void Main(string[] args) Batch.Create(); VRC.KillPotentialProcesses(); - Thread.Sleep(3000); + Thread.Sleep(3500); MainMenu: //Default jump Console.Clear(); @@ -30,18 +30,11 @@ private static void Main(string[] args) CustomLog.Msg("Welcome! Please select an option:"); CustomLog.Msg("↓↓↓\n\n[1] Delete and Clean up ALL of VRChat | [2] Delete, Uninstall, Clean ALL of VRChat and Reinstall | " + - "[3] Simple Reinstall"); - - /* - * CustomLog.Msg("↓↓↓\n\n[1] Delete and Clean up ALL of VRChat | [2] Delete, Uninstall, Clean ALL of VRChat and Reinstall | " + - "[3] Simple Reinstall | [4] Use GUI"); - */ + "[3] Simple Reinstall | [4] Check for Updates"); try { -#pragma warning disable CS8604 int selection = int.Parse(Console.ReadLine()); -#pragma warning restore CS8604 switch (selection) { case 1: @@ -103,9 +96,8 @@ private static void Main(string[] args) Quit(); break; case 4: - //Will do in a later update - Console.Clear(); - Thread.Sleep(1); + //Swapped out the GUI edition cuz its kinda pointless + UpdateUtils.Check(); goto MainMenu; default: Console.Clear(); @@ -131,12 +123,10 @@ private static void Main(string[] args) Quit(); } - //Better quit than just clicking X private static void OnProcessExit(object sender, EventArgs e) { Quit(); } private static void Quit() { - CustomLog.SaveLogs(); CustomLog.SetWorkingTitle("Shutting down app..."); Console.Clear(); CustomLog.Warn("Goodbye! :D"); diff --git a/VRC-Deep-Clean/Utils/Batch.cs b/VRC-Deep-Clean/Utils/Batch.cs index d9c7ad4..36eef90 100644 --- a/VRC-Deep-Clean/Utils/Batch.cs +++ b/VRC-Deep-Clean/Utils/Batch.cs @@ -8,11 +8,13 @@ namespace VRC_Deep_Clean.Utils { internal class Batch { + private static int VRCid { get; } = 0; public static readonly string BatchFolder = Directory.GetCurrentDirectory() + "\\Bat"; public static readonly string StartVRCBatNoVR = BatchFolder + "\\StartVRC_NoVR.bat"; public static readonly string StartVRCBatVR = BatchFolder + "\\StartVRC_VR.bat"; public static readonly string InstallVRC = BatchFolder + "\\Install.bat"; public static readonly string UninstallVRC = BatchFolder + "\\Uninstall.bat"; + public static readonly string OpenGH = BatchFolder + "\\GH.bat"; public static void Create() { @@ -30,61 +32,76 @@ public static void Create() //novr try { - File.WriteAllText(StartVRCBatNoVR, "start steam://rungameid/438100 -novr"); + File.WriteAllText(StartVRCBatNoVR, $"start steam://rungameid/{VRCid} -novr"); if(File.Exists(StartVRCBatNoVR)) { - CustomLog.Log("Batch file 1/4 created"); + CustomLog.Log("Batch file 1/5 created"); } } catch { - CustomLog.Error("Failed to write batch file 1/4"); + CustomLog.Error("Failed to write batch file 1/5"); } //vrmode try { - File.WriteAllText(StartVRCBatVR, "start steam://rungameid/438100 -vrmode"); + File.WriteAllText(StartVRCBatVR, $"start steam://rungameid/{VRCid} -vrmode"); if (File.Exists(StartVRCBatVR)) { - CustomLog.Log("Batch file 2/4 created"); + CustomLog.Log("Batch file 2/5 created"); } } catch { - CustomLog.Error("Failed to write batch file 2/4"); + CustomLog.Error("Failed to write batch file 2/5"); } //Install try { - File.WriteAllText(InstallVRC, "start steam://install/438100"); + File.WriteAllText(InstallVRC, $"start steam://install/{VRCid}"); if (File.Exists(InstallVRC)) { - CustomLog.Log("Batch file 3/4 created"); + CustomLog.Log("Batch file 3/5 created"); } } catch { - CustomLog.Error("Failed to write batch file 3/4"); + CustomLog.Error("Failed to write batch file 3/5"); } //Uninstall try { - File.WriteAllText(UninstallVRC, "start steam://uninstall/438100"); + File.WriteAllText(UninstallVRC, $"start steam://uninstall/{VRCid}"); if (File.Exists(UninstallVRC)) { - CustomLog.Log("Batch file 4/4 created"); + CustomLog.Log("Batch file 4/5 created"); } } catch { - CustomLog.Error("Failed to write batch file 4/4"); + CustomLog.Error("Failed to write batch file 4/5"); + } + + //Github redirect + try + { + File.WriteAllText(OpenGH, $"start https://github.com/scrim-dev/VRC-Deep-Clean/releases"); + + if (File.Exists(OpenGH)) + { + CustomLog.Log("Batch file 5/5 created"); + } + } + catch + { + CustomLog.Error("Failed to write batch file 5/5"); } CustomLog.SetWorkingTitle(string.Empty); diff --git a/VRC-Deep-Clean/Utils/CleanerUtils.cs b/VRC-Deep-Clean/Utils/CleanerUtils.cs index 45e01c0..532df40 100644 --- a/VRC-Deep-Clean/Utils/CleanerUtils.cs +++ b/VRC-Deep-Clean/Utils/CleanerUtils.cs @@ -51,9 +51,7 @@ public static void RegDelete(string key) try { Registry.CurrentUser.DeleteSubKeyTree(key); - bool keyExists = Registry.CurrentUser.OpenSubKey(key) != null; - - if (!keyExists) + if (Registry.CurrentUser.OpenSubKey(key) != null) { CustomLog.Log("Registry key deleted / removed!"); } diff --git a/VRC-Deep-Clean/Utils/CustomLog.cs b/VRC-Deep-Clean/Utils/CustomLog.cs index 7b6425a..515f37d 100644 --- a/VRC-Deep-Clean/Utils/CustomLog.cs +++ b/VRC-Deep-Clean/Utils/CustomLog.cs @@ -7,10 +7,6 @@ internal class CustomLog { //255, 41, 126 - secondary color //187, 28, 255 - main color - public static void SaveLogs() - { - //Need to fix this later - } public static string ConsoleTitle { get; set; } = "VRC Deep Clean"; private static string? ConsoleWorkTitleThing { get; set; } diff --git a/VRC-Deep-Clean/Utils/NetworkUtils.cs b/VRC-Deep-Clean/Utils/NetworkUtils.cs new file mode 100644 index 0000000..d4565db --- /dev/null +++ b/VRC-Deep-Clean/Utils/NetworkUtils.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VRC_Deep_Clean.Utils +{ + internal class NetworkUtils + { + public static void Reset() + { + DoCommand("ipconfig /release"); + DoCommand("ipconfig /renew"); + DoCommand("netsh winsock reset"); + DoCommand("netsh int ip reset"); + } + + private static void DoCommand(string command) + { + CustomLog.Warn("Doing a network reset..."); + CustomLog.Log($"Command: {command}"); + + ProcessStartInfo PSI = new("cmd", "/c " + command) + { + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true + }; + + using Process process = new(); + process.StartInfo = PSI; + process.Start(); + + string output = process.StandardOutput.ReadToEnd(); + string error = process.StandardError.ReadToEnd(); + + process.WaitForExit(); + + if (process.ExitCode != 0) + { + CustomLog.Error($"{command} failed!\nError: {error}"); + } + + CustomLog.Log(output); + } + } +} diff --git a/VRC-Deep-Clean/Utils/UpdateUtils.cs b/VRC-Deep-Clean/Utils/UpdateUtils.cs new file mode 100644 index 0000000..40583f1 --- /dev/null +++ b/VRC-Deep-Clean/Utils/UpdateUtils.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace VRC_Deep_Clean.Utils +{ + internal class UpdateUtils + { + public static void Check() + { + //Manual cuz I'm lowkey lazy + Console.Clear(); + CustomLog.Logo(); + CustomLog.SetWorkingTitle("Redirecting to github..."); + CustomLog.Log("Opening github..."); + try { Process.Start(Batch.OpenGH); } + catch { CustomLog.Error("Failed to redirect to github please visit manually at my website or: https://github.com/scrim-dev/VRC-Deep-Clean/releases"); } + Thread.Sleep(4000); + } + } +} diff --git a/VRC-Deep-Clean/Utils/VRC.cs b/VRC-Deep-Clean/Utils/VRC.cs index 8bd0713..27838c6 100644 --- a/VRC-Deep-Clean/Utils/VRC.cs +++ b/VRC-Deep-Clean/Utils/VRC.cs @@ -114,6 +114,27 @@ public static void Clean() #endregion #region Local + + if (Directory.Exists(LocalPath + "\\log")) + { + CustomLog.Warn($"Found: Logging local path, attempting to delete..."); + CleanerUtils.Delete(LocalPath + "\\log"); + } + else + { + CustomLog.Error("Logging local folder doesn't exist (it's probably deleted already or missing)"); + } + + if (Directory.Exists(LocalPath + "\\CrashDumps")) + { + CustomLog.Warn($"Found: CrashDumper local path, attempting to delete..."); + CleanerUtils.Delete(LocalPath + "\\CrashDumps"); + } + else + { + CustomLog.Error("CrashDumper local folder doesn't exist (it's probably deleted already or missing)"); + } + if (Directory.Exists(LocalPath + "\\VRChatCreatorCompanion")) { CustomLog.Warn($"Found: VRCCC (Creator Companion) local path, attempting to delete..."); @@ -194,9 +215,17 @@ public static void Clean() CleanerUtils.RegDelete(@"Software\VRChat"); Thread.Sleep(1000); + CleanerUtils.RegDelete(@"Software\VCC"); + Thread.Sleep(1000); + CleanerUtils.RegDelete(@"Software\Unity\UnityEditor\DefaultCompany"); + Thread.Sleep(1000); + CleanerUtils.RegDelete(@"Software\Valve\Steam\Apps\438100"); //438100 - VRChat App ID + Thread.Sleep(1000); CustomLog.Warn("Flushing DNS..."); FlushDNS(); + CustomLog.Warn("Doing other network resets..."); + NetworkUtils.Reset(); CustomLog.Log("Clean up completed!"); Thread.Sleep(4500); diff --git a/VRC-Deep-Clean/VRC-Deep-Clean.csproj b/VRC-Deep-Clean/VRC-Deep-Clean.csproj index f98e245..6fbecd5 100644 --- a/VRC-Deep-Clean/VRC-Deep-Clean.csproj +++ b/VRC-Deep-Clean/VRC-Deep-Clean.csproj @@ -18,6 +18,14 @@ 0.0.0.0 + + 1701;1702;8604;8622;8622 + + + + 1701;1702;8604;8622;8622 + +