Skip to content

Commit d8293f3

Browse files
committed
(Fix_)
1 parent 92574ee commit d8293f3

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace Bloxstrap.Integrations
5+
{
6+
internal static class AutoOptimizeService
7+
{
8+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
9+
private struct MEMORYSTATUSEX
10+
{
11+
public uint dwLength;
12+
public uint dwMemoryLoad;
13+
public ulong ullTotalPhys;
14+
public ulong ullAvailPhys;
15+
public ulong ullTotalPageFile;
16+
public ulong ullAvailPageFile;
17+
public ulong ullTotalVirtual;
18+
public ulong ullAvailVirtual;
19+
public ulong ullAvailExtendedVirtual;
20+
}
21+
22+
[DllImport("kernel32.dll", SetLastError = true)]
23+
private static extern bool GlobalMemoryStatusEx(ref MEMORYSTATUSEX lpBuffer);
24+
25+
private static ulong GetTotalPhysicalMemory()
26+
{
27+
var mem = new MEMORYSTATUSEX();
28+
mem.dwLength = (uint)Marshal.SizeOf(typeof(MEMORYSTATUSEX));
29+
if (GlobalMemoryStatusEx(ref mem))
30+
return mem.ullTotalPhys;
31+
return 0;
32+
}
33+
34+
public static bool CheckAndApply()
35+
{
36+
try
37+
{
38+
int cpu = Environment.ProcessorCount;
39+
ulong totalMem = GetTotalPhysicalMemory();
40+
// Thresholds: <=2 logical CPUs or <6GB RAM => low-end
41+
bool lowEnd = cpu <= 2 || (totalMem > 0 && totalMem < 6UL * 1024 * 1024 * 1024);
42+
if (lowEnd && !App.Settings.Prop.OptimizeForLowEnd)
43+
{
44+
App.Settings.Prop.OptimizeForLowEnd = true;
45+
try { App.Settings.Save(); } catch { }
46+
return true;
47+
}
48+
}
49+
catch { /* swallow to avoid crash */ }
50+
return false;
51+
}
52+
}
53+
}

Bloxstrap/Watcher.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,17 @@ public Watcher()
8787

8888
WindowManipulation = new(_watcherData.Handle, _watcherData.ProcessId);
8989

90+
// Auto-detect low-end systems and enable OptimizeForLowEnd if needed
91+
try
92+
{
93+
if (AutoOptimizeService.CheckAndApply())
94+
App.Logger.WriteLine(LOG_IDENT, "Auto-optimize: OptimizeForLowEnd enabled due to system detection.");
95+
}
96+
catch (Exception ex)
97+
{
98+
App.Logger.WriteException(LOG_IDENT, ex);
99+
}
100+
90101
if (App.Settings.Prop.EnableActivityTracking)
91102
{
92103
ActivityWatcher = new(_watcherData.LogFile);

0 commit comments

Comments
 (0)