Skip to content

Commit 6da78d0

Browse files
Add requirements check logic
1 parent c428c93 commit 6da78d0

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "uma-db-stuff",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "A set of experimental scripts to process Umamusume Pretty Derby game assets and database files",
55
"author": "daydreamer-json <[email protected]> (https://github.com/daydreamer-json)",
66
"license": "AGPL-3.0-or-later",

src/cmd.ts

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ async function parseCommand() {
257257
argvUtils.setArgv(argv);
258258
logger.level = argvUtils.getArgv().logLevel;
259259
logger.trace('Process started');
260+
await processUtils.checkRequirements();
260261
await processUtils.checkIsAdmin();
261262
await processUtils.checkIsGameRunning();
262263
await fileUtils.resolveGameDir();

src/utils/configEmbed.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import semver from 'semver';
22

33
export default {
44
APPLICATION_NAME: 'uma-db-stuff',
5-
VERSION_NUMBER: semver.valid('0.1.1'),
5+
VERSION_NUMBER: semver.valid('0.1.2'),
66
};

src/utils/process.ts

+73
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,79 @@
11
import bun from 'bun';
22
import prompts from 'prompts';
3+
import chalk from 'chalk';
4+
import open from 'open';
35
import logger from './logger';
46
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+
}
577

678
async function checkIsAdmin() {
779
const rsp = bun.spawnSync(['net', 'session']);
@@ -44,6 +116,7 @@ async function checkIsGameRunning() {
44116
}
45117

46118
export default {
119+
checkRequirements,
47120
checkIsAdmin,
48121
checkIsGameRunning,
49122
};

0 commit comments

Comments
 (0)