Remember ROM dir (#508)

* Remember ROM dir

* more

* more

* more

* more

* more
This commit is contained in:
Logan McNaughton 2025-07-15 20:05:46 +02:00 committed by GitHub
parent 7109d28223
commit abc39e74ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 91 additions and 30 deletions

View File

@ -15,10 +15,18 @@ pub type Cheats = std::collections::BTreeMap<String, std::collections::BTreeMap<
pub fn cheats_window(app: &AppWindow) {
let weak = app.as_weak();
app.on_cheats_select_rom_clicked(move || {
let select_rom = rfd::AsyncFileDialog::new()
.set_title("Select ROM")
.pick_file();
app.on_cheats_select_rom_clicked(move |rom_dir| {
let select_rom = if !rom_dir.is_empty()
&& let Ok(exists) = std::fs::exists(&rom_dir)
&& exists
{
rfd::AsyncFileDialog::new().set_directory(rom_dir)
} else {
rfd::AsyncFileDialog::new()
}
.set_title("Select ROM")
.add_filter("ROM files", &ui::gui::N64_EXTENSIONS)
.pick_file();
let weak = weak.clone();
tokio::spawn(async move {
if let Some(file) = select_rom.await

View File

@ -67,6 +67,7 @@ pub struct Config {
pub input: Input,
pub video: Video,
pub emulation: Emulation,
pub rom_dir: std::path::PathBuf,
}
impl Drop for Cheats {
@ -150,6 +151,7 @@ impl Config {
overclock: false,
disable_expansion_pak: false,
},
rom_dir: std::path::PathBuf::new(),
}
}
}

View File

@ -5,6 +5,8 @@ use slint::Model;
slint::include_modules!();
pub const N64_EXTENSIONS: [&str; 5] = ["n64", "v64", "z64", "7z", "zip"];
#[derive(serde::Deserialize)]
struct GithubData {
tag_name: String,
@ -101,6 +103,10 @@ fn settings_window(app: &AppWindow, config: &ui::config::Config) {
_ => 0,
};
app.set_resolution(combobox_value);
if let Some(rom_dir_str) = config.rom_dir.to_str() {
app.set_rom_dir(rom_dir_str.into());
}
}
fn update_input_profiles(weak: &slint::Weak<AppWindow>, config: &ui::config::Config) {
@ -351,6 +357,7 @@ pub fn run_rom(
.unwrap();
let mut device = device::Device::new();
device.ui.config.rom_dir = file_path.parent().unwrap().to_path_buf();
for i in 0..4 {
if gb_paths.rom[i].is_some() && gb_paths.ram[i].is_some() {
@ -390,16 +397,31 @@ pub fn run_rom(
vru_window_notifier.try_send(None).unwrap();
}
weak.upgrade_in_event_loop(move |handle| handle.set_game_running(false))
.unwrap();
let rom_dir = device.ui.config.rom_dir.clone();
weak.upgrade_in_event_loop(move |handle| {
if let Some(rom_dir_str) = rom_dir.to_str() {
handle.set_rom_dir(rom_dir_str.into());
}
handle.set_game_running(false);
})
.unwrap();
})
.unwrap();
}
fn open_rom(app: &AppWindow) {
let select_rom = rfd::AsyncFileDialog::new()
.set_title("Select ROM")
.pick_file();
let rom_dir = app.get_rom_dir();
let select_rom = if !rom_dir.is_empty()
&& let Ok(exists) = std::fs::exists(&rom_dir)
&& exists
{
rfd::AsyncFileDialog::new().set_directory(rom_dir)
} else {
rfd::AsyncFileDialog::new()
}
.set_title("Select ROM")
.add_filter("ROM files", &N64_EXTENSIONS)
.pick_file();
let mut select_gb_rom = [None, None, None, None];
let mut select_gb_ram = [None, None, None, None];
@ -408,11 +430,13 @@ fn open_rom(app: &AppWindow) {
select_gb_rom[i] = Some(
rfd::AsyncFileDialog::new()
.set_title(format!("GB ROM P{}", i + 1))
.add_filter("GB ROM files", &["gb", "gbc"])
.pick_file(),
);
select_gb_ram[i] = Some(
rfd::AsyncFileDialog::new()
.set_title(format!("GB RAM P{}", i + 1))
.add_filter("GB RAM files", &["sav", "ram"])
.pick_file(),
);
}

View File

@ -29,7 +29,7 @@ export component AppWindow inherits Window {
callback join_session_button_clicked;
callback netplay_discord_button_clicked;
callback netplay_feedback_button_clicked;
callback cheats_select_rom_clicked;
callback cheats_select_rom_clicked(string);
callback cheats_clear_clicked;
callback cheat_toggled(string, string, string, bool);
in property version <=> AboutData.version;
@ -41,6 +41,7 @@ export component AppWindow inherits Window {
in-out property overclock_n64_cpu <=> SettingsData.overclock_n64_cpu;
in-out property disable_expansion_pak <=> SettingsData.disable_expansion_pak;
in-out property resolution <=> SettingsData.resolution;
in-out property rom_dir <=> SettingsData.rom_dir;
in-out property emulate_vru <=> ControllerData.emulate_vru;
in-out property controller_enabled <=> ControllerData.controller_enabled;
in-out property transferpak <=> ControllerData.transferpak;
@ -102,8 +103,8 @@ export component AppWindow inherits Window {
}
}
if(side-bar.current-item == 3): Cheats {
cheats_select_rom_clicked => {
cheats_select_rom_clicked();
cheats_select_rom_clicked(rom_dir) => {
cheats_select_rom_clicked(rom_dir);
}
cheats_clear_clicked => {
cheats_clear_clicked();

View File

@ -3,6 +3,7 @@
import { ListView, HorizontalBox, VerticalBox, Button, GroupBox, CheckBox } from "std-widgets.slint";
import { Page } from "page.slint";
import { SettingsData } from "settings_page.slint";
export global CheatsData {
in-out property <string> cheat_game_name;
@ -12,7 +13,7 @@ export global CheatsData {
export component Cheats inherits Page {
title: @tr("Cheats");
callback cheats_select_rom_clicked;
callback cheats_select_rom_clicked(string);
callback cheats_clear_clicked;
callback cheat_toggled(string, string, string, bool);
@ -23,13 +24,13 @@ export component Cheats inherits Page {
if CheatsData.cheat_game_name == "": Button {
text: @tr("Select ROM");
clicked => {
cheats_select_rom_clicked();
cheats_select_rom_clicked(SettingsData.rom_dir);
}
}
if CheatsData.cheat_game_name != "": Button {
text: CheatsData.cheat_game_name;
clicked => {
cheats_select_rom_clicked();
cheats_select_rom_clicked(SettingsData.rom_dir);
}
}
Rectangle {

View File

@ -12,8 +12,9 @@ export component NetplayCreate inherits Window {
in-out property pending_session <=> NetplayData.pending_session;
in-out property rom_path <=> NetplayData.rom_path;
in-out property peer_addr <=> NetplayData.peer_addr;
in-out property rom_dir <=> NetplayData.rom_dir;
callback get_ping(string);
callback select_rom;
callback select_rom(string);
callback create_session(string, string, string, string, string, string, string);
VerticalBox {
@ -83,13 +84,13 @@ export component NetplayCreate inherits Window {
if NetplayData.game_name == "": Button {
text: @tr("Select ROM");
clicked => {
select_rom();
select_rom(NetplayData.rom_dir);
}
}
if NetplayData.game_name != "": Button {
text: NetplayData.game_name;
clicked => {
select_rom();
select_rom(NetplayData.rom_dir);
}
}

View File

@ -15,9 +15,10 @@ export component NetplayJoin inherits Window {
in-out property peer_addr <=> NetplayData.peer_addr;
in-out property pending_session <=> NetplayData.pending_session;
in-out property rom_path <=> NetplayData.rom_path;
in-out property rom_dir <=> NetplayData.rom_dir;
callback get_ping(string);
callback refresh_session(string);
callback select_rom;
callback select_rom(string);
callback join_session(string, string, string, int);
VerticalBox {
@ -104,13 +105,13 @@ export component NetplayJoin inherits Window {
if NetplayData.game_name == "": Button {
text: @tr("Select ROM");
clicked => {
select_rom();
select_rom(NetplayData.rom_dir);
}
}
if NetplayData.game_name != "": Button {
text: NetplayData.game_name;
clicked => {
select_rom();
select_rom(NetplayData.rom_dir);
}
}

View File

@ -20,6 +20,7 @@ export global NetplayData {
in-out property <[[StandardListViewItem]]> sessions;
in-out property <[int]> ports;
in-out property <int> current_session: -1;
in-out property <string> rom_dir;
}
export component Netplay inherits Page {

View File

@ -12,6 +12,7 @@ export global SettingsData {
in-out property <bool> overclock_n64_cpu;
in-out property <bool> disable_expansion_pak;
in-out property <int> resolution;
in-out property <string> rom_dir;
}
export component Settings inherits Page {

View File

@ -173,10 +173,21 @@ fn populate_server_names<T: ComponentHandle + NetplayPages + 'static>(weak: slin
});
}
fn select_rom<T: ComponentHandle + NetplayPages + 'static>(weak: slint::Weak<T>) {
let select_rom = rfd::AsyncFileDialog::new()
.set_title("Select ROM")
.pick_file();
fn select_rom<T: ComponentHandle + NetplayPages + 'static>(
weak: slint::Weak<T>,
rom_dir: slint::SharedString,
) {
let select_rom = if !rom_dir.is_empty()
&& let Ok(exists) = std::fs::exists(&rom_dir)
&& exists
{
rfd::AsyncFileDialog::new().set_directory(rom_dir)
} else {
rfd::AsyncFileDialog::new()
}
.set_title("Select ROM")
.add_filter("ROM files", &ui::gui::N64_EXTENSIONS)
.pick_file();
tokio::spawn(async move {
if let Some(file) = select_rom.await {
if let Some(rom_contents) = device::get_rom_contents(file.path()) {
@ -252,6 +263,7 @@ fn update_ping<T: ComponentHandle + NetplayPages + 'static>(
pub fn setup_create_window(
create_window: &NetplayCreate,
game_settings: GameSettings,
rom_dir: slint::SharedString,
weak_app: slint::Weak<AppWindow>,
) {
let (netplay_read_sender, netplay_read_receiver): (
@ -264,14 +276,15 @@ pub fn setup_create_window(
tokio::sync::broadcast::Receiver<Option<NetplayMessage>>,
) = tokio::sync::broadcast::channel(5);
create_window.set_rom_dir(rom_dir);
populate_server_names(create_window.as_weak());
let weak = create_window.as_weak();
create_window.on_get_ping(move |server_url| {
update_ping(weak.clone(), server_url.to_string());
});
let weak = create_window.as_weak();
create_window.on_select_rom(move || {
select_rom(weak.clone());
create_window.on_select_rom(move |rom_dir| {
select_rom(weak.clone(), rom_dir);
});
let weak = create_window.as_weak();
@ -937,6 +950,7 @@ fn setup_wait_window(
pub fn setup_join_window(
join_window: &NetplayJoin,
fullscreen: bool,
rom_dir: slint::SharedString,
weak_app: slint::Weak<AppWindow>,
) {
let (netplay_read_sender, netplay_read_receiver): (
@ -949,6 +963,7 @@ pub fn setup_join_window(
tokio::sync::broadcast::Receiver<Option<NetplayMessage>>,
) = tokio::sync::broadcast::channel(5);
join_window.set_rom_dir(rom_dir);
populate_server_names(join_window.as_weak());
let weak = join_window.as_weak();
join_window.on_get_ping(move |server_url| {
@ -959,8 +974,8 @@ pub fn setup_join_window(
.unwrap();
});
let weak = join_window.as_weak();
join_window.on_select_rom(move || {
select_rom(weak.clone());
join_window.on_select_rom(move |rom_dir| {
select_rom(weak.clone(), rom_dir);
});
let sender = netplay_write_sender.clone();
@ -1019,6 +1034,7 @@ pub fn netplay_window(app: &AppWindow, controller_paths: &[Option<String>]) {
disable_expansion_pak: handle.get_disable_expansion_pak(),
cheats: std::collections::HashMap::new(), // not used here
},
handle.get_rom_dir(),
weak_app,
);
})
@ -1035,7 +1051,12 @@ pub fn netplay_window(app: &AppWindow, controller_paths: &[Option<String>]) {
.upgrade_in_event_loop(move |handle| {
let join_window = NetplayJoin::new().unwrap();
save_settings(&handle, &controller_paths);
setup_join_window(&join_window, handle.get_fullscreen(), weak_app);
setup_join_window(
&join_window,
handle.get_fullscreen(),
handle.get_rom_dir(),
weak_app,
);
})
.unwrap();
});