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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ MANIFEST
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
# Hand-written, and embedded in the Windows binary
!app/mpqcli.manifest
*.spec

# Installer logs
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.13.3 - 2026-11-20

### Fixed

- Store, list, extract and read file names with non-ASCII characters correctly on Windows 10 version 1903 and later
- Print non-ASCII file names correctly in the Windows console
- Exit with 130 on Windows when interrupted, as on Linux, instead of 3
- End by SIGTERM when stopped with SIGTERM, so a shell reports 143 rather than an interrupt's 130

## 0.13.2 - 2026-11-20

### Changed
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.25)

project(mpqcli VERSION 0.13.2)
project(mpqcli VERSION 0.13.3)

# 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.
Expand Down
5 changes: 5 additions & 0 deletions app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ add_executable(mpqcli
version.cpp
)

# MSVC merges a listed .manifest into the one its linker writes and embeds the result
if(WIN32)
target_sources(mpqcli PRIVATE mpqcli.manifest)
endif()

target_link_libraries(mpqcli PRIVATE mpqcli::core CLI11::CLI11 mpqcli::warnings)
66 changes: 59 additions & 7 deletions app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,65 @@
#include "commands.h"
#include "errors.h"

#ifdef _WIN32
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#endif

namespace {

// The one piece of mutable global state: a signal handler takes no arguments and
// has nowhere else to write, and it may touch nothing but a lock-free atomic
#ifdef _WIN32
// The manifest makes UTF-8 the process code page, but a console keeps code pages of
// its own, usually the OEM one, so names would print as mojibake. The console is
// shared with the shell that started mpqcli, so what it had is put back on the way
// out. Without a console both calls fail, which is harmless.
class Utf8Console {
public:
Utf8Console() : input_(GetConsoleCP()), output_(GetConsoleOutputCP()) {
SetConsoleCP(CP_UTF8);
SetConsoleOutputCP(CP_UTF8);
}
Utf8Console(const Utf8Console &) = delete;
Utf8Console &operator=(const Utf8Console &) = delete;
~Utf8Console() {
if (input_ != 0) {
SetConsoleCP(input_);
}
if (output_ != 0) {
SetConsoleOutputCP(output_);
}
}

private:
UINT input_;
UINT output_;
};
#endif

// The only mutable global state: a signal handler takes no arguments and has nowhere
// else to write, and it may touch nothing but lock-free atomics. interrupted is what
// the core polls; interrupt_signal is which signal set it, so main can end by that
// same signal. It starts as SIGINT, which is what main used before it was recorded.
std::atomic<bool> interrupted{false};
std::atomic<int> interrupt_signal{SIGINT};
static_assert(decltype(interrupted)::is_always_lock_free,
"a signal handler may only touch a lock-free atomic");
static_assert(decltype(interrupt_signal)::is_always_lock_free,
"a signal handler may only touch a lock-free atomic");

extern "C" void OnInterrupt(int) {
extern "C" void OnInterrupt(int signal_number) {
interrupt_signal.store(signal_number, std::memory_order_relaxed);
interrupted.store(true, std::memory_order_relaxed);
}

} // namespace

int main(int argc, char **argv) {
#ifdef _WIN32
const Utf8Console console;
#endif
Context context{std::cout, std::cerr, std::cin, interrupted};

CLI::App app{
Expand Down Expand Up @@ -64,11 +108,19 @@ int main(int argc, char **argv) {
}
return app.exit(e, context.out, context.err);
} catch (const mpqcli::Interrupted &) {
// The user asked for this, so nothing is reported. Dying of the signal rather
// than returning a code is what lets the shell treat it as an interrupt.
std::signal(SIGINT, SIG_DFL);
std::raise(SIGINT);
// The user asked for this, so nothing is reported
#ifdef _WIN32
// A re-raised SIGINT would end the process with 3 here, so return what a POSIX
// shell reports for one instead
return 130;
#else
// Dying of the same signal rather than returning a code is what lets a shell or
// a supervisor see how mpqcli ended: 130 after SIGINT, 143 after SIGTERM
const int signal_number = interrupt_signal.load(std::memory_order_relaxed);
std::signal(signal_number, SIG_DFL);
std::raise(signal_number);
return 1; // Not reached
#endif
} catch (const mpqcli::Error &e) {
context.err << "[!] " << e.what() << std::endl;
return 1;
Expand Down
13 changes: 13 additions & 0 deletions app/mpqcli.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
Makes UTF-8 the process code page on Windows 10 version 1903 and later. argv,
std::filesystem's narrow conversions and StormLib's char file APIs then all use the
UTF-8 the core works in, as they do on Linux. Older Windows ignores the setting.
-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<application>
<windowsSettings>
<activeCodePage xmlns="http://schemas.microsoft.com/SMI/2019/WindowsSettings">UTF-8</activeCodePage>
</windowsSettings>
</application>
</assembly>
10 changes: 10 additions & 0 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,13 @@ PS> mpqcli.exe list wow-patch.mpq | Select-String -Pattern \.exe | `
[*] Extracted: Repair.exe
[*] Extracted: WowError.exe
```

## Find the archives that fail verification

`verify` exits `0` when an archive's signature is valid, and `1` when it is not or there is none, so a loop can act on the [exit code](./commands_list.md#exit-codes) alone. The verification result goes to stderr, which is discarded here, and the name of each archive that fails goes to `failed.txt`:

```bash
$ for f in *.mpq; do mpqcli verify "$f" 2>/dev/null || echo "$f"; done > failed.txt
$ cat failed.txt
unsigned.mpq
```
9 changes: 9 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## 0.13.3 - 2026-11-20

### Fixed

- Store, list, extract and read file names with non-ASCII characters correctly on Windows 10 version 1903 and later
- Print non-ASCII file names correctly in the Windows console
- Exit with 130 on Windows when interrupted, as on Linux, instead of 3
- End by SIGTERM when stopped with SIGTERM, so a shell reports 143 rather than an interrupt's 130

## 0.13.2 - 2026-11-20

### Changed
Expand Down
13 changes: 13 additions & 0 deletions docs/commands_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,16 @@ The `mpqcli` program has the following subcommands:
| [`read`](./commands/read.md) | Read a specific file to stdout |
| [`verify`](./commands/verify.md) | Verify an MPQ archive signature |
| [`compact`](./commands/compact.md) | Compact (defragment) an MPQ archive |

## Exit codes

Every subcommand exits with one of these codes, so a script can tell the outcomes apart. [Find the archives that fail verification](./advanced.md#find-the-archives-that-fail-verification) shows one in use.

| Code | Meaning |
|---|---|
| `0` | Success. A file `add` skipped because it is already in the archive still counts as success. |
| `1` | The command failed: for example, the archive could not be opened, a file is not in it, or `verify` found no valid signature. The reason is on stderr. |
| `2` | An unexpected internal error. Please report it. |
| `100` to `114` | The command line could not be parsed. The most common are `104` (a value of the wrong type), `105` (a value that is not allowed), `106` (a missing argument) and `109` (an extra argument). |
| `130` | Interrupted with Ctrl+C. On Linux mpqcli ends by the signal itself, which a shell reports as `130`; on Windows it exits with `130`. |
| `143` | Stopped with SIGTERM, on Linux. mpqcli ends by the signal itself, which a shell reports as `143`. |
2 changes: 2 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Both installers put `mpqcli` on the system path and may ask for elevation; pass

Check the [latest release with binaries](https://github.com/thegraydot/mpqcli/releases).

On Windows, file names with characters outside ASCII, such as `café.txt`, need Windows 10 version 1903 or later. Earlier versions store and extract them with the wrong bytes.

## Docker image

The Docker image for `mpqcli` is hosted on [GitHub Container Registry (GHCR)](https://ghcr.io). It provides a lightweight and portable way to use `mpqcli` without needing to build or download a binary.
Expand Down
30 changes: 30 additions & 0 deletions test/functional/test_add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "archive_helper.h"
#include "compressible_text.h"
#include "many_locales_archive.h"
#include "read_file.h"
#include "sample_archive.h"
#include "sample_files.h"
#include "subprocess_helper.h"
Expand Down Expand Up @@ -456,6 +457,35 @@ TEST_CASE("add: a directory keeps its structure", "[add]") {
Plus(sample_entries, {"enUS sub\\a.txt", "enUS b.txt"}));
}

TEST_CASE("add: stores a non-ASCII name from a directory", "[add]") {
// "cafe" with an acute e, which the Windows runner's code page has, and two Japanese
// characters, which no single-byte code page has. Written as UTF-8 escapes, since
// MSVC reads a source file in the build machine's code page.
const auto name =
GENERATE(as<std::string>{}, "caf\xC3\xA9.txt", "\xE6\x97\xA5\xE6\x9C\xAC.txt");
CAPTURE(name);
SampleArchive sample;
// Inside an ASCII-named directory, so the name never crosses a command line and only
// mpqcli's own conversions are tested. u8path names the file right whatever the test
// binary's code page.
const auto add_dir = sample.files.dir.Path() / "add_dir";
WriteFile(add_dir / fs::u8path(name), "Non-ASCII file.");

auto result = Run(mpqcli_binary, {"add", sample.archive.string(), add_dir.string()});

REQUIRE(result.returncode == 0);
REQUIRE(LinesToVector(result.stderr_output) ==
std::vector<std::string>{"[+] Adding file: " + name});
REQUIRE(ArchiveEntries(sample.archive) == Plus(sample_entries, {"enUS " + name}));

const auto output_dir = sample.files.dir.Path() / "out";
auto extracted =
Run(mpqcli_binary, {"extract", sample.archive.string(), "-o", output_dir.string()});

REQUIRE(extracted.returncode == 0);
REQUIRE(ReadFile(output_dir / fs::u8path(name)) == "Non-ASCII file.");
}

TEST_CASE("add: a directory with --path prefix", "[add]") {
SampleArchive sample;
const auto add_dir = sample.files.dir.Path() / "add_dir_prefix";
Expand Down
19 changes: 19 additions & 0 deletions test/functional/test_read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ TEST_CASE("read: falls back to the default locale when the file has no such vari
REQUIRE(result.stdout_output == CatsContent(""));
}

TEST_CASE("read: reads a non-ASCII name given as an argument", "[read]") {
// The names add's non-ASCII test uses, for the same reason
const auto name =
GENERATE(as<std::string>{}, "caf\xC3\xA9.txt", "\xE6\x97\xA5\xE6\x9C\xAC.txt");
CAPTURE(name);
TempDir dir;
const auto input_dir = dir.Path() / "in";
WriteFile(input_dir / fs::u8path(name), "Non-ASCII file.");
const auto archive = dir.Path() / "names.mpq";
REQUIRE(Run(mpqcli_binary, {"create", archive.string(), input_dir.string()}).returncode == 0);

// The name reaches mpqcli through argv
auto result = Run(mpqcli_binary, {"read", archive.string(), name});

REQUIRE(result.returncode == 0);
REQUIRE(result.stderr_output.empty());
REQUIRE(result.stdout_output == "Non-ASCII file.");
}

TEST_CASE("read: says nothing when enUS falls back to the neutral locale", "[read]") {
ManyLocalesArchive locales;

Expand Down