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');
|
|
|
|
|
2022-02-15 13:40:43 +00:00
|
|
|
let userData, userDataVersioned, resourcesPath, moduleData, exeDir, installPath;
|
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-15 13:40:43 +00:00
|
|
|
|
|
|
|
exports.init = () => {
|
|
|
|
const appDir = 'discord' + (buildInfo.releaseChannel === 'stable' ? '' : buildInfo.releaseChannel); // Clean channel naming up later to util?
|
|
|
|
userData = join(app.getPath('appData'), appDir);
|
|
|
|
userDataVersioned = join(userData, buildInfo.version);
|
|
|
|
|
|
|
|
exeDir = dirname(app.getPath('exe'));
|
|
|
|
if (basename(exeDir).startsWith('app-')) installPath = join(exeDir, '..');
|
|
|
|
|
|
|
|
moduleData = buildInfo.newUpdater ? join(userData, 'module_data') : join(userDataVersioned, 'modules');
|
|
|
|
resourcesPath = join(process.resourcesPath);
|
|
|
|
};
|
2022-02-02 18:35:54 +00:00
|
|
|
|
|
|
|
exports.cleanOldVersions = () => {
|
|
|
|
if (!installPath) return;
|
|
|
|
|
|
|
|
for (const x of fs.readdirSync(installPath)) {
|
2022-02-14 16:08:27 +00:00
|
|
|
if (x.startsWith('app-') && !x.includes(buildInfo.version)) fs.rmSync(join(installPath, x), { recursive: true, force: true });
|
2022-02-02 18:35:54 +00:00
|
|
|
}
|
|
|
|
};
|