diff --git a/src-tauri/src/file_helpers.rs b/src-tauri/src/file_helpers.rs index aa4ce96..ce59454 100644 --- a/src-tauri/src/file_helpers.rs +++ b/src-tauri/src/file_helpers.rs @@ -22,4 +22,9 @@ pub fn rename(path: String, new_name: String) { #[tauri::command] pub fn dir_exists(path: &str) -> bool { return fs::metadata(&path).is_ok(); +} + +#[tauri::command] +pub fn dir_is_empty(path: &str) -> bool { + return fs::read_dir(&path).unwrap().count() == 0; } \ No newline at end of file diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 0f1aae1..5d251d0 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -56,6 +56,7 @@ fn main() { unzip::unzip, file_helpers::rename, file_helpers::dir_exists, + file_helpers::dir_is_empty, downloader::download_file, downloader::stop_download, lang::get_lang, diff --git a/src/ui/components/MiniDialog.tsx b/src/ui/components/MiniDialog.tsx index 36b9e4d..69d1c27 100644 --- a/src/ui/components/MiniDialog.tsx +++ b/src/ui/components/MiniDialog.tsx @@ -16,7 +16,14 @@ export default class MiniDialog extends React.Component { } componentDidMount() { - document.addEventListener('mousedown', this.props.closeFn) + document.addEventListener('mousedown', (evt) => { + const tgt = evt.target as HTMLElement + const isInside = tgt.closest('.MiniDialog') !== null + + if (!isInside) { + this.props.closeFn() + } + }) } componentWillUnmount() { diff --git a/src/ui/components/menu/Downloads.tsx b/src/ui/components/menu/Downloads.tsx index 6fb891f..4fdff7c 100644 --- a/src/ui/components/menu/Downloads.tsx +++ b/src/ui/components/menu/Downloads.tsx @@ -149,6 +149,15 @@ export default class Downloads extends React.Component { async downloadResources() { const folder = await this.getGrasscutterFolder() this.props.downloadManager.addDownload(RESOURCES_DOWNLOAD, folder + '\\resources.zip', async () => { + // Delete the existing folder if it exists + if (await invoke('dir_exists', { + path: folder + '\\resources' + })) { + await invoke('delete_dir', { + path: folder + '\\resources' + }) + } + await unzip(folder + '\\resources.zip', folder + '\\', () => { // Rename folder to resources invoke('rename', {