remove empty resources in case of dry launch

This commit is contained in:
SpikeHD
2022-06-05 21:15:50 -07:00
parent 04a29ce567
commit c1b5256a5b
5 changed files with 11 additions and 12 deletions

9
src-tauri/Cargo.lock generated
View File

@@ -2091,12 +2091,6 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
[[package]]
name = "minisign-verify"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "933dca44d65cdd53b355d0b73d380a2ff5da71f87f036053188bf1eab6a19881"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.5.1" version = "0.5.1"
@@ -3860,7 +3854,6 @@ checksum = "a34cef4a0ebee0230baaa319b1709c4336f4add550149d2b005a9a5dc5d33617"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"attohttpc", "attohttpc",
"base64",
"bincode", "bincode",
"cocoa", "cocoa",
"dirs-next", "dirs-next",
@@ -3874,7 +3867,6 @@ dependencies = [
"heck 0.4.0", "heck 0.4.0",
"http", "http",
"ignore", "ignore",
"minisign-verify",
"notify-rust", "notify-rust",
"objc", "objc",
"once_cell", "once_cell",
@@ -3906,7 +3898,6 @@ dependencies = [
"webkit2gtk", "webkit2gtk",
"webview2-com", "webview2-com",
"windows 0.30.0", "windows 0.30.0",
"zip 0.6.2",
] ]
[[package]] [[package]]

View File

@@ -16,7 +16,7 @@ tauri-build = { version = "1.0.0-rc.8", features = [] }
[dependencies] [dependencies]
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0-rc.9", features = ["api-all", "updater"] } tauri = { version = "1.0.0-rc.9", features = ["api-all"] }
# Access system process info. # Access system process info.
sysinfo = "0.23.12" sysinfo = "0.23.12"

View File

@@ -28,3 +28,8 @@ pub fn dir_exists(path: &str) -> bool {
pub fn dir_is_empty(path: &str) -> bool { pub fn dir_is_empty(path: &str) -> bool {
return fs::read_dir(&path).unwrap().count() == 0; return fs::read_dir(&path).unwrap().count() == 0;
} }
#[tauri::command]
pub fn dir_delete(path: &str) {
fs::remove_dir_all(path).unwrap();
}

View File

@@ -59,6 +59,7 @@ fn main() {
file_helpers::rename, file_helpers::rename,
file_helpers::dir_exists, file_helpers::dir_exists,
file_helpers::dir_is_empty, file_helpers::dir_is_empty,
file_helpers::dir_delete,
downloader::download_file, downloader::download_file,
downloader::stop_download, downloader::stop_download,
lang::get_lang, lang::get_lang,

View File

@@ -73,7 +73,9 @@ export default class Downloads extends React.Component<IProps, IState> {
if (gc_path) { if (gc_path) {
const resources_exist: boolean = await invoke('dir_exists', { const resources_exist: boolean = await invoke('dir_exists', {
path: path + '\\resources' path: path + '\\resources'
}) }) as boolean && !(await invoke('dir_is_empty', {
path: path + '\\resources'
})) as boolean
this.setState({ this.setState({
grasscutter_set: gc_path !== '', grasscutter_set: gc_path !== '',
@@ -153,7 +155,7 @@ export default class Downloads extends React.Component<IProps, IState> {
if (await invoke('dir_exists', { if (await invoke('dir_exists', {
path: folder + '\\resources' path: folder + '\\resources'
})) { })) {
await invoke('delete_dir', { await invoke('dir_delete', {
path: folder + '\\resources' path: folder + '\\resources'
}) })
} }