Skip to content

Add Package.RenameFile, lowercase paths like Valve and fix writes that corrupt or truncate VPKs - #38

Closed
w1tcherrr wants to merge 3 commits into
ValveResourceFormat:masterfrom
w1tcherrr:rename-file
Closed

w1tcherrr wants to merge 3 commits into
ValveResourceFormat:masterfrom
w1tcherrr:rename-file

Conversation

@w1tcherrr

@w1tcherrr w1tcherrr commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Adds Package.RenameFile to move an entry without reading its data and adding it again.

Also fixes what Valve does:

  • Paths with an empty file name or extension, like .hidden or trailing., or a null character, now throw instead of writing a broken VPK.
  • Paths are lowercased like Valve does, because the game can't find entries with uppercase letters. On a package that isn't optimized with OrdinalIgnoreCase, FindEntry needs the lowercased path to find an added file.
  • Leading and trailing slashes are trimmed from added and renamed paths, the same as FindEntry already does.
  • Renaming onto a path that only differs in case from an existing entry throws.
  • Write only truncates an existing file after writing, so a package that can't be written leaves it untouched.

And a few other fixes:

  • Adding, removing, renaming or writing after Dispose throws instead of truncating chunk files.
  • Read throws on a package that files were added to, instead of dropping them.
  • Malformed archive MD5 section sizes and entry lengths throw before allocating, instead of allocating gigabytes.
  • An other MD5 section that isn't 48 bytes is skipped, so the signature is read from the right offset.
  • IsSigned tells unsigned packages apart, since IsSignatureValid returns true for them.
  • VerifyHashes reports tree and archive section checksum mismatches instead of throwing when the whole file checksum matches, because many of Valve's map paks have garbage there. It also returns for version 1 packages, which have no checksums. It now takes a progress reporter like the other verify methods.
  • WriteChunkSize defaults to 100 MiB and a new chunk file only starts once the current one is larger than it, like Valve's workshop uploader.

@w1tcherrr
w1tcherrr force-pushed the rename-file branch 2 times, most recently from fd35dd8 to 64cae9e Compare October 17, 2026 20:29
@w1tcherrr w1tcherrr changed the title Add Package.RenameFile to move an entry to a new path Add Package.RenameFile, lowercase paths like Valve and fix writes that corrupt or truncate VPKs Oct 17, 2026
Comment thread ValvePak/ValvePak/Package.Save.cs Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants