-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { | ||
BaseDirectory, | ||
exists, | ||
createDir, | ||
readTextFile, | ||
writeTextFile, | ||
} from "@tauri-apps/api/fs"; | ||
|
||
const APP_DATA_FOLDER = "ArcdpsUpdaterDx11"; | ||
const CONFIG_FILE_NAME = "app.config.json"; | ||
|
||
/* ------------------------- */ | ||
|
||
interface AppConfig { | ||
gameDir?: string; | ||
} | ||
|
||
console.log("Loading App Config..."); | ||
|
||
let appConfig: AppConfig = { | ||
gameDir: "", | ||
}; | ||
appConfig = await readConfigJson(); | ||
|
||
console.log("App Config loaded successfully.", appConfig); | ||
|
||
/* ------------------------- */ | ||
|
||
export async function createDataFolder() { | ||
return createDir(APP_DATA_FOLDER, { | ||
dir: BaseDirectory.Data, | ||
recursive: true, | ||
}); | ||
} | ||
|
||
export async function readConfigJson() { | ||
const filepath = `${APP_DATA_FOLDER}/${CONFIG_FILE_NAME}`; | ||
try { | ||
exists(filepath, { dir: BaseDirectory.Data }); | ||
const filedata = await readTextFile(filepath, { dir: BaseDirectory.Data }); | ||
return JSON.parse(filedata); | ||
} catch (error) { | ||
saveConfigJson(); | ||
return appConfig; | ||
} | ||
} | ||
|
||
export async function saveConfigJson() { | ||
const filepath = `${APP_DATA_FOLDER}/${CONFIG_FILE_NAME}`; | ||
writeTextFile(filepath, JSON.stringify(appConfig, undefined, 3), { | ||
dir: BaseDirectory.Data, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters