Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions apps/desktop/src-tauri/core/src/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,12 +725,14 @@ fn finish_extracted(raw: Vec<(String, Vec<u8>)>) -> Result<ExtractedHud, Profile
})
}

/// The refusal for an archive or folder with no `info.vdf`: not a HUD at all,
/// which is how an ordinary mod picked in the HUD pane ends up.
pub const NO_HUD_FOUND: &str = "No HUD folder was found (missing info.vdf). Choose a complete HUD download or its extracted HUD folder.";

fn validate_hud_info(tree: &HudTree) -> 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!(
Expand Down
5 changes: 4 additions & 1 deletion apps/desktop/src-tauri/core/src/viewmodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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") {
Expand Down
12 changes: 12 additions & 0 deletions apps/desktop/src-tauri/src/commands/hud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
Expand Down Expand Up @@ -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!(
Expand Down
21 changes: 15 additions & 6 deletions apps/desktop/src-tauri/src/commands/viewmodel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand Down
42 changes: 37 additions & 5 deletions apps/desktop/src/HudPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
HUD_SORTS,
hudAuthorCopy,
hudCatalogControls,
hudCatalogMatch,
hudDisplayName,
hudInstallSourceCopy,
hudOptionsDirty,
Expand Down Expand Up @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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."
Expand Down Expand Up @@ -322,6 +331,27 @@ export function HudPane({
}
/>

{modsImportHint ? (
<Alert tone="warn" testId="hud-import-not-a-hud" className="mb-4">
<span className="block font-medium">That isn't a HUD</span>
<span className="mt-1 block">
It has no info.vdf, so nothing was imported. A mod is imported in Mods.
</span>
<span className="mt-3 flex flex-wrap gap-2">
{onOpenMods ? (
<button type="button" className="btn btn-ghost" onClick={onOpenMods}>
Open Mods
</button>
) : null}
{onDismissModsImportHint ? (
<button type="button" className="btn btn-quiet" onClick={onDismissModsImportHint}>
Dismiss
</button>
) : null}
</span>
</Alert>
) : null}

<div className="pane-views">
<ClassTabs
label="HUD workspace"
Expand Down Expand Up @@ -371,8 +401,10 @@ export function HudPane({
{installedEntry ? `${hudAuthorCopy(installedEntry)} · ` : ""}
{installedLabel}
</p>
{state.inferred ? (
<p className="t-meta mt-3">Match it to hud-db to enable updates.</p>
{catalogMatch ? (
<p className="t-meta mt-3">
Match it to {hudDisplayName(catalogMatch)} in the catalog to get updates.
</p>
) : null}
<div className="mt-3 flex flex-wrap gap-2">
{state.updateAvailable ? (
Expand All @@ -387,16 +419,16 @@ export function HudPane({
{running ? "Close TF2 to update" : "Update HUD"}
</button>
) : null}
{state.inferred ? (
{catalogMatch ? (
<button
type="button"
data-testid="hud-match"
disabled={mutationBlocked}
title={mutationReason}
onClick={() => onMatch(installedId)}
onClick={() => onMatch(catalogMatch.id)}
className="btn btn-ghost"
>
Match to catalog…
Match to catalog
</button>
) : null}
<button
Expand Down
22 changes: 22 additions & 0 deletions apps/desktop/src/SettingsHost.hud-loading.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ let container: HTMLDivElement;
let refreshKey: number;
let running: boolean;
let onPendingChange: ReturnType<typeof vi.fn<(pending: boolean) => void>>;
let onNavigate: ReturnType<typeof vi.fn<(tab: string) => void>>;
function makeApi() {
return {
getFilesContext: vi.fn(async () => ({ profileId, root: "fixture", layer: "vanilla" })),
Expand Down Expand Up @@ -104,6 +105,7 @@ async function render() {
onBindSyncHandled={() => {}}
onBusyChange={() => {}}
onPendingChange={onPendingChange}
onNavigate={onNavigate}
onError={() => {}}
/>
</AppStatusProvider>
Expand Down Expand Up @@ -131,6 +133,7 @@ beforeEach(() => {
refreshKey = 1;
api = makeApi();
onPendingChange = vi.fn();
onNavigate = vi.fn();
});
afterEach(async () => {
await act(async () => root.unmount());
Expand Down Expand Up @@ -322,6 +325,25 @@ describe("HUD loading through the real settings host and pane", () => {
expect(element("toast").getAttribute("data-kind")).toBe("saved");
});

it("points an import that is not a HUD to Mods instead of a bare failure", async () => {
await render();
api.importHudArchive.mockRejectedValueOnce({
code: "NotAHud",
message: "No HUD folder was found (missing info.vdf).",
});
await click("hud-import");
await click("hud-import-archive");
const hint = element("hud-import-not-a-hud");
expect(hint.textContent).toContain("That isn't a HUD");
expect(container.querySelector('[data-testid="toast"][data-kind="error"]')).toBeNull();
const open = Array.from(hint.querySelectorAll("button")).find(
(button) => button.textContent === "Open Mods",
);
await act(async () => open?.click());
expect(onNavigate).toHaveBeenCalledWith("mods");
expect(container.querySelector('[data-testid="hud-import-not-a-hud"]')).toBeNull();
});

it("retains a same-HUD dirty draft through schema failure and retry without saving unavailable controls", async () => {
vi.useFakeTimers();
running = true;
Expand Down
31 changes: 31 additions & 0 deletions apps/desktop/src/SettingsHost.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,13 @@ export function SettingsHost({
}, [settled, onSettledChange]);
// biome-ignore lint/correctness/useExhaustiveDependencies: Profile changes invalidate guidance from the previous import attempt.
useEffect(() => setModsHudImportRequired(null), [profileId]);
// An import refused because the pick belongs in Mods, kept on its pane.
const [modsImportHint, setModsImportHint] = useState<{
tab: "hud" | "viewmodels";
message: string;
} | null>(null);
// biome-ignore lint/correctness/useExhaustiveDependencies: the notice belongs to the profile it was raised in.
useEffect(() => setModsImportHint(null), [profileId]);
const hud = useHudResources(
api,
profileId,
Expand Down Expand Up @@ -654,6 +661,15 @@ export function SettingsHost({
options?.onHandledFailure?.("review-required");
return false;
}
if (failure.code === "NotAHud" || failure.code === "ViewmodelMixedContent") {
if (started) toast.cancelSave(copy?.source);
setModsImportHint({
tab: failure.code === "NotAHud" ? "hud" : "viewmodels",
message: failure.message,
});
options?.onFailure?.(failure.message);
return false;
}
if (
(failure.code === "HudReviewRequired" || failure.code === "HudLiveReviewRequired") &&
expectedProfileId &&
Expand Down Expand Up @@ -1118,8 +1134,15 @@ export function SettingsHost({
await hud.reloadLocal();
});
}}
modsImportHint={modsImportHint?.tab === "hud" ? modsImportHint.message : null}
onOpenMods={() => {
setModsImportHint(null);
onNavigate?.("mods");
}}
onDismissModsImportHint={() => setModsImportHint(null)}
onImportArchive={() => {
setModsHudImportRequired(null);
setModsImportHint(null);
return write(
async () => {
if ((await api.importHudArchive()) === null) return null;
Expand All @@ -1131,6 +1154,7 @@ export function SettingsHost({
}}
onImportFolder={() => {
setModsHudImportRequired(null);
setModsImportHint(null);
return write(
async () => {
if ((await api.importHudFolder()) === null) return null;
Expand Down Expand Up @@ -1236,7 +1260,14 @@ export function SettingsHost({
}}
profilePreload={modsPayload?.profilePreload ?? null}
loadCatalog={api.getViewmodelSourceCatalog}
modsImportHint={modsImportHint?.tab === "viewmodels" ? modsImportHint.message : null}
onOpenMods={() => {
setModsImportHint(null);
onNavigate?.("mods");
}}
onDismissModsImportHint={() => setModsImportHint(null)}
onImport={(preload) => {
setModsImportHint(null);
return write(
async () => {
if ((await api.importViewmodels(preload)) === null) return null;
Expand Down
27 changes: 27 additions & 0 deletions apps/desktop/src/ViewmodelPane.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { DownloadSimple, Trash } from "@phosphor-icons/react";
import { useState } from "react";
import { Alert } from "./components/ui/Alert";
import { ClassTabs } from "./components/ui/ClassTabs";
import { PaneHeader } from "./components/ui/PaneHeader";
import { useAppStatus, useCanWrite } from "./hooks/useAppStatus";
Expand All @@ -24,6 +25,9 @@ export function ViewmodelPane({
onImport,
onBuild,
onRemove,
modsImportHint = null,
onOpenMods,
onDismissModsImportHint,
}: {
active: boolean;
profileId: string | null;
Expand All @@ -33,6 +37,10 @@ export function ViewmodelPane({
profilePreload: boolean | null;
loadCatalog: () => Promise<ViewmodelSourceCatalog>;
onImport: (preload: boolean) => void;
/** Why the last VPK was refused for carrying more than viewmodels. */
modsImportHint?: string | null;
onOpenMods?: () => void;
onDismissModsImportHint?: () => void;
onBuild: (request: ViewmodelBuildRequest) => Promise<boolean>;
onRemove: () => void;
}) {
Expand Down Expand Up @@ -69,6 +77,25 @@ export function ViewmodelPane({
onRemovePack={onRemove}
/>

{modsImportHint ? (
<Alert tone="warn" testId="viewmodel-import-mixed" className="mb-4">
<span className="block font-medium">That pack has more than viewmodels</span>
<span className="mt-1 block">{modsImportHint}</span>
<span className="mt-3 flex flex-wrap gap-2">
{onOpenMods ? (
<button type="button" className="btn btn-ghost" onClick={onOpenMods}>
Open Mods
</button>
) : null}
{onDismissModsImportHint ? (
<button type="button" className="btn btn-quiet" onClick={onDismissModsImportHint}>
Dismiss
</button>
) : null}
</span>
</Alert>
) : null}

<section
data-testid="viewmodel-saved-pack"
aria-labelledby="viewmodel-pack-heading"
Expand Down
Loading
Loading