From 306046b57e833b4573de023999bdc4b67a8eee6a Mon Sep 17 00:00:00 2001 From: ySKELLETONX <168378312+ySKELLETONX@users.noreply.github.com> Date: Sun, 29 Nov 2026 15:24:11 -0300 Subject: [PATCH] Find and play a VIctory build whose program has another name A fork can rename the `victory` package's program (SlaktarnVI builds `valhalla`). The launcher recorded some other program, then looked for victory.exe anyway, so Play and Fix and verify said it was not installed or that its program was missing. Build that program by name, record it as a VIctory build, and use the recorded program wherever one is looked up. Programs that are not VIctory builds get no game-file search or D3D12 files for it. Co-Authored-By: Claude Opus 5.5 --- src-tauri/src/launcher.rs | 91 +++++++++++++------ .../src/launcher/parallel_install_tests.rs | 64 +++++++++++++ src-tauri/src/rust_project.rs | 66 +++++++++++--- 3 files changed, 179 insertions(+), 42 deletions(-) diff --git a/src-tauri/src/launcher.rs b/src-tauri/src/launcher.rs index a28833e..ed0fcde 100644 --- a/src-tauri/src/launcher.rs +++ b/src-tauri/src/launcher.rs @@ -100,7 +100,7 @@ impl Project { self.archive_exe .as_deref() .is_some_and(|exe| !build_zip::is_victory(exe)) - || rust_install(&self.repo).is_some() + || rust_install(&self.repo).is_some_and(|install| !install.victory) } fn web_url(&self) -> String { @@ -1095,12 +1095,24 @@ fn slug(repo: &str) -> String { #[derive(Serialize, Deserialize)] struct RustInstall { executable: Option, + /// The program is a VIctory build under its own name (`valhalla`): played as one. + #[serde(default)] + victory: bool, } fn rust_install_file(repo: &str) -> PathBuf { target_dir(repo).join("mandyhub-rust.json") } +fn record_rust_install(repo: &str, install: &RustInstall) -> Result<(), String> { + let marker = rust_install_file(repo); + let temporary = marker.with_extension("tmp"); + let record = serde_json::to_vec(install).map_err(|error| error.to_string())?; + std::fs::write(&temporary, record) + .and_then(|_| std::fs::rename(&temporary, &marker)) + .map_err(|error| format!("Could not record the installed Rust project: {error}")) +} + fn rust_install(repo: &str) -> Option { serde_json::from_slice(&std::fs::read(rust_install_file(repo)).ok()?).ok() } @@ -2460,7 +2472,11 @@ fn install( } // The runtime loads Microsoft's D3D12 Agility files from D3D12\ next to its exe. Put them // there now and check them, so the new build is playable as soon as it finishes. - if let Ok(exe) = project_exe(p) { + // Other Rust programs need none of that. + let runtime = project_exe(p) + .ok() + .filter(|exe| !p.runs_standalone() || diagnose::exe_names_agility(exe)); + if let Some(exe) = runtime { let data = project_data(&p.repo); let cache = project_cache(&p.repo); let check = diagnose::Check { @@ -2531,14 +2547,12 @@ fn build_project( ) -> Result<(), String> { let workspace = cargo_workspace(dir)?; let metadata = rust_project::metadata(&workspace)?; - // A listed project is built by name only when its workspace has the `victory` program; - // otherwise the whole workspace is built and its program found from Cargo's output. - let victory = if p.custom { - rust_project::is_victory(&workspace, &metadata) - } else { - rust_project::has_victory_program(&metadata) - }; - let profile = if victory { + // A listed project is built by name only when its workspace has the `victory` program + // (under any name); otherwise the whole workspace is built and its program found from + // Cargo's output. + let victory = rust_project::victory_program(&metadata) + .filter(|_| !p.custom || rust_project::is_victory(&workspace, &metadata)); + let profile = if victory.is_some() { detect_build_profile(&workspace) } else { "release" @@ -2551,18 +2565,33 @@ fn build_project( cargo.arg("--locked"); } cargo.current_dir(&workspace); - if victory { + if let Some(program) = victory { + let renamed = program != "victory"; cargo.args(["-p", "victory"]); - if documented_scarlet_script(&workspace).is_some() { - cargo.args(["--bin", "victory"]); + if renamed || documented_scarlet_script(&workspace).is_some() { + cargo.args(["--bin", program]); } run(job, ctx, &mut cargo)?; - let executable = victory_program(&target.join(profile)); + let dir = target.join(profile); + let executable = if renamed { + dir.join(crate::platform::exe_name(program)) + } else { + victory_program(&dir) + }; if !executable.is_file() { return Err(format!("the build made no {}", executable.display())); } let marker = rust_install_file(&p.repo); - if marker.exists() { + if renamed { + let executable = Path::new(profile).join(crate::platform::exe_name(program)); + record_rust_install( + &p.repo, + &RustInstall { + executable: Some(executable), + victory: true, + }, + )?; + } else if marker.exists() { std::fs::remove_file(marker).map_err(|error| error.to_string())?; } } else { @@ -2590,13 +2619,13 @@ fn build_project( .map(|exe| Path::new(exe).strip_prefix(target).map(Path::to_owned)) .transpose() .map_err(|_| "Cargo reported an executable outside the install folder")?; - let marker = rust_install_file(&p.repo); - let temporary = marker.with_extension("tmp"); - let record = - serde_json::to_vec(&RustInstall { executable }).map_err(|error| error.to_string())?; - std::fs::write(&temporary, record) - .and_then(|_| std::fs::rename(&temporary, &marker)) - .map_err(|error| format!("Could not record the installed Rust project: {error}"))?; + record_rust_install( + &p.repo, + &RustInstall { + executable, + victory: false, + }, + )?; } Ok(()) } @@ -2901,12 +2930,13 @@ fn runnable(path: PathBuf) -> Result { Ok(path) } -/// The victory program `p` runs with: its build, or a build already on this PC. +/// The program `p` runs with: its build (under whatever name the project gives it), or a +/// build already on this PC. fn project_exe(p: &Project) -> Result { let exe = p .archive_program() .or_else(|| p.local_exe.as_ref().map(PathBuf::from)) - .unwrap_or_else(|| built_exe(&p.repo)); + .unwrap_or_else(|| installed_exe(&p.repo)); if crate::platform::is_program(&exe) { Ok(exe) } else { @@ -3821,8 +3851,8 @@ fn fix_build( stage(job, ctx, msg_str!("Rebuilding the missing program")); install(job, ctx, p, project_installed(&p.repo), l)?; // The build just ran, so a missing program is not "not installed": the file is gone - // (antivirus often removes a new victory.exe) or the build left it elsewhere. - let expected = built_exe(&p.repo); + // (antivirus often removes a new program) or the build left it elsewhere. + let expected = installed_exe(&p.repo); let found = project_exe(p).map_err(|_| { format!( "The build finished, but its program is not at {}. Check whether antivirus removed it, then press Fix and verify again.", @@ -4236,8 +4266,13 @@ fn run_fixes( )); continue; } - // A standalone program can run without the game folder; the others cannot. - if p.runs_standalone() && finding.fix == Some(diagnose::FIX_GAME_FILES) { + // A standalone program can run without the game folder, and without the Agility + // SDK when it does not name it; the others cannot. + if p.runs_standalone() + && (finding.fix == Some(diagnose::FIX_GAME_FILES) + || (finding.fix == Some(diagnose::FIX_AGILITY) + && !diagnose::exe_names_agility(&exe))) + { continue; } tried += 1; diff --git a/src-tauri/src/launcher/parallel_install_tests.rs b/src-tauri/src/launcher/parallel_install_tests.rs index 3e1f01c..87f31a2 100644 --- a/src-tauri/src/launcher/parallel_install_tests.rs +++ b/src-tauri/src/launcher/parallel_install_tests.rs @@ -65,6 +65,17 @@ fn two_installs_and_an_update_overlap() { first.lock().unwrap().running = false; let prior = repo_state(update).built.unwrap(); assert!(installed_exe(&update.repo).is_file()); + // The program is not called `victory`: Play and Fix and verify must still find it, and a + // program that does not load the Agility SDK gets no D3D12 folder (#69, #88). + let program = project_exe(update).unwrap(); + assert_eq!(program, installed_exe(&update.repo)); + assert_eq!( + program.file_name().unwrap(), + std::ffi::OsStr::new(&crate::platform::exe_name("fixture_update")) + ); + assert!(!program.with_file_name("D3D12").exists()); + assert!(update.runs_standalone()); + renamed_victory_is_installed(&root, &ctx); for name in names { let source = root.join(name); @@ -121,6 +132,59 @@ fn two_installs_and_an_update_overlap() { ); } +/// A fork that renamed the `victory` package's program, beside a helper program named as its +/// package (SlaktarnVI's `valhalla` and `xtask`): the renamed one is recorded and played as a +/// VIctory build. +fn renamed_victory_is_installed(root: &Path, ctx: &Ctx) { + let dir = root.join("renamed_victory"); + let write = |path: &str, text: &str| { + let path = dir.join(path); + fs::create_dir_all(path.parent().unwrap()).unwrap(); + fs::write(path, text).unwrap(); + }; + let package = + |name: &str| format!("[package]\nname = '{name}'\nversion = '0.1.0'\nedition = '2021'\n"); + write( + "Cargo.toml", + "[workspace]\nresolver = '2'\nmembers = ['apps/victory', 'victory-hle', 'xtask']\n", + ); + write( + "apps/victory/Cargo.toml", + &format!( + "{}[[bin]]\nname = 'valhalla'\npath = 'src/main.rs'\n", + package("victory") + ), + ); + write("apps/victory/src/main.rs", "fn main() {}\n"); + write("victory-hle/Cargo.toml", &package("victory-hle")); + write("victory-hle/src/lib.rs", ""); + write("xtask/Cargo.toml", &package("xtask")); + write("xtask/src/main.rs", "fn main() {}\n"); + git(&dir, &["init", "-q"]); + git(&dir, &["add", "."]); + git(&dir, &["commit", "-qm", "Initial fixture"]); + for custom in [true, false] { + let project = Project { + name: "renamed".into(), + custom, + repo: url::Url::from_directory_path(&dir).unwrap().to_string(), + ..test_project() + }; + let job = Arc::new(Mutex::new(Job::default())); + let target = target_dir(&project.repo); + build_project(&job, ctx, &project, &dir, &target) + .unwrap_or_else(|error| panic!("{error}\n{}", job.lock().unwrap().log.join("\n"))); + assert_eq!( + project_exe(&project).unwrap(), + target + .join("release") + .join(crate::platform::exe_name("valhalla")) + ); + assert!(!project.runs_standalone()); + assert!(project_installed(&project.repo)); + } +} + fn make_project(root: &Path, name: &str) -> Project { let dir = root.join(name); fs::create_dir_all(dir.join("src")).unwrap(); diff --git a/src-tauri/src/rust_project.rs b/src-tauri/src/rust_project.rs index a2212a4..c3912dc 100644 --- a/src-tauri/src/rust_project.rs +++ b/src-tauri/src/rust_project.rs @@ -33,14 +33,26 @@ fn binaries(package: &Value) -> impl Iterator { }) } -/// Whether the workspace has the `victory` package with its `victory` program: the one -/// the launcher builds by name (`cargo build -p victory`). -pub fn has_victory_program(metadata: &Value) -> bool { - metadata["packages"].as_array().is_some_and(|packages| { - packages.iter().any(|package| { - package["name"] == "victory" && binaries(package).any(|name| name == "victory") - }) - }) +/// The program of the workspace's `victory` package: the one the launcher builds by name +/// (`cargo build -p victory`). It is `victory`, or the package's only program when a fork +/// renamed it (Valhalla's `valhalla`) and kept the layer's own crates. +pub fn victory_program(metadata: &Value) -> Option<&str> { + let packages = metadata["packages"].as_array()?; + let package = packages + .iter() + .find(|package| package["name"] == "victory")?; + if binaries(package).any(|name| name == "victory") { + return Some("victory"); + } + let mut programs = binaries(package); + let only = programs.next()?; + (programs.next().is_none() && has_layer_crates(packages)).then_some(only) +} + +fn has_layer_crates(packages: &[Value]) -> bool { + packages + .iter() + .any(|package| package["name"] == "victory-hle" || package["name"] == "victory-loader") } /// Whether a custom project is a VIctory build: the program, plus the layer's own folders @@ -49,13 +61,11 @@ pub fn is_victory(workspace: &Path, metadata: &Value) -> bool { let Some(packages) = metadata["packages"].as_array() else { return false; }; - has_victory_program(metadata) + victory_program(metadata).is_some() && (["apps/victory", "crates/victory", "victory"] .iter() .any(|path| workspace.join(path).join("Cargo.toml").is_file()) - || packages.iter().any(|package| { - package["name"] == "victory-hle" || package["name"] == "victory-loader" - })) + || has_layer_crates(packages)) } pub fn select_executable<'a>(metadata: &Value, artifacts: &'a [Value]) -> Option<&'a str> { @@ -96,14 +106,42 @@ fn a_listed_project_without_the_victory_package_is_not_built_by_name() { "targets": [{ "kind": ["bin"], "name": "anyxboxx" }] }] }); - assert!(!has_victory_program(&without)); + assert_eq!(victory_program(&without), None); let with = serde_json::json!({ "packages": [{ "name": "victory", "targets": [{ "kind": ["bin"], "name": "victory" }] }] }); - assert!(has_victory_program(&with)); + assert_eq!(victory_program(&with), Some("victory")); +} + +#[cfg(test)] +#[test] +fn a_renamed_victory_program_is_still_the_victory_package() { + // SlaktarnVI (#69, #88): the `victory` package's only program is `valhalla`. + let hle = serde_json::json!({ + "name": "victory-hle", "targets": [{ "kind": ["lib"], "name": "victory_hle" }] + }); + let app = |bins: &[&str]| { + let targets: Vec<_> = bins + .iter() + .map(|name| serde_json::json!({ "kind": ["bin"], "name": name })) + .collect(); + serde_json::json!({ "name": "victory", "targets": targets }) + }; + let workspace = |packages: &[&Value]| serde_json::json!({ "packages": packages }); + let renamed = workspace(&[&app(&["valhalla"]), &hle]); + assert_eq!(victory_program(&renamed), Some("valhalla")); + // Its own name wins; another package called victory, or one of several programs, is no guess. + let both = workspace(&[&app(&["other", "victory"]), &hle]); + assert_eq!(victory_program(&both), Some("victory")); + assert_eq!(victory_program(&workspace(&[&app(&["valhalla"])])), None); + assert_eq!( + victory_program(&workspace(&[&app(&["a", "b"]), &hle])), + None + ); + assert_eq!(victory_program(&workspace(&[&app(&[]), &hle])), None); } #[test]