Target:
D:\servermulti-solution Windows C++ game server. Aligned with: Playbook P0–P4 (Source UTF-8 Unification & Cross-Platform Charset). Scope: Source → UTF-8 without BOM only./utf-8flag, rebuild, and smoke tests are covered in the original Playbook §2–§3.
cargo build --release
./target/release/utf8-forge scan --root D:\server --report D:\tmp\scan.json
./target/release/utf8-forge convert --root D:\server --dry-run --report D:\tmp\dry.json
./target/release/utf8-forge convert --root D:\server --backup-dir D:\backup\utf8-forge
./target/release/utf8-forge verify --root D:\server
# Shortcut: convert + verify in one pass (exit 3 when the gate fails)
./target/release/utf8-forge fix --root D:\server --report D:\tmp\fix.json
If any step reports Unknown or DecodeError, stop and read §6.
| Item | Requirement |
|---|---|
| OS | Windows 10/11 (tool is cross-platform; rollout target is Windows) |
| Rust | Stable toolchain supporting edition 2024 |
| SVN | Working copy clean; coordinate a “transcode window” |
| Disk | Space for backup (≈ source tree size) |
| Permissions | Read/write on D:\server |
| IDE | Close auto-save on the target directory |
cd D:\server
svn status :: must be empty
svn info :: record revision
# In-tree
cd utf8-forge
cargo build --release
# Binary: target\release\utf8-forge.exe
# Or install to PATH
cargo install --path . --locked
Smoke:
utf8-forge --version
utf8-forge scan --help
If you enabled only default features,
reqwestis compiled in. To build a local-only binary:cargo build --release --no-default-features
utf8-forge scan ^
--root D:\server ^
--report D:\backup\utf8-forge\scan-before.json ^
--verbose
Expected summary (excerpt, order of magnitude):
{
"summary": {
"total_files": 1247,
"candidates": 1247,
"utf8": 1035,
"utf8_bom": 34,
"utf16le": 2,
"utf16be": 0,
"utf32le": 0,
"utf32be": 0,
"gb18030": 171,
"unknown": 5,
"errors": 0,
"too_large": 0
}
}
Check:
gb18030 ≈ 171 (Playbook §1.2);utf16le ≈ 2 (GameServer/room/FieldData.cpp × 2);unknown is manually confirmed.Exit criteria: report archived; team notified; unknown files triaged.
utf8-forge convert ^
--root D:\server ^
--dry-run ^
--report D:\backup\utf8-forge\dry.json ^
--verbose
Audit dry.json:
| Check | Expected |
|---|---|
action == "would_convert" |
Only expected paths |
dep/, _tools/, temp/, OutputFile*/ |
Absent |
.png/.zip/.exe/.lib/.dll |
Absent |
.rc |
Absent (unless --include-rc) |
| Any file > 200 MiB | None (or adjust --max-file-size) |
Stop immediately if anything unexpected appears. Adjust --exclude / --ext and re-run dry-run.
utf8-forge convert ^
--root D:\server ^
--backup-dir D:\backup\utf8-forge\orig ^
--report D:\backup\utf8-forge\apply.json ^
--verbose
Guarantees:
already_utf8 untouched (no mtime churn).Output:
[utf8-forge] mode=convert target=utf-8 root=D:\server
[utf8-forge] scanned=1247 candidates=1247
[utf8-forge] already_utf8=1035 converted=207 unknown=5 errors=0
[utf8-forge] duration=8.3s report=D:\backup\utf8-forge\apply.json
utf8-forge verify --root D:\server --report D:\backup\utf8-forge\verify1.json
summary.failed == 0 → pass.If
unknown > 0,verifywill return 3 because those files remain non-UTF-8. This is expected; triage per §6.
utf8-forge convert --root D:\server --report D:\backup\utf8-forge\apply2.json
Expected: converted=0. If not, stop — a third settled run isolates
concurrent edits:
utf8-forge convert --root D:\server --report D:\backup\utf8-forge\apply3.json
utf8-forge diff --before D:\backup\utf8-forge\apply2.json --after D:\backup\utf8-forge\apply3.json --fail-on-change
Comparing run 1 against run 2 always reports drift (every
convertedrow becomesunchanged), so the diff gate must compare two settled runs. Run 1 vs run 2 is still useful read-only: achangedentry whosebeforeaction isunchangedmeans the file was modified between the runs (a concurrent edit, or the expected one-pass double-BOM convergence).
convert converted matches dry-run prediction.convert converted == 0 (idempotent).verify exit 0 (or only known unknowns)./utf-8 (Tool Does Not Participate)Per Playbook §2.2:
1. Add /utf-8 to every production .vcxproj ClCompile section.
2. Remove 3 per-file /utf-8 exceptions in GameServer.vcxproj.
3. Clean Rebuild.
Precondition: verify passed (source 100% UTF-8). Otherwise do not enable /utf-8 — it will cause
double-mojibake.
Optional: if
.vcxproj/.slnshould also be unified, useutf8-forge convert --root D:\server --include-msbuild. VS2019 may re-save with BOM — harmless.
Follow Playbook §7 checklist. This tool provides only the encoding evidence:
- [x] verify passes
- [ ] Clean Rebuild passes
- [ ] Chinese logs readable
- [ ] Chinese protocol/DB regression
- [ ] genbin Chinese export correct
:: pre-commit hook (Windows batch sketch)
utf8-forge verify --root %CD% --ext %CHANGED_EXTS% || exit /b 1
# Generic CI step
- name: Verify encoding
run: utf8-forge verify --root . --report encoding-report.json
Also commit .editorconfig:
root = true
[*.{c,cc,cpp,h,hpp,inl,proto}]
charset = utf-8
end_of_line = crlf
insert_final_newline = true
cd D:\server
svn status > D:\backup\utf8-forge\before-status.txt
svn status > D:\backup\utf8-forge\after-status.txt
svn diff --summarize > D:\backup\utf8-forge\summary.txt
Must satisfy:
summary.txt ∈ files[].path from apply.json.dep/, _tools/, temp/, OutputFile*/.GameServer/Channel.cppGameServer/GameProcess.cppShare/common/String.hGameServer/room/FieldData.cpp (original UTF-16)genbin/genbin.cpputf8-forge convert ^
--root D:\server ^
--ext h,hpp,c,cpp,cc,inl,proto,txt ^
--backup-dir D:\backup\utf8-forge\orig
utf8-forge convert ^
--root D:\server ^
--include-msbuild ^
--backup-dir D:\backup\utf8-forge\orig
utf8-forge scan ^
--root D:\server ^
--exclude "GameServer201,Test_Client" ^
--exclude-glob "**/Generated/**"
utf8-forge scan --root D:\server --report scan.json -q
:: Fetch a GBK-encoded file from an HTTP endpoint and save as UTF-8
utf8-forge convert ^
--url https://example.com/data/legacy_server.cpp ^
--output D:\server\external\legacy_server.cpp ^
--target utf-8 ^
--report D:\backup\utf8-forge\fetch-report.json
Notes:
--output omitted → filename derived from the URL’s last path segment: an
extension is kept verbatim (…/a.cpp → a.cpp); .utf8 is appended only
when the segment has none (…/foo → foo.utf8); with no usable segment the
fallback is download.utf8. The derived path is recorded in the report
relative to the current working directory.--max-file-size applies to the remote download too: an oversized payload
fails with exit 1 (summary.too_large=1, files[0].action="skipped_too_large")
and nothing is written.--backup-dir cannot be combined with --url — fatal (exit 2).summary.fetch_error=1, exit 1.files[0].action="skipped_unknown", counted in
summary.unknown, listed in unknown_files (not error_files), with one
stderr problem line.error record with io_error: file is write-protected
(read-only); chmod +w to convert; the destination file is left untouched.mode: "fetch" with url set; root is omitted; in options,
exclude_ext/exclude_globs/backup_dir are omitted when empty (empty
extensions/exclude_dirs remain).--dry-run works with --url: fetches and reports, but does not write.--config cannot be combined with --url — fatal (exit 2); fetch reads no
config. The same --report pre-flight as tree modes (unwritable report
directory, an existing directory, a write-protected report file — the
ignore-file rule is tree-only, since fetch loads no ignore file) runs
before the download, so a failure
writes nothing; a decode error prints exactly one stderr problem line (for
the output path).utf8-forge convert ^
--root D:\server\legacy\scripts ^
--target gb18030 ^
--ext bat,cmd ^
--backup-dir D:\backup\utf8-forge\orig-gbk
⚠️ Do not use unless a legacy external dependency requires GBK.
Content containing U+E5E5 is refused (exit 1); already-GB18030 files are rewritten to their canonical WHATWG byte forms on the first pass (idempotent from the second pass on).
| Report Category | Meaning | Action |
|---|---|---|
unknown |
Not UTF-8 / UTF-16 / UTF-32 / GB18030 | Inspect hex; often a binary with a text extension |
decode_error |
Legal encoding, truncated bytes | Hex editor; ask original author |
encode_error |
Decodes cleanly but the target encoding would produce unreadable bytes (utf-16le + leading U+0000, gb18030 + U+E5E5) |
Pick another target, drop the leading NUL / the U+E5E5 character |
too_large |
> --max-file-size |
Usually skip; raise limit only if necessary |
io_error |
Permission / locked file | Close the locking process or fix ACLs |
fetch_error |
--url network/TLS failure |
Check URL, proxy, timeout |
Principles:
convert..cpp, exclude it from the whitelist.copy /Y D:\backup\utf8-forge\orig\GameServer\Channel.cpp D:\server\GameServer\Channel.cpp
Backups mirror the tree relative to
--root; only rewritten files get a backup (unchanged/skipped files have none).
cd D:\server
svn revert -R .
svn status :: must be empty
If already committed:
svn merge -c -<rev> .
utf8-forge scan to confirm baseline.| Playbook Phase | This Manual | Tool Command |
|---|---|---|
| P0 Inventory & Freeze | §3.1 | scan --report |
| P1 Source Transcode | §3.2 | convert [--dry-run] --backup-dir |
| P1 Exit Criteria | §3.3 | verify + idempotence check (a single fix run can replace convert + verify) |
P2 Global /utf-8 |
§3.4 (tool not involved) | — |
| P3 Rebuild & Smoke | §3.5 | verify as evidence |
| P4 CI Hardening | §3.6 | verify in pre-commit/CI |
| Optional Remote Source | §5.5 | convert --url ... --output ... |
| Risk | Mitigation |
|---|---|
Incomplete transcode before /utf-8 |
verify exit 0 as P2 gate |
| Console mojibake (narrow strings) | P3 smoke scope; tool only guarantees source bytes |
| PCH / incremental stale objects | Clean Rebuild in P3 |
Accidental dep/ modification |
Default blacklist + dry-run audit |
| Large SVN diff / partial commit | Single window + svn diff --summarize |
| Runtime protocol/DB regression | Boundaries already UTF-8; regression tests cover |
| Remote fetch hangs | --max-file-size + 120 s timeout |
svn status emptyscan.json archived and revieweddry.json reviewed; path list cleanconvert converted = dry-run predictionapply.json has no error entriesunknown list generated and assignedverify exit 0 (or only known unknowns)convert converted == 0svn diff --summarize only expected files/utf-8 added per Playbook §2.2/utf-8 exceptions removed| Symptom | Check | Fix |
|---|---|---|
| Files not converted | -v; check whitelist, excluded dirs, hidden flag |
Adjust --ext / --include-hidden |
verify exit 3 |
Read report for non-UTF-8 files | If unknown, §6; if missed, re-run convert |
| Chinese comments became mojibake | Likely double-transcode or wrong target | svn diff; roll back single file |
Unexpected dirs in svn diff |
Dry-run skipped or ignored | Roll back; re-run dry-run |
| Very slow conversion | Large files included | Lower --max-file-size; tune --threads |
| Huge backup directory | Backup uses original bytes | Keep ≥ 1 version cycle; prune later |
--url returns 403/404 |
Server-side auth / path | Verify URL; use a direct download link |
--url memory spike |
Download streams to a temp file, capped per chunk — memory is bounded by --max-file-size |
Raise limit cautiously or split file |
Optional keys are omitted when empty: url appears only with --url; a
fetch report omits root; options.exclude_ext / exclude_globs /
backup_dir are omitted when empty/none; options.ignore_file is omitted when
no ignore rules are active; options.config_file is omitted without --config;
files[].detected is omitted when the file was not read (unreadable or oversized);
warnings is omitted when there are no walk/ignore warnings;
verify_failed_files is omitted unless a file’s verify record actually
failed (a warning-only gate failure exits 3 without it).
options reflects the post-config effective values (after merging
--config); config_file records the --config value verbatim.
{
"tool": "utf8-forge",
"version": "0.2.5",
"mode": "convert", // scan | convert | verify | fetch | fix
"root": "D:\\server", // omitted in fetch mode
"url": "https://example.com/a.cpp", // omitted without --url
"started_at": "2026-...", // captured when per-file processing begins
// (tree modes: after traversal; fetch: at request start)
"duration_ms": 8300, // tree modes: per-file processing + console lines (traversal
// and report assembly excluded); fetch: download + transcode only
"options": {
"target": "utf-8",
"dry_run": false,
"extensions": ["c","cpp","h","hpp"],
"exclude_dirs": ["_tools","dep"],
"exclude_ext": ["png"], // omitted when empty
"exclude_globs": ["**/Generated/**"], // omitted when empty
"backup_dir": "D:\\backup\\utf8-forge\\orig", // omitted when none
"config_file": "D:\\server\\forge.toml", // omitted without --config
"ignore_file": "D:\\server\\.utf8forgeignore" // omitted when no rules active
},
"summary": { /* mode-specific; see the shapes below */ },
"files": [
{
"path": "D:\\server\\GameServer\\Channel.cpp",
"detected": "gb18030",
"action": "converted", // detected | passed | failed | would_convert | converted |
// unchanged | skipped_unknown | skipped_too_large | error
"bytes_before": 12873,
"bytes_after": 15201,
"duration_us": 912
},
{
"path": "D:\\server\\GameServer\\Locked.cpp",
"detected": "gb18030",
"action": "error",
"bytes_before": 9001,
"duration_us": 120,
"error": "io_error: file is write-protected (read-only); chmod +w to convert"
// present only on error/failed records
}
],
"unknown_files": [], // detection unknown (any mode) or skipped_unknown in convert, fetch and fix
"error_files": [ // action error or verify failed — a file may appear in both; in fix
"D:\\server\\GameServer\\Locked.cpp"
],
// mode verify failures are listed only in verify_failed_files
"verify_failed_files": [], // fix mode only: paths whose verify record is failed;
// omitted when the gate is clean
"warnings": [ // walk/ignore warnings (e.g. a directory the traversal
"walk warning at .\locked: Permission denied (os error 13)"
] // omitted when empty
}
summary is a per-mode block (mode determines the shape):
// scan — encoding distribution:
{ "total_files": 1247, "candidates": 1247, "utf8": 1035, "utf8_bom": 34,
"utf16le": 2, "utf16be": 0, "utf32le": 0, "utf32be": 0, "gb18030": 171,
"unknown": 5, "errors": 0, "too_large": 0 }
// errors counts unreadable files, so buckets + errors == candidates
// (equivalently buckets + errors + too_large == total_files)
// verify — gate result (candidates == total_files; oversized files are
// gate-failed, never subtracted):
{ "total_files": 1247, "candidates": 1247, "passed": 1242, "failed": 5 }
// convert / fetch — outcome counts:
{ "total_files": 1247, "candidates": 1247, "already_utf8": 1035, "converted": 207,
"unknown": 5, "decode_errors": 0, "encode_errors": 0, "io_errors": 0, "too_large": 0, "fetch_error": 0 }
// fix — convert counters (no fetch_error) plus the verify gate on the same tree:
{ "total_files": 1247, "candidates": 1247, "already_utf8": 1035, "converted": 207,
"unknown": 5, "decode_errors": 0, "encode_errors": 0, "io_errors": 0, "too_large": 0,
"passed": 1242, "failed": 5 }
started_atis captured when per-file processing begins; in tree modes neither it norduration_msincludes the directory walk.
diff does not produce a run report; it emits its own document type (to
--report, or pretty-printed on stdout when the flag is absent — the summary
line always goes to stderr, so diff … | jq . works):
{
"tool": "utf8-forge",
"version": "0.2.5",
"mode": "diff",
"before": "apply2.json", // --before value verbatim
"after": "apply3.json", // --after value verbatim
"before_root": "D:\\server", // input report's root; omitted when absent
"after_root": "D:\\server", // input report's root; omitted when absent
"before_mode": "convert", // input report's mode; omitted when absent
"after_mode": "convert",
"summary": {
"added": 0, "removed": 0, "action_changed": 1, "unchanged": 1246
},
"added": [], // paths only in the after report
"removed": [], // paths only in the before report
"changed": [ // action OR byte-count drift
{
"path": "GameServer/Channel.cpp",
"before": { "path": "...", "action": "unchanged", "bytes_before": 15201, "bytes_after": 15201 },
"after": { "path": "...", "action": "converted", "bytes_before": 15201, "bytes_after": 16840 }
}
]
}
Inputs must be utf8-forge reports with a files[] array — anything else
(wrong schema, bare array, malformed JSON) is a fatal exit 2. Record paths are
compared relative to each report’s root: the root prefix is stripped
(separators normalized to /) before comparing, so identical trees scanned
under different root directories no longer diff as full churn; paths in this
document are therefore root-relative. Differing root fields still print a
stderr warning; any report mode with files[] is a valid input; verify
outcomes are not compared. Duplicate paths within one input resolve to the
last occurrence.
The field list above is normative for the diff document.