From 1a631c897339a050098e43a4c9601af9e97dbbae Mon Sep 17 00:00:00 2001 From: Putta Khunchalee Date: Tue, 3 Dec 2024 01:27:48 +0700 Subject: [PATCH] Initializes setup page to set system root (#1156) --- Cargo.lock | 50 +++++++++++++++++++++++++++++---------- gui/Cargo.toml | 11 +++++---- gui/initialize_wizard.cpp | 31 ------------------------ gui/src/setup/mod.rs | 19 +++++++++++++-- gui/ui/setup.slint | 45 ++++++++++++++++++++++------------- gui/ui/setup/root.slint | 29 +++++++++++++++++++++++ 6 files changed, 118 insertions(+), 67 deletions(-) create mode 100644 gui/ui/setup/root.slint diff --git a/Cargo.lock b/Cargo.lock index 03181b7a7..5cfa0bafb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ dependencies = [ "ndk-context", "ndk-sys", "num_enum", - "thiserror", + "thiserror 1.0.66", ] [[package]] @@ -536,7 +536,7 @@ dependencies = [ "polling", "rustix", "slab", - "thiserror", + "thiserror 1.0.66", ] [[package]] @@ -1312,7 +1312,7 @@ dependencies = [ "bitflags 2.6.0", "serde", "serde_yaml", - "thiserror", + "thiserror 1.0.66", ] [[package]] @@ -1587,7 +1587,7 @@ dependencies = [ "serde", "slint", "slint-build", - "thiserror", + "thiserror 2.0.3", "uuid", "windows-sys 0.52.0", "winres", @@ -1757,7 +1757,7 @@ dependencies = [ "rowan", "smol_str 0.3.2", "strum", - "thiserror", + "thiserror 1.0.66", "url", ] @@ -2145,7 +2145,7 @@ dependencies = [ "combine", "jni-sys", "log", - "thiserror", + "thiserror 1.0.66", "walkdir", "windows-sys 0.45.0", ] @@ -2304,7 +2304,7 @@ name = "llt" version = "0.1.0" dependencies = [ "libc", - "thiserror", + "thiserror 1.0.66", "tls", "windows-sys 0.52.0", ] @@ -2332,7 +2332,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ca94c7bf1e2557c2798989c43416822c12fc5dcc5e17cc3307ef0e71894a955" dependencies = [ "lyon_path", - "thiserror", + "thiserror 1.0.66", ] [[package]] @@ -2462,7 +2462,7 @@ dependencies = [ "ndk-sys", "num_enum", "raw-window-handle", - "thiserror", + "thiserror 1.0.66", ] [[package]] @@ -2545,7 +2545,11 @@ dependencies = [ [[package]] name = "obfw" version = "0.1.0" -source = "git+https://github.com/obhq/firmware-dumper.git#093f4117db5ec339bf704f92ac669adeb681dc69" +source = "git+https://github.com/obhq/firmware-dumper.git?rev=1953715b15dd3284d4188a9afff6a462dc47f47e#1953715b15dd3284d4188a9afff6a462dc47f47e" +dependencies = [ + "num_enum", + "thiserror 2.0.3", +] [[package]] name = "objc" @@ -3458,7 +3462,7 @@ checksum = "ec068281021ccd3a69dbe36a0caf207d88aa5b50945ced9000f17a5d2b139003" dependencies = [ "i-slint-compiler", "spin_on", - "thiserror", + "thiserror 1.0.66", "toml_edit", ] @@ -3503,7 +3507,7 @@ dependencies = [ "log", "memmap2", "rustix", - "thiserror", + "thiserror 1.0.66", "wayland-backend", "wayland-client", "wayland-csd-frame", @@ -3717,7 +3721,16 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d171f59dbaa811dbbb1aee1e73db92ec2b122911a48e1390dfe327a821ddede" dependencies = [ - "thiserror-impl", + "thiserror-impl 1.0.66", +] + +[[package]] +name = "thiserror" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c006c85c7651b3cf2ada4584faa36773bd07bac24acfb39f3c431b36d7e667aa" +dependencies = [ + "thiserror-impl 2.0.3", ] [[package]] @@ -3731,6 +3744,17 @@ dependencies = [ "syn", ] +[[package]] +name = "thiserror-impl" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f077553d607adc1caf65430528a576c757a71ed73944b66ebb58ef2bbd243568" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tiff" version = "0.9.1" diff --git a/gui/Cargo.toml b/gui/Cargo.toml index f5fee10ad..e95ac2a3e 100644 --- a/gui/Cargo.toml +++ b/gui/Cargo.toml @@ -17,16 +17,17 @@ gdbstub_arch = "0.3.1" humansize = "2.1.3" libc = "0.2.164" obconf = { path = "../src/obconf", features = ["serde", "virt"] } -obfw = { git = "https://github.com/obhq/firmware-dumper.git", features = [ - "read", - "std", -] } open = { version = "5.3.1" } raw-window-handle = "0.6.2" serde = { version = "1.0.209", features = ["derive"] } -thiserror = "1.0" +thiserror = "2.0.3" uuid = { version = "1.11.0", features = ["serde", "v4"] } +[dependencies.obfw] +git = "https://github.com/obhq/firmware-dumper.git" +rev = "1953715b15dd3284d4188a9afff6a462dc47f47e" +features = ["read"] + [dependencies.slint] version = "1.8.0" features = [ diff --git a/gui/initialize_wizard.cpp b/gui/initialize_wizard.cpp index 951626f7d..18bd3b44b 100644 --- a/gui/initialize_wizard.cpp +++ b/gui/initialize_wizard.cpp @@ -17,36 +17,12 @@ #define FIELD_GAMES_LOCATION "gamesLocation" enum PageId { - PageIntro, PageSystem, PageGame, PageFirmware, PageConclusion }; -class IntroPage : public QWizardPage { -public: - IntroPage() - { - auto layout = new QVBoxLayout(); - - // Page properties. - setTitle("Introduction"); - - // Introduction. - auto intro = new QLabel( - "This wizard will help you setup Obliteration. To ensure you're ready, make sure you " - "have a firmware dumped from your PS4 using " - "Firmware Dumper."); - intro->setWordWrap(true); - intro->setOpenExternalLinks(true); - - layout->addWidget(intro); - - setLayout(layout); - } -}; - class SystemPage : public QWizardPage { public: SystemPage() : m_input(nullptr) @@ -297,7 +273,6 @@ InitializeWizard::InitializeWizard() #endif // Pages. - setPage(PageIntro, new IntroPage()); setPage(PageSystem, new SystemPage()); setPage(PageGame, new GamePage()); setPage(PageFirmware, new FirmwarePage()); @@ -311,12 +286,6 @@ InitializeWizard::~InitializeWizard() int InitializeWizard::nextId() const { switch (currentId()) { - case PageIntro: - if (!hasSystemDirectorySetting()) { - return PageSystem; - } - - [[fallthrough]]; case PageSystem: if (!hasGamesDirectorySetting()) { return PageGame; diff --git a/gui/src/setup/mod.rs b/gui/src/setup/mod.rs index aeccd6511..9d24b8a61 100644 --- a/gui/src/setup/mod.rs +++ b/gui/src/setup/mod.rs @@ -1,8 +1,10 @@ use crate::dialogs::{open_file, FileType}; use crate::ui::SetupWizard; use erdp::ErrorDisplay; +use obfw::DumpReader; use slint::{ComponentHandle, PlatformError}; use std::cell::Cell; +use std::error::Error; use std::fs::File; use std::rc::Rc; use thiserror::Error; @@ -65,15 +67,28 @@ async fn browse_firmware(win: SetupWizard) { } fn install_firmware(win: SetupWizard) { - // Open firmware dump. + // Get dump path. let dump = win.get_firmware_dump(); - let dump = match File::open(dump.as_str()) { + + if dump.is_empty() { + win.set_error_message("You need to select a firmware dump before proceed.".into()); + return; + } + + // Open firmware dump. + let dump = match File::open(dump.as_str()) + .map_err::, _>(|e| e.into()) + .and_then(|f| DumpReader::new(f).map_err(|e| e.into())) + { Ok(v) => v, Err(e) => { win.set_error_message(format!("Failed to open {}: {}.", dump, e.display()).into()); return; } }; + + // TODO: Spawn a thread to extract the dump. + win.invoke_show_firmware_installer(); } /// Represents an error when [`run_setup()`] fails. diff --git a/gui/ui/setup.slint b/gui/ui/setup.slint index 2ad6a66d5..9c1c577df 100644 --- a/gui/ui/setup.slint +++ b/gui/ui/setup.slint @@ -4,27 +4,24 @@ import { Conclusion } from "setup/conclusion.slint"; import { NavBar } from "setup/nav.slint"; import { Palette } from "std-widgets.slint"; import { ErrorPopup } from "error.slint"; +import { SystemRoot } from "setup/root.slint"; // https://github.com/slint-ui/slint/issues/6880 enum WizardPage { Intro, + SystemRoot, Firmware, Conclusion } -export enum FirmwareInstaller { - Stopped, - Running -} - export component SetupWizard inherits Window { in-out property firmware-dump; - in-out property firmware-installer; in property firmware-status; in property firmware-progress; in-out property error-message; pure callback cancel <=> nav.cancel; + pure callback set-system-root() -> bool; pure callback browse-firmware(); pure callback install-firmware(); pure callback finish(); @@ -47,6 +44,10 @@ export component SetupWizard inherits Window { vertical-stretch: 1; } + if page == WizardPage.SystemRoot: SystemRoot { + vertical-stretch: 1; + } + if page == WizardPage.Firmware: Firmware { firmware-dump: firmware-dump; vertical-stretch: 1; @@ -69,16 +70,25 @@ export component SetupWizard inherits Window { back-enabled: root.page != WizardPage.Intro && root.page != WizardPage.Conclusion; next-text: "Next >"; back-clicked => { - if root.page == WizardPage.Firmware { - root.page = WizardPage.Intro; + if page == WizardPage.SystemRoot { + page = WizardPage.Intro; + } else if page == WizardPage.Firmware { + page = WizardPage.SystemRoot; } } next-clicked => { - if root.page == WizardPage.Intro { - root.page = WizardPage.Firmware; - } else if root.page == WizardPage.Firmware { + if page == WizardPage.Intro { + page = WizardPage.SystemRoot; + } else if page == WizardPage.SystemRoot { + // https://github.com/slint-ui/slint/issues/2752 + if set-system-root() { + page = WizardPage.Conclusion; + } else { + page = WizardPage.Firmware; + } + } else if page == WizardPage.Firmware { install-firmware(); - } else if root.page == WizardPage.Conclusion { + } else if page == WizardPage.Conclusion { finish(); } } @@ -104,10 +114,13 @@ export component SetupWizard inherits Window { } } - changed firmware-installer => { - if firmware-installer == FirmwareInstaller.Running { - firmware-popup.show(); - } + public function show-firmware-installer() { + firmware-popup.show(); + } + + public function set-firmware-finished() { + firmware-popup.close(); + page = WizardPage.Conclusion; } changed error-message => { diff --git a/gui/ui/setup/root.slint b/gui/ui/setup/root.slint new file mode 100644 index 000000000..f9a539f8f --- /dev/null +++ b/gui/ui/setup/root.slint @@ -0,0 +1,29 @@ +import { VerticalBox, HorizontalBox, LineEdit, Button } from "std-widgets.slint"; +import { Header } from "header.slint"; + +export component SystemRoot { + VerticalBox { + Header { + title: "Data Location"; + } + + Text { + text: "Select a directory to store Obliteration data. This directory will be used to store everything, including firmware and games."; + wrap: word-wrap; + } + + HorizontalBox { + padding: 0; + + LineEdit { + placeholder-text: "Path to a directory"; + } + + Button { + text: "..."; + } + } + + Rectangle { } + } +}