Fixed unicode conversion on Windows almost
This commit is contained in:
parent
aec95e0200
commit
98248d59fd
3 changed files with 25 additions and 83 deletions
|
@ -4,20 +4,27 @@
|
|||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h> // For MultiByteToWideChar (cannon UTF-8 with Windows)
|
||||
#endif
|
||||
|
||||
/* TODO: Add support for 'https://github.com/unicode-org/icu' to handle UTF-8.
|
||||
* This will be necessary for support UTF-8 cannon on Linux and macOS conversions.
|
||||
*/
|
||||
|
||||
#include "common/fs/fs_util.h"
|
||||
#include "common/polyfill_ranges.h"
|
||||
|
||||
namespace Common::FS {
|
||||
|
||||
std::u8string ToU8String(std::string_view string) {
|
||||
return std::u8string{reinterpret_cast<const char8_t*>(string.data())};
|
||||
}
|
||||
|
||||
std::u8string ToU8String(std::wstring_view w_string) {
|
||||
return std::u8string{reinterpret_cast<const char8_t*>(w_string.data())};
|
||||
}
|
||||
|
||||
std::u8string ToU8String(std::string_view string) {
|
||||
return std::u8string{string.begin(), string.end()};
|
||||
}
|
||||
|
||||
std::u8string BufferToU8String(std::span<const u8> buffer) {
|
||||
return std::u8string{buffer.begin(), std::ranges::find(buffer, u8{0})};
|
||||
}
|
||||
|
@ -27,7 +34,14 @@ std::u8string_view BufferToU8StringView(std::span<const u8> buffer) {
|
|||
}
|
||||
|
||||
std::wstring ToWString(std::u8string_view utf8_string) {
|
||||
#ifdef _WIN32
|
||||
int size_needed = MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<const char*>(utf8_string.data()), -1, NULL, 0);
|
||||
std::wstring wstr(size_needed, 0);
|
||||
MultiByteToWideChar(CP_UTF8, 0, reinterpret_cast<const char*>(utf8_string.data()), -1, &wstr[0], size_needed);
|
||||
return wstr;
|
||||
#else
|
||||
return std::wstring{utf8_string.begin(), utf8_string.end()};
|
||||
#endif
|
||||
}
|
||||
|
||||
std::string ToUTF8String(std::u8string_view u8_string) {
|
||||
|
@ -46,72 +60,4 @@ std::string PathToUTF8String(const std::filesystem::path& path) {
|
|||
return ToUTF8String(path.u8string());
|
||||
}
|
||||
|
||||
/*
|
||||
std::u8string UTF8FilenameSantizer(std::u8string u8filename) {
|
||||
std::u8string u8path_santized = u8filename;
|
||||
|
||||
size_t eSizeSanitized =
|
||||
u8path_santized.size(); // Cambiado a size_t para coincidir con el tipo de i
|
||||
|
||||
// Special case for ":", for example: 'Pepe: La secuela' --> 'Pepe - La
|
||||
// secuela' or 'Pepe : La secuela' --> 'Pepe - La secuela'
|
||||
for (size_t i = 0; i < eSizeSanitized; i++) {
|
||||
|
||||
switch (u8path_santized[i]) {
|
||||
case u8':':
|
||||
if (i == 0 || i == eSizeSanitized - 1) {
|
||||
u8path_santized.replace(i, 1, u8"_");
|
||||
} else if (u8path_santized[i - 1] == u8' ') {
|
||||
u8path_santized.replace(i, 1, u8"-");
|
||||
} else {
|
||||
u8path_santized.replace(i, 1, u8" -");
|
||||
eSizeSanitized++;
|
||||
}
|
||||
break;
|
||||
case u8'\\':
|
||||
[[fallthrough]];
|
||||
case u8'/':
|
||||
[[fallthrough]];
|
||||
case u8'*':
|
||||
[[fallthrough]];
|
||||
case u8'?':
|
||||
[[fallthrough]];
|
||||
case u8'\"':
|
||||
[[fallthrough]];
|
||||
case u8'<':
|
||||
[[fallthrough]];
|
||||
case u8'>':
|
||||
[[fallthrough]];
|
||||
case u8'|':
|
||||
[[fallthrough]];
|
||||
case u8'\0':
|
||||
u8path_santized.replace(i, 1, u8"_");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete duplicated spaces || Delete duplicated dots (MacOS i think)
|
||||
for (size_t i = 0; i < eSizeSanitized; i++) {
|
||||
if ((u8path_santized[i] == u8' ' && u8path_santized[i + 1] == u8' ') ||
|
||||
(u8path_santized[i] == u8'.' && u8path_santized[i + 1] == u8'.')) {
|
||||
u8path_santized.erase(i, 1);
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all spaces and dots at the end (Windows almost)
|
||||
while (u8path_santized.back() == u8' ' || u8path_santized.back() == u8'.') {
|
||||
u8path_santized.pop_back();
|
||||
}
|
||||
|
||||
if (u8path_santized.empty()) {
|
||||
return u8"";
|
||||
}
|
||||
|
||||
return u8path_santized;
|
||||
}
|
||||
*/
|
||||
|
||||
} // namespace Common::FS
|
||||
|
|
|
@ -99,13 +99,4 @@ concept IsChar = std::same_as<T, char>;
|
|||
*/
|
||||
[[nodiscard]] std::string PathToUTF8String(const std::filesystem::path& path);
|
||||
|
||||
/**
|
||||
* Fix filename (remove invalid characters)
|
||||
* @param dirty UTF-8 encoded
|
||||
*
|
||||
* @returns UTF-8 encoded fixed
|
||||
*
|
||||
*/
|
||||
// [[nodiscard]] std::u8string UTF8FilenameSantizer(std::u8string &u8filename);
|
||||
|
||||
} // namespace Common::FS
|
|
@ -3025,9 +3025,14 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const QString& game_p
|
|||
#endif // __linux__ || __FreeBSD__ || _WIN32
|
||||
|
||||
#if defined(__linux__) || defined(__FreeBSD__)
|
||||
std::string arguments =
|
||||
fmt::format("{}-g \"{:s}\"", (result == QMessageBox::Yes) ? "-f " : "", game_path);
|
||||
|
||||
std::string arguments;
|
||||
if (result == QMessageBox::Yes) {
|
||||
arguments = fmt::format("-f -g \"{:s}\"", game_path);
|
||||
|
||||
} else {
|
||||
arguments = fmt::format("-g \"{:s}\"", game_path);
|
||||
}
|
||||
const std::string comment =
|
||||
tr("Start %1 with the yuzu Emulator").arg(QString::fromStdString(title)).toStdString();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue