summaryrefslogtreecommitdiff
path: root/src/common/fs/fs_util.cpp
diff options
context:
space:
mode:
authorGravatar boludoz2023-10-15 02:02:22 -0300
committerGravatar boludoz2023-10-15 02:02:22 -0300
commit3062a35eb1297067446156c43e9d0df2f684edff (patch)
treef2ca58e0b8a6c413f3c6783a1501204729e0394c /src/common/fs/fs_util.cpp
parentMerge pull request #11780 from Darkness4/master (diff)
downloadyuzu-3062a35eb1297067446156c43e9d0df2f684edff.tar.gz
yuzu-3062a35eb1297067446156c43e9d0df2f684edff.tar.xz
yuzu-3062a35eb1297067446156c43e9d0df2f684edff.zip
Improved shortcut: add games in applist for Windows, question for start game at fullscreen & better unicode support for some Windows path funcs.
Diffstat (limited to 'src/common/fs/fs_util.cpp')
-rw-r--r--src/common/fs/fs_util.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp
index 813a713c3..442f63728 100644
--- a/src/common/fs/fs_util.cpp
+++ b/src/common/fs/fs_util.cpp
@@ -36,4 +36,63 @@ std::string PathToUTF8String(const std::filesystem::path& path) {
36 return ToUTF8String(path.u8string()); 36 return ToUTF8String(path.u8string());
37} 37}
38 38
39std::u8string U8FilenameSantizer(const std::u8string_view u8filename) {
40 std::u8string u8path_santized{u8filename.begin(), u8filename.end()};
41 size_t eSizeSanitized = u8path_santized.size();
42
43 // Special case for ":", for example: 'Pepe: La secuela' --> 'Pepe - La
44 // secuela' or 'Pepe : La secuela' --> 'Pepe - La secuela'
45 for (size_t i = 0; i < eSizeSanitized; i++) {
46 switch (u8path_santized[i]) {
47 case u8':':
48 if (i == 0 || i == eSizeSanitized - 1) {
49 u8path_santized.replace(i, 1, u8"_");
50 } else if (u8path_santized[i - 1] == u8' ') {
51 u8path_santized.replace(i, 1, u8"-");
52 } else {
53 u8path_santized.replace(i, 1, u8" -");
54 eSizeSanitized++;
55 }
56 break;
57 case u8'\\':
58 case u8'/':
59 case u8'*':
60 case u8'?':
61 case u8'\"':
62 case u8'<':
63 case u8'>':
64 case u8'|':
65 case u8'\0':
66 u8path_santized.replace(i, 1, u8"_");
67 break;
68 default:
69 break;
70 }
71 }
72
73 // Delete duplicated spaces || Delete duplicated dots (MacOS i think)
74 for (size_t i = 0; i < eSizeSanitized - 1; i++) {
75 if ((u8path_santized[i] == u8' ' && u8path_santized[i + 1] == u8' ') ||
76 (u8path_santized[i] == u8'.' && u8path_santized[i + 1] == u8'.')) {
77 u8path_santized.erase(i, 1);
78 i--;
79 }
80 }
81
82 // Delete all spaces and dots at the end (Windows almost)
83 while (u8path_santized.back() == u8' ' || u8path_santized.back() == u8'.') {
84 u8path_santized.pop_back();
85 }
86
87 if (u8path_santized.empty()) {
88 return u8"";
89 }
90
91 return u8path_santized;
92}
93
94std::string UTF8FilenameSantizer(const std::string_view filename) {
95 return ToUTF8String(U8FilenameSantizer(ToU8String(filename)));
96}
97
39} // namespace Common::FS 98} // namespace Common::FS