Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lukexor/tetanes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukexor committed Nov 18, 2023
2 parents ab1388e + 9964b69 commit 35bb424
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/nes/menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,23 @@ use std::{
pub(crate) mod types;
pub(crate) use types::{Menu, Player};

#[cfg(not(target_os = "windows"))]
const PARENT_DIR: &str = "../";

#[cfg(target_os = "windows")]
const PARENT_DIR: &str = "..\\";

#[cfg(not(target_os = "windows"))]
const fn friendly_path(p: &str) -> &str {
p
}

#[cfg(target_os = "windows")]
fn friendly_path(p: &str) -> &str {
const VERBATIM_PREFIX: &str = r#"\\?\"#;
p.strip_prefix(VERBATIM_PREFIX).unwrap_or(p)
}

impl Nes {
pub(crate) fn open_menu(&mut self, s: &mut PixState, menu: Menu) -> PixResult<()> {
s.cursor(Cursor::arrow())?;
Expand Down Expand Up @@ -376,7 +393,7 @@ impl Nes {
s.select_list(
format!(
"{}##{}",
rom_dir.to_string_lossy(),
friendly_path(&rom_dir.to_string_lossy()),
self.config.show_hidden_files
),
&mut self.selected_path,
Expand Down Expand Up @@ -434,7 +451,7 @@ impl Nes {
.for_each(|p| self.paths.push(p));
self.paths.sort();
if path.parent().is_some() {
self.paths.insert(0, PathBuf::from("../"));
self.paths.insert(0, PathBuf::from(PARENT_DIR));
}
}
Err(err) => {
Expand Down

0 comments on commit 35bb424

Please sign in to comment.