Skip to content

Commit

Permalink
Added the last known IP in vars.json and in the GUI, reading and writ…
Browse files Browse the repository at this point in the history
…ing this value in this file
  • Loading branch information
Sergey004 committed Apr 28, 2024
1 parent 074059f commit 29e0642
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
22 changes: 21 additions & 1 deletion Quest2-VRC.Core/Services/Check_Vars.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json.Linq;
using System;
using System.IO;
using System.Net;

namespace Quest2_VRC
{
Expand All @@ -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());
Expand All @@ -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"]);

}

}
}
2 changes: 1 addition & 1 deletion Quest2-VRC.Core/Services/Sender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

namespace Quest2_VRC
{
static class Sender
public static class Sender
{
public class Global
{
Expand Down
4 changes: 3 additions & 1 deletion Quest2-VRC.GUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class MainWindow : MaterialForm
{
public MainWindow()
{

string lastip = null;
ResourceManager resources = new ComponentResourceManager(typeof(MainWindow));
InitializeComponent();
materialTextBox1.Enabled = false;
Expand All @@ -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);

}

Expand Down Expand Up @@ -323,6 +324,7 @@ private void Form1_FormClosing(object sender, FormClosingEventArgs e)
}
else
{
Check_Vars.WriteJSON(materialTextBox1.Text);
File.Delete("odtout.txt");
ADB.StopADB();
}
Expand Down
12 changes: 6 additions & 6 deletions Quest2-VRC.GUI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,22 @@ 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");
GUI();
}
if (forceeng == false && enhancedoculuscontrol == true)
{
Notify_service.NotfyStarting();

OculusStaff.DisableASW();
OculusStaff.HighPriority();
var tasks = new[]
Expand All @@ -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();
Expand All @@ -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);
Expand Down

0 comments on commit 29e0642

Please sign in to comment.