Skip to content

Commit

Permalink
Initializes file picker for Linux (#1139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Nov 24, 2024
1 parent 87f11ff commit 3c916a6
Show file tree
Hide file tree
Showing 23 changed files with 643 additions and 653 deletions.
556 changes: 549 additions & 7 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ members = [
"src/fs",
"src/llt",
"src/obconf",
"src/param",
"src/pfs",
"src/tls",
]
Expand Down
10 changes: 0 additions & 10 deletions gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ if(WIN32 OR (UNIX AND NOT APPLE))
find_package(Vulkan REQUIRED)
endif()

if(APPLE)
find_library(HYPERVISOR Hypervisor REQUIRED)
endif()

# Setup GUI.
add_executable(obliteration WIN32 MACOSX_BUNDLE
app_data.cpp
Expand Down Expand Up @@ -37,10 +33,6 @@ endif()

set_target_properties(obliteration PROPERTIES AUTOMOC ON AUTORCC ON)

if(WIN32)
set_target_properties(obliteration PROPERTIES OUTPUT_NAME Obliteration)
endif()

target_compile_features(obliteration PRIVATE cxx_std_17)

target_link_libraries(obliteration PRIVATE Qt6::Svg Qt6::Widgets)
Expand All @@ -53,8 +45,6 @@ endif()

if(WIN32)
target_link_libraries(obliteration PRIVATE bcrypt imm32 ntdll setupapi userenv version winhvplatform winmm ws2_32)
elseif(APPLE)
target_link_libraries(obliteration PRIVATE ${HYPERVISOR})
else()
target_link_libraries(obliteration PRIVATE ${CMAKE_DL_LIBS})
endif()
15 changes: 13 additions & 2 deletions gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ obfw = { git = "https://github.com/obhq/firmware-dumper.git", features = [
"std",
] }
open = { version = "5.3.1", optional = true }
param = { path = "../src/param" }
raw-window-handle = "0.6.2"
serde = { version = "1.0.209", features = ["derive"] }
thiserror = "1.0"
uuid = { version = "1.11.0", features = ["serde", "v4"] }

[dependencies.slint]
version = "1.8.0"
features = ["compat-1-2", "std", "backend-winit", "renderer-femtovg"]
features = [
"backend-winit",
"compat-1-2",
"raw-window-handle-06",
"renderer-femtovg",
"std",
]
default-features = false
optional = true

Expand All @@ -63,6 +69,11 @@ features = [
"Win32_System_SystemInformation",
]

[target.'cfg(target_os = "linux")'.dependencies.ashpd]
version = "0.10.2"
features = ["async-std", "raw_handle"]
default-features = false

[target.'cfg(target_os = "macos")'.dependencies]
applevisor-sys = "0.1.3"
core-graphics-types = "0.1.3"
Expand Down
18 changes: 0 additions & 18 deletions gui/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ void error_free(struct RustError *e);

const char *error_message(const struct RustError *e);

Param *param_open(const char *file, struct RustError **error);

void param_close(Param *p);

char *param_app_ver_get(const Param *p);

char *param_category_get(const Param *p);

char *param_content_id_get(const Param *p);

char *param_short_content_id_get(const Param *p);

char *param_title_get(const Param *p);

char *param_title_id_get(const Param *p);

char *param_version_get(const Param *p);

struct Profile *profile_new(const char *name);

struct Profile *profile_load(const char *path, struct RustError **err);
Expand Down
9 changes: 0 additions & 9 deletions gui/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,6 @@ inline void Rust<char>::free()
m_ptr = nullptr;
}

template<>
inline void Rust<Param>::free()
{
if (m_ptr) {
param_close(m_ptr);
m_ptr = nullptr;
}
}

template<>
inline void Rust<Profile>::free()
{
Expand Down
2 changes: 1 addition & 1 deletion gui/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ int main(int argc, char *argv[])
MainWindow win(args, &vulkan, std::move(vkDevices));
#endif

if (!win.loadProfiles() || !win.loadGames()) {
if (!win.loadProfiles()) {
return 1;
}

Expand Down
72 changes: 0 additions & 72 deletions gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -172,37 +172,6 @@ bool MainWindow::loadProfiles()
return true;
}

bool MainWindow::loadGames()
{
// Get game counts.
auto directory = readGamesDirectorySetting();
auto games = QDir(directory).entryList(QDir::Dirs | QDir::NoDotAndDotDot);

// Setup loading progress.
QProgressDialog progress(this);
int step = -1;

progress.setMaximum(games.size());
progress.setCancelButtonText("Cancel");
progress.setWindowModality(Qt::WindowModal);
progress.setValue(++step);

// Load games
progress.setLabelText("Loading games...");

for (auto &gameId : games) {
if (progress.wasCanceled() || !loadGame(gameId)) {
return false;
}

progress.setValue(++step);
}

m_games->sort(0);

return true;
}

void MainWindow::closeEvent(QCloseEvent *event)
{
// This will set to accept by QMainWindow::closeEvent.
Expand Down Expand Up @@ -299,47 +268,6 @@ void MainWindow::waitKernelExit(bool success)
m_main->setCurrentIndex(0);
}

bool MainWindow::loadGame(const QString &gameId)
{
auto gamesDirectory = readGamesDirectorySetting();
auto gamePath = joinPath(gamesDirectory, gameId);

// Ignore entry if it is DLC or Patch.
auto lastSlashPos = gamePath.find_last_of("/\\");
auto lastFolder = (lastSlashPos != std::string::npos) ? gamePath.substr(lastSlashPos + 1) : gamePath;
bool isPatch = lastFolder.find("-PATCH-") != std::string::npos;
bool isAddCont = lastFolder.size() >= 8 && lastFolder.substr(lastFolder.size() - 8) == "-ADDCONT";

if (!isPatch && !isAddCont) {

// Read game information from param.sfo.
auto paramDir = joinPath(gamePath.c_str(), "sce_sys");
auto paramPath = joinPath(paramDir.c_str(), "param.sfo");
Rust<RustError> error;
Rust<Param> param;

param = param_open(paramPath.c_str(), &error);

if (!param) {
QMessageBox::critical(
this,
"Error",
QString("Cannot open %1: %2").arg(paramPath.c_str()).arg(error_message(error)));
return false;
}

// Add to list.
Rust<char> titleId, title;

titleId = param_title_id_get(param);
title = param_title_get(param);

m_games->add(new Game(titleId.get(), title.get(), gamePath.c_str()));
}

return true;
}

void MainWindow::restoreGeometry()
{
QSettings settings;
Expand Down
2 changes: 0 additions & 2 deletions gui/main_window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class MainWindow final : public QMainWindow {
~MainWindow() override;

bool loadProfiles();
bool loadGames();
void restoreGeometry();
protected:
void closeEvent(QCloseEvent *event) override;
Expand All @@ -42,7 +41,6 @@ private slots:
private:
void vmmError(const QString &msg);
void waitKernelExit(bool success);
bool loadGame(const QString &gameId);
void stopDebug();
void killVmm();

Expand Down
33 changes: 33 additions & 0 deletions gui/src/dialogs/linux/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use super::FileType;
use ashpd::desktop::file_chooser::{FileFilter, SelectedFiles};
use ashpd::WindowIdentifier;
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
use slint::ComponentHandle;

pub async fn open_file<T: ComponentHandle>(parent: &T, title: impl AsRef<str>, ty: FileType) {
// Get display handle. All local variable here must not get dropped until the operation is
// complete.
let parent = parent.window().window_handle();
let display = parent.display_handle();
let display = display.as_ref().map(|v| v.as_ref()).ok();

// Get parent handle.
let parent = parent.window_handle();
let parent = parent.as_ref().map(|v| v.as_ref()).unwrap();
let parent = WindowIdentifier::from_raw_handle(parent, display).await;

// Build filter.
let filter = match ty {
FileType::Firmware => FileFilter::new("Firmware Dump").glob("*.obf"),
};

// Send the request
SelectedFiles::open_file()
.identifier(parent)
.title(title.as_ref())
.modal(true)
.filter(filter)
.send()
.await
.unwrap();
}
6 changes: 6 additions & 0 deletions gui/src/dialogs/macos/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use super::FileType;
use slint::ComponentHandle;

pub async fn open_file<T: ComponentHandle>(parent: &T, title: impl AsRef<str>, ty: FileType) {
todo!();
}
11 changes: 11 additions & 0 deletions gui/src/dialogs/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub use self::os::*;

#[cfg_attr(target_os = "linux", path = "linux/mod.rs")]
#[cfg_attr(target_os = "macos", path = "macos/mod.rs")]
#[cfg_attr(target_os = "windows", path = "windows/mod.rs")]
mod os;

/// File type to use open from [`open_file()`].
pub enum FileType {
Firmware,
}
6 changes: 6 additions & 0 deletions gui/src/dialogs/windows/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use super::FileType;
use slint::ComponentHandle;

pub async fn open_file<T: ComponentHandle>(parent: &T, title: impl AsRef<str>, ty: FileType) {
todo!();
}
1 change: 0 additions & 1 deletion gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod debug;
mod error;
mod graphics;
mod hv;
mod param;
mod profile;
mod string;
mod system;
Expand Down
2 changes: 1 addition & 1 deletion gui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use thiserror::Error;

mod args;
mod debug;
mod dialogs;
mod error;
mod graphics;
mod hv;
mod param;
mod profile;
#[cfg(unix)]
mod rlim;
Expand Down
58 changes: 0 additions & 58 deletions gui/src/param/ffi.rs

This file was deleted.

2 changes: 0 additions & 2 deletions gui/src/param/mod.rs

This file was deleted.

13 changes: 13 additions & 0 deletions gui/src/setup/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::dialogs::{open_file, FileType};
use crate::ui::SetupWizard;
use slint::{ComponentHandle, PlatformError};
use thiserror::Error;
Expand All @@ -12,11 +13,23 @@ pub fn run_setup() -> Result<(), SetupError> {
move || win.unwrap().hide().unwrap()
});

win.on_browse_firmware({
let win = win.as_weak();

move || {
slint::spawn_local(browse_firmware(win.unwrap())).unwrap();
}
});

win.run().map_err(SetupError::RunWindow)?;

Ok(())
}

async fn browse_firmware(win: SetupWizard) {
open_file(&win, "Select a firmware dump", FileType::Firmware).await;
}

/// Represents an error when [`run_setup()`] fails.
#[derive(Debug, Error)]
pub enum SetupError {
Expand Down
Loading

0 comments on commit 3c916a6

Please sign in to comment.