Skip to content

Commit

Permalink
fix: crashing on windows when extracting
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Nov 29, 2023
1 parent 183f09d commit f79a014
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
34 changes: 17 additions & 17 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
)]

use tauri::api::dialog;
use std::{fs::{File, remove_dir_all}, path::{PathBuf, Path}, time, thread, io::{Write, Seek, SeekFrom}, process::Command};
use std::{fs::{File, remove_dir_all}, path::{PathBuf, Path}, time, thread, io::{Write, Seek, SeekFrom}, process::Command, sync::Arc};
use compress_tools::{uncompress_archive, Ownership};

mod qemu_install;
Expand Down Expand Up @@ -101,38 +101,38 @@ fn start_install(
iso_file: String,
install_dir: String,
) -> Result<String, String> {
let window = Arc::new(window);
let source = File::open(iso_file).map_err(|err| err.to_string())?;
let filesize = source.metadata().unwrap().len();

let install_dir1 = install_dir.clone();
let window_ = window.clone();
thread::spawn(move || {
let file_path = Path::new(&install_dir1);
let mut init_size = fs_extra::dir::get_size(file_path).unwrap();
let mut progress_eq = false;
let mut progress = 0;
let mut progress_before = 1;
loop {
let size = fs_extra::dir::get_size(file_path).unwrap();
if size > init_size {
let new_progress = (size - init_size) * 100 / filesize;

if progress == new_progress {
if progress_eq { window.emit("new-dir-size", 100).unwrap(); break; }
progress_eq = true;
}

progress = new_progress;
window.emit("new-dir-size", progress).unwrap();
let current_size = fs_extra::dir::get_size(file_path).unwrap();
if current_size > init_size {
let mut new_progress = (current_size - init_size) * 100 / filesize;
// increment progress every 1 seconds if stuck
if new_progress == progress_before { new_progress = progress_before + 5 }
// 100 will be sent only from the other thread
if new_progress != 100 { window.emit("new-dir-size", new_progress).unwrap(); }
progress_before = new_progress;
} else {
init_size = size;
init_size = current_size;
}
thread::sleep(time::Duration::from_secs(2));
thread::sleep(time::Duration::from_secs(1));
}
});

let window = Arc::clone(&window_);
thread::spawn(move || {
let dest_dir = Path::new(&install_dir);
uncompress_archive(source, dest_dir, Ownership::Preserve).unwrap();

window.emit("new-dir-size", 100).unwrap();

let fs_install_dir = get_fs_install_dir(install_dir.clone());

let contents = format!(r#"
Expand Down
2 changes: 1 addition & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function updateProgress() {
await listen('new-dir-size', (event) => {
installEl.updateProgress(event.payload)
});
if (installEl.progressPercent_ >= 100) {
if (installEl.progressPercent_ == 100) {
createDataImg();

installEl.bootloaderMsg_ = await invoke("create_grub_entry", {
Expand Down

0 comments on commit f79a014

Please sign in to comment.