[PR #1064] [MERGED] Use fs::path::native whenever possible, avoid unnecessary fs->string conversions in GUI code #1910

Closed
opened 2026-02-27 21:14:25 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/shadps4-emu/shadPS4/pull/1064
Author: @OFFTKP
Created: 9/25/2024
Status: Merged
Merged: 9/26/2024
Merged by: @georgemoralis

Base: mainHead: wstr


📝 Commits (10+)

  • 662ae57 Use filesystem::path whenever possible, remove fs::path::string
  • 9a4f57e My hatred for Windows grows with every passing day
  • 3640783 More Qt stuff
  • 43aeee7 custom u8string formatter for fmt library
  • 481c3d0 Merge pull request #1 from viniciuslrangel/str-fmt
  • 4fd41bf Use u8string for imgui
  • 87b8342 Fix toml errors hopefully
  • 51d21a2 Fix not printing issue
  • 62a3f1c Oh and on SDL
  • 265698d I hate Windows even more today

📊 Changes

30 files changed (+271 additions, -125 deletions)

View changed files

📝 src/common/config.cpp (+31 -10)
📝 src/common/config.h (+2 -2)
📝 src/common/logging/formatter.h (+21 -0)
📝 src/common/memory_patcher.cpp (+4 -4)
📝 src/common/path_util.cpp (+22 -0)
📝 src/common/path_util.h (+23 -0)
📝 src/core/file_format/pkg.cpp (+2 -3)
📝 src/core/file_format/splash.cpp (+2 -2)
📝 src/core/file_format/splash.h (+2 -1)
📝 src/core/file_format/trp.cpp (+1 -1)
📝 src/core/libraries/np_trophy/np_trophy.cpp (+2 -2)
📝 src/core/libraries/save_data/save_backup.cpp (+7 -5)
📝 src/core/libraries/save_data/save_memory.cpp (+3 -2)
📝 src/core/libraries/save_data/savedata.cpp (+2 -2)
📝 src/emulator.cpp (+3 -3)
📝 src/imgui/renderer/imgui_core.cpp (+12 -4)
📝 src/main.cpp (+8 -0)
📝 src/qt_gui/cheats_patches.cpp (+18 -15)
📝 src/qt_gui/game_grid_frame.cpp (+6 -7)
📝 src/qt_gui/game_info.cpp (+4 -2)

...and 10 more files

📄 Description

The problem is that std::filesystem::path::string throws an exception on Windows if the path contains special characters.

This causes the emulator to mysteriously crash with no immediately obvious error on Windows if the executable (or config files or other paths used by the GUI) are in some path that contains special characters (such as Cyrillic, Spanish etc.)

This has been a very annoying problem that gets a lot of users to report it in discord, and it's not easy to solve because a lot of times users don't know what a path is.


The native string format used on Windows for paths is wstring, which supports special characters. On POSIX it's regular old std::string. path::native returns the correct type based on OS.
This PR reduces some unnecessary uses of path::string by using the fs::path itself, and opts for path::native on the rest.

An annoying side effect is that fmt::format & co (for good reason) doesn't allow you to:

  • Mix strings and wstrings
  • Use wstrings without adding L in front of the format string

Emulator code that does path->string conversions was ignored because there was a lot of them in logging facilities which are the most annoying to deal with, and most likely there isn't going to be any paths with wide characters used in games


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/shadps4-emu/shadPS4/pull/1064 **Author:** [@OFFTKP](https://github.com/OFFTKP) **Created:** 9/25/2024 **Status:** ✅ Merged **Merged:** 9/26/2024 **Merged by:** [@georgemoralis](https://github.com/georgemoralis) **Base:** `main` ← **Head:** `wstr` --- ### 📝 Commits (10+) - [`662ae57`](https://github.com/shadps4-emu/shadPS4/commit/662ae5743576c624bc6bac49eec81635d530ad3a) Use filesystem::path whenever possible, remove fs::path::string - [`9a4f57e`](https://github.com/shadps4-emu/shadPS4/commit/9a4f57e4e694e1a0b024ff8168a27016488ca03b) My hatred for Windows grows with every passing day - [`3640783`](https://github.com/shadps4-emu/shadPS4/commit/364078339a39ad317f70f3bc7802a2233331a0ce) More Qt stuff - [`43aeee7`](https://github.com/shadps4-emu/shadPS4/commit/43aeee743fe1376ac93073b30b03849f73d7aba3) custom u8string formatter for fmt library - [`481c3d0`](https://github.com/shadps4-emu/shadPS4/commit/481c3d06405c65103c6cb2d10aacc43323970994) Merge pull request #1 from viniciuslrangel/str-fmt - [`4fd41bf`](https://github.com/shadps4-emu/shadPS4/commit/4fd41bfb3904005f1a41850a56c7962e75c54398) Use u8string for imgui - [`87b8342`](https://github.com/shadps4-emu/shadPS4/commit/87b8342b08bb480caeaf38bc6e74d639e4a8e14e) Fix toml errors hopefully - [`51d21a2`](https://github.com/shadps4-emu/shadPS4/commit/51d21a274e55faa426235938b69105f32025a897) Fix not printing issue - [`62a3f1c`](https://github.com/shadps4-emu/shadPS4/commit/62a3f1cbedced98f64ceca430947b7a23cad93bb) Oh and on SDL - [`265698d`](https://github.com/shadps4-emu/shadPS4/commit/265698d6bfe5a2e868b3ee4196f4467e74d52f3e) I hate Windows even more today ### 📊 Changes **30 files changed** (+271 additions, -125 deletions) <details> <summary>View changed files</summary> 📝 `src/common/config.cpp` (+31 -10) 📝 `src/common/config.h` (+2 -2) 📝 `src/common/logging/formatter.h` (+21 -0) 📝 `src/common/memory_patcher.cpp` (+4 -4) 📝 `src/common/path_util.cpp` (+22 -0) 📝 `src/common/path_util.h` (+23 -0) 📝 `src/core/file_format/pkg.cpp` (+2 -3) 📝 `src/core/file_format/splash.cpp` (+2 -2) 📝 `src/core/file_format/splash.h` (+2 -1) 📝 `src/core/file_format/trp.cpp` (+1 -1) 📝 `src/core/libraries/np_trophy/np_trophy.cpp` (+2 -2) 📝 `src/core/libraries/save_data/save_backup.cpp` (+7 -5) 📝 `src/core/libraries/save_data/save_memory.cpp` (+3 -2) 📝 `src/core/libraries/save_data/savedata.cpp` (+2 -2) 📝 `src/emulator.cpp` (+3 -3) 📝 `src/imgui/renderer/imgui_core.cpp` (+12 -4) 📝 `src/main.cpp` (+8 -0) 📝 `src/qt_gui/cheats_patches.cpp` (+18 -15) 📝 `src/qt_gui/game_grid_frame.cpp` (+6 -7) 📝 `src/qt_gui/game_info.cpp` (+4 -2) _...and 10 more files_ </details> ### 📄 Description The problem is that `std::filesystem::path::string` throws an exception on Windows if the path contains special characters. This causes the emulator to mysteriously crash with no immediately obvious error on Windows if the executable (or config files or other paths used by the GUI) are in some path that contains special characters (such as Cyrillic, Spanish etc.) This has been a very annoying problem that gets a lot of users to report it in discord, and it's not easy to solve because a lot of times users don't know what a path is. --- The native string format used on Windows for paths is wstring, which supports special characters. On POSIX it's regular old std::string. path::native returns the correct type based on OS. This PR reduces some unnecessary uses of `path::string` by using the fs::path itself, and opts for `path::native` on the rest. An annoying side effect is that fmt::format & co (for good reason) doesn't allow you to: - Mix strings and wstrings - Use wstrings without adding `L` in front of the format string --- Emulator code that does path->string conversions was ignored because there was a lot of them in logging facilities which are the most annoying to deal with, and most likely there isn't going to be any paths with wide characters used in games --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-27 21:14:25 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shadPS4#1910
No description provided.