From 5cdd45c71bc22db7a51b97d01edd6ab19bd3e0d2 Mon Sep 17 00:00:00 2001 From: thomaslaurenson Date: Sat, 31 Oct 2026 09:42:17 +1300 Subject: [PATCH 1/4] Accepted forward slashes in archive paths when looking files up --- src/mpq/extract.cpp | 13 +++--- src/mpq/query.cpp | 16 +++++++ src/mpq/query.h | 8 ++++ src/mpq/read.cpp | 16 ++++--- src/mpq/remove.cpp | 14 +++--- src/mpq/rename.cpp | 13 +++--- test/fixtures/raw_archive.h | 43 ++++++++++++++++++ test/functional/test_extract.cpp | 16 +++++++ test/functional/test_read.cpp | 13 ++++++ test/functional/test_remove.cpp | 18 ++++++++ test/functional/test_rename.cpp | 19 ++++++++ test/unit/commands/test_extract.cpp | 15 +++++++ test/unit/commands/test_read.cpp | 17 ++++++++ test/unit/mpq/test_query.cpp | 67 +++++++++++++++++++++++++++++ 14 files changed, 262 insertions(+), 26 deletions(-) create mode 100644 test/fixtures/raw_archive.h diff --git a/src/mpq/extract.cpp b/src/mpq/extract.cpp index e762346..614bb5d 100644 --- a/src/mpq/extract.cpp +++ b/src/mpq/extract.cpp @@ -100,15 +100,16 @@ int ExtractFiles(HANDLE archive, const fs::path &output, const std::vector #include #include #include @@ -32,6 +33,21 @@ bool FileExistsInArchiveForLocale(const HANDLE archive, const std::string &file_ return file_exists; } +std::string StoredFileName(HANDLE archive, const std::string &file_path, LCID locale) { + SFileSetLocale(locale); + if (SFileHasFile(archive, file_path.c_str())) { + return file_path; + } + // Replaced byte by byte rather than through WindowsifyFilePath: its filesystem::path + // re-encodes a name on Windows, and a lookup must hand StormLib the stored bytes + std::string backslashed = file_path; + std::replace(backslashed.begin(), backslashed.end(), '/', '\\'); + if (backslashed != file_path && SFileHasFile(archive, backslashed.c_str())) { + return backslashed; + } + return file_path; +} + bool ArchivedFileMatches(HANDLE archive, HANDLE file, const fs::path &local_file, std::string &match_reason) { const DWORD archived_size = SFileGetFileSize(file, nullptr); diff --git a/src/mpq/query.h b/src/mpq/query.h index 5888fca..21e0555 100644 --- a/src/mpq/query.h +++ b/src/mpq/query.h @@ -17,6 +17,14 @@ inline const std::vector special_mpq_files = {"(listfile)", "(signa bool FileExistsInArchiveForLocale(HANDLE archive, const std::string &file_path, LCID locale); +/// Returns the name the archive stores file_path under, looked up under locale +/// +/// An MPQ normally stores paths with backslashes, and StormLib hashes / and \ as different +/// characters, so a path written with forward slashes misses. The path is tried as given +/// first, since an archive from another tool may store forward slashes itself, then with +/// every / turned into \. A path found in neither form comes back as given. +std::string StoredFileName(HANDLE archive, const std::string &file_path, LCID locale); + /// Reports whether the archived copy of local_file is byte-for-byte current bool ArchivedFileMatches(HANDLE archive, HANDLE file, const std::filesystem::path &local_file, std::string &match_reason); diff --git a/src/mpq/read.cpp b/src/mpq/read.cpp index 3fc329e..594021f 100644 --- a/src/mpq/read.cpp +++ b/src/mpq/read.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -14,23 +15,24 @@ std::unique_ptr ReadArchivedFile(HANDLE archive, const char *file_name, unsigned int *file_size, LCID preferred_locale, std::ostream &err) { SFileSetLocale(preferred_locale); - if (!FileExistsInArchiveForLocale(archive, file_name, preferred_locale) && - !FileExistsInArchiveForLocale(archive, file_name, default_locale)) { + const std::string stored_name = StoredFileName(archive, file_name, preferred_locale); + if (!FileExistsInArchiveForLocale(archive, stored_name, preferred_locale) && + !FileExistsInArchiveForLocale(archive, stored_name, default_locale)) { err << "[!] Failed: File doesn't exist" - << PrettyPrintLocale(preferred_locale, " for locale ", true) << ": " << file_name + << PrettyPrintLocale(preferred_locale, " for locale ", true) << ": " << stored_name << std::endl; return nullptr; } HANDLE file; - if (!SFileOpenFileEx(archive, file_name, SFILE_OPEN_FROM_MPQ, &file)) { - err << "[!] Failed: File cannot be opened: " << file_name << std::endl; + if (!SFileOpenFileEx(archive, stored_name.c_str(), SFILE_OPEN_FROM_MPQ, &file)) { + err << "[!] Failed: File cannot be opened: " << stored_name << std::endl; return nullptr; } *file_size = SFileGetFileSize(file, nullptr); if (*file_size == SFILE_INVALID_SIZE) { - err << "[!] Failed: Invalid file size for: " << file_name << std::endl; + err << "[!] Failed: Invalid file size for: " << stored_name << std::endl; SFileCloseFile(file); return nullptr; } @@ -38,7 +40,7 @@ std::unique_ptr ReadArchivedFile(HANDLE archive, const char *file_name, auto file_content = std::make_unique(*file_size); DWORD bytes_read; if (!SFileReadFile(file, file_content.get(), *file_size, &bytes_read, nullptr)) { - err << "[!] Failed: Cannot read file contents for: " << file_name << std::endl; + err << "[!] Failed: Cannot read file contents for: " << stored_name << std::endl; SFileCloseFile(file); return nullptr; } diff --git a/src/mpq/remove.cpp b/src/mpq/remove.cpp index d77b9a9..400bf68 100644 --- a/src/mpq/remove.cpp +++ b/src/mpq/remove.cpp @@ -13,19 +13,19 @@ namespace mpqcli { int RemoveFile(HANDLE archive, const std::string &archive_file_path, LCID locale, std::ostream &err) { SFileSetLocale(locale); - err << "[-] Removing file" << PrettyPrintLocale(locale, " for locale ") << ": " - << archive_file_path << std::endl; + const std::string stored_path = StoredFileName(archive, archive_file_path, locale); + err << "[-] Removing file" << PrettyPrintLocale(locale, " for locale ") << ": " << stored_path + << std::endl; - if (!FileExistsInArchiveForLocale(archive, archive_file_path, locale)) { + if (!FileExistsInArchiveForLocale(archive, stored_path, locale)) { err << "[!] Failed: File doesn't exist" << PrettyPrintLocale(locale, " for locale ", true) - << ": " << archive_file_path << std::endl; + << ": " << stored_path << std::endl; return 1; } - if (!SFileRemoveFile(archive, archive_file_path.c_str(), 0)) { + if (!SFileRemoveFile(archive, stored_path.c_str(), 0)) { err << "[!] Failed: File cannot be removed" - << PrettyPrintLocale(locale, " for locale ", true) << ": " << archive_file_path - << std::endl; + << PrettyPrintLocale(locale, " for locale ", true) << ": " << stored_path << std::endl; return 1; } diff --git a/src/mpq/rename.cpp b/src/mpq/rename.cpp index 4aea16e..1aa214d 100644 --- a/src/mpq/rename.cpp +++ b/src/mpq/rename.cpp @@ -14,20 +14,21 @@ namespace mpqcli { int RenameFile(HANDLE archive, const std::string &old_archive_file_path, const std::string &new_archive_file_path, LCID locale, std::ostream &err) { SFileSetLocale(locale); + const std::string old_stored_path = StoredFileName(archive, old_archive_file_path, locale); const std::string new_stored_path = WindowsifyFilePath(new_archive_file_path); err << "[~] Renaming file" << PrettyPrintLocale(locale, " for locale ") << ": " - << old_archive_file_path << " -> " << new_stored_path << std::endl; + << old_stored_path << " -> " << new_stored_path << std::endl; - if (!FileExistsInArchiveForLocale(archive, old_archive_file_path, locale)) { + if (!FileExistsInArchiveForLocale(archive, old_stored_path, locale)) { err << "[!] Failed: File doesn't exist" << PrettyPrintLocale(locale, " for locale ", true) - << ": " << old_archive_file_path << std::endl; + << ": " << old_stored_path << std::endl; return 1; } - if (!SFileRenameFile(archive, old_archive_file_path.c_str(), new_stored_path.c_str())) { + if (!SFileRenameFile(archive, old_stored_path.c_str(), new_stored_path.c_str())) { err << "[!] Failed: File cannot be renamed" - << PrettyPrintLocale(locale, " for locale ", true) << ": " << old_archive_file_path - << " -> " << new_stored_path << std::endl; + << PrettyPrintLocale(locale, " for locale ", true) << ": " << old_stored_path << " -> " + << new_stored_path << std::endl; return 1; } diff --git a/test/fixtures/raw_archive.h b/test/fixtures/raw_archive.h new file mode 100644 index 0000000..aea1acf --- /dev/null +++ b/test/fixtures/raw_archive.h @@ -0,0 +1,43 @@ +#ifndef RAW_ARCHIVE_H +#define RAW_ARCHIVE_H + +#include +#include +#include +#include +#include + +#include + +namespace mpqcli::testing { + +/// Writes an archive holding each name under its locale, through StormLib directly +/// +/// mpqcli stores every path with backslashes, but StormLib stores a name exactly as given, +/// so this is how a test gets an archive another tool wrote with forward slashes. Each file +/// holds its own name as its content, so a read shows which entry it found. Throws +/// std::runtime_error when StormLib refuses, since that is a broken fixture. +inline void WriteRawArchive(const std::filesystem::path &path, + const std::vector> &entries) { + HANDLE archive = nullptr; + if (!SFileCreateArchive(path.string().c_str(), MPQ_CREATE_LISTFILE | MPQ_CREATE_ARCHIVE_V1, 16, + &archive)) { + throw std::runtime_error("WriteRawArchive: cannot create " + path.string()); + } + for (const auto &[name, locale] : entries) { + const auto size = static_cast(name.size()); + HANDLE file = nullptr; + if (!SFileCreateFile(archive, name.c_str(), 0, size, locale, 0, &file) || + !SFileWriteFile(file, name.data(), size, 0) || !SFileFinishFile(file)) { + SFileCloseArchive(archive); + throw std::runtime_error("WriteRawArchive: cannot add " + name); + } + } + if (!SFileCloseArchive(archive)) { + throw std::runtime_error("WriteRawArchive: cannot close " + path.string()); + } +} + +} // namespace mpqcli::testing + +#endif // RAW_ARCHIVE_H diff --git a/test/functional/test_extract.cpp b/test/functional/test_extract.cpp index ecdd6e0..28f7ffd 100644 --- a/test/functional/test_extract.cpp +++ b/test/functional/test_extract.cpp @@ -397,6 +397,22 @@ TEST_CASE("extract: a named nested file keeps its folder", "[extract]") { REQUIRE(ReadFile(output_dir / "texts" / "cats.txt") == "This is a file about cats.\n"); } +TEST_CASE("extract: a named nested file given with forward slashes", "[extract]") { + SampleArchive sample; + AddNestedCats(sample); + const auto output_dir = sample.files.dir.Path() / "extracted_nested"; + + auto result = Run(mpqcli_binary, {"extract", "-o", output_dir.string(), sample.archive.string(), + "texts/cats.txt"}); + + REQUIRE(result.returncode == 0); + REQUIRE(result.stdout_output.empty()); + REQUIRE(LinesToSet(result.stderr_output) == + std::set{"[*] Extracted: " + Native("texts\\cats.txt")}); + REQUIRE(DirectoryEntries(output_dir) == std::set{"texts"}); + REQUIRE(ReadFile(output_dir / "texts" / "cats.txt") == "This is a file about cats.\n"); +} + TEST_CASE("extract: a named nested file drops its folder with --flat", "[extract]") { const auto flag = GENERATE(as{}, "-j", "--flat"); CAPTURE(flag); diff --git a/test/functional/test_read.cpp b/test/functional/test_read.cpp index 28abb0e..d044aa3 100644 --- a/test/functional/test_read.cpp +++ b/test/functional/test_read.cpp @@ -221,6 +221,19 @@ TEST_CASE("read: takes a nested entry by its backslash path", "[read]") { REQUIRE(result.stdout_output == "nested file"); } +TEST_CASE("read: takes a nested entry by a forward-slash path", "[read]") { + TempDir dir; + const auto source_dir = dir.Path() / "src"; + WriteFile(source_dir / "sub" / "nested.txt", "nested file"); + const auto archive = dir.Path() / "nested.mpq"; + REQUIRE(Run(mpqcli_binary, {"create", archive.string(), source_dir.string()}).returncode == 0); + + auto result = Run(mpqcli_binary, {"read", archive.string(), "sub/nested.txt"}); + + REQUIRE(result.returncode == 0); + REQUIRE(result.stdout_output == "nested file"); +} + TEST_CASE("read: hands back a file larger than one sector intact", "[read]") { TempDir dir; const auto source_dir = dir.Path() / "src"; diff --git a/test/functional/test_remove.cpp b/test/functional/test_remove.cpp index 6a17923..b5df7c4 100644 --- a/test/functional/test_remove.cpp +++ b/test/functional/test_remove.cpp @@ -262,6 +262,24 @@ TEST_CASE("remove: a nested entry by its backslash path", "[remove]") { REQUIRE(ArchiveEntries(archive) == std::set{"enUS root.txt"}); } +TEST_CASE("remove: a nested entry by a forward-slash path", "[remove]") { + TempDir dir; + const auto source_dir = dir.Path() / "src"; + WriteFile(source_dir / "root.txt", "root file"); + WriteFile(source_dir / "sub" / "nested.txt", "nested file"); + const auto archive = dir.Path() / "nested.mpq"; + REQUIRE(Run(mpqcli_binary, {"create", archive.string(), source_dir.string()}).returncode == 0); + + auto result = Run(mpqcli_binary, {"remove", archive.string(), "sub/nested.txt"}); + + // The message names the entry as the archive stores it + REQUIRE(result.returncode == 0); + REQUIRE(result.stdout_output.empty()); + REQUIRE(LinesToVector(result.stderr_output) == + std::vector{Removing("sub\\nested.txt")}); + REQUIRE(ArchiveEntries(archive) == std::set{"enUS root.txt"}); +} + TEST_CASE("remove: the default-locale variant when no locale is given", "[remove]") { ManyLocalesArchive locales; diff --git a/test/functional/test_rename.cpp b/test/functional/test_rename.cpp index eb6c74f..1c8f97f 100644 --- a/test/functional/test_rename.cpp +++ b/test/functional/test_rename.cpp @@ -300,6 +300,25 @@ TEST_CASE("rename: a nested entry by its backslash path", "[rename]") { REQUIRE(ReadEntry(archive, "top.txt") == std::set{"nested file"}); } +TEST_CASE("rename: a nested entry by a forward-slash path", "[rename]") { + TempDir dir; + const auto source_dir = dir.Path() / "src"; + WriteFile(source_dir / "root.txt", "root file"); + WriteFile(source_dir / "sub" / "nested.txt", "nested file"); + const auto archive = dir.Path() / "nested.mpq"; + REQUIRE(Run(mpqcli_binary, {"create", archive.string(), source_dir.string()}).returncode == 0); + + auto result = Run(mpqcli_binary, {"rename", archive.string(), "sub/nested.txt", "top.txt"}); + + // The message names the entry as the archive stores it + REQUIRE(result.returncode == 0); + REQUIRE(result.stdout_output.empty()); + REQUIRE(LinesToVector(result.stderr_output) == + std::vector{Renaming("sub\\nested.txt", "top.txt")}); + REQUIRE(ArchiveEntries(archive) == std::set{"enUS root.txt", "enUS top.txt"}); + REQUIRE(ReadEntry(archive, "top.txt") == std::set{"nested file"}); +} + TEST_CASE("rename: the default-locale variant when no locale is given", "[rename]") { ManyLocalesArchive locales; diff --git a/test/unit/commands/test_extract.cpp b/test/unit/commands/test_extract.cpp index b07a10e..384b0ed 100644 --- a/test/unit/commands/test_extract.cpp +++ b/test/unit/commands/test_extract.cpp @@ -9,11 +9,14 @@ #include "commands/extract.h" #include "created_archive.h" #include "errors.h" +#include "raw_archive.h" #include "read_file.h" #include "sample_files.h" +#include "util/locales.h" namespace fs = std::filesystem; +using mpqcli::default_locale; using mpqcli::Extract; using mpqcli::ExtractOptions; using mpqcli::testing::CancelAfter; @@ -21,6 +24,7 @@ using mpqcli::testing::CreatedArchive; using mpqcli::testing::CreateWithoutListfile; using mpqcli::testing::ReadFile; using mpqcli::testing::SampleFiles; +using mpqcli::testing::WriteRawArchive; TEST_CASE("Extract", "[commands/extract]") { CreatedArchive created; @@ -39,6 +43,17 @@ TEST_CASE("Extract", "[commands/extract]") { } } + SECTION("extracts every file of an archive that stores forward slashes") { + // Another tool may store a path with forward slashes, which only that spelling finds + options.archive = created.files.dir.Path() / "slashes.mpq"; + WriteRawArchive(options.archive, + {{"fwd/a.txt", default_locale}, {"bck\\b.txt", default_locale}}); + const std::atomic cancelled{false}; + REQUIRE(Extract(options, err, cancelled)); + REQUIRE(ReadFile(output / "fwd" / "a.txt") == "fwd/a.txt"); + REQUIRE(ReadFile(output / "bck" / "b.txt") == "bck\\b.txt"); + } + SECTION("fails on a named file missing from the archive, leaving no output directory") { options.files = std::vector{"nope.txt"}; const std::atomic cancelled{false}; diff --git a/test/unit/commands/test_read.cpp b/test/unit/commands/test_read.cpp index bf0ebdb..4004c1a 100644 --- a/test/unit/commands/test_read.cpp +++ b/test/unit/commands/test_read.cpp @@ -1,14 +1,19 @@ #include #include +#include #include "commands/read.h" #include "created_archive.h" +#include "raw_archive.h" #include "sample_files.h" +#include "util/locales.h" +using mpqcli::default_locale; using mpqcli::Read; using mpqcli::ReadOptions; using mpqcli::testing::CreatedArchive; using mpqcli::testing::SampleFiles; +using mpqcli::testing::WriteRawArchive; TEST_CASE("Read", "[read]") { CreatedArchive created; @@ -25,4 +30,16 @@ TEST_CASE("Read", "[read]") { REQUIRE(out.str() == content); } } + + SECTION("reads a path an archive stores with forward slashes") { + // Another tool may store a path with forward slashes, which only that spelling finds + ReadOptions options; + options.archive = created.files.dir.Path() / "slashes.mpq"; + WriteRawArchive(options.archive, {{"fwd/a.txt", default_locale}}); + options.file = "fwd/a.txt"; + std::ostringstream out; + std::ostringstream err; + REQUIRE(Read(options, out, err)); + REQUIRE(out.str() == "fwd/a.txt"); + } } diff --git a/test/unit/mpq/test_query.cpp b/test/unit/mpq/test_query.cpp index b5a79b3..14e84f3 100644 --- a/test/unit/mpq/test_query.cpp +++ b/test/unit/mpq/test_query.cpp @@ -3,15 +3,82 @@ #include #include +#include + +#include "mpq/archive.h" #include "mpq/query.h" +#include "raw_archive.h" #include "temp_dir.h" +#include "util/locales.h" #include "write_file.h" namespace fs = std::filesystem; +using mpqcli::Archive; +using mpqcli::default_locale; +using mpqcli::StoredFileName; using mpqcli::UsableListfile; using mpqcli::testing::TempDir; using mpqcli::testing::WriteFile; +using mpqcli::testing::WriteRawArchive; + +namespace { + +constexpr LCID german = 0x407; + +} // namespace + +TEST_CASE("StoredFileName", "[query]") { + TempDir dir; + const auto path = dir.Path() / "slashes.mpq"; + WriteRawArchive(path, {{"back\\slash.txt", default_locale}, + {"forward/slash.txt", default_locale}, + {"both/forms.txt", default_locale}, + {"both\\forms.txt", default_locale}, + {"caf\xC3\xA9\\menu.txt", default_locale}, + {"german\\only.txt", german}}); + const auto archive = Archive::Open(path, MPQ_OPEN_READ_ONLY); + + SECTION("finds a path stored with backslashes when given forward slashes") { + REQUIRE(StoredFileName(archive.Handle(), "back/slash.txt", default_locale) == + "back\\slash.txt"); + } + + SECTION("keeps a path given with the backslashes it is stored under") { + REQUIRE(StoredFileName(archive.Handle(), "back\\slash.txt", default_locale) == + "back\\slash.txt"); + } + + SECTION("keeps a path stored with forward slashes as given") { + REQUIRE(StoredFileName(archive.Handle(), "forward/slash.txt", default_locale) == + "forward/slash.txt"); + } + + SECTION("prefers the path as given when the archive stores both forms") { + REQUIRE(StoredFileName(archive.Handle(), "both/forms.txt", default_locale) == + "both/forms.txt"); + REQUIRE(StoredFileName(archive.Handle(), "both\\forms.txt", default_locale) == + "both\\forms.txt"); + } + + SECTION("keeps the bytes of a name outside ASCII") { + // On Windows a conversion through filesystem::path would re-encode these bytes + // from the ANSI code page, and the lookup would miss + REQUIRE(StoredFileName(archive.Handle(), "caf\xC3\xA9/menu.txt", default_locale) == + "caf\xC3\xA9\\menu.txt"); + } + + SECTION("returns a path found in neither form as given") { + REQUIRE(StoredFileName(archive.Handle(), "missing/file.txt", default_locale) == + "missing/file.txt"); + } + + SECTION("looks the path up under the given locale") { + REQUIRE(StoredFileName(archive.Handle(), "german/only.txt", german) == "german\\only.txt"); + REQUIRE(StoredFileName(archive.Handle(), "german/only.txt", default_locale) == + "german/only.txt"); + } +} TEST_CASE("UsableListfile", "[query]") { TempDir dir; From 084a95437044e2ef1a0506033462855830b97a86 Mon Sep 17 00:00:00 2001 From: thomaslaurenson Date: Sat, 31 Oct 2026 10:06:53 +1300 Subject: [PATCH 2/4] Removed the duplicate return from NormalizeFilePath --- src/util/path.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/util/path.cpp b/src/util/path.cpp index 47d8d56..25d457d 100644 --- a/src/util/path.cpp +++ b/src/util/path.cpp @@ -18,10 +18,8 @@ std::string NormalizeFilePath(const fs::path &path) { std::string file_path = path.u8string(); #ifndef _WIN32 std::replace(file_path.begin(), file_path.end(), '\\', '/'); - return file_path; -#else - return file_path; #endif + return file_path; } std::string WindowsifyFilePath(const fs::path &path) { From 0b5718bf239c5a4c560cece798401acfc707b251 Mon Sep 17 00:00:00 2001 From: thomaslaurenson Date: Sat, 14 Nov 2026 09:28:10 +1300 Subject: [PATCH 3/4] Documented that archive paths take either slash --- docs/advanced.md | 2 +- docs/commands/extract.md | 2 +- docs/commands/read.md | 8 ++++++++ docs/commands/remove.md | 3 +++ docs/commands/rename.md | 3 +++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/advanced.md b/docs/advanced.md index 68c51e6..935e6ee 100644 --- a/docs/advanced.md +++ b/docs/advanced.md @@ -16,7 +16,7 @@ $ mpqcli list wow-patch.mpq | grep -i \.exe | mpqcli extract wow-patch.mpq - [*] Extracted: WowError.exe ``` -Note that directories are specified with backslashes. The names reach `mpqcli extract` on stdin unchanged, so only the backslash in the `grep` pattern needs escaping. The following example extracts all `dat` files in the `arr` directory from the `StarDat.mpq` archive, keeping the folder. +Note that `list` prints directories with backslashes, as the archive stores them. The names reach `mpqcli extract` on stdin unchanged, so only the backslash in the `grep` pattern needs escaping. The following example extracts all `dat` files in the `arr` directory from the `StarDat.mpq` archive, keeping the folder. ```bash $ mpqcli list -l scbw.txt StarDat.mpq | grep -i 'arr\\.*dat$' | sort | mpqcli extract StarDat.mpq - diff --git a/docs/commands/extract.md b/docs/commands/extract.md index 9317ad1..d34a02f 100644 --- a/docs/commands/extract.md +++ b/docs/commands/extract.md @@ -47,7 +47,7 @@ The listfile only applies when extracting every file, so it cannot be combined w ## Extract specific files -Name one or more files after the archive to extract only those. A file nested in a directory needs its full path in the archive, and is extracted with its folders; add `--flat` to drop them. Similar to the examples above, you can use the `-o` argument to specify the output directory. +Name one or more files after the archive to extract only those. A file nested in a directory needs its full path in the archive, with its directories separated by `\` or `/`, and is extracted with its folders; add `--flat` to drop them. Similar to the examples above, you can use the `-o` argument to specify the output directory. ```bash $ mpqcli extract "World of Warcraft_1.12.1.5875/Data/base.MPQ" \ diff --git a/docs/commands/read.md b/docs/commands/read.md index 337a108..e4c99cf 100644 --- a/docs/commands/read.md +++ b/docs/commands/read.md @@ -37,6 +37,14 @@ $ mpqcli read wow-patch.mpq "WoW.exe" | xxd 00000030: 4504 8080 0280 9002 8098 0281 d801 0585 E............... ``` +## Read a file in a directory + +Give the file's full path in the archive. Directories can be separated with `\`, as the archive stores them, or with `/`. + +```bash +$ mpqcli read Patch_rt.mpq "rez/stat_txt.tbl" +``` + ## Read one specific file with locale Use the `-e` or `--locale` argument to specify the locale of the file to read. If there is no file with the requested name and locale, the default locale will be used instead. diff --git a/docs/commands/remove.md b/docs/commands/remove.md index 3c67151..77717d7 100644 --- a/docs/commands/remove.md +++ b/docs/commands/remove.md @@ -5,6 +5,9 @@ Remove one or more files from an existing MPQ archive. The archive is always the first positional argument, followed by one or more archive paths to remove. All removals happen in a single open/close cycle. +Directories in an archive path can be separated with `\`, as the archive stores them, or with +`/`. Messages show the path as the archive stores it. + ## Remove a single file ```bash diff --git a/docs/commands/rename.md b/docs/commands/rename.md index b8732a9..ea1492e 100644 --- a/docs/commands/rename.md +++ b/docs/commands/rename.md @@ -5,6 +5,9 @@ The archive is the first positional argument, followed by the current and new ar This operation does not cause MPQ fragmentation, and thus it is not necessary to [`compact`](compact.md) the archive. +Directories in either path can be separated with `\` or `/`. The new path is stored with `\`, +and messages show both paths as the archive stores them. + ```bash $ mpqcli rename wow-patch.mpq old-name.txt new-name.txt [~] Renaming file: old-name.txt -> new-name.txt From 64b46d65a33c5f3c64f9fcafc4dd20829230b350 Mon Sep 17 00:00:00 2001 From: thomaslaurenson Date: Sat, 14 Nov 2026 09:29:28 +1300 Subject: [PATCH 4/4] Added the 0.13.1 changelog entry and bumped the project version --- CHANGELOG.md | 19 +++++++++++++++++++ CMakeLists.txt | 2 +- README.md | 2 +- docs/changelog.md | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4844132..ce680e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,24 @@ # Changelog +## 0.13.1 - 2026-11-14 + +### Changed + +- Stop printing the m, n and f flags in the flags property, which carried no information +- Show an error's number only when the text comes from the operating system + +### Fixed + +- Find files given with forward slashes in read, extract, remove and rename +- Stop add from leaving files out when one run fills the archive's file table +- Reject a create sector size below 1024 or not a power of two, which StormLib cannot read back +- Accept locale names in any case, so dede is deDE rather than the locale ID 0xDEDE +- Ignore an empty listfile with a warning instead of failing +- List and extract an archive with no entries as empty instead of failing +- Leave no empty output directory behind when extract writes nothing or is interrupted +- Describe Windows system errors with the Windows message rather than an unrelated one +- Describe verify --print as writing raw bytes, not hex, in the help, docs and completions + ## 0.13.0 - 2026-10-16 ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index ceb80ab..14c08a5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.25) -project(mpqcli VERSION 0.13.0) +project(mpqcli VERSION 0.13.1) # An option() name is global to the CMake cache, including a consumer's, so these # carry the project prefix; a bare BUILD_STATIC claims a name anyone might want. diff --git a/README.md b/README.md index 9946845..cc4a7f1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Release Build](https://img.shields.io/github/actions/workflow/status/thegraydot/mpqcli/tag.yml?style=flat&label=release&logo=github) ![Main Build](https://img.shields.io/github/actions/workflow/status/thegraydot/mpqcli/main.yml?style=flat&label=main&logo=github) -![Release Version](https://img.shields.io/github/v/release/thegraydot/mpqcli?style=flat&logo=github) ![Release downloads](https://img.shields.io/github/downloads/thegraydot/mpqcli/total?style=flat&label=downloads&logo=github) ![Package downloads](https://img.shields.io/badge/package_downloads-1.2k-green?style=flat&logo=github) +![Release Version](https://img.shields.io/github/v/release/thegraydot/mpqcli?style=flat&logo=github) ![Release downloads](https://img.shields.io/github/downloads/thegraydot/mpqcli/total?style=flat&label=downloads&logo=github) ![Package downloads](https://img.shields.io/badge/package_downloads-1.3k-green?style=flat&logo=github) ![C++ Version](https://img.shields.io/badge/Version-17-blue?style=flat&logo=cplusplus) diff --git a/docs/changelog.md b/docs/changelog.md index 4844132..ce680e0 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,24 @@ # Changelog +## 0.13.1 - 2026-11-14 + +### Changed + +- Stop printing the m, n and f flags in the flags property, which carried no information +- Show an error's number only when the text comes from the operating system + +### Fixed + +- Find files given with forward slashes in read, extract, remove and rename +- Stop add from leaving files out when one run fills the archive's file table +- Reject a create sector size below 1024 or not a power of two, which StormLib cannot read back +- Accept locale names in any case, so dede is deDE rather than the locale ID 0xDEDE +- Ignore an empty listfile with a warning instead of failing +- List and extract an archive with no entries as empty instead of failing +- Leave no empty output directory behind when extract writes nothing or is interrupted +- Describe Windows system errors with the Windows message rather than an unrelated one +- Describe verify --print as writing raw bytes, not hex, in the help, docs and completions + ## 0.13.0 - 2026-10-16 ### Added