OpenAsar/src/paths.js

32 lines
1.2 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');
let userData, userDataVersioned, resourcesPath, moduleData, exeDir, installPath;
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;
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
global.moduleDataPath = moduleData; // Global because discord
app.setPath('userData', userData); // Set userData properly because electron
2022-02-02 18:35:54 +00:00
};