OctoLauncher 1.3.1
Manifest-based CDN updater and mod manager for the OctoWoW 1.12.1 client: launcher-owned realmlist, torrent-backed content sync with bundled aria2c, antivirus and Defender exclusion handling, hardware-aware render distance, optional client tweaks and mods, and the in-launcher news feed.
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
import { workerData, parentPort } from 'worker_threads';
|
||||
|
||||
import git from 'isomorphic-git';
|
||||
import http from 'isomorphic-git/http/node';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const port = parentPort;
|
||||
if (!port) throw new Error('IllegalState');
|
||||
|
||||
const { dir, url, ref } = workerData;
|
||||
|
||||
const tmpDir = `${dir}.tmp`;
|
||||
const bakDir = `${dir}.bak`;
|
||||
|
||||
const run = async () => {
|
||||
await fs.remove(tmpDir);
|
||||
await git.clone({
|
||||
dir: tmpDir,
|
||||
fs,
|
||||
http,
|
||||
url,
|
||||
ref,
|
||||
singleBranch: !ref || ref === 'master' || ref === 'main',
|
||||
onProgress: (...args) => port.postMessage({ cb: 'onProgress', args })
|
||||
});
|
||||
|
||||
await fs.remove(bakDir);
|
||||
const hadExisting = await fs.pathExists(dir);
|
||||
if (hadExisting) await fs.move(dir, bakDir);
|
||||
|
||||
try {
|
||||
await fs.move(tmpDir, dir);
|
||||
} catch (e) {
|
||||
if (hadExisting) await fs.move(bakDir, dir).catch(() => undefined);
|
||||
throw e;
|
||||
}
|
||||
|
||||
await fs.remove(bakDir).catch(() => undefined);
|
||||
};
|
||||
|
||||
run()
|
||||
.then(() => port.postMessage(true))
|
||||
.catch(async err => {
|
||||
await fs.remove(tmpDir).catch(() => undefined);
|
||||
throw err;
|
||||
});
|
||||
Reference in New Issue
Block a user