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