potentially fixed auto updater, made sdk also up to date

This commit is contained in:
Devin Bot
2026-10-25 19:27:25 -07:00
parent d9ae75e9cb
commit 1b2c97e74b
5 changed files with 125 additions and 19 deletions

View File

@@ -105,23 +105,51 @@ class Patcher {
}
}
async extractToStaging(zipPath, onFile) {
const stagingDir = path.join(this.appDataPath, '.staging');
fs.rmSync(stagingDir, { recursive: true, force: true });
fs.mkdirSync(stagingDir, { recursive: true });
const zip = new AdmZip(zipPath);
const entries = zip.getEntries().filter((e) => !e.isDirectory);
if (entries.length === 0) {
throw new Error('Downloaded archive is empty, invalid, or truncated.');
}
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
zip.extractEntryTo(entry, stagingDir, true, true);
if (onFile) onFile(entry.entryName, i + 1, entries.length);
if (i % 20 === 0) await new Promise((resolve) => setImmediate(resolve));
}
return stagingDir;
}
commitStaging(stagingDir) {
this.purgeOldCode();
for (const name of fs.readdirSync(stagingDir)) {
const dest = path.join(this.appDataPath, name);
fs.rmSync(dest, { recursive: true, force: true });
fs.renameSync(path.join(stagingDir, name), dest);
}
fs.rmSync(stagingDir, { recursive: true, force: true });
}
verifyChecksum(zipPath, expectedSha256) {
if (!expectedSha256) return true;
if (!expectedSha256) return false;
const hash = crypto.createHash('sha256');
const data = fs.readFileSync(zipPath);
hash.update(data);
const calculated = hash.digest('hex');
return calculated === expectedSha256;
return calculated === String(expectedSha256).trim().toLowerCase();
}
verifyExtraction() {
verifyExtraction(root = this.appDataPath) {
const requiredFiles = [
'frontend/server.js',
'player/server.js'
];
for (const file of requiredFiles) {
const fullPath = path.join(this.appDataPath, file);
const fullPath = path.join(root, file);
if (!fs.existsSync(fullPath)) {
return false;
}