diff --git a/Cargo.lock b/Cargo.lock index cfc3ac5..25f75df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -815,6 +815,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "futures" version = "0.3.30" @@ -3173,6 +3179,7 @@ dependencies = [ name = "workshop_uploader" version = "0.1.0" dependencies = [ + "fs_extra", "iced", "image", "native-dialog", diff --git a/Cargo.toml b/Cargo.toml index 697fdea..f4dc2d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ iced = "0.6" native-dialog = "0.6.3" image = "0.24.7" open = "5.1.2" +fs_extra = "1.3.0" [build-dependencies] winres = "0.1.12" diff --git a/src/my_steamworks.rs b/src/my_steamworks.rs index 2b3344b..953b055 100644 --- a/src/my_steamworks.rs +++ b/src/my_steamworks.rs @@ -5,6 +5,7 @@ use std::sync::{atomic::AtomicUsize, atomic::Ordering, Arc}; use std::thread::Thread; use std::time::Duration; use steamworks::{Client, PublishedFileId, QueryResult, QueryResults, SingleClient, SteamError}; +use std::fs; #[derive(Debug, Clone)] pub struct SingleClientExecutor { @@ -198,6 +199,21 @@ impl WorkshopClient { item_id: PublishedFileId, item_info: ItemInfo, ) -> Result<(PublishedFileId, bool), SteamError> { + let temp_dir = std::env::temp_dir(); // Get the temporary directory + let temp_folder = temp_dir.join("wani_workshop_folder"); // Create a specific folder within temporary directory + let full_folder = temp_folder.join("mods"); + + // Create the folders if they doesn't exist + if !temp_folder.exists() { + let _ = fs::create_dir(&temp_folder); + } + if !full_folder.exists() { + let _ = fs::create_dir(&full_folder); + } + + // // Copy the contents of the target folder to the temporary folder + let _ = fs_extra::dir::copy(&item_info.target_folder, &full_folder, &fs_extra::dir::CopyOptions::new()); + let rx = { let app_id = self.steam_client.utils().app_id(); @@ -212,7 +228,7 @@ impl WorkshopClient { .ugc() .start_item_update(app_id, item_id) .title(item_info.name.as_str()) - .content_path(&item_info.target_folder); + .content_path(&temp_folder); // Set the temporary folder as the content path if item_info.preview_image.exists() { update_handle = update_handle.preview_path(&item_info.preview_image) @@ -227,9 +243,14 @@ impl WorkshopClient { rx }; - rx.await + let result = rx.await .map_err(|iced::futures::channel::oneshot::Canceled| SteamError::Cancelled) - .and_then(|x| x) + .and_then(|x| x); + + // Clear the temporary folder after the upload is done + let _ = std::fs::remove_dir_all(&full_folder); + + Ok(result?) } }