Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion crates/viport-hle/src/modules/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ pub fn mount_at(letter: char, root: &Path) {
}

/// `root` as UTF-16, absolute, without trailing separators (a drive root
/// keeps its own).
/// keeps its own). An empty root is the current directory, as it is to a
/// path joined to it: it is the title's folder when the title is run by its
/// file name alone (`victory run GTA6.exe`).
fn root_wide(root: &Path) -> Vec<u16> {
let root = if root.as_os_str().is_empty() {
Path::new(".")
} else {
root
};
let root = std::path::absolute(root).unwrap_or_else(|_| root.to_owned());
let mut wide: Vec<u16> = root.as_os_str().encode_wide().collect();
while wide.len() > 3 && wide.last().is_some_and(|c| SEPARATORS.contains(c)) {
Expand Down Expand Up @@ -815,6 +822,17 @@ mod tests {
);
}

/// A title run by its file name alone has an empty folder: the drive
/// over it is the current directory, not the current drive's root.
#[test]
fn an_empty_root_is_the_current_directory() {
let letter = mount(Path::new("")).unwrap();
let path = format!(r"{letter}:\a.rpf");
let host = translate(&w(&path)[..path.len()]).map(|v| text(&v));
let cwd = std::env::current_dir().unwrap();
assert_eq!(host, Some(cwd.join("a.rpf").display().to_string()));
}

#[test]
fn long_title_paths_work_on_the_host() {
let dir = tempfile::tempdir().unwrap();
Expand Down