small fix that should make compiling for linux users work

This commit is contained in:
Yuhki 2025-04-07 15:40:30 +02:00
parent ef9cbad14a
commit 4d70933c4f
6 changed files with 59 additions and 16 deletions

4
Cargo.lock generated
View file

@ -150,9 +150,9 @@ dependencies = [
[[package]]
name = "ctrlc"
version = "3.4.5"
version = "3.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90eeab0aa92f3f9b4e87f258c72b139c207d251f9cbc1080a0086b86a8870dd3"
checksum = "697b5419f348fd5ae2478e8018cb016c00a5881c7f46c717de98ffd135a5651c"
dependencies = [
"nix",
"windows-sys 0.59.0",

View file

@ -4,20 +4,22 @@ version = "0.1.0"
edition = "2024"
build = "build.rs"
[build-dependencies]
winres = "0.1.12"
[dependencies]
colored = "3.0.0"
md-5 = "0.10.6"
reqwest = { version = "0.12.15", features = ["blocking", "json"] }
serde_json = "1.0.140"
serde = "1.0.219"
winconsole = "0.11.1"
ctrlc = "3.4.5"
ctrlc = "3.4.6"
shellexpand = "3.1.0"
flate2 = "1.1.1"
[target.'cfg(windows)'.dependencies]
winconsole = "0.11.1"
[target.'cfg(windows)'.build-dependencies]
winres = "0.1.12"
[profile.release]
strip = true
lto = true

View file

@ -1,5 +1,6 @@
fn main() {
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
#[cfg(windows)]
{
let mut res = winres::WindowsResource::new();
res.set_icon("zani.ico");
res.compile().unwrap();

View file

@ -2,6 +2,7 @@ use std::{fs::File, io, sync::Arc, thread, time::{Duration, Instant}};
use colored::Colorize;
use reqwest::blocking::Client;
use serde_json::Value;
#[cfg(windows)]
use winconsole::console::{clear, set_title};
use crate::{config::{cfg::Config, status::Status}, download::progress::DownloadProgress, io::logging::log_error, network::client::download_file};
@ -95,7 +96,10 @@ pub fn get_version(data: &Value, category: &str, version: &str) -> Result<String
pub fn exit_with_error(log_file: &File, error: &str) -> ! {
log_error(log_file, error);
#[cfg(windows)]
clear().unwrap();
println!("{} {}", Status::error(), error);
println!("\n{} Press Enter to exit...", Status::warning());
let _ = io::stdin().read_line(&mut String::new());
@ -162,7 +166,9 @@ pub fn start_title_thread(
eta_str
);
#[cfg(windows)]
set_title(&title).unwrap();
thread::sleep(Duration::from_secs(1));
}
})
@ -171,7 +177,10 @@ pub fn start_title_thread(
pub fn setup_ctrlc(should_stop: Arc<std::sync::atomic::AtomicBool>) {
ctrlc::set_handler(move || {
should_stop.store(true, std::sync::atomic::Ordering::SeqCst);
#[cfg(windows)]
clear().unwrap();
println!("\n{} Download interrupted by user", Status::warning());
})
.unwrap();

View file

@ -1,6 +1,7 @@
use colored::*;
use reqwest::blocking::Client;
use serde_json::Value;
#[cfg(windows)]
use winconsole::console::{clear, set_title};
use wuwa_downloader::{
@ -17,7 +18,9 @@ use wuwa_downloader::{
};
fn main() {
#[cfg(windows)]
set_title("Wuthering Waves Downloader").unwrap();
let log_file = setup_logging();
let client = Client::new();
@ -27,6 +30,8 @@ fn main() {
};
let folder = get_dir();
#[cfg(windows)]
clear().unwrap();
println!(
"\n{} Download folder: {}\n",
@ -47,6 +52,8 @@ fn main() {
);
let total_size = calculate_total_size(resources, &client, &config);
#[cfg(windows)]
clear().unwrap();
let (should_stop, success, progress) = track_progress(total_size);
@ -74,7 +81,9 @@ fn main() {
should_stop.store(true, std::sync::atomic::Ordering::SeqCst);
title_thread.join().unwrap();
#[cfg(windows)]
clear().unwrap();
print_results(
success.load(std::sync::atomic::Ordering::SeqCst),
resources.len(),

View file

@ -2,8 +2,9 @@ use colored::Colorize;
use flate2::read::GzDecoder;
use reqwest::blocking::Client;
use serde_json::{from_reader, from_str, Value};
use winconsole::console::{self, clear};
use std::{io::{Read, Write}, fs, io, path::Path, time::Duration};
#[cfg(windows)]
use winconsole::console::clear;
use crate::config::cfg::Config;
use crate::download::progress::DownloadProgress;
@ -27,7 +28,10 @@ pub fn fetch_index(client: &Client, config: &Config, log_file: &fs::File) -> Val
Ok(resp) => resp,
Err(e) => {
log_error(log_file, &format!("Error fetching index file: {}", e));
console::clear().unwrap();
#[cfg(windows)]
clear().unwrap();
println!("{} Error fetching index file: {}", Status::error(), e);
println!("\n{} Press Enter to exit...", Status::warning());
let _ = io::stdin().read_line(&mut String::new());
@ -38,7 +42,10 @@ pub fn fetch_index(client: &Client, config: &Config, log_file: &fs::File) -> Val
if !response.status().is_success() {
let msg = format!("Error fetching index file: HTTP {}", response.status());
log_error(log_file, &msg);
console::clear().unwrap();
#[cfg(windows)]
clear().unwrap();
println!("{} {}", Status::error(), msg);
println!("\n{} Press Enter to exit...", Status::warning());
let _ = io::stdin().read_line(&mut String::new());
@ -55,7 +62,10 @@ pub fn fetch_index(client: &Client, config: &Config, log_file: &fs::File) -> Val
let mut buffer = Vec::new();
if let Err(e) = response.copy_to(&mut buffer) {
log_error(log_file, &format!("Error reading index file bytes: {}", e));
console::clear().unwrap();
#[cfg(windows)]
clear().unwrap();
println!("{} Error reading index file: {}", Status::error(), e);
println!("\n{} Press Enter to exit...", Status::warning());
let _ = io::stdin().read_line(&mut String::new());
@ -66,7 +76,10 @@ pub fn fetch_index(client: &Client, config: &Config, log_file: &fs::File) -> Val
let mut decompressed_text = String::new();
if let Err(e) = gz.read_to_string(&mut decompressed_text) {
log_error(log_file, &format!("Error decompressing index file: {}", e));
console::clear().unwrap();
#[cfg(windows)]
clear().unwrap();
println!("{} Error decompressing index file: {}", Status::error(), e);
println!("\n{} Press Enter to exit...", Status::warning());
let _ = io::stdin().read_line(&mut String::new());
@ -81,7 +94,10 @@ pub fn fetch_index(client: &Client, config: &Config, log_file: &fs::File) -> Val
log_file,
&format!("Error reading index file response: {}", e),
);
console::clear().unwrap();
#[cfg(windows)]
clear().unwrap();
println!("{} Error reading index file: {}", Status::error(), e);
println!("\n{} Press Enter to exit...", Status::warning());
let _ = io::stdin().read_line(&mut String::new());
@ -96,7 +112,10 @@ pub fn fetch_index(client: &Client, config: &Config, log_file: &fs::File) -> Val
Ok(v) => v,
Err(e) => {
log_error(log_file, &format!("Error parsing index file JSON: {}", e));
console::clear().unwrap();
#[cfg(windows)]
clear().unwrap();
println!("{} Error parsing index file: {}", Status::error(), e);
println!("\n{} Press Enter to exit...", Status::warning());
let _ = io::stdin().read_line(&mut String::new());
@ -293,7 +312,10 @@ fn download_single_file(
pub fn get_config(client: &Client) -> Result<Config, String> {
let selected_index_url = fetch_gist(client)?;
#[cfg(windows)]
clear().unwrap();
println!("{} Fetching download configuration...", Status::info());
let mut response = client