From d884883103f180c5dfb043ffb1cbc8315dc9e731 Mon Sep 17 00:00:00 2001 From: EliteAsian <29520859+EliteAsian123@users.noreply.github.com> Date: Fri, 21 Jul 2023 14:46:22 -0400 Subject: [PATCH] Prevent user from selecting non-empty folders --- src-tauri/src/main.rs | 11 ++++++- src/assets/Icons/Warning.svg | 3 ++ src/assets/Icons/index.ts | 4 ++- src/components/LaunchPage/styles.module.css | 2 +- src/dialogs/DialogProvider.module.css | 2 ++ .../Dialogs/InstallFolderDialog.module.css | 20 +++++++++++++ src/dialogs/Dialogs/InstallFolderDialog.tsx | 29 +++++++++++++++---- 7 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 src/assets/Icons/Warning.svg diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 584717a..94563bc 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -436,6 +436,14 @@ async fn get_download_location(state: tauri::State<'_, State>) -> Result bool { + match fs::read_dir(path) { + Ok(mut entries) => entries.next().is_none(), + Err(_) => false, + } +} + fn main() { tauri::Builder::default() .plugin(tauri_plugin_log::Builder::default().build()) @@ -457,7 +465,8 @@ fn main() { get_os, is_initialized, set_download_location, - get_download_location + get_download_location, + is_dir_empty ]) .setup(|app| { let window = app.get_window("main").unwrap(); diff --git a/src/assets/Icons/Warning.svg b/src/assets/Icons/Warning.svg new file mode 100644 index 0000000..71e1bea --- /dev/null +++ b/src/assets/Icons/Warning.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/assets/Icons/index.ts b/src/assets/Icons/index.ts index ed87356..e8243aa 100644 --- a/src/assets/Icons/index.ts +++ b/src/assets/Icons/index.ts @@ -22,6 +22,7 @@ import { ReactComponent as UpdateIcon } from "./Update.svg"; import { ReactComponent as DriveIcon } from "./Drive.svg"; import { ReactComponent as UnknownUserIcon } from "./UnknownUser.svg"; import { ReactComponent as BackIcon } from "./Back.svg"; +import { ReactComponent as WarningIcon } from "./Warning.svg"; export { AddIcon, @@ -47,5 +48,6 @@ export { UpdateIcon, DriveIcon, UnknownUserIcon, - BackIcon + BackIcon, + WarningIcon }; \ No newline at end of file diff --git a/src/components/LaunchPage/styles.module.css b/src/components/LaunchPage/styles.module.css index 94dee96..52f9d8c 100644 --- a/src/components/LaunchPage/styles.module.css +++ b/src/components/LaunchPage/styles.module.css @@ -26,7 +26,7 @@ .icon_container { position: relative; - z-index: 100; + z-index: 1; } .icon { diff --git a/src/dialogs/DialogProvider.module.css b/src/dialogs/DialogProvider.module.css index 56460e2..7bbbd5e 100644 --- a/src/dialogs/DialogProvider.module.css +++ b/src/dialogs/DialogProvider.module.css @@ -3,6 +3,7 @@ position: fixed; inset: 0; animation: overlayShow 150ms cubic-bezier(0.16, 1, 0.3, 1); + z-index: 9998; } .content { @@ -10,6 +11,7 @@ padding: 25px 50px; flex-direction: column; align-items: center; + z-index: 9999; border-radius: 8px; background: linear-gradient(360deg, rgba(255, 255, 255, 0.25) 0%, rgba(184, 184, 184, 0.25) 100%), #FFF; diff --git a/src/dialogs/Dialogs/InstallFolderDialog.module.css b/src/dialogs/Dialogs/InstallFolderDialog.module.css index 85fe822..8ba56de 100644 --- a/src/dialogs/Dialogs/InstallFolderDialog.module.css +++ b/src/dialogs/Dialogs/InstallFolderDialog.module.css @@ -36,4 +36,24 @@ font-weight: 600; line-height: normal; text-transform: uppercase; +} + +.warning_box { + margin-top: 10px; + + display: flex; + padding: 15px; + align-items: center; + gap: 10px; + align-self: stretch; + + border-radius: var(--web-radius, 8px); + border: 1px solid #FFA800; + background: rgba(255, 168, 0, 0.10); + + color: #7C5200; + font-size: 12px; + font-style: normal; + font-weight: 400; + line-height: normal; } \ No newline at end of file diff --git a/src/dialogs/Dialogs/InstallFolderDialog.tsx b/src/dialogs/Dialogs/InstallFolderDialog.tsx index 9dee3cc..e26dedc 100644 --- a/src/dialogs/Dialogs/InstallFolderDialog.tsx +++ b/src/dialogs/Dialogs/InstallFolderDialog.tsx @@ -2,25 +2,28 @@ import Button, { ButtonColor } from "@app/components/Button"; import { BaseDialog } from "./BaseDialog"; import { open } from "@tauri-apps/api/dialog"; import styles from "./InstallFolderDialog.module.css"; -import { DriveIcon } from "@app/assets/Icons"; +import { DriveIcon, WarningIcon } from "@app/assets/Icons"; import { invoke } from "@tauri-apps/api"; interface State { path?: string; + empty: boolean; } export class InstallFolderDialog extends BaseDialog { constructor(props: Record) { super(props); this.state = { - path: undefined + path: undefined, + empty: true }; // Load the default path (async () => { const path = await invoke("get_download_location") as string; this.setState(() => ({ - path: path + path: path, + empty: true })); })(); } @@ -40,6 +43,12 @@ export class InstallFolderDialog extends BaseDialog { + {!this.state.empty ? +
+ The folder selected is not empty! Make sure it doesn't have any files in it. +
+ : "" + } ; } @@ -49,8 +58,12 @@ export class InstallFolderDialog extends BaseDialog { }); if (typeof select === "string") { + const path: string = select; + const empty: boolean = await invoke("is_dir_empty", { path: path }); + this.setState(() => ({ - path: select as string + path: path, + empty: empty })); } } @@ -62,7 +75,13 @@ export class InstallFolderDialog extends BaseDialog { getButtons() { return <> - + ; } } \ No newline at end of file