mirror of
https://github.com/jkocon/g-helper.git
synced 2026-02-23 13:00:52 +01:00
Fix to prevent config corruption
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using GHelper.Mode;
|
using GHelper.Mode;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Management;
|
using System.Management;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
|
|
||||||
@@ -13,6 +12,7 @@ public static class AppConfig
|
|||||||
private static string? _bios;
|
private static string? _bios;
|
||||||
|
|
||||||
private static Dictionary<string, object> config = new Dictionary<string, object>();
|
private static Dictionary<string, object> config = new Dictionary<string, object>();
|
||||||
|
private static System.Timers.Timer timer = new System.Timers.Timer(1000);
|
||||||
|
|
||||||
static AppConfig()
|
static AppConfig()
|
||||||
{
|
{
|
||||||
@@ -52,8 +52,39 @@ public static class AppConfig
|
|||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timer.Elapsed += Timer_Elapsed;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void Timer_Elapsed(object? sender, System.Timers.ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
|
||||||
|
timer.Stop();
|
||||||
|
string jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
||||||
|
var backup = configFile + ".bak";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File.WriteAllText(backup, jsonString);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Logger.WriteLine(ex.ToString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.Sleep(500);
|
||||||
|
|
||||||
|
if (File.ReadAllText(backup).Contains("}"))
|
||||||
|
{
|
||||||
|
File.Copy(backup, configFile, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Logger.WriteLine("Error writing config");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetModel()
|
public static string GetModel()
|
||||||
{
|
{
|
||||||
@@ -157,16 +188,7 @@ public static class AppConfig
|
|||||||
|
|
||||||
private static void Write()
|
private static void Write()
|
||||||
{
|
{
|
||||||
string jsonString = JsonSerializer.Serialize(config, new JsonSerializerOptions { WriteIndented = true });
|
timer.Start();
|
||||||
try
|
|
||||||
{
|
|
||||||
File.WriteAllText(configFile + ".bak", jsonString);
|
|
||||||
File.Copy(configFile + ".bak", configFile, true);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Debug.Write(e.ToString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void Set(string name, int value)
|
public static void Set(string name, int value)
|
||||||
|
|||||||
@@ -556,7 +556,7 @@ public class AsusACPI
|
|||||||
|
|
||||||
public bool IsNVidiaGPU()
|
public bool IsNVidiaGPU()
|
||||||
{
|
{
|
||||||
return (!IsAllAmdPPT() && Program.acpi.DeviceGet(GPUEco) >= 0);
|
return (!IsAllAmdPPT() && Program.acpi.DeviceGet(GPUEco) >= 0 && !AppConfig.IsAlly());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAPUMem(int memory = 4)
|
public void SetAPUMem(int memory = 4)
|
||||||
|
|||||||
Reference in New Issue
Block a user