[Paths] Add cleanOldVersions
This commit is contained in:
parent
733d35a537
commit
4c49ef4754
|
@ -110,6 +110,8 @@ const startUpdate = () => {
|
||||||
const startMinimized = process.argv.includes('--start-minimized');
|
const startMinimized = process.argv.includes('--start-minimized');
|
||||||
log('Bootstrap', 'Start minimized:', startMinimized);
|
log('Bootstrap', 'Start minimized:', startMinimized);
|
||||||
|
|
||||||
|
paths.cleanOldVersions();
|
||||||
|
|
||||||
appUpdater.update(startMinimized, () => {
|
appUpdater.update(startMinimized, () => {
|
||||||
if (process.env.OPENASAR_NOSTART) {
|
if (process.env.OPENASAR_NOSTART) {
|
||||||
log('Bootstrap', 'Found nostart variable, halting bootstrap');
|
log('Bootstrap', 'Found nostart variable, halting bootstrap');
|
||||||
|
|
19
src/paths.js
19
src/paths.js
|
@ -1,4 +1,5 @@
|
||||||
const { join, dirname, basename } = require('path');
|
const { join, dirname, basename } = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
const { app } = require('electron');
|
const { app } = require('electron');
|
||||||
|
|
||||||
const buildInfo = require('./utils/buildInfo');
|
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 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 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.getUserData = () => userData;
|
||||||
exports.getUserDataVersioned = () => userDataVersioned;
|
exports.getUserDataVersioned = () => userDataVersioned;
|
||||||
|
@ -21,6 +22,18 @@ exports.getResources = () => resourcesPath;
|
||||||
exports.getModuleDataPath = () => moduleData;
|
exports.getModuleDataPath = () => moduleData;
|
||||||
exports.getInstallPath = () => installPath;
|
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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue