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