Skip to content

Commit 04fd381

Browse files
committed
feat(cli): install HLAE and encoder software if necessary
1 parent 682e13a commit 04fd381

File tree

3 files changed

+43
-11
lines changed

3 files changed

+43
-11
lines changed

src/cli/commands/video-command.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,21 @@ import { getSettings } from 'csdm/node/settings/get-settings';
88
import { getDemoFromFilePath } from 'csdm/node/demo/get-demo-from-file-path';
99
import { generateVideo } from 'csdm/node/video/generation/generate-video';
1010
import type { Sequence } from 'csdm/common/types/sequence';
11-
import type { EncoderSoftware } from 'csdm/common/types/encoder-software';
11+
import { EncoderSoftware } from 'csdm/common/types/encoder-software';
1212
import { isValidEncoderSoftware } from 'csdm/common/types/encoder-software';
13-
import type { RecordingSystem } from 'csdm/common/types/recording-system';
13+
import { RecordingSystem } from 'csdm/common/types/recording-system';
1414
import { isValidRecordingSystem } from 'csdm/common/types/recording-system';
15-
import type { RecordingOutput } from 'csdm/common/types/recording-output';
15+
import { RecordingOutput } from 'csdm/common/types/recording-output';
1616
import { isValidRecordingOutput } from 'csdm/common/types/recording-output';
1717
import type { VideoContainer } from 'csdm/common/types/video-container';
1818
import { isValidVideoContainer } from 'csdm/common/types/video-container';
1919
import { InvalidArgument } from 'csdm/cli/errors/invalid-argument';
20+
import { isHlaeInstalled } from 'csdm/node/video/hlae/is-hlae-installed';
21+
import { installHlae } from 'csdm/node/video/hlae/install-hlae';
22+
import { isVirtualDubInstalled } from 'csdm/node/video/virtual-dub/is-virtual-dub-installed';
23+
import { downloadAndExtractVirtualDub } from 'csdm/node/video/virtual-dub/download-and-extract-virtual-dub';
24+
import { isFfmpegInstalled } from 'csdm/node/video/ffmpeg/is-ffmpeg-installed';
25+
import { installFfmpeg } from 'csdm/node/video/ffmpeg/install-ffmpeg';
2026

2127
export class VideoCommand extends Command {
2228
public static Name = 'video';
@@ -72,7 +78,7 @@ export class VideoCommand extends Command {
7278
private cfg: string | undefined;
7379

7480
public getDescription() {
75-
return 'Generate a video from a demo.';
81+
return 'Generate videos from demos.';
7682
}
7783

7884
public printHelp() {
@@ -132,6 +138,25 @@ export class VideoCommand extends Command {
132138
cfg: this.cfg,
133139
};
134140

141+
const recordingSystem = this.recordingSystem ?? settings.video.recordingSystem;
142+
if (recordingSystem === RecordingSystem.HLAE && !(await isHlaeInstalled())) {
143+
console.log('Installing HLAE...');
144+
await installHlae();
145+
}
146+
147+
const recordingOutput = this.recordingOutput ?? settings.video.recordingOutput;
148+
const shouldGenerateVideo = recordingOutput !== RecordingOutput.Images;
149+
const encoderSoftware = this.encoderSoftware ?? settings.video.encoderSoftware;
150+
if (shouldGenerateVideo && encoderSoftware === EncoderSoftware.VirtualDub && !(await isVirtualDubInstalled())) {
151+
console.log('Installing VirtualDub...');
152+
await downloadAndExtractVirtualDub();
153+
}
154+
155+
if (shouldGenerateVideo && encoderSoftware === EncoderSoftware.FFmpeg && !(await isFfmpegInstalled())) {
156+
console.log('Installing FFmpeg...');
157+
await installFfmpeg();
158+
}
159+
135160
const videoId = randomUUID();
136161
const controller = new AbortController();
137162

@@ -140,9 +165,9 @@ export class VideoCommand extends Command {
140165
checksum: demo.checksum,
141166
game: demo.game,
142167
tickrate: demo.tickrate,
143-
recordingSystem: this.recordingSystem ?? settings.video.recordingSystem,
144-
recordingOutput: this.recordingOutput ?? settings.video.recordingOutput,
145-
encoderSoftware: this.encoderSoftware ?? settings.video.encoderSoftware,
168+
recordingSystem,
169+
recordingOutput,
170+
encoderSoftware,
146171
framerate: this.framerate ?? settings.video.framerate,
147172
width: this.width ?? settings.video.width,
148173
height: this.height ?? settings.video.height,
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { downloadHlae } from './download-hlae';
2+
import { getDefaultHlaeInstallationFolderPath } from './hlae-location';
3+
4+
export async function installHlae() {
5+
const installationFolderPath = getDefaultHlaeInstallationFolderPath();
6+
const version = await downloadHlae(installationFolderPath);
7+
8+
return version;
9+
}

src/server/handlers/renderer-process/video/install-hlae-handler.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import { downloadHlae } from 'csdm/node/video/hlae/download-hlae';
2-
import { getDefaultHlaeInstallationFolderPath } from 'csdm/node/video/hlae/hlae-location';
31
import { handleError } from '../../handle-error';
2+
import { installHlae } from 'csdm/node/video/hlae/install-hlae';
43

54
export async function installHlaeHandler() {
65
try {
7-
const installationFolderPath = getDefaultHlaeInstallationFolderPath();
8-
const version = await downloadHlae(installationFolderPath);
6+
const version = await installHlae();
97

108
return version;
119
} catch (error) {

0 commit comments

Comments
 (0)