[Paths] Add cleanOldVersions

This commit is contained in:
Ducko 2022-02-02 18:35:54 +00:00
parent 733d35a537
commit 4c49ef4754
2 changed files with 18 additions and 3 deletions

2
src/bootstrap.js vendored
View file

@ -110,6 +110,8 @@ const startUpdate = () => {
const startMinimized = process.argv.includes('--start-minimized');
log('Bootstrap', 'Start minimized:', startMinimized);
paths.cleanOldVersions();
appUpdater.update(startMinimized, () => {
if (process.env.OPENASAR_NOSTART) {
log('Bootstrap', 'Found nostart variable, halting bootstrap');

View file

@ -1,4 +1,5 @@
const { join, dirname, basename } = require('path');
const fs = require('fs');
const { app } = require('electron');
const buildInfo = require('./utils/buildInfo');
@ -12,7 +13,7 @@ const exeDir = dirname(app.getPath('exe'));
const installPath = /^app-[0-9]+\.[0-9]+\.[0-9]+/.test(basename(exeDir)) ? join(exeDir, '..') : null;
const moduleData = buildInfo.newUpdater ? join(userData, 'module_data') : join(userDataVersioned, 'modules');
const resourcesPath = join(process.resourcesPath); // Discord uses path and require.main.filename here because ??
const resourcesPath = join(process.resourcesPath);
exports.getUserData = () => userData;
exports.getUserDataVersioned = () => userDataVersioned;
@ -21,6 +22,18 @@ exports.getResources = () => resourcesPath;
exports.getModuleDataPath = () => moduleData;
exports.getInstallPath = () => installPath;
exports.getExeDir = () => exeDir; // Custom / non-standard
exports.getExeDir = () => exeDir;
exports.init = () => {}; // Stub as we setup on require
exports.init = () => {}; // Stub as we setup on require
exports.cleanOldVersions = () => {
if (!installPath) return;
log('Paths', 'Cleaning old app dirs...');
for (const x of fs.readdirSync(installPath)) {
if (x.startsWith('app-') && !x.includes(buildInfo.version)) {
log('Paths', 'Removing', x);
fs.rmSync(join(installPath, x), { recursive: true, force: true });
}
}
};