OpenAsar/src/paths.js

35 lines
1.3 KiB
JavaScript
Raw Normal View History

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;
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;
2022-02-02 18:35:54 +00:00
exports.init = () => {}; // Stub as we setup on require
exports.cleanOldVersions = () => {
if (!installPath) return;
for (const x of fs.readdirSync(installPath)) {
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
}
};