From 0105c5975afde1cd5f3c51fe1d78d6eda4a4684d Mon Sep 17 00:00:00 2001 From: HorizonCode Date: Wed, 4 Nov 2026 21:29:02 +0100 Subject: [PATCH] fix: unsafe use --- src-tauri/src/commands.rs | 114 ++++++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 48 deletions(-) diff --git a/src-tauri/src/commands.rs b/src-tauri/src/commands.rs index 051ca19..c96a680 100644 --- a/src-tauri/src/commands.rs +++ b/src-tauri/src/commands.rs @@ -265,8 +265,7 @@ pub async fn read_file_chunk(path: String, offset: u64, length: u64) -> Result String { - get_id() - .unwrap_or("recorderinsandybridge".to_string()) + get_id().unwrap_or("recorderinsandybridge".to_string()) } /// Show the native macOS picker, which can select `osu!.app` bundles as files. @@ -551,18 +550,19 @@ pub async fn get_skins_count(folder: String) -> Option { if let Ok(mut entries) = fs::read_dir(skins_folder).await { while let Ok(Some(entry)) = entries.next_entry().await { if let Ok(ft) = entry.file_type().await - && ft.is_dir() { - let dir_path = entry.path(); - let has_ini = tokio::fs::try_exists(dir_path.join("skin.ini")) + && ft.is_dir() + { + let dir_path = entry.path(); + let has_ini = tokio::fs::try_exists(dir_path.join("skin.ini")) + .await + .unwrap_or(false) + || tokio::fs::try_exists(dir_path.join("Skin.ini")) .await - .unwrap_or(false) - || tokio::fs::try_exists(dir_path.join("Skin.ini")) - .await - .unwrap_or(false); - if has_ini { - count += 1; - } + .unwrap_or(false); + if has_ini { + count += 1; } + } } } Some(count) @@ -759,7 +759,7 @@ pub async fn run_osu( #[cfg(windows)] if optimize { #[link(name = "winmm")] - extern "system" { + unsafe extern "system" { fn timeBeginPeriod(uPeriod: u32) -> u32; } unsafe { @@ -906,7 +906,7 @@ pub async fn run_osu( #[cfg(windows)] if optimize { #[link(name = "winmm")] - extern "system" { + unsafe extern "system" { fn timeEndPeriod(uPeriod: u32) -> u32; } unsafe { @@ -1062,7 +1062,10 @@ pub async fn download_ezpp_launcher_update_files( #[cfg(target_os = "macos")] { - let patcher_exe = osu_path.join("EZPPLauncher").join("patcher").join("osu!.patcher.exe"); + let patcher_exe = osu_path + .join("EZPPLauncher") + .join("patcher") + .join("osu!.patcher.exe"); if patcher_exe.is_file() { let _ = crate::utils::ensure_patcher_compatibility(&patcher_exe); } @@ -1938,18 +1941,19 @@ pub(crate) fn theme_root() -> Result { #[cfg(any(target_os = "linux", target_os = "macos"))] fn loopback_theme_asset_base() -> String { if crate::theme_server::base_url().is_none() - && let Ok(root) = theme_root() { - match crate::theme_server::media_root() { - Ok(media) => { - if let Err(error) = crate::theme_server::start(root, media) { - log::warn!(target: "launcher", "Could not start the theme asset server: {error}"); - } - } - Err(error) => { - log::warn!(target: "launcher", "Could not prepare the media cache: {error}"); + && let Ok(root) = theme_root() + { + match crate::theme_server::media_root() { + Ok(media) => { + if let Err(error) = crate::theme_server::start(root, media) { + log::warn!(target: "launcher", "Could not start the theme asset server: {error}"); } } + Err(error) => { + log::warn!(target: "launcher", "Could not prepare the media cache: {error}"); + } } + } crate::theme_server::base_url().unwrap_or_default() } @@ -2097,7 +2101,14 @@ pub async fn optimize_theme_media(app: AppHandle, source_url: String) -> Result< }; tokio::task::spawn_blocking(move || { - optimize_theme_media_blocking(&ffmpeg, &source, &original, &cache_name, &destination, on_progress) + optimize_theme_media_blocking( + &ffmpeg, + &source, + &original, + &cache_name, + &destination, + on_progress, + ) }) .await .map_err(|error| format!("Theme media optimizer thread failed: {error}"))? @@ -2258,17 +2269,20 @@ async fn download_ffmpeg(app: &AppHandle) -> Result { .await .map_err(|error| format!("Could not write the FFmpeg archive: {error}"))?; - if let Some(percent) = (received.min(total) * 100).checked_div(total).map(|v| v as u8) - && percent != last_percent { - last_percent = percent; - let _ = app.emit( - "theme-media-progress", - ThemeMediaProgress { - stage: "download".to_string(), - progress: percent as f64 / 100.0, - }, - ); - } + if let Some(percent) = (received.min(total) * 100) + .checked_div(total) + .map(|v| v as u8) + && percent != last_percent + { + last_percent = percent; + let _ = app.emit( + "theme-media-progress", + ThemeMediaProgress { + stage: "download".to_string(), + progress: percent as f64 / 100.0, + }, + ); + } } file.flush() @@ -2715,15 +2729,18 @@ pub async fn open_presence_editor(app: AppHandle) -> Result<(), String> { return Ok(()); } - let window = - WebviewWindowBuilder::new(&app, "presence-editor", WebviewUrl::App("index.html".into())) - .title("EZPPLauncher — Discord Rich Presence Editor") - .inner_size(1200.0, 800.0) - .min_inner_size(980.0, 650.0) - .resizable(true) - .center() - .build() - .map_err(|error| format!("Could not open the presence editor: {error}"))?; + let window = WebviewWindowBuilder::new( + &app, + "presence-editor", + WebviewUrl::App("index.html".into()), + ) + .title("EZPPLauncher — Discord Rich Presence Editor") + .inner_size(1200.0, 800.0) + .min_inner_size(980.0, 650.0) + .resizable(true) + .center() + .build() + .map_err(|error| format!("Could not open the presence editor: {error}"))?; let main_window = app.clone(); window.on_window_event(move |event| { @@ -3118,9 +3135,10 @@ fn collect_theme_asset_refs(value: &Value, assets: &mut HashSet) { for (key, value) in object { if (key == "src" || key == "preview") && let Some(src) = value.as_str() - && let Some(path) = theme_asset_reference(src) { - assets.insert(path); - } + && let Some(path) = theme_asset_reference(src) + { + assets.insert(path); + } collect_theme_asset_refs(value, assets); } }