mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 15:14:35 +01:00
@@ -177,6 +177,19 @@ async function readConfigFile() {
|
|||||||
configFilePath = local + 'cultivation/configuration.json'
|
configFilePath = local + 'cultivation/configuration.json'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const dataFiles = await fs.readDir(local + 'cultivation')
|
||||||
|
|
||||||
|
// Ensure config exists
|
||||||
|
if (!dataFiles.find((fileOrDir) => fileOrDir?.name === 'configuration.json')) {
|
||||||
|
// Create config file
|
||||||
|
const file: fs.FsTextFileOption = {
|
||||||
|
path: configFilePath,
|
||||||
|
contents: JSON.stringify(defaultConfig),
|
||||||
|
}
|
||||||
|
|
||||||
|
await fs.writeFile(file)
|
||||||
|
}
|
||||||
|
|
||||||
// Read existing config to get profile name
|
// Read existing config to get profile name
|
||||||
const raw = await fs.readTextFile(configFilePath)
|
const raw = await fs.readTextFile(configFilePath)
|
||||||
const cfg = <Configuration>JSON.parse(raw)
|
const cfg = <Configuration>JSON.parse(raw)
|
||||||
@@ -206,19 +219,6 @@ async function readConfigFile() {
|
|||||||
await fs.createDir(local + 'cultivation/grasscutter').catch((e) => console.log(e))
|
await fs.createDir(local + 'cultivation/grasscutter').catch((e) => console.log(e))
|
||||||
}
|
}
|
||||||
|
|
||||||
const dataFiles = await fs.readDir(local + 'cultivation')
|
|
||||||
|
|
||||||
// Ensure config exists
|
|
||||||
if (!dataFiles.find((fileOrDir) => fileOrDir?.name === 'configuration.json')) {
|
|
||||||
// Create config file
|
|
||||||
const file: fs.FsTextFileOption = {
|
|
||||||
path: configFilePath,
|
|
||||||
contents: JSON.stringify(defaultConfig),
|
|
||||||
}
|
|
||||||
|
|
||||||
await fs.writeFile(file)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Finally, read the file
|
// Finally, read the file
|
||||||
return await fs.readTextFile(configFilePath)
|
return await fs.readTextFile(configFilePath)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user