Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.

Commit 722a8dd

Browse files
fix: Some additional fixes
1 parent 918d851 commit 722a8dd

File tree

2 files changed

+19
-33
lines changed

2 files changed

+19
-33
lines changed

src/main/modules/patcher.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ export async function installMod(callback, { patchType = PatchTypes.DEFAULT, fro
199199
await prepareModAsarFile(patchType, asarPath, callback);
200200

201201
await createBackups(callback, asarPath);
202+
202203
await replaceAsar(callback, patchType, fromAsarSrc, asarPath);
203204

204205
const isAsarIntegrityBypassed = await bypassAsarIntegrity(YM_PATH, callback);
@@ -209,6 +210,7 @@ export async function installMod(callback, { patchType = PatchTypes.DEFAULT, fro
209210
}
210211

211212
callback(1, 'Installed!');
213+
212214
logger.log('Installed mod version:', modVersion, 'YM version:', ymMetadata.version, 'Patch type:', patchType);
213215

214216
await clearCaches(callback);
@@ -248,7 +250,7 @@ async function downloadAsar(callback, metadata) {
248250

249251
const downloadPath = shouldDecompress ? (compressionType === 'zst' ? ASAR_ZST_TMP_PATH : ASAR_GZ_TMP_PATH) : ASAR_TMP_PATH;
250252

251-
await downloadFile(url, path.join(downloadPath),
253+
await downloadFile(url, downloadPath,
252254
(progress, label) => {
253255
callback(progress*0.6, label);
254256
}
@@ -286,7 +288,7 @@ async function createDirIfNotExist(target) {
286288
}
287289

288290
async function decompressFile(target, dest, compressionType) {
289-
const compressedData = await fsp.readFile(target);
291+
const compressedData = await fso.promises.readFile(target);
290292

291293
const decompressedData = await (compressionType === 'zst' ? zstdDecompressPromise(compressedData) : unzipPromise(compressedData));
292294

src/main/modules/utils.js

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import path from "path";
22
import { promisify } from 'util'
3+
import { pipeline } from 'stream/promises';
34
import { exec, spawn } from 'child_process'
45
import { app, nativeImage } from "electron";
56
import axios from "axios";
6-
import o_fs from "original-fs";
7+
import fso from "original-fs";
78
import unzipper from "unzipper";
89
import fs from "fs";
910
import { Logger } from "./Logger.js";
@@ -24,7 +25,7 @@ export const getNativeImg = (relativePath) => {
2425
: path.join(__dirname, '..', '..', 'assets')
2526

2627
const filePath = path.join(basePath, relativePath);
27-
if (!filePath || !o_fs.existsSync(filePath)) {
28+
if (!filePath || !fso.existsSync(filePath)) {
2829
logger.log(`File path is undefined for relative path: ${filePath}`);
2930
}
3031
return nativeImage.createFromPath(filePath)
@@ -130,36 +131,19 @@ export async function downloadFile(url, dest, callback) {
130131
onDownloadProgress: progress => {
131132
callback(progress.progress, `Downloading ${path.basename(dest)}...`);
132133
}
133-
})
134-
return new Promise((resolve, reject) => {
135-
const writer = o_fs.createWriteStream(dest);
136-
137-
response.data.pipe(writer);
138-
139-
writer.on('finish', () => {
140-
writer.close((err)=>{
141-
if (err) {
142-
callback(-1, 'Error closing file: ' + err);
143-
reject(err);
144-
return;
145-
}
146-
callback(1, 'Download completed: ' + path.basename(dest));
147-
});
148-
resolve(dest);
149-
});
150-
151-
writer.on('error', (error) => {
152-
writer.close?.();
153-
callback(-1, 'Download error: ' + error);
154-
reject(error);
155-
});
156-
157-
response.data.on('error', (error) => {
158-
writer.close?.();
159-
callback(-1, 'Download error: ' + error);
160-
reject(error);
161-
});
162134
});
135+
136+
const writer = fso.createWriteStream(dest);
137+
138+
try {
139+
await pipeline(response.data, writer);
140+
callback(1, 'Download completed: ' + path.basename(dest));
141+
return dest;
142+
} catch (err) {
143+
writer.close();
144+
callback(-1, 'Download error: ' + err);
145+
throw err;
146+
}
163147
}
164148

165149
export async function checkIfLegacyYMInstalled() {

0 commit comments

Comments
 (0)