mirror of
https://git.sanhost.net/sanasol/hytale-f2p
synced 2026-02-26 09:21:48 -03:00
fix: major bug - hytale won't launch with laptop machine and ghost processes
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
const { execSync } = require('child_process');
|
const { execSync, spawnSync } = require('child_process');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
function getOS() {
|
function getOS() {
|
||||||
@@ -300,29 +300,81 @@ function detectGpuLinux() {
|
|||||||
function detectGpuWindows() {
|
function detectGpuWindows() {
|
||||||
let output = '';
|
let output = '';
|
||||||
let commandUsed = 'cim'; // Track which command succeeded
|
let commandUsed = 'cim'; // Track which command succeeded
|
||||||
|
const POWERSHELL_TIMEOUT = 5000; // 5 second timeout to prevent hanging
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Use spawnSync with explicit timeout instead of execSync to avoid ghost processes
|
||||||
// Fetch Name and AdapterRAM (VRAM in bytes)
|
// Fetch Name and AdapterRAM (VRAM in bytes)
|
||||||
output = execSync(
|
const result = spawnSync('powershell.exe', [
|
||||||
'powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-CimInstance Win32_VideoController | Select-Object Name, AdapterRAM | ConvertTo-Csv -NoTypeInformation"',
|
'-NoProfile',
|
||||||
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
|
'-ExecutionPolicy', 'Bypass',
|
||||||
);
|
'-Command',
|
||||||
|
'Get-CimInstance Win32_VideoController | Select-Object Name, AdapterRAM | ConvertTo-Csv -NoTypeInformation'
|
||||||
|
], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
timeout: POWERSHELL_TIMEOUT,
|
||||||
|
stdio: ['ignore', 'pipe', 'ignore'],
|
||||||
|
windowsHide: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
throw result.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status === 0 && result.stdout) {
|
||||||
|
output = result.stdout;
|
||||||
|
} else {
|
||||||
|
throw new Error(`PowerShell returned status ${result.status || result.signal}`);
|
||||||
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
try {
|
try {
|
||||||
// Fallback to Get-WmiObject (Older PowerShell)
|
// Fallback to Get-WmiObject (Older PowerShell)
|
||||||
commandUsed = 'wmi';
|
commandUsed = 'wmi';
|
||||||
output = execSync(
|
const result = spawnSync('powershell.exe', [
|
||||||
'powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-WmiObject Win32_VideoController | Select-Object Name, AdapterRAM | ConvertTo-Csv -NoTypeInformation"',
|
'-NoProfile',
|
||||||
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
|
'-ExecutionPolicy', 'Bypass',
|
||||||
);
|
'-Command',
|
||||||
|
'Get-WmiObject Win32_VideoController | Select-Object Name, AdapterRAM | ConvertTo-Csv -NoTypeInformation'
|
||||||
|
], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
timeout: POWERSHELL_TIMEOUT,
|
||||||
|
stdio: ['ignore', 'pipe', 'ignore'],
|
||||||
|
windowsHide: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
throw result.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status === 0 && result.stdout) {
|
||||||
|
output = result.stdout;
|
||||||
|
} else {
|
||||||
|
throw new Error(`PowerShell WMI returned status ${result.status || result.signal}`);
|
||||||
|
}
|
||||||
} catch (e2) {
|
} catch (e2) {
|
||||||
// Fallback to wmic (Deprecated, often missing on newer Windows)
|
// Fallback to wmic (Deprecated, often missing on newer Windows)
|
||||||
// Note: This fallback likely won't provide VRAM in the same reliable CSV format easily,
|
// Note: This fallback likely won't provide VRAM in the same reliable CSV format easily,
|
||||||
// so we stick to just getting the Name to at least allow the app to launch.
|
// so we stick to just getting the Name to at least allow the app to launch.
|
||||||
try {
|
try {
|
||||||
commandUsed = 'wmic';
|
commandUsed = 'wmic';
|
||||||
output = execSync('wmic path win32_VideoController get name', { encoding: 'utf8' });
|
const result = spawnSync('wmic.exe', ['path', 'win32_VideoController', 'get', 'name'], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
timeout: POWERSHELL_TIMEOUT,
|
||||||
|
stdio: ['ignore', 'pipe', 'ignore'],
|
||||||
|
windowsHide: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error) {
|
||||||
|
throw result.error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (result.status === 0 && result.stdout) {
|
||||||
|
output = result.stdout;
|
||||||
|
} else {
|
||||||
|
throw new Error(`wmic returned status ${result.status || result.signal}`);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.warn('All Windows GPU detection methods failed:', err.message);
|
||||||
return { mode: 'unknown', vendor: 'none', integratedName: null, dedicatedName: null };
|
return { mode: 'unknown', vendor: 'none', integratedName: null, dedicatedName: null };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -583,10 +635,27 @@ function getSystemTypeLinux() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getSystemTypeWindows() {
|
function getSystemTypeWindows() {
|
||||||
|
const POWERSHELL_TIMEOUT = 5000; // 5 second timeout
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const output = execSync(
|
// Use spawnSync instead of execSync to avoid ghost processes
|
||||||
'powershell -NoProfile -ExecutionPolicy Bypass -Command "Get-CimInstance Win32_SystemEnclosure | Select-Object -ExpandProperty ChassisTypes"',
|
const result = spawnSync('powershell.exe', [
|
||||||
{ encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }).trim();
|
'-NoProfile',
|
||||||
|
'-ExecutionPolicy', 'Bypass',
|
||||||
|
'-Command',
|
||||||
|
'Get-CimInstance Win32_SystemEnclosure | Select-Object -ExpandProperty ChassisTypes'
|
||||||
|
], {
|
||||||
|
encoding: 'utf8',
|
||||||
|
timeout: POWERSHELL_TIMEOUT,
|
||||||
|
stdio: ['ignore', 'pipe', 'ignore'],
|
||||||
|
windowsHide: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.error || result.status !== 0) {
|
||||||
|
throw new Error(`PowerShell failed: ${result.error?.message || result.signal}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = (result.stdout || '').trim();
|
||||||
// Output might be a single number or array.
|
// Output might be a single number or array.
|
||||||
// Clean it up
|
// Clean it up
|
||||||
const types = output.split(/\s+/).map(t => parseInt(t)).filter(n => !isNaN(n));
|
const types = output.split(/\s+/).map(t => parseInt(t)).filter(n => !isNaN(n));
|
||||||
@@ -601,9 +670,22 @@ function getSystemTypeWindows() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Fallback wmic
|
// Fallback wmic
|
||||||
try {
|
try {
|
||||||
const output = execSync('wmic path win32_systemenclosure get chassistypes', { encoding: 'utf8' }).trim();
|
const result = spawnSync('wmic.exe', ['path', 'win32_systemenclosure', 'get', 'chassistypes'], {
|
||||||
if (output.includes('8') || output.includes('9') || output.includes('10') || output.includes('14')) return 'laptop';
|
encoding: 'utf8',
|
||||||
} catch (err) {}
|
timeout: POWERSHELL_TIMEOUT,
|
||||||
|
stdio: ['ignore', 'pipe', 'ignore'],
|
||||||
|
windowsHide: true
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.status === 0 && result.stdout) {
|
||||||
|
const output = result.stdout.trim();
|
||||||
|
if (output.includes('8') || output.includes('9') || output.includes('10') || output.includes('14')) {
|
||||||
|
return 'laptop';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('System type detection failed:', err.message);
|
||||||
|
}
|
||||||
return 'desktop';
|
return 'desktop';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user