2021-12-09 16:25:14 +00:00
|
|
|
const { join, dirname, basename } = require('path');
|
2022-02-02 18:35:54 +00:00
|
|
|
const fs = require('fs');
|
2021-12-09 16:25:14 +00:00
|
|
|
const { app } = require('electron');
|
|
|
|
|
|
|
|
const buildInfo = require('./utils/buildInfo');
|
|
|
|
|
|
|
|
|
|
|
|
const appDir = 'discord' + (buildInfo.releaseChannel === 'stable' ? '' : buildInfo.releaseChannel); // Clean channel naming up later to util?
|
|
|
|
const userData = join(app.getPath('appData'), appDir);
|
|
|
|
const userDataVersioned = join(userData, buildInfo.version);
|
|
|
|
|
|
|
|
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');
|
2022-02-02 18:35:54 +00:00
|
|
|
const resourcesPath = join(process.resourcesPath);
|
2021-12-09 16:25:14 +00:00
|
|
|
|
|
|
|
exports.getUserData = () => userData;
|
|
|
|
exports.getUserDataVersioned = () => userDataVersioned;
|
|
|
|
|
2021-12-10 17:17:00 +00:00
|
|
|
exports.getResources = () => resourcesPath;
|
2021-12-09 16:25:14 +00:00
|
|
|
exports.getModuleDataPath = () => moduleData;
|
|
|
|
exports.getInstallPath = () => installPath;
|
|
|
|
|
2022-02-02 18:35:54 +00:00
|
|
|
exports.getExeDir = () => exeDir;
|
2021-12-11 15:19:04 +00:00
|
|
|
|
2022-02-02 18:35:54 +00:00
|
|
|
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 });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|