forked from ShuriZma/suyu
Typing and formatting errors fixed.
This commit is contained in:
parent
4d4fe69223
commit
9ffa1801c7
|
@ -36,21 +36,21 @@ std::string PathToUTF8String(const std::filesystem::path& path) {
|
||||||
return ToUTF8String(path.u8string());
|
return ToUTF8String(path.u8string());
|
||||||
}
|
}
|
||||||
|
|
||||||
std::u8string U8FilenameSantizer(const std::u8string_view u8filename) {
|
std::u8string U8FilenameSanitizer(const std::u8string_view u8filename) {
|
||||||
std::u8string u8path_santized{u8filename.begin(), u8filename.end()};
|
std::u8string u8path_sanitized{u8filename.begin(), u8filename.end()};
|
||||||
size_t eSizeSanitized = u8path_santized.size();
|
size_t eSizeSanitized = u8path_sanitized.size();
|
||||||
|
|
||||||
// Special case for ":", for example: 'Pepe: La secuela' --> 'Pepe - La
|
// The name is improved to make it look more beautiful and prohibited characters and shapes are
|
||||||
// secuela' or 'Pepe : La secuela' --> 'Pepe - La secuela'
|
// removed. Switch is used since it is better with many conditions.
|
||||||
for (size_t i = 0; i < eSizeSanitized; i++) {
|
for (size_t i = 0; i < eSizeSanitized; i++) {
|
||||||
switch (u8path_santized[i]) {
|
switch (u8path_sanitized[i]) {
|
||||||
case u8':':
|
case u8':':
|
||||||
if (i == 0 || i == eSizeSanitized - 1) {
|
if (i == 0 || i == eSizeSanitized - 1) {
|
||||||
u8path_santized.replace(i, 1, u8"_");
|
u8path_sanitized.replace(i, 1, u8"_");
|
||||||
} else if (u8path_santized[i - 1] == u8' ') {
|
} else if (u8path_sanitized[i - 1] == u8' ') {
|
||||||
u8path_santized.replace(i, 1, u8"-");
|
u8path_sanitized.replace(i, 1, u8"-");
|
||||||
} else {
|
} else {
|
||||||
u8path_santized.replace(i, 1, u8" -");
|
u8path_sanitized.replace(i, 1, u8" -");
|
||||||
eSizeSanitized++;
|
eSizeSanitized++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -63,36 +63,36 @@ std::u8string U8FilenameSantizer(const std::u8string_view u8filename) {
|
||||||
case u8'>':
|
case u8'>':
|
||||||
case u8'|':
|
case u8'|':
|
||||||
case u8'\0':
|
case u8'\0':
|
||||||
u8path_santized.replace(i, 1, u8"_");
|
u8path_sanitized.replace(i, 1, u8"_");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete duplicated spaces || Delete duplicated dots (MacOS i think)
|
// Delete duplicated spaces and dots
|
||||||
for (size_t i = 0; i < eSizeSanitized - 1; i++) {
|
for (size_t i = 0; i < eSizeSanitized - 1; i++) {
|
||||||
if ((u8path_santized[i] == u8' ' && u8path_santized[i + 1] == u8' ') ||
|
if ((u8path_sanitized[i] == u8' ' && u8path_sanitized[i + 1] == u8' ') ||
|
||||||
(u8path_santized[i] == u8'.' && u8path_santized[i + 1] == u8'.')) {
|
(u8path_sanitized[i] == u8'.' && u8path_sanitized[i + 1] == u8'.')) {
|
||||||
u8path_santized.erase(i, 1);
|
u8path_sanitized.erase(i, 1);
|
||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete all spaces and dots at the end (Windows almost)
|
// Delete all spaces and dots at the end of the name
|
||||||
while (u8path_santized.back() == u8' ' || u8path_santized.back() == u8'.') {
|
while (u8path_sanitized.back() == u8' ' || u8path_sanitized.back() == u8'.') {
|
||||||
u8path_santized.pop_back();
|
u8path_sanitized.pop_back();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (u8path_santized.empty()) {
|
if (u8path_sanitized.empty()) {
|
||||||
return u8"";
|
return u8"";
|
||||||
}
|
}
|
||||||
|
|
||||||
return u8path_santized;
|
return u8path_sanitized;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string UTF8FilenameSantizer(const std::string_view filename) {
|
std::string UTF8FilenameSanitizer(const std::string_view filename) {
|
||||||
return ToUTF8String(U8FilenameSantizer(ToU8String(filename)));
|
return ToUTF8String(U8FilenameSanitizer(ToU8String(filename)));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Common::FS
|
} // namespace Common::FS
|
||||||
|
|
|
@ -87,19 +87,19 @@ concept IsChar = std::same_as<T, char>;
|
||||||
*
|
*
|
||||||
* @param u8_string dirty encoded filename string
|
* @param u8_string dirty encoded filename string
|
||||||
*
|
*
|
||||||
* @returns utf8_string santized filename string
|
* @returns utf8_string sanitized filename string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::u8string U8FilenameSantizer(const std::u8string_view u8filename);
|
[[nodiscard]] std::u8string U8FilenameSanitizer(const std::u8string_view u8filename);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix filename (remove invalid characters)
|
* Fix filename (remove invalid characters)
|
||||||
*
|
*
|
||||||
* @param utf8_string dirty encoded filename string
|
* @param utf8_string dirty encoded filename string
|
||||||
*
|
*
|
||||||
* @returns utf8_string santized filename string
|
* @returns utf8_string sanitized filename string
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] std::string UTF8FilenameSantizer(const std::string_view filename);
|
[[nodiscard]] std::string UTF8FilenameSanitizer(const std::string_view filename);
|
||||||
|
|
||||||
} // namespace Common::FS
|
} // namespace Common::FS
|
|
@ -260,8 +260,7 @@ fs::path GetExeDirectory() {
|
||||||
// the Windows library (Filesystem converts the strings literally).
|
// the Windows library (Filesystem converts the strings literally).
|
||||||
return fs::path{Common::UTF16ToUTF8(wideExePath)}.parent_path();
|
return fs::path{Common::UTF16ToUTF8(wideExePath)}.parent_path();
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Common_Filesystem,
|
LOG_ERROR(Common_Filesystem, "Failed to get the path to the executable of the current "
|
||||||
"[GetExeDirectory] Failed to get the path to the executable of the current "
|
|
||||||
"process");
|
"process");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,8 +278,7 @@ fs::path GetAppDataRoamingDirectory() {
|
||||||
// the Windows library (Filesystem converts the strings literally).
|
// the Windows library (Filesystem converts the strings literally).
|
||||||
return fs::path{Common::UTF16ToUTF8(wideAppdataRoamingPath)};
|
return fs::path{Common::UTF16ToUTF8(wideAppdataRoamingPath)};
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Common_Filesystem,
|
LOG_ERROR(Common_Filesystem, "Failed to get the path to the %APPDATA% directory");
|
||||||
"[GetAppDataRoamingDirectory] Failed to get the path to the %APPDATA% directory");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return fs::path{};
|
return fs::path{};
|
||||||
|
|
|
@ -2851,7 +2851,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
|
||||||
|
|
||||||
// Replace characters that are illegal in Windows filenames
|
// Replace characters that are illegal in Windows filenames
|
||||||
std::filesystem::path shortcut_path_full =
|
std::filesystem::path shortcut_path_full =
|
||||||
shortcut_path / Common::FS::UTF8FilenameSantizer(name);
|
shortcut_path / Common::FS::UTF8FilenameSanitizer(name);
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
shortcut_path_full += ".desktop";
|
shortcut_path_full += ".desktop";
|
||||||
|
@ -2859,8 +2859,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
|
||||||
shortcut_path_full += ".lnk";
|
shortcut_path_full += ".lnk";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LOG_INFO(Common, "[GMainWindow::CreateShortcutLink] Create shortcut path: {}",
|
LOG_ERROR(Frontend, "Create shortcut path: {}", shortcut_path_full.string());
|
||||||
shortcut_path_full.string());
|
|
||||||
|
|
||||||
#if defined(__linux__) || defined(__FreeBSD__)
|
#if defined(__linux__) || defined(__FreeBSD__)
|
||||||
// This desktop file template was writing referencing
|
// This desktop file template was writing referencing
|
||||||
|
@ -2869,7 +2868,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
|
||||||
|
|
||||||
// Plus 'Type' is required
|
// Plus 'Type' is required
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Name is empty");
|
LOG_ERROR(Frontend, "Name is empty");
|
||||||
shortcut_succeeded = false;
|
shortcut_succeeded = false;
|
||||||
return shortcut_succeeded;
|
return shortcut_succeeded;
|
||||||
}
|
}
|
||||||
|
@ -2911,14 +2910,13 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Failed to create shortcut");
|
LOG_ERROR(Frontend, "Failed to create shortcut");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
shortcut_stream.close();
|
shortcut_stream.close();
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Failed to create shortcut: {}",
|
LOG_ERROR(Frontend, "Failed to create shortcut: {}", e.what());
|
||||||
e.what());
|
|
||||||
}
|
}
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
// Initialize COM
|
// Initialize COM
|
||||||
|
@ -2970,7 +2968,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
|
||||||
pPersistFile->Release();
|
pPersistFile->Release();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Failed to create IShellLinkWinstance");
|
LOG_ERROR(Frontend, "Failed to create IShellLinkWinstance");
|
||||||
}
|
}
|
||||||
|
|
||||||
ps1->Release();
|
ps1->Release();
|
||||||
|
@ -2978,9 +2976,9 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (shortcut_succeeded && std::filesystem::is_regular_file(shortcut_path_full)) {
|
if (shortcut_succeeded && std::filesystem::is_regular_file(shortcut_path_full)) {
|
||||||
LOG_INFO(Common, "[GMainWindow::CreateShortcutLink] Shortcut created");
|
LOG_ERROR(Frontend, "Shortcut created");
|
||||||
} else {
|
} else {
|
||||||
LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Shortcut error, failed to create it");
|
LOG_ERROR(Frontend, "Shortcut error, failed to create it");
|
||||||
shortcut_succeeded = false;
|
shortcut_succeeded = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3047,7 +3045,7 @@ bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_vi
|
||||||
icons_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "icons";
|
icons_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "icons";
|
||||||
ico_extension = "ico";
|
ico_extension = "ico";
|
||||||
#elif defined(__linux__) || defined(__FreeBSD__)
|
#elif defined(__linux__) || defined(__FreeBSD__)
|
||||||
icons_path = GetDataDirectory("XDG_DATA_HOME") / "icons/hicolor/256x256";
|
icons_path = Common::FS::GetDataDirectory("XDG_DATA_HOME") / "icons/hicolor/256x256";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Create icons directory if it doesn't exist
|
// Create icons directory if it doesn't exist
|
||||||
|
@ -3130,7 +3128,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||||
QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
|
QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size()));
|
||||||
|
|
||||||
if (GMainWindow::MakeShortcutIcoPath(program_id, title, icons_path)) {
|
if (GMainWindow::MakeShortcutIcoPath(program_id, title, icons_path)) {
|
||||||
if (!SaveIconToFile(icon_data, icons_path)) {
|
if (!SaveIconToFile(icons_path, icon_data)) {
|
||||||
LOG_ERROR(Frontend, "Could not write icon to file");
|
LOG_ERROR(Frontend, "Could not write icon to file");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3138,7 +3136,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
|
||||||
} else {
|
} else {
|
||||||
GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR,
|
GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR,
|
||||||
title);
|
title);
|
||||||
LOG_ERROR(Frontend, "[GMainWindow::OnGameListCreateShortcut] Invalid shortcut target");
|
LOG_ERROR(Frontend, "Invalid shortcut target");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ QPixmap CreateCirclePixmapFromColor(const QColor& color) {
|
||||||
return circle_pixmap;
|
return circle_pixmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SaveIconToFile(const QImage& image, const std::filesystem::path& icon_path) {
|
bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image) {
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
#pragma pack(push, 2)
|
#pragma pack(push, 2)
|
||||||
struct IconDir {
|
struct IconDir {
|
||||||
|
@ -142,7 +142,6 @@ bool SaveIconToFile(const QImage& image, const std::filesystem::path& icon_path)
|
||||||
} else {
|
} else {
|
||||||
LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string());
|
LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
#else
|
#else
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -15,21 +15,15 @@
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a circle pixmap from a specified color
|
* Creates a circle pixmap from a specified color
|
||||||
*
|
|
||||||
* @param color The color the pixmap shall have
|
* @param color The color the pixmap shall have
|
||||||
*
|
|
||||||
* @return QPixmap circle pixmap
|
* @return QPixmap circle pixmap
|
||||||
*/
|
*/
|
||||||
|
|
||||||
[[nodiscard]] QPixmap CreateCirclePixmapFromColor(const QColor& color);
|
[[nodiscard]] QPixmap CreateCirclePixmapFromColor(const QColor& color);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a windows icon to a file
|
* Saves a windows icon to a file
|
||||||
*
|
|
||||||
* @param image The image to save
|
|
||||||
*
|
|
||||||
* @param path The icons path
|
* @param path The icons path
|
||||||
*
|
* @param image The image to save
|
||||||
* @return bool If the operation succeeded
|
* @return bool If the operation succeeded
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] bool SaveIconToFile(const QImage& image, const std::filesystem::path& icon_path);
|
[[nodiscard]] bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image);
|
||||||
|
|
Loading…
Reference in New Issue