From 29e064263f6f856fed480d88b9ec041ba9df3f1a Mon Sep 17 00:00:00 2001 From: Sergey004 Date: Sun, 28 Apr 2024 16:18:02 +0400 Subject: [PATCH] Added the last known IP in vars.json and in the GUI, reading and writing this value in this file --- Quest2-VRC.Core/Services/Check_Vars.cs | 22 +++++++++++++++++++++- Quest2-VRC.Core/Services/Sender.cs | 2 +- Quest2-VRC.GUI/MainWindow.cs | 4 +++- Quest2-VRC.GUI/Program.cs | 12 ++++++------ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/Quest2-VRC.Core/Services/Check_Vars.cs b/Quest2-VRC.Core/Services/Check_Vars.cs index 282968e..c623271 100644 --- a/Quest2-VRC.Core/Services/Check_Vars.cs +++ b/Quest2-VRC.Core/Services/Check_Vars.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json.Linq; using System; using System.IO; +using System.Net; namespace Quest2_VRC { @@ -21,7 +22,8 @@ public static void CheckVars() new JProperty("Receive_addr", "/avatar/parameters/Eyes mode"), new JProperty("Receive_addr_test", "/avatar/parameters/Eyes_mode"), new JProperty("SendPort", "9000"), - new JProperty("HostIP", "127.0.0.1")); + new JProperty("HostIP", "127.0.0.1"), + new JProperty("LastKnownIP", "127.0.0.1")); File.WriteAllText(@"vars.json", vars.ToString()); @@ -33,5 +35,23 @@ public static void CheckVars() Console.WriteLine("vars.json exists"); } } + public static void WriteJSON(string lastip) + { + string jsonString = File.ReadAllText("vars.json"); + JObject jObject = Newtonsoft.Json.JsonConvert.DeserializeObject(jsonString) as JObject; + JToken jToken = jObject.SelectToken("LastKnownIP"); + jToken.Replace(lastip); + string updatedJsonString = jObject.ToString(); + File.WriteAllText("vars.json", updatedJsonString); + } + public static string ReadJSON(string lastip) + { + string jsonString = File.ReadAllText("vars.json"); + JObject vars = JObject.Parse(jsonString); + + return _ = ((string)vars["LastKnownIP"]); + + } + } } diff --git a/Quest2-VRC.Core/Services/Sender.cs b/Quest2-VRC.Core/Services/Sender.cs index 1341890..752f631 100644 --- a/Quest2-VRC.Core/Services/Sender.cs +++ b/Quest2-VRC.Core/Services/Sender.cs @@ -15,7 +15,7 @@ namespace Quest2_VRC { - static class Sender + public static class Sender { public class Global { diff --git a/Quest2-VRC.GUI/MainWindow.cs b/Quest2-VRC.GUI/MainWindow.cs index 3088a8f..5025e2d 100644 --- a/Quest2-VRC.GUI/MainWindow.cs +++ b/Quest2-VRC.GUI/MainWindow.cs @@ -19,7 +19,7 @@ public partial class MainWindow : MaterialForm { public MainWindow() { - + string lastip = null; ResourceManager resources = new ComponentResourceManager(typeof(MainWindow)); InitializeComponent(); materialTextBox1.Enabled = false; @@ -37,6 +37,7 @@ public MainWindow() } AdbServer server = new AdbServer(); StartServerResult result = server.StartServer(@"platform-tools\adb.exe", false); + materialTextBox1.Text = Check_Vars.ReadJSON(lastip); } @@ -323,6 +324,7 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e) } else { + Check_Vars.WriteJSON(materialTextBox1.Text); File.Delete("odtout.txt"); ADB.StopADB(); } diff --git a/Quest2-VRC.GUI/Program.cs b/Quest2-VRC.GUI/Program.cs index 040a784..6bb05e1 100644 --- a/Quest2-VRC.GUI/Program.cs +++ b/Quest2-VRC.GUI/Program.cs @@ -42,14 +42,14 @@ static void Handler(bool forceeng, bool enhancedoculuscontrol) { if (forceeng == false && enhancedoculuscontrol == false) { - Notify_service.NotfyStarting(); + Check_Vars.CheckVars(); Console.WriteLine("Logs redirected to main window"); GUI(); } if (forceeng == true && enhancedoculuscontrol == false) { - Notify_service.NotfyStarting(); + Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); Check_Vars.CheckVars(); Console.WriteLine("Logs redirected to main window"); @@ -57,7 +57,7 @@ static void Handler(bool forceeng, bool enhancedoculuscontrol) } if (forceeng == false && enhancedoculuscontrol == true) { - Notify_service.NotfyStarting(); + OculusStaff.DisableASW(); OculusStaff.HighPriority(); var tasks = new[] @@ -70,7 +70,7 @@ static void Handler(bool forceeng, bool enhancedoculuscontrol) } if (forceeng == true && enhancedoculuscontrol == true) { - Notify_service.NotfyStarting(); + Thread.CurrentThread.CurrentUICulture = new CultureInfo("en"); OculusStaff.DisableASW(); OculusStaff.HighPriority(); @@ -95,14 +95,14 @@ static void GUI() if (processes.Length > 1) { - + Application.EnableVisualStyles(); MessageBox.Show("Only one instance of the program can be opened!", System.Reflection.Assembly.GetExecutingAssembly().GetName().Name, MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(1987); } else { - + Notify_service.NotfyStarting(); Application.EnableVisualStyles(); Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.SetCompatibleTextRenderingDefault(false);