|
1 | 1 | import bun from 'bun';
|
2 | 2 | import prompts from 'prompts';
|
| 3 | +import chalk from 'chalk'; |
| 4 | +import open from 'open'; |
3 | 5 | import logger from './logger';
|
4 | 6 | import exitUtils from './exit';
|
| 7 | +import subProcessUtils from './subProcess'; |
| 8 | + |
| 9 | +async function checkRequirements() { |
| 10 | + logger.debug('Checking system requirements ...'); |
| 11 | + if (process.platform !== 'win32' || process.arch !== 'x64') { |
| 12 | + logger.fatal(`This platform is not supported: ${process.platform}, ${process.arch}`); |
| 13 | + await exitUtils.pressAnyKeyToExit(1); |
| 14 | + } else { |
| 15 | + logger.trace(`This platform is supported: ${process.platform}, ${process.arch}`); |
| 16 | + } |
| 17 | + const requirements: { key: string; pretty: string; url: string; isInstalled: boolean }[] = [ |
| 18 | + { |
| 19 | + key: 'vcredist', |
| 20 | + pretty: 'Microsoft VC++ Redist', |
| 21 | + url: 'https://aka.ms/vs/17/release/vc_redist.x64.exe', |
| 22 | + isInstalled: await (async (): Promise<boolean> => { |
| 23 | + const regKey = 'HKLM\\SOFTWARE\\Microsoft\\VisualStudio\\14.0\\VC\\Runtimes\\x64'; |
| 24 | + const regValueName = 'Installed'; |
| 25 | + let isInstalled: boolean = false; |
| 26 | + try { |
| 27 | + const response = await subProcessUtils.spawnAsync('reg', ['query', regKey, '/v', regValueName], {}); |
| 28 | + isInstalled = response.exitCode === 0 && /0x1/.test(response.stdout) === true; |
| 29 | + } catch (_) {} |
| 30 | + return isInstalled; |
| 31 | + })(), |
| 32 | + }, |
| 33 | + { |
| 34 | + key: 'dotnet8', |
| 35 | + pretty: 'Microsoft .NET Desktop Runtime 8.0', |
| 36 | + url: 'https://aka.ms/dotnet/8.0/windowsdesktop-runtime-win-x64.exe', |
| 37 | + isInstalled: await (async (): Promise<boolean> => { |
| 38 | + let isInstalled: boolean = false; |
| 39 | + try { |
| 40 | + const response = await subProcessUtils.spawnAsync('dotnet', ['--list-runtimes'], {}); |
| 41 | + if (response.exitCode === 0) { |
| 42 | + isInstalled = response.stdout |
| 43 | + .split(/\r?\n/) |
| 44 | + .some((line) => /^Microsoft\.WindowsDesktop\.App 8\.\d+\.\d+/.test(line)); |
| 45 | + } |
| 46 | + } catch (_) {} |
| 47 | + return isInstalled; |
| 48 | + })(), |
| 49 | + }, |
| 50 | + ]; |
| 51 | + logger.trace( |
| 52 | + `Installed requirements: ${JSON.stringify(Object.fromEntries(requirements.map((obj) => [obj.key, obj.isInstalled])))}`, |
| 53 | + ); |
| 54 | + for (const requirementsEntry of requirements) { |
| 55 | + if (requirementsEntry.isInstalled !== true) { |
| 56 | + logger.fatal(`${chalk.bold.red(`${requirementsEntry.pretty} is not installed.`)} Please install it`); |
| 57 | + if ( |
| 58 | + ( |
| 59 | + await prompts({ |
| 60 | + type: 'toggle', |
| 61 | + name: 'value', |
| 62 | + message: 'Do you want to download the installer?', |
| 63 | + initial: true, |
| 64 | + active: 'yes', |
| 65 | + inactive: 'no', |
| 66 | + }) |
| 67 | + ).value |
| 68 | + ) { |
| 69 | + await open(requirementsEntry.url); |
| 70 | + // await exitUtils.pressAnyKeyToExit(1); |
| 71 | + } else { |
| 72 | + } |
| 73 | + await exitUtils.pressAnyKeyToExit(1); |
| 74 | + } |
| 75 | + } |
| 76 | +} |
5 | 77 |
|
6 | 78 | async function checkIsAdmin() {
|
7 | 79 | const rsp = bun.spawnSync(['net', 'session']);
|
@@ -44,6 +116,7 @@ async function checkIsGameRunning() {
|
44 | 116 | }
|
45 | 117 |
|
46 | 118 | export default {
|
| 119 | + checkRequirements, |
47 | 120 | checkIsAdmin,
|
48 | 121 | checkIsGameRunning,
|
49 | 122 | };
|
0 commit comments