diff --git a/CHANGELOG.md b/CHANGELOG.md index 55fd9337..c6dd981b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ User-facing changes only. The release workflow publishes the matching ### Fixed +- HUD and Viewmodels: importing something that belongs in Mods now says so and offers Open Mods, + instead of only failing. +- HUD: an imported HUD that is also in the catalog now offers Match to catalog, so it can get + updates. The button was missing for imported HUDs. - Mods: when a mod you import or download turns out to be a HUD, the file review now offers Install as HUD. Before, the install was refused and you had to import the file again in HUD. - Mods: a HUD found on GameBanana can now be installed from its card with Install HUD. Open HUD diff --git a/apps/desktop/src-tauri/core/src/hud.rs b/apps/desktop/src-tauri/core/src/hud.rs index 03f306e4..50fbc836 100644 --- a/apps/desktop/src-tauri/core/src/hud.rs +++ b/apps/desktop/src-tauri/core/src/hud.rs @@ -725,12 +725,14 @@ fn finish_extracted(raw: Vec<(String, Vec)>) -> Result Result<(), ProfileError> { - let info = tree.info_vdf().ok_or_else(|| { - ProfileError::Io( - "No HUD folder was found (missing info.vdf). Choose a complete HUD download or its extracted HUD folder.".into(), - ) - })?; + let info = tree + .info_vdf() + .ok_or_else(|| ProfileError::Io(NO_HUD_FOUND.into()))?; match std::str::from_utf8(info).ok().and_then(parse_ui_version) { Some(CURRENT_HUD_UI_VERSION) => Ok(()), Some(version) => Err(ProfileError::Io(format!( diff --git a/apps/desktop/src-tauri/core/src/viewmodel.rs b/apps/desktop/src-tauri/core/src/viewmodel.rs index a571cf0b..023cdf71 100644 --- a/apps/desktop/src-tauri/core/src/viewmodel.rs +++ b/apps/desktop/src-tauri/core/src/viewmodel.rs @@ -1081,6 +1081,9 @@ fn validate_viewmodel_import_metadata( Ok(()) } +/// Ends the refusal for a VPK that carries more than viewmodels. +pub const MIXED_VIEWMODEL_PACK: &str = "Import mixed-content packs through Mods."; + /// A custom VPK mounts every member as game content. Keep the Viewmodels /// shortcut limited to compiled first-person weapon models; mixed packs belong /// in Mods, where CFG members receive their separate trust review. @@ -1089,7 +1092,7 @@ fn validate_viewmodel_vpk(bytes: &[u8]) -> Result<(), ProfileError> { validate_vpk_dir_bytes_with_paths(bytes, &mut |path| { if !is_viewmodel_member(path) { return Err(VpkError(format!( - "Viewmodel VPK contains unrelated content: {path}. Import mixed-content packs through Mods." + "Viewmodel VPK contains unrelated content: {path}. {MIXED_VIEWMODEL_PACK}" ))); } if path.to_ascii_lowercase().ends_with(".mdl") { diff --git a/apps/desktop/src-tauri/src/commands/hud.rs b/apps/desktop/src-tauri/src/commands/hud.rs index 55590b9c..f8dca382 100644 --- a/apps/desktop/src-tauri/src/commands/hud.rs +++ b/apps/desktop/src-tauri/src/commands/hud.rs @@ -377,8 +377,13 @@ pub(super) fn install_local_hud( // These errors describe rejected input before any profile write. Keep the // core error code without its generic profile-library write failure prefix. +// A pick with no `info.vdf` gets its own code so the HUD pane can point an +// ordinary mod to Mods. pub(super) fn hud_input_error(error: execs_core::ProfileError) -> CommandError { match error { + execs_core::ProfileError::Io(message) if message == execs_core::hud::NO_HUD_FOUND => { + CommandError::new("NotAHud", message) + } execs_core::ProfileError::Io(message) => CommandError::new("Io", message), other => other.into(), } @@ -721,6 +726,13 @@ mod tests { assert!(invalid.message.contains("not a ZIP, 7z or RAR")); assert!(!invalid.message.contains("profile library")); + // An ordinary mod has no info.vdf; its own code lets the pane offer Mods. + let not_a_hud = hud_input_error(execs_core::ProfileError::Io( + execs_core::hud::NO_HUD_FOUND.into(), + )); + assert_eq!(not_a_hud.code, "NotAHud"); + assert_eq!(not_a_hud.message, execs_core::hud::NO_HUD_FOUND); + let lock = hud_input_error(execs_core::ProfileError::GameRunning); assert_eq!(lock.code, "GameRunning"); assert_eq!( diff --git a/apps/desktop/src-tauri/src/commands/viewmodel.rs b/apps/desktop/src-tauri/src/commands/viewmodel.rs index bf5ed25f..ae5b5863 100644 --- a/apps/desktop/src-tauri/src/commands/viewmodel.rs +++ b/apps/desktop/src-tauri/src/commands/viewmodel.rs @@ -519,17 +519,26 @@ pub async fn import_viewmodels( with_profile(move |root, profile_id| { context.ensure_current(&root, &profile_id)?; ensure_viewmodel_unchanged(&profile_id, initial_viewmodel.as_ref())?; - Ok(execs_core::import_viewmodel_vpk( - &root, - &profile_id, - &bytes, - preload, - )?) + execs_core::import_viewmodel_vpk(&root, &profile_id, &bytes, preload) + .map_err(viewmodel_input_error) }) .await .map(Some) } +// A VPK with more than viewmodels gets its own code so the pane can point it +// to Mods. +fn viewmodel_input_error(error: execs_core::ProfileError) -> CommandError { + match error { + execs_core::ProfileError::Io(message) + if message.ends_with(execs_core::viewmodel::MIXED_VIEWMODEL_PACK) => + { + CommandError::new("ViewmodelMixedContent", message) + } + other => other.into(), + } +} + fn ensure_viewmodel_unchanged( profile_id: &str, expected: Option<&execs_core::ViewmodelRecord>, diff --git a/apps/desktop/src/HudPane.tsx b/apps/desktop/src/HudPane.tsx index 5947611d..f88ac638 100644 --- a/apps/desktop/src/HudPane.tsx +++ b/apps/desktop/src/HudPane.tsx @@ -50,6 +50,7 @@ import { HUD_SORTS, hudAuthorCopy, hudCatalogControls, + hudCatalogMatch, hudDisplayName, hudInstallSourceCopy, hudOptionsDirty, @@ -116,6 +117,9 @@ export function HudPane({ onApplyOptions, onImportArchive, onImportFolder, + modsImportHint = null, + onOpenMods, + onDismissModsImportHint, }: { api: Api; /** The profile this draft belongs to; a switch discards it. */ @@ -147,6 +151,10 @@ export function HudPane({ /** Install a HUD from a ZIP, 7z or RAR, or a folder on this computer. */ onImportArchive: () => HudMutationResult; onImportFolder: () => HudMutationResult; + /** Why the last import was refused as not being a HUD; it may be a mod. */ + modsImportHint?: string | null; + onOpenMods?: () => void; + onDismissModsImportHint?: () => void; }) { const { running, busy, setError } = useAppStatus(); const active = useContext(AutosaveActivity); @@ -224,6 +232,7 @@ export function HudPane({ const installedEntry = installedId ? (catalog.find((entry) => entry.id.toLowerCase() === installedId.toLowerCase()) ?? null) : null; + const catalogMatch = hudCatalogMatch(catalog, state); const mutationBlocked = locked || dirty || stateLoading || stateError !== null; const mutationReason = running ? "Close TF2 before changing the installed HUD." @@ -322,6 +331,27 @@ export function HudPane({ } /> + {modsImportHint ? ( + + That isn't a HUD + + It has no info.vdf, so nothing was imported. A mod is imported in Mods. + + + {onOpenMods ? ( + + ) : null} + {onDismissModsImportHint ? ( + + ) : null} + + + ) : null} +
- {state.inferred ? ( -

Match it to hud-db to enable updates.

+ {catalogMatch ? ( +

+ Match it to {hudDisplayName(catalogMatch)} in the catalog to get updates. +

) : null}
{state.updateAvailable ? ( @@ -387,16 +419,16 @@ export function HudPane({ {running ? "Close TF2 to update" : "Update HUD"} ) : null} - {state.inferred ? ( + {catalogMatch ? ( ) : null} + ) : null} + {onDismissModsImportHint ? ( + + ) : null} + + + ) : null} +
{ }); }); +describe("hudCatalogMatch", () => { + const catalog = [{ id: "rayshud" }, { id: "Middle-Mann" }, { id: "m0re-hud" }, { id: "m0rehud" }]; + const match = (id: string, source: "local" | "hudDb" = "local", inferred = false) => + hudCatalogMatch(catalog as never, { + installed: { id, hash: null, source, options: {} }, + inferred, + schemaSupported: false, + catalogHash: null, + updateAvailable: false, + })?.id ?? null; + + it("offers the catalog HUD an imported folder is a copy of", () => { + expect(match("rayshud")).toBe("rayshud"); + expect(match("RaysHUD-master")).toBe("rayshud"); + expect(match("middlemann-main")).toBe("Middle-Mann"); + expect(match("rayshud", "hudDb", true)).toBe("rayshud"); + }); + + it("offers nothing for a catalog install, an unknown HUD or an unclear name", () => { + expect(match("rayshud", "hudDb")).toBeNull(); + expect(match("pure-hud")).toBeNull(); + expect(match("m0re_hud")).toBeNull(); + expect(match("m0re-hud")).toBe("m0re-hud"); + }); +}); + describe("hudIdFromName", () => { it("matches the folder id a HUD is installed under", () => { expect(hudIdFromName("Pure HUD")).toBe("pure-hud"); diff --git a/apps/desktop/src/lib/hud-ui.ts b/apps/desktop/src/lib/hud-ui.ts index d5835a21..cc4b0b3a 100644 --- a/apps/desktop/src/lib/hud-ui.ts +++ b/apps/desktop/src/lib/hud-ui.ts @@ -539,6 +539,32 @@ export function formatHudRgba(r: number, g: number, b: number, a: number): strin return `${r} ${g} ${b} ${a}`; } +/** Letters and digits only, without the branch suffix GitHub adds to a downloaded folder. */ +function normalizeHudName(name: string): string { + const lower = name.trim().toLowerCase(); + const suffix = ["-master", "-main"].find((end) => lower.endsWith(end)); + return (suffix ? lower.slice(0, -suffix.length) : lower).replace(/[^a-z0-9]/g, ""); +} + +/** + * The catalog HUD an imported or found HUD can be matched to: the one with its + * folder name, ignoring case, punctuation and a `-master`/`-main` suffix. Null + * when the HUD already comes from the catalog, or when no single entry fits. + */ +export function hudCatalogMatch( + catalog: HudCatalogEntry[], + state: HudUiState, +): HudCatalogEntry | null { + const installed = state.installed; + if (!installed || (installed.source === "hudDb" && !state.inferred)) return null; + const exact = catalog.find((entry) => entry.id.toLowerCase() === installed.id.toLowerCase()); + if (exact) return exact; + const wanted = normalizeHudName(installed.id); + if (wanted === "") return null; + const close = catalog.filter((entry) => normalizeHudName(entry.id) === wanted); + return close.length === 1 ? close[0] : null; +} + /** * The folder id a HUD gets when it is installed under `name` (an archive, a * folder or a GameBanana listing title). Mirrors the native `hud_id_from_name` diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index cc5a15c8..ac8862e5 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -95,7 +95,7 @@ Change install opens the finder with the previous install remembered in memory o - Mouse `sensitivity` and `zoom_sensitivity_ratio` are exact decimal fields owned by the Gameplay scope (native `managed_cfg` and the frontend scope agree); input accepts plain positive decimals up to 1000 because the pinned dump documents no range, and an invalid entry is shown with a reason but never saved. Because the managed cfg runs after `config.cfg`, a completed absorb that saw `config.cfg` drift rewrites only the managed lines when TF2's options changed them; the sync never adds lines the managed file did not set. Raw input and acceleration stay with mastercomfig's Flat mouse addon, and no recommended sensitivity is offered. - Gameplay's Weapons group holds auto reload, fast switch and Medigun auto-heal (`tf_medigun_autoheal`); Combat feedback holds damage numbers, combined damage numbers and healing numbers (`hud_combattext`, `_batching`, `_healing`). All are archived client cvars with no sv_cheats or server requirement; values seed from the effective cfg and TF2's defaults apply only when absent. Colors and the batching window are not offered. The same after-game sync covers these toggles, auto reload and fast switch because TF2's Advanced options write them to `config.cfg`; it accepts only values those options would write. - **HUD** — hud-db catalog (paginated, sorted by name / tf2huds.dev listing activity / downloads / views from exact matched statistics, cached a day), one HUD per profile, install kinds by host (GitHub codeload zip, Dropbox `dl=1`, GameBanana download page, teamfortress.tv thread scrape, or link out), import picker offers ZIP/7z/RAR/folder, and Dropbox, teamfortress.tv and single-file GameBanana HUD downloads accept the same three archive formats through the shared bounded reader, TF2HUD.Editor schemas consumed as data (parser strips `//` comments, options may lack `Name`). Listing activity is not a HUD release date; missing statistics never enter metric rankings. Imgur albums open in the browser; GitHub `showcase.md` albums load in-app. -- HUD browsing uses six previews per page with numbered navigation and page jumps above and below results; one Import HUD entry offers archive or extracted-folder choices. Imports unwrap a unique nested HUD only when every retained file belongs to it. Multiple HUD roots or sibling files require the user to follow the author's instructions and import one extracted HUD folder. `info.vdf` must declare UI version 3 before install; metadata and payloads are never synthesized or rewritten to imply compatibility. Dropbox download shards are trusted only as Dropbox redirects, one label below `dl.dropboxusercontent.com`. +- HUD browsing uses six previews per page with numbered navigation and page jumps above and below results; one Import HUD entry offers archive or extracted-folder choices. An imported or found HUD whose folder name matches exactly one catalog entry (ignoring case, punctuation and a `-master`/`-main` suffix) offers Match to catalog, which pairs the record with that entry and renames the folder to its id. Imports unwrap a unique nested HUD only when every retained file belongs to it. A pick with no `info.vdf` is refused as not a HUD (`NotAHud`), and the pane keeps a notice with Open Mods; a Viewmodels VPK refused for carrying other content (`ViewmodelMixedContent`) gets the same notice. Multiple HUD roots or sibling files require the user to follow the author's instructions and import one extracted HUD folder. `info.vdf` must declare UI version 3 before install; metadata and payloads are never synthesized or rewritten to imply compatibility. Dropbox download shards are trusted only as Dropbox redirects, one label below `dl.dropboxusercontent.com`. - Catalog HUD install and update emit `hud-install-progress` (downloading → checking → installing, the last after the write gate is taken). The card being installed shows exactly those steps, and the header status names the operation ("Installing HUD…"); there is no separate progress banner or percentage. Local imports have no download steps and show no card overlay. - HUD/mod ZIP, 7z and folder imports share the profile ownership junk policy: case-insensitive `.bak`, `.cache`, `.ztmp`, `.execs-part`, VCS/OS metadata and `node_modules` components are skipped before root detection. Payload bytes and archive/path limits remain unchanged. - HUD metric sorts rank only entries with a valid selected statistic; coverage and missing counts are explicit, and A to Z includes the full catalog. Statistics reloads serialize independently of the catalog and report loading/failure. tf2huds.dev counts follow its HUD list, then match explicit comfig links or unique GitHub repositories; names and missing values are never guessed into rankings. Browser fixture data is labeled Preview data. diff --git a/docs/guide/hud.md b/docs/guide/hud.md index 437de323..6c41ad77 100644 --- a/docs/guide/hud.md +++ b/docs/guide/hud.md @@ -12,7 +12,9 @@ A HUD that is on GameBanana but not in this list can be installed from Mods: fin ## Importing -**Import HUD** takes a ZIP, 7z or RAR, or a folder you already extracted. execs checks that it is a TF2 HUD (its `info.vdf` declares UI version 3) before installing it. An archive with several HUDs inside asks you to import the one you want as a folder. +**Import HUD** takes a ZIP, 7z or RAR, or a folder you already extracted. execs checks that it is a TF2 HUD (its `info.vdf` declares UI version 3) before installing it. An archive with several HUDs inside asks you to import the one you want as a folder. If what you picked isn't a HUD at all, execs says so and offers **Open Mods**, where ordinary mods are imported. + +An imported HUD that is also in the catalog shows **Match to catalog** on the Installed view. Matching it lets execs check that HUD for updates; a folder named after a download (`rayshud-master`) is renamed to the catalog's name. When you install or import a HUD over another one, the old HUD is kept as a backup outside TF2's HUD folders. App settings → Storage lists those backups. diff --git a/docs/guide/viewmodels.md b/docs/guide/viewmodels.md index 0aa671f8..659f697e 100644 --- a/docs/guide/viewmodels.md +++ b/docs/guide/viewmodels.md @@ -24,6 +24,6 @@ If TF2 updates its files while you have choices waiting, execs keeps them but ca ## Packs you already have -**Use your own VPK…** installs a viewmodel VPK instead of the one execs builds. Showing every weapon again and applying removes the pack; **Remove pack** does that directly. Profile exports carry the build recipe, not the built model files, so whoever imports the profile builds it from their own TF2. +**Use your own VPK…** installs a viewmodel VPK instead of the one execs builds. It must hold only viewmodel files; a VPK with anything else is refused with **Open Mods**, where such packs are imported. Showing every weapon again and applying removes the pack; **Remove pack** does that directly. Profile exports carry the build recipe, not the built model files, so whoever imports the profile builds it from their own TF2. Custom viewmodels on Valve Casual need the profile's preload launch option; see [Mods → Casual setup](mods.md#casual-setup).