I cant get hidden process working >:((((

This commit is contained in:
lunarcleint
2023-03-23 10:13:43 -07:00
parent 6aec2e024b
commit 099c9a7d55
8 changed files with 157 additions and 15 deletions
+83
View File
@@ -1,5 +1,6 @@
package funkin.utils;
import native.HiddenProcess;
#if cpp
import cpp.vm.Gc;
#elseif hl
@@ -11,6 +12,56 @@ import neko.vm.Gc;
#end
import openfl.system.System;
#if cpp
@:cppFileCode("
#if defined(HX_WINDOWS)
#include <windows.h>
long long totalMem() {
unsigned long long allocatedRAM = 0;
GetPhysicallyInstalledSystemMemory(&allocatedRAM);
return (allocatedRAM / 1024);
}
#endif
#if define(HX_MAC)
#include <stdio.h>
long long totalMem() {
int mib [] = { CTL_HW, HW_MEMSIZE };
int64_t value = 0;
size_t length = sizeof(value);
if(-1 == sysctl(mib, 2, &value, &length, NULL, 0))
return -1; // An error occurred
return value / 1024 / 1024;
}
#endif
#if defined(HX_LINUX)
#include <sys/sysctl.h>
long long totalMem() {
FILE *meminfo = fopen('/proc/meminfo', 'r');
if(meminfo == NULL) return -1;
char line[256];
while(fgets(line, sizeof(line), meminfo))
{
int ram;
if(sscanf(line, 'MemTotal: %d kB', &ram) == 1)
{
fclose(meminfo);
return (ram / 1024);
}
}
fclose(meminfo);
return -1;
}
#endif
")
#end
class MemoryUtil {
public static var disableCount:Int = 0;
@@ -60,6 +111,14 @@ class MemoryUtil {
#end
}
#if cpp
@:functionCode("return totalMem();")
public static function getTotalMem():Float
{
return 0;
}
#end
public static inline function currentMemUsage() {
#if cpp
return Gc.memInfo64(Gc.MEM_INFO_USAGE);
@@ -70,6 +129,30 @@ class MemoryUtil {
#end
}
public static function getMemType():String {
#if windows
if (Assets.exists(Paths.ps1("powershell/ramtype"))) {
var process = new HiddenProcess("powershell", ["-ExecutionPolicy", "ByPass", "-File", (Sys.getCwd() + Paths.ps1("powershell/ramtype")).replace("/", "\\")]);
if (process.exitCode() == 0) return process.stdout.readAll().toString().trim().split("\n")[0].trim();
}
#elseif mac
var process = new HiddenProcess("system_profiler", ["SPMemoryDataType"]);
if (process.exitCode() == 0) return process.stdout.readAll().toString().match(/Type: (.+)/)[1];
#elseif linux
var process = HiddenProcess("sudo", ["dmidecode", "--type", "17"]);
if (process.exitCode() != 0) return "Unknown";
var lines = process.stdout.readAll().toString().split("\n");
for (line in lines) {
if (line.indexOf("Type:") == 0) {
return line.substring("Type:".length).trim();
}
}
#end
return "Unknown";
}
private static var _nb:Int = 0;
private static var _nbD:Int = 0;
private static var _zombie:Dynamic;