fix: unsafe use
This commit is contained in:
1 file changed
+66
-48
+66
-48
@@ -265,8 +265,7 @@ pub async fn read_file_chunk(path: String, offset: u64, length: u64) -> Result<V
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn get_hwid() -> String {
|
pub fn get_hwid() -> String {
|
||||||
get_id()
|
get_id().unwrap_or("recorderinsandybridge".to_string())
|
||||||
.unwrap_or("recorderinsandybridge".to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Show the native macOS picker, which can select `osu!.app` bundles as files.
|
/// 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<u64> {
|
|||||||
if let Ok(mut entries) = fs::read_dir(skins_folder).await {
|
if let Ok(mut entries) = fs::read_dir(skins_folder).await {
|
||||||
while let Ok(Some(entry)) = entries.next_entry().await {
|
while let Ok(Some(entry)) = entries.next_entry().await {
|
||||||
if let Ok(ft) = entry.file_type().await
|
if let Ok(ft) = entry.file_type().await
|
||||||
&& ft.is_dir() {
|
&& ft.is_dir()
|
||||||
let dir_path = entry.path();
|
{
|
||||||
let has_ini = tokio::fs::try_exists(dir_path.join("skin.ini"))
|
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
|
.await
|
||||||
.unwrap_or(false)
|
.unwrap_or(false);
|
||||||
|| tokio::fs::try_exists(dir_path.join("Skin.ini"))
|
if has_ini {
|
||||||
.await
|
count += 1;
|
||||||
.unwrap_or(false);
|
|
||||||
if has_ini {
|
|
||||||
count += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(count)
|
Some(count)
|
||||||
@@ -759,7 +759,7 @@ pub async fn run_osu(
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
if optimize {
|
if optimize {
|
||||||
#[link(name = "winmm")]
|
#[link(name = "winmm")]
|
||||||
extern "system" {
|
unsafe extern "system" {
|
||||||
fn timeBeginPeriod(uPeriod: u32) -> u32;
|
fn timeBeginPeriod(uPeriod: u32) -> u32;
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -906,7 +906,7 @@ pub async fn run_osu(
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
if optimize {
|
if optimize {
|
||||||
#[link(name = "winmm")]
|
#[link(name = "winmm")]
|
||||||
extern "system" {
|
unsafe extern "system" {
|
||||||
fn timeEndPeriod(uPeriod: u32) -> u32;
|
fn timeEndPeriod(uPeriod: u32) -> u32;
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
@@ -1062,7 +1062,10 @@ pub async fn download_ezpp_launcher_update_files(
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[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() {
|
if patcher_exe.is_file() {
|
||||||
let _ = crate::utils::ensure_patcher_compatibility(&patcher_exe);
|
let _ = crate::utils::ensure_patcher_compatibility(&patcher_exe);
|
||||||
}
|
}
|
||||||
@@ -1938,18 +1941,19 @@ pub(crate) fn theme_root() -> Result<PathBuf, String> {
|
|||||||
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
#[cfg(any(target_os = "linux", target_os = "macos"))]
|
||||||
fn loopback_theme_asset_base() -> String {
|
fn loopback_theme_asset_base() -> String {
|
||||||
if crate::theme_server::base_url().is_none()
|
if crate::theme_server::base_url().is_none()
|
||||||
&& let Ok(root) = theme_root() {
|
&& let Ok(root) = theme_root()
|
||||||
match crate::theme_server::media_root() {
|
{
|
||||||
Ok(media) => {
|
match crate::theme_server::media_root() {
|
||||||
if let Err(error) = crate::theme_server::start(root, media) {
|
Ok(media) => {
|
||||||
log::warn!(target: "launcher", "Could not start the theme asset server: {error}");
|
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}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Err(error) => {
|
||||||
|
log::warn!(target: "launcher", "Could not prepare the media cache: {error}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
crate::theme_server::base_url().unwrap_or_default()
|
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 || {
|
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
|
.await
|
||||||
.map_err(|error| format!("Theme media optimizer thread failed: {error}"))?
|
.map_err(|error| format!("Theme media optimizer thread failed: {error}"))?
|
||||||
@@ -2258,17 +2269,20 @@ async fn download_ffmpeg(app: &AppHandle) -> Result<PathBuf, String> {
|
|||||||
.await
|
.await
|
||||||
.map_err(|error| format!("Could not write the FFmpeg archive: {error}"))?;
|
.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)
|
if let Some(percent) = (received.min(total) * 100)
|
||||||
&& percent != last_percent {
|
.checked_div(total)
|
||||||
last_percent = percent;
|
.map(|v| v as u8)
|
||||||
let _ = app.emit(
|
&& percent != last_percent
|
||||||
"theme-media-progress",
|
{
|
||||||
ThemeMediaProgress {
|
last_percent = percent;
|
||||||
stage: "download".to_string(),
|
let _ = app.emit(
|
||||||
progress: percent as f64 / 100.0,
|
"theme-media-progress",
|
||||||
},
|
ThemeMediaProgress {
|
||||||
);
|
stage: "download".to_string(),
|
||||||
}
|
progress: percent as f64 / 100.0,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
file.flush()
|
file.flush()
|
||||||
@@ -2715,15 +2729,18 @@ pub async fn open_presence_editor(app: AppHandle) -> Result<(), String> {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let window =
|
let window = WebviewWindowBuilder::new(
|
||||||
WebviewWindowBuilder::new(&app, "presence-editor", WebviewUrl::App("index.html".into()))
|
&app,
|
||||||
.title("EZPPLauncher — Discord Rich Presence Editor")
|
"presence-editor",
|
||||||
.inner_size(1200.0, 800.0)
|
WebviewUrl::App("index.html".into()),
|
||||||
.min_inner_size(980.0, 650.0)
|
)
|
||||||
.resizable(true)
|
.title("EZPPLauncher — Discord Rich Presence Editor")
|
||||||
.center()
|
.inner_size(1200.0, 800.0)
|
||||||
.build()
|
.min_inner_size(980.0, 650.0)
|
||||||
.map_err(|error| format!("Could not open the presence editor: {error}"))?;
|
.resizable(true)
|
||||||
|
.center()
|
||||||
|
.build()
|
||||||
|
.map_err(|error| format!("Could not open the presence editor: {error}"))?;
|
||||||
|
|
||||||
let main_window = app.clone();
|
let main_window = app.clone();
|
||||||
window.on_window_event(move |event| {
|
window.on_window_event(move |event| {
|
||||||
@@ -3118,9 +3135,10 @@ fn collect_theme_asset_refs(value: &Value, assets: &mut HashSet<String>) {
|
|||||||
for (key, value) in object {
|
for (key, value) in object {
|
||||||
if (key == "src" || key == "preview")
|
if (key == "src" || key == "preview")
|
||||||
&& let Some(src) = value.as_str()
|
&& let Some(src) = value.as_str()
|
||||||
&& let Some(path) = theme_asset_reference(src) {
|
&& let Some(path) = theme_asset_reference(src)
|
||||||
assets.insert(path);
|
{
|
||||||
}
|
assets.insert(path);
|
||||||
|
}
|
||||||
collect_theme_asset_refs(value, assets);
|
collect_theme_asset_refs(value, assets);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user