mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
Refactor spacing
This commit is contained in:
@@ -26,7 +26,7 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
||||
Err(_e) => {
|
||||
emit_download_err(window, format!("Failed to request {}", url), path);
|
||||
return Err(format!("Failed to request {}", url));
|
||||
},
|
||||
}
|
||||
};
|
||||
let total_size = res
|
||||
.content_length()
|
||||
@@ -38,7 +38,7 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
||||
Err(_e) => {
|
||||
emit_download_err(window, format!("Failed to create file '{}'", path), path);
|
||||
return Err(format!("Failed to create file '{}'", path));
|
||||
},
|
||||
}
|
||||
};
|
||||
let mut downloaded: u64 = 0;
|
||||
|
||||
@@ -60,7 +60,7 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
||||
Err(e) => {
|
||||
emit_download_err(window, format!("Error while downloading file"), path);
|
||||
return Err(format!("Error while downloading file: {}", e));
|
||||
},
|
||||
}
|
||||
};
|
||||
let vect = &chunk.to_vec()[..];
|
||||
|
||||
@@ -70,7 +70,7 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
||||
Err(e) => {
|
||||
emit_download_err(window, format!("Error while writing file"), path);
|
||||
return Err(format!("Error while writing file: {}", e));
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// New progress
|
||||
@@ -81,17 +81,17 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
||||
|
||||
res_hash.insert(
|
||||
"downloaded".to_string(),
|
||||
downloaded.to_string()
|
||||
downloaded.to_string(),
|
||||
);
|
||||
|
||||
res_hash.insert(
|
||||
"total".to_string(),
|
||||
total_size.to_string()
|
||||
total_size.to_string(),
|
||||
);
|
||||
|
||||
res_hash.insert(
|
||||
"path".to_string(),
|
||||
path.to_string()
|
||||
path.to_string(),
|
||||
);
|
||||
|
||||
// Create event to send to frontend
|
||||
@@ -110,12 +110,12 @@ pub fn emit_download_err(window: tauri::Window, msg: std::string::String, path:
|
||||
|
||||
res_hash.insert(
|
||||
"error".to_string(),
|
||||
msg.to_string()
|
||||
msg.to_string(),
|
||||
);
|
||||
|
||||
res_hash.insert(
|
||||
"path".to_string(),
|
||||
path.to_string()
|
||||
path.to_string(),
|
||||
);
|
||||
|
||||
window.emit("download_error", &res_hash).unwrap();
|
||||
|
||||
@@ -45,7 +45,7 @@ pub fn emit_lang_err(window: tauri::Window, msg: std::string::String) {
|
||||
|
||||
res_hash.insert(
|
||||
"error".to_string(),
|
||||
msg.to_string()
|
||||
msg.to_string(),
|
||||
);
|
||||
|
||||
window.emit("lang_error", &res_hash).unwrap();
|
||||
|
||||
@@ -164,7 +164,7 @@ async fn get_bg_file(bg_path: String) -> String {
|
||||
// Copy was successful, lets return true
|
||||
let cwd = std::env::current_dir().unwrap();
|
||||
return format!("{}\\{}", cwd.display(), response_data.backgroundFile.as_str());
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
// Copy failed, lets return false
|
||||
println!("Failed to copy background image: {}", e);
|
||||
|
||||
@@ -10,7 +10,7 @@ use hudsucker::{
|
||||
async_trait::async_trait,
|
||||
certificate_authority::RcgenAuthority,
|
||||
hyper::{Body, Request, Response},
|
||||
*
|
||||
*,
|
||||
};
|
||||
|
||||
use std::net::SocketAddr;
|
||||
@@ -44,30 +44,26 @@ pub fn set_proxy_addr(addr: String){
|
||||
impl HttpHandler for ProxyHandler {
|
||||
async fn handle_request(&mut self,
|
||||
_context: &HttpContext,
|
||||
mut request: Request<Body>
|
||||
mut request: Request<Body>,
|
||||
) -> RequestOrResponse {
|
||||
println!("Request: {}", &request.uri());
|
||||
|
||||
// Get request URI
|
||||
// Get request URI.
|
||||
let uri = request.uri().to_string();
|
||||
let uri_path = request.uri().path();
|
||||
|
||||
// Only switch up if request is to the game servers
|
||||
// Only switch up if request is to the game servers.
|
||||
if uri.contains("hoyoverse.com") || uri.contains("mihoyo.com") || uri.contains("yuanshen.com") {
|
||||
// Copy the request and just change the URI
|
||||
// Create new URI.
|
||||
let uri = format!("https://{}{}", SERVER.lock().unwrap(), uri_path).parse::<Uri>().unwrap();
|
||||
|
||||
// Set request URI to the new one.
|
||||
*request.uri_mut() = uri;
|
||||
}
|
||||
|
||||
println!("New request: {}", &request.uri());
|
||||
|
||||
RequestOrResponse::Request(request)
|
||||
}
|
||||
|
||||
async fn handle_response(&mut self,
|
||||
_context: &HttpContext,
|
||||
response: Response<Body>
|
||||
response: Response<Body>,
|
||||
) -> Response<Body> { response }
|
||||
}
|
||||
|
||||
|
||||
@@ -26,19 +26,19 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
|
||||
match zip_extract::extract(&f, &full_path, true) {
|
||||
Ok(_) => {
|
||||
println!("Extracted zip file to: {}", full_path.to_str().unwrap_or("Error"));
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to extract zip file: {}", e);
|
||||
let mut res_hash = std::collections::HashMap::new();
|
||||
|
||||
res_hash.insert(
|
||||
"error".to_string(),
|
||||
e.to_string()
|
||||
e.to_string(),
|
||||
);
|
||||
|
||||
res_hash.insert(
|
||||
"path".to_string(),
|
||||
zipfile.to_string()
|
||||
zipfile.to_string(),
|
||||
);
|
||||
|
||||
window.emit("download_error", &res_hash).unwrap();
|
||||
@@ -59,7 +59,7 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
|
||||
match std::fs::remove_file(&zipfile) {
|
||||
Ok(_) => {
|
||||
println!("Deleted zip file: {}", zipfile);
|
||||
},
|
||||
}
|
||||
Err(e) => {
|
||||
println!("Failed to delete zip file: {}", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user