Fix Unicode paths on Windows #716

Manually merged
github merged 5 commits from gh-pr/716/head into gh-pr/716/base 2026-11-26 09:30:33 +00:00
Owner

@⁠AghastyGD on GitHub · 2026-09-19 13:51 UTC · original
AghastyGD:fix/windows-unicode-paths → main · +194 −119 · 9 files · 5 commits · merged 2026-09-19 22:14 UTC

Closes #714

Root cause

Windows uses UTF-16 for native filesystem paths, but some paths were being converted through UTF-8 strings and later reconstructed as narrow std::filesystem::path values.

This works for ASCII paths, but can break paths containing characters such as é or Japanese characters depending on the active Windows code page.

One place where this caused a problem was module discovery. During sce_module enumeration, the game path went through a std::filesystem::path -> UTF-8 std::string -> narrow std::filesystem::path round trip before reaching the wide Win32 APIs.

With a Unicode game path, module enumeration could fail silently. In my case, libc.prx was not discovered, which later resulted in an unresolved libc_v1 import and a crash in the runtime linker.

The same kind of conversion also affected other paths, including command-line arguments and icon loading.

Fix

  • Keep native std::filesystem::path values native during Windows filesystem operations.
  • Avoid unnecessary UTF-8 round trips before calling wide Win32 filesystem APIs.
  • Convert guest UTF-8 paths explicitly when joining them with native paths.
  • Receive Windows command-line arguments as UTF-16 through wmain() and convert them to UTF-8 before parsing.
  • Convert path-valued command-line options explicitly to native paths.
  • Preserve native paths when loading game icons.
  • Preserve Unicode paths passed through --game-patch.
  • Add regression tests for Unicode filesystem paths.

Test

Tested locally on Windows with a Debug clang-cl build.

I tested the same game using:

  • Teste
  • Testé
  • Test日本語

Before the fix, only the ASCII path worked correctly. After the fix, all three work. The game is detected, the icon loads, sce_module is enumerated correctly, and the required modules are loaded.

The Unicode filesystem regression tests pass locally.

kernel_file_system_tests currently requires the Windows linking fix from #712 to build. After applying the equivalent fix locally, the test binary runs and reaches the existing unrelated socket failure:

guest PEEK and WAITALL preserve the wake bytes

**@⁠AghastyGD** on GitHub · 2026-09-19 13:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/716) `AghastyGD:fix/windows-unicode-paths` → `main` · +194 −119 · 9 files · 5 commits · merged 2026-09-19 22:14 UTC Closes #714 ## Root cause Windows uses UTF-16 for native filesystem paths, but some paths were being converted through UTF-8 strings and later reconstructed as narrow `std::filesystem::path` values. This works for ASCII paths, but can break paths containing characters such as `é` or Japanese characters depending on the active Windows code page. One place where this caused a problem was module discovery. During `sce_module` enumeration, the game path went through a `std::filesystem::path` -> UTF-8 `std::string` -> narrow `std::filesystem::path` round trip before reaching the wide Win32 APIs. With a Unicode game path, module enumeration could fail silently. In my case, `libc.prx` was not discovered, which later resulted in an unresolved `libc_v1` import and a crash in the runtime linker. The same kind of conversion also affected other paths, including command-line arguments and icon loading. ## Fix - Keep native `std::filesystem::path` values native during Windows filesystem operations. - Avoid unnecessary UTF-8 round trips before calling wide Win32 filesystem APIs. - Convert guest UTF-8 paths explicitly when joining them with native paths. - Receive Windows command-line arguments as UTF-16 through `wmain()` and convert them to UTF-8 before parsing. - Convert path-valued command-line options explicitly to native paths. - Preserve native paths when loading game icons. - Preserve Unicode paths passed through `--game-patch`. - Add regression tests for Unicode filesystem paths. ## Test Tested locally on Windows with a Debug `clang-cl` build. I tested the same game using: - `Teste` - `Testé` - `Test日本語` Before the fix, only the ASCII path worked correctly. After the fix, all three work. The game is detected, the icon loads, `sce_module` is enumerated correctly, and the required modules are loaded. The Unicode filesystem regression tests pass locally. `kernel_file_system_tests` currently requires the Windows linking fix from #712 to build. After applying the equivalent fix locally, the test binary runs and reaches the existing unrelated socket failure: `guest PEEK and WAITALL preserve the wake bytes`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:30:31 +00:00
github manually merged commit fe45265fcd into gh-pr/716/base 2026-11-26 09:30:33 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-19 13:56 UTC · original · edited 2026-09-19 15:57 UTC

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 43651441-65fa-4e06-bb9c-a3e7ae63dd0e

📥 Commits

Reviewing files that changed from the base of the PR and between 8b294eb5b8 and fe45265fcd.

📒 Files selected for processing (2)
  • src/common/file.cpp
  • tests/KernelFileSystemTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change replaces string-based path handling with std::filesystem::path across directory operations, Windows enumeration, mount resolution, icon loading, command-line inputs, and system content APIs. It adds UTF-8 path conversion and a Windows wmain wrapper. Filesystem tests now cover Unicode directories and filenames.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix · Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 9 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: fixing Unicode path handling on Windows.
Description check ✅ Passed The description directly explains the Windows Unicode path issue, the root cause, the implemented fixes, and the regression testing. It is fully related to the changeset.
Linked Issues check ✅ Passed Issue #714 requires game detection and loading to work with Unicode paths on Windows. The PR converts Windows arguments through wmain(), converts UTF-8 path inputs with Common::PathFromUtf8, and p…
Out of Scope Changes check ✅ Passed The changes support Issue #714. The path conversion helper, native path propagation, Windows wide-argument entry point, wide filesystem enumeration, icon and patch handling, directory handling, and Un…

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-19 13:56 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/716#issuecomment-5742438413) · edited 2026-09-19 15:57 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/716#gh-light-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg" alt="Review Change Stack" width="202" height="32"></a><a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/716#gh-dark-mode-only"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg" alt="Review Change Stack" width="202" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `43651441-65fa-4e06-bb9c-a3e7ae63dd0e` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 8b294eb5b86ebd9036a73dce7dfbf7d8fc94b7b4 and fe45265fcd7c74809fbeb8dd4b060f94f7bdfd88. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/common/file.cpp` * `tests/KernelFileSystemTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The change replaces string-based path handling with `std::filesystem::path` across directory operations, Windows enumeration, mount resolution, icon loading, command-line inputs, and system content APIs. It adds UTF-8 path conversion and a Windows `wmain` wrapper. Filesystem tests now cover Unicode directories and filenames. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"fe45265fcd7c74809fbeb8dd4b060f94f7bdfd88" --> **Change:** Bug fix · **Severity of issue fixed:** Medium <!-- change_assessment_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 3.13% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 9 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly and concisely identifies the main change: fixing Unicode path handling on Windows. | | Description check | ✅ Passed | The description directly explains the Windows Unicode path issue, the root cause, the implemented fixes, and the regression testing. It is fully related to the changeset. | | Linked Issues check | ✅ Passed | Issue `#714` requires game detection and loading to work with Unicode paths on Windows. The PR converts Windows arguments through `wmain()`, converts UTF-8 path inputs with `Common::PathFromUtf8`, and p… | | Out of Scope Changes check | ✅ Passed | The changes support Issue `#714`. The path conversion helper, native path propagation, Windows wide-argument entry point, wide filesystem enumeration, icon and patch handling, directory handling, and Un… | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-19 13:56 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟠 Major · Keep native paths in CreateDirectories. · file.cpp:278

src/common/file.cpp:278
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep native paths in CreateDirectories.

PathToGenericString(path) converts the native path to UTF-8 text. The later IsDirectoryExisting(p) and CreateDirectory(p) calls reconstruct std::filesystem::path from narrow strings. On Windows with a non-UTF-8 active code page, creating a file below a missing Unicode directory can therefore still target a corrupted path or fail.

Build each intermediate directory as a std::filesystem::path from path.root_path() and path.relative_path() components. Do not round-trip through std::string.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: ce257984-3bce-4f38-8f99-acdd086b93cd

📥 Commits

Reviewing files that changed from the base of the PR and between f100f785da and 8b294eb5b8.

📒 Files selected for processing (9)
  • src/common/file.cpp
  • src/common/platform/sysWindowsFileIO.cpp
  • src/common/stringUtils.h
  • src/graphics/presentation/window/window.cpp
  • src/kernel/fileSystem.cpp
  • src/loader/systemContent.cpp
  • src/loader/systemContent.h
  • src/main.cpp
  • tests/KernelFileSystemTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-19 13:56 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/716#pullrequestreview-5255933838) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><em>🟠 Major</em> · Keep native paths in <code>CreateDirectories</code>. · <code>file.cpp:278</code></summary><blockquote> > > `src/common/file.cpp:278` > _🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_ > > **Keep native paths in `CreateDirectories`.** > > `PathToGenericString(path)` converts the native path to UTF-8 text. The later `IsDirectoryExisting(p)` and `CreateDirectory(p)` calls reconstruct `std::filesystem::path` from narrow strings. On Windows with a non-UTF-8 active code page, creating a file below a missing Unicode directory can therefore still target a corrupted path or fail. > > Build each intermediate directory as a `std::filesystem::path` from `path.root_path()` and `path.relative_path()` components. Do not round-trip through `std::string`. > > <!-- cr-comment:v1:9a68659a89bb9740ac8f323b --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `ce257984-3bce-4f38-8f99-acdd086b93cd` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between f100f785dafa108bbf5b40ea8e425e08236f981a and 8b294eb5b86ebd9036a73dce7dfbf7d8fc94b7b4. </details> <details> <summary>📒 Files selected for processing (9)</summary> * `src/common/file.cpp` * `src/common/platform/sysWindowsFileIO.cpp` * `src/common/stringUtils.h` * `src/graphics/presentation/window/window.cpp` * `src/kernel/fileSystem.cpp` * `src/loader/systemContent.cpp` * `src/loader/systemContent.h` * `src/main.cpp` * `tests/KernelFileSystemTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
This discussion has been locked. Commenting is limited to contributors.
No description provided.