This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathfile_manager.ts
61 lines (52 loc) · 1.82 KB
/
file_manager.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { promises } from "fs";
import FsExtensions from "./fs_extensions";
const process = global.process;
class FileManager {
public static fileListPath: string | null
public static async Init() {
this.fileListPath = await this.GetPath();
}
/**
* Gets the mod's file list
* @param {string} modName Mod name
*/
public static async GetFileList(modName: string) {
const path = this.fileListPath + modName + "_files.json";
if (await FsExtensions.fileExists(path)) {
const json = await promises.readFile(path, { encoding: "utf8" });
return JSON.parse(json);
}
else {
//Make new object and return it.
return {
files: []
};
}
}
/**
* Saves the mod's file list
* @param {string} fileList file list
* @param {string} modName mod name
*/
public static async SaveFileList(fileList: string, modName: string) {
const path = this.fileListPath + modName + "_files.json";
await promises.writeFile(path, JSON.stringify(fileList), "utf-8");
}
/**
* Removes the mod's file list
* @param {string} modName mod name
*/
public static async RemoveFileList(modName: string) {
const path = this.fileListPath + modName + "_files.json";
if (await FsExtensions.fileExists(path)) {
await promises.unlink(path);
}
}
public static async GetPath(): Promise<string> {
const path = (process.env.APPDATA || (process.platform == "darwin" ? process.env.HOME + "/Library/Preferences" : process.env.HOME + "/.local/share")) + "/creators-tf-launcher";
await FsExtensions.ensureDirectoryExists(path);
const fullPath = path + "/";
return fullPath;
}
}
export default FileManager;