diff options
| author | 2023-10-15 20:57:06 -0300 | |
|---|---|---|
| committer | 2023-10-15 20:57:06 -0300 | |
| commit | 9ffa1801c75073afb851351ecdd1a8b40e33cc5c (patch) | |
| tree | abaf913d230182e94e47bc2d9ea8783fc4e56470 /src | |
| parent | Unnecessary feature removed (diff) | |
| download | yuzu-9ffa1801c75073afb851351ecdd1a8b40e33cc5c.tar.gz yuzu-9ffa1801c75073afb851351ecdd1a8b40e33cc5c.tar.xz yuzu-9ffa1801c75073afb851351ecdd1a8b40e33cc5c.zip | |
Typing and formatting errors fixed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/fs/fs_util.cpp | 44 | ||||
| -rw-r--r-- | src/common/fs/fs_util.h | 8 | ||||
| -rw-r--r-- | src/common/fs/path_util.cpp | 8 | ||||
| -rw-r--r-- | src/yuzu/main.cpp | 24 | ||||
| -rw-r--r-- | src/yuzu/util/util.cpp | 3 | ||||
| -rw-r--r-- | src/yuzu/util/util.h | 10 |
6 files changed, 43 insertions, 54 deletions
diff --git a/src/common/fs/fs_util.cpp b/src/common/fs/fs_util.cpp index 442f63728..e77958224 100644 --- a/src/common/fs/fs_util.cpp +++ b/src/common/fs/fs_util.cpp | |||
| @@ -36,21 +36,21 @@ std::string PathToUTF8String(const std::filesystem::path& path) { | |||
| 36 | return ToUTF8String(path.u8string()); | 36 | return ToUTF8String(path.u8string()); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | std::u8string U8FilenameSantizer(const std::u8string_view u8filename) { | 39 | std::u8string U8FilenameSanitizer(const std::u8string_view u8filename) { |
| 40 | std::u8string u8path_santized{u8filename.begin(), u8filename.end()}; | 40 | std::u8string u8path_sanitized{u8filename.begin(), u8filename.end()}; |
| 41 | size_t eSizeSanitized = u8path_santized.size(); | 41 | size_t eSizeSanitized = u8path_sanitized.size(); |
| 42 | 42 | ||
| 43 | // Special case for ":", for example: 'Pepe: La secuela' --> 'Pepe - La | 43 | // The name is improved to make it look more beautiful and prohibited characters and shapes are |
| 44 | // secuela' or 'Pepe : La secuela' --> 'Pepe - La secuela' | 44 | // removed. Switch is used since it is better with many conditions. |
| 45 | for (size_t i = 0; i < eSizeSanitized; i++) { | 45 | for (size_t i = 0; i < eSizeSanitized; i++) { |
| 46 | switch (u8path_santized[i]) { | 46 | switch (u8path_sanitized[i]) { |
| 47 | case u8':': | 47 | case u8':': |
| 48 | if (i == 0 || i == eSizeSanitized - 1) { | 48 | if (i == 0 || i == eSizeSanitized - 1) { |
| 49 | u8path_santized.replace(i, 1, u8"_"); | 49 | u8path_sanitized.replace(i, 1, u8"_"); |
| 50 | } else if (u8path_santized[i - 1] == u8' ') { | 50 | } else if (u8path_sanitized[i - 1] == u8' ') { |
| 51 | u8path_santized.replace(i, 1, u8"-"); | 51 | u8path_sanitized.replace(i, 1, u8"-"); |
| 52 | } else { | 52 | } else { |
| 53 | u8path_santized.replace(i, 1, u8" -"); | 53 | u8path_sanitized.replace(i, 1, u8" -"); |
| 54 | eSizeSanitized++; | 54 | eSizeSanitized++; |
| 55 | } | 55 | } |
| 56 | break; | 56 | break; |
| @@ -63,36 +63,36 @@ std::u8string U8FilenameSantizer(const std::u8string_view u8filename) { | |||
| 63 | case u8'>': | 63 | case u8'>': |
| 64 | case u8'|': | 64 | case u8'|': |
| 65 | case u8'\0': | 65 | case u8'\0': |
| 66 | u8path_santized.replace(i, 1, u8"_"); | 66 | u8path_sanitized.replace(i, 1, u8"_"); |
| 67 | break; | 67 | break; |
| 68 | default: | 68 | default: |
| 69 | break; | 69 | break; |
| 70 | } | 70 | } |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | // Delete duplicated spaces || Delete duplicated dots (MacOS i think) | 73 | // Delete duplicated spaces and dots |
| 74 | for (size_t i = 0; i < eSizeSanitized - 1; i++) { | 74 | for (size_t i = 0; i < eSizeSanitized - 1; i++) { |
| 75 | if ((u8path_santized[i] == u8' ' && u8path_santized[i + 1] == u8' ') || | 75 | if ((u8path_sanitized[i] == u8' ' && u8path_sanitized[i + 1] == u8' ') || |
| 76 | (u8path_santized[i] == u8'.' && u8path_santized[i + 1] == u8'.')) { | 76 | (u8path_sanitized[i] == u8'.' && u8path_sanitized[i + 1] == u8'.')) { |
| 77 | u8path_santized.erase(i, 1); | 77 | u8path_sanitized.erase(i, 1); |
| 78 | i--; | 78 | i--; |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | // Delete all spaces and dots at the end (Windows almost) | 82 | // Delete all spaces and dots at the end of the name |
| 83 | while (u8path_santized.back() == u8' ' || u8path_santized.back() == u8'.') { | 83 | while (u8path_sanitized.back() == u8' ' || u8path_sanitized.back() == u8'.') { |
| 84 | u8path_santized.pop_back(); | 84 | u8path_sanitized.pop_back(); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | if (u8path_santized.empty()) { | 87 | if (u8path_sanitized.empty()) { |
| 88 | return u8""; | 88 | return u8""; |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | return u8path_santized; | 91 | return u8path_sanitized; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | std::string UTF8FilenameSantizer(const std::string_view filename) { | 94 | std::string UTF8FilenameSanitizer(const std::string_view filename) { |
| 95 | return ToUTF8String(U8FilenameSantizer(ToU8String(filename))); | 95 | return ToUTF8String(U8FilenameSanitizer(ToU8String(filename))); |
| 96 | } | 96 | } |
| 97 | 97 | ||
| 98 | } // namespace Common::FS | 98 | } // namespace Common::FS |
diff --git a/src/common/fs/fs_util.h b/src/common/fs/fs_util.h index dbb4f5a9a..daec1f8cb 100644 --- a/src/common/fs/fs_util.h +++ b/src/common/fs/fs_util.h | |||
| @@ -87,19 +87,19 @@ concept IsChar = std::same_as<T, char>; | |||
| 87 | * | 87 | * |
| 88 | * @param u8_string dirty encoded filename string | 88 | * @param u8_string dirty encoded filename string |
| 89 | * | 89 | * |
| 90 | * @returns utf8_string santized filename string | 90 | * @returns utf8_string sanitized filename string |
| 91 | * | 91 | * |
| 92 | */ | 92 | */ |
| 93 | [[nodiscard]] std::u8string U8FilenameSantizer(const std::u8string_view u8filename); | 93 | [[nodiscard]] std::u8string U8FilenameSanitizer(const std::u8string_view u8filename); |
| 94 | 94 | ||
| 95 | /** | 95 | /** |
| 96 | * Fix filename (remove invalid characters) | 96 | * Fix filename (remove invalid characters) |
| 97 | * | 97 | * |
| 98 | * @param utf8_string dirty encoded filename string | 98 | * @param utf8_string dirty encoded filename string |
| 99 | * | 99 | * |
| 100 | * @returns utf8_string santized filename string | 100 | * @returns utf8_string sanitized filename string |
| 101 | * | 101 | * |
| 102 | */ | 102 | */ |
| 103 | [[nodiscard]] std::string UTF8FilenameSantizer(const std::string_view filename); | 103 | [[nodiscard]] std::string UTF8FilenameSanitizer(const std::string_view filename); |
| 104 | 104 | ||
| 105 | } // namespace Common::FS \ No newline at end of file | 105 | } // namespace Common::FS \ No newline at end of file |
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index bccf953e4..3d88fcf4f 100644 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp | |||
| @@ -260,9 +260,8 @@ fs::path GetExeDirectory() { | |||
| 260 | // the Windows library (Filesystem converts the strings literally). | 260 | // the Windows library (Filesystem converts the strings literally). |
| 261 | return fs::path{Common::UTF16ToUTF8(wideExePath)}.parent_path(); | 261 | return fs::path{Common::UTF16ToUTF8(wideExePath)}.parent_path(); |
| 262 | } else { | 262 | } else { |
| 263 | LOG_ERROR(Common_Filesystem, | 263 | LOG_ERROR(Common_Filesystem, "Failed to get the path to the executable of the current " |
| 264 | "[GetExeDirectory] Failed to get the path to the executable of the current " | 264 | "process"); |
| 265 | "process"); | ||
| 266 | } | 265 | } |
| 267 | 266 | ||
| 268 | return fs::path{}; | 267 | return fs::path{}; |
| @@ -279,8 +278,7 @@ fs::path GetAppDataRoamingDirectory() { | |||
| 279 | // the Windows library (Filesystem converts the strings literally). | 278 | // the Windows library (Filesystem converts the strings literally). |
| 280 | return fs::path{Common::UTF16ToUTF8(wideAppdataRoamingPath)}; | 279 | return fs::path{Common::UTF16ToUTF8(wideAppdataRoamingPath)}; |
| 281 | } else { | 280 | } else { |
| 282 | LOG_ERROR(Common_Filesystem, | 281 | LOG_ERROR(Common_Filesystem, "Failed to get the path to the %APPDATA% directory"); |
| 283 | "[GetAppDataRoamingDirectory] Failed to get the path to the %APPDATA% directory"); | ||
| 284 | } | 282 | } |
| 285 | 283 | ||
| 286 | return fs::path{}; | 284 | return fs::path{}; |
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index fd68ac9b6..c3c12eeec 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp | |||
| @@ -2851,7 +2851,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path, | |||
| 2851 | 2851 | ||
| 2852 | // Replace characters that are illegal in Windows filenames | 2852 | // Replace characters that are illegal in Windows filenames |
| 2853 | std::filesystem::path shortcut_path_full = | 2853 | std::filesystem::path shortcut_path_full = |
| 2854 | shortcut_path / Common::FS::UTF8FilenameSantizer(name); | 2854 | shortcut_path / Common::FS::UTF8FilenameSanitizer(name); |
| 2855 | 2855 | ||
| 2856 | #if defined(__linux__) || defined(__FreeBSD__) | 2856 | #if defined(__linux__) || defined(__FreeBSD__) |
| 2857 | shortcut_path_full += ".desktop"; | 2857 | shortcut_path_full += ".desktop"; |
| @@ -2859,8 +2859,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path, | |||
| 2859 | shortcut_path_full += ".lnk"; | 2859 | shortcut_path_full += ".lnk"; |
| 2860 | #endif | 2860 | #endif |
| 2861 | 2861 | ||
| 2862 | LOG_INFO(Common, "[GMainWindow::CreateShortcutLink] Create shortcut path: {}", | 2862 | LOG_ERROR(Frontend, "Create shortcut path: {}", shortcut_path_full.string()); |
| 2863 | shortcut_path_full.string()); | ||
| 2864 | 2863 | ||
| 2865 | #if defined(__linux__) || defined(__FreeBSD__) | 2864 | #if defined(__linux__) || defined(__FreeBSD__) |
| 2866 | // This desktop file template was writing referencing | 2865 | // This desktop file template was writing referencing |
| @@ -2869,7 +2868,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path, | |||
| 2869 | 2868 | ||
| 2870 | // Plus 'Type' is required | 2869 | // Plus 'Type' is required |
| 2871 | if (name.empty()) { | 2870 | if (name.empty()) { |
| 2872 | LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Name is empty"); | 2871 | LOG_ERROR(Frontend, "Name is empty"); |
| 2873 | shortcut_succeeded = false; | 2872 | shortcut_succeeded = false; |
| 2874 | return shortcut_succeeded; | 2873 | return shortcut_succeeded; |
| 2875 | } | 2874 | } |
| @@ -2911,14 +2910,13 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path, | |||
| 2911 | return true; | 2910 | return true; |
| 2912 | 2911 | ||
| 2913 | } else { | 2912 | } else { |
| 2914 | LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Failed to create shortcut"); | 2913 | LOG_ERROR(Frontend, "Failed to create shortcut"); |
| 2915 | return false; | 2914 | return false; |
| 2916 | } | 2915 | } |
| 2917 | 2916 | ||
| 2918 | shortcut_stream.close(); | 2917 | shortcut_stream.close(); |
| 2919 | } catch (const std::exception& e) { | 2918 | } catch (const std::exception& e) { |
| 2920 | LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Failed to create shortcut: {}", | 2919 | LOG_ERROR(Frontend, "Failed to create shortcut: {}", e.what()); |
| 2921 | e.what()); | ||
| 2922 | } | 2920 | } |
| 2923 | #elif defined(_WIN32) | 2921 | #elif defined(_WIN32) |
| 2924 | // Initialize COM | 2922 | // Initialize COM |
| @@ -2970,7 +2968,7 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path, | |||
| 2970 | pPersistFile->Release(); | 2968 | pPersistFile->Release(); |
| 2971 | } | 2969 | } |
| 2972 | } else { | 2970 | } else { |
| 2973 | LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Failed to create IShellLinkWinstance"); | 2971 | LOG_ERROR(Frontend, "Failed to create IShellLinkWinstance"); |
| 2974 | } | 2972 | } |
| 2975 | 2973 | ||
| 2976 | ps1->Release(); | 2974 | ps1->Release(); |
| @@ -2978,9 +2976,9 @@ bool GMainWindow::CreateShortcutLink(const std::filesystem::path& shortcut_path, | |||
| 2978 | #endif | 2976 | #endif |
| 2979 | 2977 | ||
| 2980 | if (shortcut_succeeded && std::filesystem::is_regular_file(shortcut_path_full)) { | 2978 | if (shortcut_succeeded && std::filesystem::is_regular_file(shortcut_path_full)) { |
| 2981 | LOG_INFO(Common, "[GMainWindow::CreateShortcutLink] Shortcut created"); | 2979 | LOG_ERROR(Frontend, "Shortcut created"); |
| 2982 | } else { | 2980 | } else { |
| 2983 | LOG_ERROR(Common, "[GMainWindow::CreateShortcutLink] Shortcut error, failed to create it"); | 2981 | LOG_ERROR(Frontend, "Shortcut error, failed to create it"); |
| 2984 | shortcut_succeeded = false; | 2982 | shortcut_succeeded = false; |
| 2985 | } | 2983 | } |
| 2986 | 2984 | ||
| @@ -3047,7 +3045,7 @@ bool GMainWindow::MakeShortcutIcoPath(const u64 program_id, const std::string_vi | |||
| 3047 | icons_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "icons"; | 3045 | icons_path = Common::FS::GetYuzuPath(Common::FS::YuzuPath::ConfigDir) / "icons"; |
| 3048 | ico_extension = "ico"; | 3046 | ico_extension = "ico"; |
| 3049 | #elif defined(__linux__) || defined(__FreeBSD__) | 3047 | #elif defined(__linux__) || defined(__FreeBSD__) |
| 3050 | icons_path = GetDataDirectory("XDG_DATA_HOME") / "icons/hicolor/256x256"; | 3048 | icons_path = Common::FS::GetDataDirectory("XDG_DATA_HOME") / "icons/hicolor/256x256"; |
| 3051 | #endif | 3049 | #endif |
| 3052 | 3050 | ||
| 3053 | // Create icons directory if it doesn't exist | 3051 | // Create icons directory if it doesn't exist |
| @@ -3130,7 +3128,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga | |||
| 3130 | QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); | 3128 | QImage::fromData(icon_image_file.data(), static_cast<int>(icon_image_file.size())); |
| 3131 | 3129 | ||
| 3132 | if (GMainWindow::MakeShortcutIcoPath(program_id, title, icons_path)) { | 3130 | if (GMainWindow::MakeShortcutIcoPath(program_id, title, icons_path)) { |
| 3133 | if (!SaveIconToFile(icon_data, icons_path)) { | 3131 | if (!SaveIconToFile(icons_path, icon_data)) { |
| 3134 | LOG_ERROR(Frontend, "Could not write icon to file"); | 3132 | LOG_ERROR(Frontend, "Could not write icon to file"); |
| 3135 | } | 3133 | } |
| 3136 | } | 3134 | } |
| @@ -3138,7 +3136,7 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga | |||
| 3138 | } else { | 3136 | } else { |
| 3139 | GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, | 3137 | GMainWindow::CreateShortcutMessagesGUI(this, GMainWindow::CREATE_SHORTCUT_MSGBOX_ERROR, |
| 3140 | title); | 3138 | title); |
| 3141 | LOG_ERROR(Frontend, "[GMainWindow::OnGameListCreateShortcut] Invalid shortcut target"); | 3139 | LOG_ERROR(Frontend, "Invalid shortcut target"); |
| 3142 | return; | 3140 | return; |
| 3143 | } | 3141 | } |
| 3144 | 3142 | ||
diff --git a/src/yuzu/util/util.cpp b/src/yuzu/util/util.cpp index 9755004ad..7b2a47496 100644 --- a/src/yuzu/util/util.cpp +++ b/src/yuzu/util/util.cpp | |||
| @@ -42,7 +42,7 @@ QPixmap CreateCirclePixmapFromColor(const QColor& color) { | |||
| 42 | return circle_pixmap; | 42 | return circle_pixmap; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | bool SaveIconToFile(const QImage& image, const std::filesystem::path& icon_path) { | 45 | bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image) { |
| 46 | #if defined(WIN32) | 46 | #if defined(WIN32) |
| 47 | #pragma pack(push, 2) | 47 | #pragma pack(push, 2) |
| 48 | struct IconDir { | 48 | struct IconDir { |
| @@ -142,7 +142,6 @@ bool SaveIconToFile(const QImage& image, const std::filesystem::path& icon_path) | |||
| 142 | } else { | 142 | } else { |
| 143 | LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string()); | 143 | LOG_INFO(Frontend, "Wrote an icon to {}", icon_path.string()); |
| 144 | } | 144 | } |
| 145 | |||
| 146 | return true; | 145 | return true; |
| 147 | #else | 146 | #else |
| 148 | return false; | 147 | return false; |
diff --git a/src/yuzu/util/util.h b/src/yuzu/util/util.h index 31e82ff67..4094cf6c2 100644 --- a/src/yuzu/util/util.h +++ b/src/yuzu/util/util.h | |||
| @@ -15,21 +15,15 @@ | |||
| 15 | 15 | ||
| 16 | /** | 16 | /** |
| 17 | * Creates a circle pixmap from a specified color | 17 | * Creates a circle pixmap from a specified color |
| 18 | * | ||
| 19 | * @param color The color the pixmap shall have | 18 | * @param color The color the pixmap shall have |
| 20 | * | ||
| 21 | * @return QPixmap circle pixmap | 19 | * @return QPixmap circle pixmap |
| 22 | */ | 20 | */ |
| 23 | |||
| 24 | [[nodiscard]] QPixmap CreateCirclePixmapFromColor(const QColor& color); | 21 | [[nodiscard]] QPixmap CreateCirclePixmapFromColor(const QColor& color); |
| 25 | 22 | ||
| 26 | /** | 23 | /** |
| 27 | * Saves a windows icon to a file | 24 | * Saves a windows icon to a file |
| 28 | * | ||
| 29 | * @param image The image to save | ||
| 30 | * | ||
| 31 | * @param path The icons path | 25 | * @param path The icons path |
| 32 | * | 26 | * @param image The image to save |
| 33 | * @return bool If the operation succeeded | 27 | * @return bool If the operation succeeded |
| 34 | */ | 28 | */ |
| 35 | [[nodiscard]] bool SaveIconToFile(const QImage& image, const std::filesystem::path& icon_path); | 29 | [[nodiscard]] bool SaveIconToFile(const std::filesystem::path& icon_path, const QImage& image); |