From 76fed6fa40e7cb8ac6ab407d2490334f5ccf24d4 Mon Sep 17 00:00:00 2001 From: Xtr126 <80520774+Xtr126@users.noreply.github.com> Date: Wed, 16 Oct 2024 09:25:04 +0530 Subject: [PATCH] feat: Add recovery support --- src-tauri/.cargo/config.toml | 7 +++++++ src-tauri/src/main.rs | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 src-tauri/.cargo/config.toml diff --git a/src-tauri/.cargo/config.toml b/src-tauri/.cargo/config.toml new file mode 100644 index 0000000..139e204 --- /dev/null +++ b/src-tauri/.cargo/config.toml @@ -0,0 +1,7 @@ +[target.x86_64-pc-windows-msvc] +linker = "lld" +rustflags = [ + "-Lnative=/home/hp/.xwin/crt/lib/x86_64", + "-Lnative=/home/hp/.xwin/sdk/lib/um/x86_64", + "-Lnative=/home/hp/.xwin/sdk/lib/ucrt/x86_64", +] diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 8a7c136..55e36ee 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -4,7 +4,7 @@ )] use tauri::api::dialog; -use std::{fs::{File, remove_dir}, path::{PathBuf, Path}, time, thread, sync::Arc}; +use std::{fs::{remove_dir, File}, io::{Bytes, Seek, Write}, path::{Path, PathBuf}, sync::Arc, thread, time}; use compress_tools::{uncompress_archive, Ownership}; mod qemu_install; @@ -133,6 +133,20 @@ pub fn get_fs_install_dir(install_dir: String) -> String { return install_dir; } +// For recovery https://github.com/BlissOS/bootable_newinstaller/blob/c81bcf9d8148f3f071013161c3eb4a3ee58a1189/install/scripts/1-install#L987 +fn prepare_recovery( + dest_dir: &Path, +) -> Result<(), String> { + std::fs::rename(dest_dir.join("ramdisk-recovery.img"), dest_dir.join("recovery.img")).map_err(|err| err.to_string())?; + let misc_img_path = dest_dir.join("misc.img"); + let mut misc_img_file = File::create(misc_img_path).map_err(|err| err.to_string())?; + let megabyte = 1024 << 10; // megabyte size in bytes + // Generate 10 MB misc.img + misc_img_file.seek(std::io::SeekFrom::Start(megabyte * 10)).map_err(|err| err.to_string())?; + misc_img_file.write(&[0]).map_err(|err| err.to_string())?; + Ok(()) +} + #[tauri::command] fn start_install( window: tauri::Window, @@ -182,7 +196,7 @@ fn start_install( let window = Arc::clone(&window_); thread::spawn(move || { - let dest_dir = Path::new(&install_dir); + let dest_dir: &Path = Path::new(&install_dir); uncompress_archive(source, dest_dir, Ownership::Preserve).map_err(|err| err.to_string()).unwrap(); window.emit("new-dir-size", 100).unwrap(); @@ -198,6 +212,9 @@ fn start_install( "#); std::fs::write(dest_dir.join("boot/grub/grub.cfg"), contents).unwrap(); std::fs::create_dir(dest_dir.join("data")).unwrap(); + + let _ = std::fs::remove_file(dest_dir.join("install.img")); + let _ = prepare_recovery(dest_dir); }); Ok("Success".to_string()) }