Procházet zdrojové kódy

Files: a title run by its file name alone gets its own folder as G:

`victory run GTA6.exe`, run from the game folder, gives an exe path with
an empty parent, and that empty folder was mounted as G:. An empty path
cannot be made absolute, so the root stayed empty and G:\x64\a.rpf
became \x64\a.rpf: the root of the current drive. The title then found
none of its files.

An empty root is now the current directory, which is what an empty
folder means everywhere else (`Path::new("").join("x")` is `x` in the
current directory). Passing a path with a folder in it is unaffected.

(cherry picked from commit 01ae55a3ba04c39a0e8851cc00da16af7a49adbd)
Duff před 3 dny
rodič
revize
9a34298a0b
1 změnil soubory, kde provedl 19 přidání a 1 odebrání
  1. 19 1
      crates/victory-hle/src/modules/files.rs

+ 19 - 1
crates/victory-hle/src/modules/files.rs

@@ -83,8 +83,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)) {
@@ -865,6 +872,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();