Skip to content
This repository was archived by the owner on Oct 21, 2024. It is now read-only.

Commit 18963c4

Browse files
committed
Fix SML pak not being downloaded
1 parent 98c9c71 commit 18963c4

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

src/smlHandler.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs';
33
import bindings from 'bindings';
44
import { valid, coerce } from 'semver';
55
import {
6-
downloadFile, fileURLExists,
6+
downloadFile,
77
} from './utils';
88
import { ModNotFoundError } from './errors';
99
import { debug } from './logging';
@@ -42,11 +42,14 @@ async function getSMLVersionCache(version: string): Promise<string> {
4242
}
4343
const smlDLLDownloadLink = `${smlReleaseURL.replace('/tag/', '/download/')}/${SMLDLLFileName}`;
4444
const smlPakDownloadLink = `${smlReleaseURL.replace('/tag/', '/download/')}/${SMLPakFileName}`;
45-
const hasPak = await fileURLExists(smlPakDownloadLink);
46-
await downloadFile(smlDLLDownloadLink, smlDLLVerionCacheFile, `SML ${hasPak ? '(1/2)' : '(1/1)'}`, validVersion);
47-
if (hasPak) {
48-
await downloadFile(smlPakDownloadLink, smlPakVerionCacheFile, 'SML (2/2)', validVersion);
45+
let hasPak = true;
46+
try {
47+
await downloadFile(smlPakDownloadLink, smlPakVerionCacheFile, 'SML (1/2)', validVersion);
48+
} catch (e) {
49+
hasPak = false;
50+
debug(`Pak of SML version ${version} not found.`);
4951
}
52+
await downloadFile(smlDLLDownloadLink, smlDLLVerionCacheFile, `SML ${hasPak ? '(2/2)' : '(1/1)'}`, validVersion);
5053
}
5154
return smlVersionCacheDir;
5255
}

src/utils.ts

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { execSync } from 'child_process';
66
import got, { HTTPError, Progress } from 'got';
77
import { createHash } from 'crypto';
88
import {
9-
setLogDebug, debug, error,
9+
setLogDebug, debug,
1010
} from './logging';
1111
import { NetworkError } from './errors';
1212
import {
@@ -101,25 +101,6 @@ export function addDownloadProgressCallback(cb: ProgressCallback): void {
101101
}
102102
}
103103

104-
export async function fileURLExists(url: string): Promise<boolean> {
105-
try {
106-
const res = await got(url, {
107-
method: 'HEAD',
108-
dnsCache: false,
109-
headers: {
110-
'User-Agent': UserAgent,
111-
},
112-
});
113-
return res.statusCode === 200;
114-
} catch (e) {
115-
if (e instanceof HTTPError) {
116-
return false;
117-
}
118-
error(e);
119-
throw new Error(`Error checking if ${url} exists.`);
120-
}
121-
}
122-
123104
export async function downloadFile(url: string, file: string, name: string, version: string): Promise<void> {
124105
let interval: NodeJS.Timeout | undefined;
125106
try {

0 commit comments

Comments
 (0)