this repo has no description
at v1.0.1 1.7 kB view raw
1import { constants } from "@moonlight-mod/types"; 2import requireImport from "./import"; 3 4export function getMoonlightDir(): string { 5 const { app, ipcRenderer } = require("electron"); 6 const fs = requireImport("fs"); 7 const path = requireImport("path"); 8 9 let appData = ""; 10 injector: { 11 appData = app.getPath("appData"); 12 } 13 14 nodePreload: { 15 appData = ipcRenderer.sendSync(constants.ipcGetAppData); 16 } 17 18 const dir = path.join(appData, "moonlight-mod"); 19 if (!fs.existsSync(dir)) fs.mkdirSync(dir); 20 21 return dir; 22} 23 24type BuildInfo = { 25 releaseChannel: string; 26 version: string; 27}; 28 29export function getConfigPath(): string { 30 const dir = getMoonlightDir(); 31 const fs = requireImport("fs"); 32 const path = requireImport("path"); 33 34 const buildInfoPath = path.join(process.resourcesPath, "build_info.json"); 35 const buildInfo: BuildInfo = JSON.parse( 36 fs.readFileSync(buildInfoPath, "utf8") 37 ); 38 39 const configPath = path.join(dir, buildInfo.releaseChannel + ".json"); 40 return configPath; 41} 42 43function getPathFromMoonlight(...names: string[]): string { 44 const dir = getMoonlightDir(); 45 const fs = requireImport("fs"); 46 const path = requireImport("path"); 47 48 const target = path.join(dir, ...names); 49 if (!fs.existsSync(target)) fs.mkdirSync(target); 50 51 return target; 52} 53 54export function getExtensionsPath(): string { 55 return getPathFromMoonlight(constants.extensionsDir); 56} 57 58export function getCoreExtensionsPath(): string { 59 if (MOONLIGHT_PROD) { 60 return getPathFromMoonlight(constants.distDir, constants.coreExtensionsDir); 61 } else { 62 const path = requireImport("path"); 63 return path.join(__dirname, constants.coreExtensionsDir); 64 } 65}