From e7287673f54ae94d90749e033bdf8d0d9c5c58a9 Mon Sep 17 00:00:00 2001 From: SpikeHD Date: Mon, 16 May 2022 20:30:53 -0700 Subject: [PATCH] default install path in appdata --- src/ui/components/menu/Downloads.tsx | 22 +++++++++++++++++++++- src/utils/configuration.ts | 9 +++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/ui/components/menu/Downloads.tsx b/src/ui/components/menu/Downloads.tsx index b35db6e..e598b03 100644 --- a/src/ui/components/menu/Downloads.tsx +++ b/src/ui/components/menu/Downloads.tsx @@ -4,10 +4,11 @@ import Tr from '../../../utils/language' import DownloadHandler from '../../../utils/download' import { unzip } from '../../../utils/zip_utils' import BigButton from '../common/BigButton' +import { dataDir } from '@tauri-apps/api/path' import './Downloads.css' import Divider from './Divider' -import { getConfigOption } from '../../../utils/configuration' +import { getConfigOption, setConfigOption } from '../../../utils/configuration' import { invoke } from '@tauri-apps/api' const STABLE_REPO_DOWNLOAD = 'https://github.com/Grasscutters/Grasscutter/archive/refs/heads/stable.zip' @@ -52,6 +53,16 @@ export default class Downloads extends React.Component { async componentDidMount() { const gc_path = await getConfigOption('grasscutter_path') + + if (!gc_path || gc_path === '') { + this.setState({ + grasscutter_set: false, + resources_exist: false + }) + + return + } + const path = gc_path.substring(0, gc_path.lastIndexOf('\\')) if (gc_path) { @@ -70,6 +81,15 @@ export default class Downloads extends React.Component { const path = await getConfigOption('grasscutter_path') let folderPath + // Set to default if not set + if (!path || path === '') { + const appdata = await dataDir() + folderPath = appdata + 'cultivation\\grasscutter' + + // Early return since its formatted properly + return folderPath + } + if (path.includes('/')) { folderPath = path.substring(0, path.lastIndexOf('/')) } else { diff --git a/src/utils/configuration.ts b/src/utils/configuration.ts index d1f554c..560997b 100644 --- a/src/utils/configuration.ts +++ b/src/utils/configuration.ts @@ -87,6 +87,15 @@ async function readConfigFile() { await fs.createDir(local + 'cultivation') } + const innerDirs = await fs.readDir(local + '\\cultivation') + + // Create grasscutter dir for potential installation + if (!innerDirs.find((fileOrDir) => fileOrDir?.name === 'grasscutter')) { + // Create dir + await fs.createDir(local + 'cultivation\\grasscutter') + } + + const dataFiles = await fs.readDir(local + 'cultivation') // Ensure config exists