Skip to content

Commit

Permalink
Initializes setup page to set system root (#1156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Dec 2, 2024
1 parent c23fa96 commit 1a631c8
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 67 deletions.
50 changes: 37 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
31 changes: 0 additions & 31 deletions gui/initialize_wizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
"<a href=\"https://github.com/obhq/firmware-dumper\">Firmware Dumper</a>.");
intro->setWordWrap(true);
intro->setOpenExternalLinks(true);

layout->addWidget(intro);

setLayout(layout);
}
};

class SystemPage : public QWizardPage {
public:
SystemPage() : m_input(nullptr)
Expand Down Expand Up @@ -297,7 +273,6 @@ InitializeWizard::InitializeWizard()
#endif

// Pages.
setPage(PageIntro, new IntroPage());
setPage(PageSystem, new SystemPage());
setPage(PageGame, new GamePage());
setPage(PageFirmware, new FirmwarePage());
Expand All @@ -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;
Expand Down
19 changes: 17 additions & 2 deletions gui/src/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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::<Box<dyn Error>, _>(|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.
Expand Down
45 changes: 29 additions & 16 deletions gui/ui/setup.slint
Original file line number Diff line number Diff line change
Expand Up @@ -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 <string> firmware-dump;
in-out property <FirmwareInstaller> firmware-installer;
in property <string> firmware-status;
in property <float> firmware-progress;
in-out property <string> error-message;

pure callback cancel <=> nav.cancel;
pure callback set-system-root() -> bool;
pure callback browse-firmware();
pure callback install-firmware();
pure callback finish();
Expand All @@ -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;
Expand All @@ -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();
}
}
Expand All @@ -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 => {
Expand Down
29 changes: 29 additions & 0 deletions gui/ui/setup/root.slint
Original file line number Diff line number Diff line change
@@ -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 { }
}
}

0 comments on commit 1a631c8

Please sign in to comment.