*Force create of config directory if it does not exist

This commit is contained in:
Derrick Hammer 2022-12-06 16:38:58 -05:00
parent 3e412d5090
commit 7c631f3af5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 10 additions and 0 deletions

View File

@ -80,6 +80,7 @@ export default class Config {
}
}
}
public inject(options: object) {
for (const key of Object.keys(options)) {
const value = options[key];
@ -174,6 +175,10 @@ export default class Config {
const fullPath = Path.join(this.str("configdir"), file);
if (!fs.existsSync(fullPath)) {
fs.mkdirSync(fullPath, { recursive: true });
}
fs.writeFileSync(fullPath, JSON.stringify(data));
this.openJson(fullPath);
}
@ -317,6 +322,7 @@ export default class Config {
return value;
}
int(key, fallback = null) {
const value = this.get(key);
@ -398,6 +404,7 @@ export default class Config {
return num;
}
ufloat(key, fallback = null) {
const value = this.float(key);
if (value === null) {
@ -424,6 +431,7 @@ export default class Config {
throw new Error(`${fmt(key)} must be a fixed number.`);
}
}
ufixed(key, exp, fallback = null) {
const value = this.fixed(key, exp);
@ -473,6 +481,7 @@ export default class Config {
throw new Error(`${fmt(key)} must be a boolean.`);
}
buf(key: string, fallback = null, enc: BufferEncoding = "hex") {
const value = this.get(key);
@ -875,6 +884,7 @@ export default class Config {
return this.parseForm(query, "?", this.query);
}
public parseHash(hash: string) {
if (typeof hash !== "string") {
if (!global.location) {