From e22aad419b55bac6325ed7df4f2a1e22fc481da5 Mon Sep 17 00:00:00 2001 From: Viacelaus Date: Sat, 6 Nov 2021 13:20:49 +0200 Subject: [PATCH] =?UTF-8?q?=D0=A2=D0=B0=D1=81=D0=BA=20=D0=BC=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0=D0=B3=D0=B5=D1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../OSTaskManager/OSTaskManager.fsproj | 16 +++++++ .../OSTaskManager/OSTaskManager.sln | 25 +++++++++++ src/Extreme Soft/OSTaskManager/Program.fs | 43 +++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 src/Extreme Soft/OSTaskManager/OSTaskManager.fsproj create mode 100644 src/Extreme Soft/OSTaskManager/OSTaskManager.sln create mode 100644 src/Extreme Soft/OSTaskManager/Program.fs diff --git a/src/Extreme Soft/OSTaskManager/OSTaskManager.fsproj b/src/Extreme Soft/OSTaskManager/OSTaskManager.fsproj new file mode 100644 index 0000000..b7bb3ac --- /dev/null +++ b/src/Extreme Soft/OSTaskManager/OSTaskManager.fsproj @@ -0,0 +1,16 @@ + + + + Exe + net5.0 + + + + + + + + + + + diff --git a/src/Extreme Soft/OSTaskManager/OSTaskManager.sln b/src/Extreme Soft/OSTaskManager/OSTaskManager.sln new file mode 100644 index 0000000..30e5959 --- /dev/null +++ b/src/Extreme Soft/OSTaskManager/OSTaskManager.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31129.286 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "OSTaskManager", "OSTaskManager.fsproj", "{CAAA271A-B23A-41E2-AE4E-4EF846AA199A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {CAAA271A-B23A-41E2-AE4E-4EF846AA199A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CAAA271A-B23A-41E2-AE4E-4EF846AA199A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CAAA271A-B23A-41E2-AE4E-4EF846AA199A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CAAA271A-B23A-41E2-AE4E-4EF846AA199A}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {56079CA1-154C-4679-8410-80D59FDA600E} + EndGlobalSection +EndGlobal diff --git a/src/Extreme Soft/OSTaskManager/Program.fs b/src/Extreme Soft/OSTaskManager/Program.fs new file mode 100644 index 0000000..68e24ad --- /dev/null +++ b/src/Extreme Soft/OSTaskManager/Program.fs @@ -0,0 +1,43 @@ +open System +open System.Management +open System.Diagnostics +open System.IO + +let getSysData () = + let wql = ObjectQuery("SELECT * FROM Win32_OperatingSystem"); + let searcher = new ManagementObjectSearcher(wql); + let results = searcher.Get(); + let arrResults = Array.create 1 null + results.CopyTo(arrResults, 0) + arrResults + +let limpopoPath = @$"{Environment.CurrentDirectory}\..\..\..\..\..\Games\Limpopo\limpopo.exe" + +[] +let main _ = + let loop = async { + while true do + let! sleep = Async.Sleep(3000); + + let data = getSysData() + data + |> Array.iter(fun d -> + if d <> null + then + let total = Convert.ToDouble(d.["TotalVisibleMemorySize"]) + let free = Convert.ToDouble(d.["FreePhysicalMemory"]) + if free / total < 0.5 + then + + let info = ProcessStartInfo(limpopoPath, "\q"); + info.CreateNoWindow <- false; + info.UseShellExecute <- true; + let proc = Process.Start info + () + ) + () + } + + loop |> Async.RunSynchronously + + 0 \ No newline at end of file