added unzip process
This commit is contained in:
parent
fc9ed2fe99
commit
a137c79045
4 changed files with 34 additions and 7 deletions
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
|
@ -3366,6 +3366,7 @@ dependencies = [
|
|||
"serde_json",
|
||||
"tauri",
|
||||
"tauri-build",
|
||||
"zip",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -16,6 +16,7 @@ tauri = { version = "1.0.0-beta.8", features = ["dialog-open", "path-all", "shel
|
|||
reqwest = { version = "0.11.9", features = ["blocking", "json", "stream"] }
|
||||
futures-util = "0.3.19"
|
||||
json = "0.12.4"
|
||||
zip = { version = "0.5.13", default-features = false }
|
||||
|
||||
[build-dependencies]
|
||||
tauri-build = { version = "1.0.0-beta.4" }
|
||||
|
|
|
@ -32,7 +32,9 @@ pub async fn install(window: Window, game_path: String) -> i64 {
|
|||
|
||||
// todo: download things in parallel when possible
|
||||
|
||||
//
|
||||
// get game path
|
||||
//
|
||||
|
||||
let game_path = if game_path.is_empty() {
|
||||
// if game_path argument is empty, get the default path
|
||||
|
@ -47,15 +49,22 @@ pub async fn install(window: Window, game_path: String) -> i64 {
|
|||
} else {
|
||||
// otherwise, use the passed value
|
||||
|
||||
// todo: check if game path is valid
|
||||
game_path
|
||||
};
|
||||
let game_path = game_path.as_str();
|
||||
|
||||
//
|
||||
// start installation
|
||||
//
|
||||
|
||||
install_bepinex(&window, game_path).await;
|
||||
download_wbm_zip(&window, game_path).await;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
util::emit(&window, constants::EVENT_INSTALL, InstallSteps::Done as i64);
|
||||
println!("Install complete!");
|
||||
|
||||
|
@ -85,22 +94,29 @@ async fn install_bepinex(window: &Window, game_path: &str) {
|
|||
|
||||
// download file to cache directory
|
||||
|
||||
println!("Downloading BepInEx.zip");
|
||||
let result = util::download_zip_to_cache_dir(bepinex_zip_url, "BepInEx.zip").await;
|
||||
match result {
|
||||
Ok(path) => {
|
||||
println!("downloaded BepInEx.zip: {}", path);
|
||||
Ok(bepinex_path) => {
|
||||
println!("Downloaded BepInEx.zip: {}", bepinex_path);
|
||||
println!("Unzipping BepInEx.zip");
|
||||
match util::unzip(bepinex_path.as_str(), &game_path) {
|
||||
Ok(()) => {
|
||||
println!("Successfully unzipped BepInEx.zip to {}", game_path);
|
||||
}
|
||||
|
||||
Err(err) => {
|
||||
panic!("{:#?}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Err(_) => {
|
||||
// todo: handle error
|
||||
panic!("failed to download BepInEx.zip")
|
||||
panic!("Failed to download BepInEx.zip")
|
||||
}
|
||||
}
|
||||
|
||||
// unzip file
|
||||
|
||||
println!("{}", game_path);
|
||||
|
||||
// done
|
||||
|
||||
util::emit(
|
||||
|
|
|
@ -44,6 +44,7 @@ pub fn get_default_game_path() -> Option<String> {
|
|||
return None;
|
||||
}
|
||||
|
||||
/// convert `Option<PathBuf>` to `Option<String>`
|
||||
pub fn buf2str(input: Option<PathBuf>) -> Option<String> {
|
||||
if input.is_none() {
|
||||
return None;
|
||||
|
@ -123,3 +124,11 @@ pub async fn download_zip_to_cache_dir(url: &str, file_name: &str) -> Result<Str
|
|||
pub fn emit<S: Serialize>(window: &Window, event: &str, payload: S) {
|
||||
window.emit(event, payload).unwrap();
|
||||
}
|
||||
|
||||
pub fn unzip(path: &str, destination: &str) -> Result<(), zip::result::ZipError> {
|
||||
let fname = std::path::Path::new(path);
|
||||
let zipfile = std::fs::File::open(&fname).unwrap();
|
||||
let mut archive = zip::ZipArchive::new(zipfile).unwrap();
|
||||
|
||||
return archive.extract(destination);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue