Skip to content

Commit

Permalink
Make cold clear download more modifiable
Browse files Browse the repository at this point in the history
  • Loading branch information
Not-A-Normal-Robot committed Oct 31, 2024
1 parent 704aafa commit 3c90679
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
10 changes: 6 additions & 4 deletions src/cold_clear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn format_time(secs: i32) -> String {
}
}

pub fn download_cold_clear() -> Result<(), reqwest::Error> {
pub fn download_cold_clear(version: &str) -> Result<(), reqwest::Error> {
let (tx, rx) = mpsc::channel::<LoadingIPCMessage>();

let window = ColdClearWaitWindow::new()
Expand All @@ -60,14 +60,16 @@ pub fn download_cold_clear() -> Result<(), reqwest::Error> {
window.on_format_bytes(format_bytes);

let window_weak = window.as_weak();
let version = version.to_owned();
thread::spawn(move || {
let rt = Runtime::new()
.expect("Failed to create Tokio runtime");

rt.block_on(async move {
let url = paths::COLD_CLEAR_DOWNLOAD_URL;
let save_path = paths::get_cold_clear_download_path();
let version = version.as_str();
let url = paths::get_cold_clear_download_url(version);
let save_path = paths::get_cold_clear_download_path(version);

rt.block_on(async move {
let begin_time = Instant::now();

let client = reqwest::Client::new();
Expand Down
50 changes: 26 additions & 24 deletions src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,33 +152,35 @@ pub mod paths {
return get_conf_dir_path().join("config.json");
}

pub fn get_cold_clear_download_path() -> PathBuf {
return get_conf_dir_path().join("cold_clear.zip");
pub fn get_cold_clear_download_path(version: &str) -> PathBuf {
return get_conf_dir_path()
.join("cold_clear")
.join(version.to_string() + ".zip");
}

pub const COLD_CLEAR_DOWNLOAD_URL: &str =
if cfg!(target_os = "windows") {
"https://github.com/26F-Studio/cold_clear_ai_love2d_wrapper/releases/download/11.4.2/Windows.zip"
} else if cfg!(target_os = "macos") {
"https://github.com/26F-Studio/cold_clear_ai_love2d_wrapper/releases/download/11.4.2/macOS.zip"
} else if cfg!(target_os = "linux") {
"https://github.com/26F-Studio/cold_clear_ai_love2d_wrapper/releases/download/11.4.2/Linux.zip"
} else if cfg!(target_os = "android") {
"https://github.com/26F-Studio/cold_clear_ai_love2d_wrapper/releases/download/11.4.2/Android.zip"
} else if cfg!(target_os = "ios") {
"https://github.com/26F-Studio/cold_clear_ai_love2d_wrapper/releases/download/11.4.2/iOS.zip"
} else {
#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "android",
target_os = "ios"
)))]
compile_error!("Unsupported operating system: {}", std::env::consts::OS);

unreachable!();
pub fn get_cold_clear_download_url(version: &str) -> String {
let file_name = match std::env::consts::OS {
"windows" => "Windows.zip",
"macos" => "macOS.zip",
"linux" => "Linux.zip",
"android" => "Android.zip",
"ios" => "iOS.zip",
_ => unreachable!()
};

#[cfg(not(any(
target_os = "windows",
target_os = "macos",
target_os = "linux",
target_os = "android",
target_os = "ios"
)))]
compile_error!("Unsupported operating system: {}", std::env::consts::OS);

return format!(
"https://github.com/26F-Studio/cold_clear_ai_love2d_wrapper/releases/download/{version}/{file_name}"
);
}

#[cfg(not(any(
target_os = "windows",
Expand Down

0 comments on commit 3c90679

Please sign in to comment.