Skip to content

Commit 6229c8a

Browse files
Only upgrade main.unity3d request to HTTPS if it's available
1 parent 83316b5 commit 6229c8a

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -561,9 +561,14 @@ async fn prep_launch(
561561
state.proxy = Some(handle);
562562
}
563563

564-
// Upgrade the main URL to HTTPS, since ffrunner supports it
564+
// Upgrade the main URL to HTTPS, if it's available, since ffrunner supports it
565565
if main_url.starts_with("http://") {
566-
main_url = main_url.replacen("http://", "https://", 1);
566+
let main_url_upgraded = main_url.replacen("http://", "https://", 1);
567+
if util::does_web_file_exist(&main_url_upgraded).await {
568+
main_url = main_url_upgraded;
569+
} else if !util::does_web_file_exist(&main_url).await {
570+
return Err(format!("Main file not found: {}", main_url).into());
571+
}
567572
}
568573

569574
debug!("Asset URL: {}", asset_url);

src-tauri/src/util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,3 +554,14 @@ pub(crate) fn log_command(command: &Command) {
554554
let command_str = get_launch_cmd_dbg_str(command, true);
555555
debug!("Launching game: {}", command_str);
556556
}
557+
558+
pub(crate) async fn does_web_file_exist(url: &str) -> bool {
559+
let client = get_http_client();
560+
match client.head(url).send().await {
561+
Ok(response) => response.status().is_success(),
562+
Err(e) => {
563+
debug!("Failed to check if web file exists: {}", e);
564+
false
565+
}
566+
}
567+
}

0 commit comments

Comments
 (0)