diff --git a/src/bootstrap.js b/src/bootstrap.js index 477c0a3..6bfbbcb 100644 --- a/src/bootstrap.js +++ b/src/bootstrap.js @@ -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'); diff --git a/src/paths.js b/src/paths.js index 58e4d69..6512c09 100644 --- a/src/paths.js +++ b/src/paths.js @@ -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 \ No newline at end of file +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 }); + } + } +}; \ No newline at end of file