Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 13 additions & 0 deletions src-tauri/src/appimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ pub(crate) fn installed_image(dir: &Path) -> Option<PathBuf> {
.map(|s| s.eq_ignore_ascii_case("appimage"))
!= Some(true)
|| !entry.file_type().ok()?.is_file()
|| crate::install::mac_metadata(&path)
{
continue;
}
Expand Down Expand Up @@ -525,6 +526,18 @@ pub(crate) mod tests {
bytes
}

#[test]
fn a_macs_metadata_file_beside_the_appimage_isnt_a_second_one() {
let d = std::env::temp_dir().join(format!("rl-appledouble-image-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&d);
std::fs::create_dir_all(&d).unwrap();
std::fs::write(d.join("Game.AppImage"), b"image").unwrap();
std::fs::write(d.join("._Game.AppImage"), b"\x00\x05\x16\x07AppleDouble").unwrap();
let got = installed_image(&d);
let _ = std::fs::remove_dir_all(&d);
assert_eq!(got, Some(d.join("Game.AppImage")));
}

#[cfg(unix)]
#[test]
fn an_appimage_unpacks_into_a_plain_folder_without_running() {
Expand Down
36 changes: 35 additions & 1 deletion src-tauri/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1497,7 +1497,7 @@ pub fn find_setup(dir: &Path, os: &str, game: Option<&Path>) -> Option<PathBuf>
}
continue;
}
if !(is_program(&p, os) || (os == "windows" && is_script(&p))) {
if mac_metadata(&p) || !(is_program(&p, os) || (os == "windows" && is_script(&p))) {
continue;
}
let t = tokens(p.file_stem().and_then(|s| s.to_str()).unwrap_or(""));
Expand Down Expand Up @@ -1532,7 +1532,16 @@ pub fn looks_like_setup(p: &Path) -> bool {
t.iter().any(|x| SETUP_WORDS.contains(&x.as_str()))
}

/// A Mac's metadata file ("._Game.exe"), which a Mac writes beside each file on a drive formatted
/// for Windows, or into an archive it packs. It's never a program, whatever its name ends in.
pub fn mac_metadata(p: &Path) -> bool {
p.file_name().is_some_and(|n| n.to_string_lossy().starts_with("._"))
}

pub fn is_program(p: &Path, os: &str) -> bool {
if mac_metadata(p) {
return false;
}
let n = p.file_name().and_then(|s| s.to_str()).unwrap_or("").to_lowercase();
if os == "windows" {
return n.ends_with(".exe");
Expand Down Expand Up @@ -2074,6 +2083,31 @@ mod tests {
fs::write(p, vec![7u8; bytes]).unwrap();
}

/// What a Mac writes beside a file on a drive or in an archive: "._" and the file's name.
fn mac_metadata_beside(p: &Path) {
let name = format!("._{}", p.file_name().unwrap().to_string_lossy());
fs::write(p.with_file_name(name), b"\x00\x05\x16\x07AppleDouble").unwrap();
}

#[test]
fn a_macs_metadata_file_is_never_the_setup() {
let d = tmp("appledouble-setup");
put(&d.join("Game.exe"), 2_000_000);
put(&d.join("Game-setup.exe"), 1_000_000);
mac_metadata_beside(&d.join("Game-setup.exe"));
assert_eq!(find_setup(&d, "windows", Some(Path::new("Game.exe"))), Some(PathBuf::from("Game-setup.exe")));
}

#[test]
fn a_macs_metadata_file_is_never_a_linux_program() {
assert!(!is_program(Path::new("/games/x/._game.x86_64"), "linux"));
}

#[test]
fn a_macs_metadata_file_is_never_a_windows_program() {
assert!(!is_program(Path::new("/games/x/._Game.exe"), "windows"));
}

#[test]
fn the_windowed_program_goes_ahead_of_its_command_line_build() {
let d = tmp("cli-build");
Expand Down
Loading