diff options
| author | 2023-10-15 02:02:22 -0300 | |
|---|---|---|
| committer | 2023-10-15 02:02:22 -0300 | |
| commit | 3062a35eb1297067446156c43e9d0df2f684edff (patch) | |
| tree | f2ca58e0b8a6c413f3c6783a1501204729e0394c /src/common/fs/path_util.cpp | |
| parent | Merge pull request #11780 from Darkness4/master (diff) | |
| download | yuzu-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/path_util.cpp')
| -rw-r--r-- | src/common/fs/path_util.cpp | 87 |
1 files changed, 74 insertions, 13 deletions
diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index 0abd81a45..a461161ed 100644 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <unordered_map> | 6 | #include <unordered_map> |
| 7 | 7 | ||
| 8 | #include "common/fs/fs.h" | 8 | #include "common/fs/fs.h" |
| 9 | #include "common/string_util.h" | ||
| 9 | #ifdef ANDROID | 10 | #ifdef ANDROID |
| 10 | #include "common/fs/fs_android.h" | 11 | #include "common/fs/fs_android.h" |
| 11 | #endif | 12 | #endif |
| @@ -14,7 +15,7 @@ | |||
| 14 | #include "common/logging/log.h" | 15 | #include "common/logging/log.h" |
| 15 | 16 | ||
| 16 | #ifdef _WIN32 | 17 | #ifdef _WIN32 |
| 17 | #include <shlobj.h> // Used in GetExeDirectory() | 18 | #include <shlobj.h> // Used in GetExeDirectory() and GetWindowsDesktop() |
| 18 | #else | 19 | #else |
| 19 | #include <cstdlib> // Used in Get(Home/Data)Directory() | 20 | #include <cstdlib> // Used in Get(Home/Data)Directory() |
| 20 | #include <pwd.h> // Used in GetHomeDirectory() | 21 | #include <pwd.h> // Used in GetHomeDirectory() |
| @@ -250,30 +251,39 @@ void SetYuzuPath(YuzuPath yuzu_path, const fs::path& new_path) { | |||
| 250 | #ifdef _WIN32 | 251 | #ifdef _WIN32 |
| 251 | 252 | ||
| 252 | fs::path GetExeDirectory() { | 253 | fs::path GetExeDirectory() { |
| 253 | wchar_t exe_path[MAX_PATH]; | 254 | WCHAR exe_path[MAX_PATH]; |
| 254 | 255 | ||
| 255 | if (GetModuleFileNameW(nullptr, exe_path, MAX_PATH) == 0) { | 256 | if (SUCCEEDED(GetModuleFileNameW(nullptr, exe_path, MAX_PATH))) { |
| 257 | std::wstring wideExePath(exe_path); | ||
| 258 | |||
| 259 | // UTF-16 filesystem lib to UTF-8 is broken, so we need to convert to UTF-8 with the with | ||
| 260 | // the Windows library (Filesystem converts the strings literally). | ||
| 261 | return fs::path{Common::UTF16ToUTF8(wideExePath)}.parent_path(); | ||
| 262 | } else { | ||
| 256 | LOG_ERROR(Common_Filesystem, | 263 | LOG_ERROR(Common_Filesystem, |
| 257 | "Failed to get the path to the executable of the current process"); | 264 | "[GetExeDirectory] Failed to get the path to the executable of the current " |
| 265 | "process"); | ||
| 258 | } | 266 | } |
| 259 | 267 | ||
| 260 | return fs::path{exe_path}.parent_path(); | 268 | return fs::path{}; |
| 261 | } | 269 | } |
| 262 | 270 | ||
| 263 | fs::path GetAppDataRoamingDirectory() { | 271 | fs::path GetAppDataRoamingDirectory() { |
| 264 | PWSTR appdata_roaming_path = nullptr; | 272 | PWSTR appdata_roaming_path = nullptr; |
| 265 | 273 | ||
| 266 | SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &appdata_roaming_path); | 274 | if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &appdata_roaming_path))) { |
| 267 | 275 | std::wstring wideAppdataRoamingPath(appdata_roaming_path); | |
| 268 | auto fs_appdata_roaming_path = fs::path{appdata_roaming_path}; | 276 | CoTaskMemFree(appdata_roaming_path); |
| 269 | |||
| 270 | CoTaskMemFree(appdata_roaming_path); | ||
| 271 | 277 | ||
| 272 | if (fs_appdata_roaming_path.empty()) { | 278 | // UTF-16 filesystem lib to UTF-8 is broken, so we need to convert to UTF-8 with the with |
| 273 | LOG_ERROR(Common_Filesystem, "Failed to get the path to the %APPDATA% directory"); | 279 | // the Windows library (Filesystem converts the strings literally). |
| 280 | return fs::path{Common::UTF16ToUTF8(wideAppdataRoamingPath)}; | ||
| 281 | } else { | ||
| 282 | LOG_ERROR(Common_Filesystem, | ||
| 283 | "[GetAppDataRoamingDirectory] Failed to get the path to the %APPDATA% directory"); | ||
| 274 | } | 284 | } |
| 275 | 285 | ||
| 276 | return fs_appdata_roaming_path; | 286 | return fs::path{}; |
| 277 | } | 287 | } |
| 278 | 288 | ||
| 279 | #else | 289 | #else |
| @@ -338,6 +348,57 @@ fs::path GetBundleDirectory() { | |||
| 338 | 348 | ||
| 339 | #endif | 349 | #endif |
| 340 | 350 | ||
| 351 | fs::path GetDesktopPath() { | ||
| 352 | #if defined(_WIN32) | ||
| 353 | PWSTR DesktopPath = nullptr; | ||
| 354 | |||
| 355 | if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Desktop, 0, NULL, &DesktopPath))) { | ||
| 356 | std::wstring wideDesktopPath(DesktopPath); | ||
| 357 | CoTaskMemFree(DesktopPath); | ||
| 358 | |||
| 359 | // UTF-16 filesystem lib to UTF-8 is broken, so we need to convert to UTF-8 with the with | ||
| 360 | // the Windows library (Filesystem converts the strings literally). | ||
| 361 | return fs::path{Common::UTF16ToUTF8(wideDesktopPath)}; | ||
| 362 | } else { | ||
| 363 | LOG_ERROR(Common_Filesystem, | ||
| 364 | "[GetDesktopPath] Failed to get the path to the desktop directory"); | ||
| 365 | } | ||
| 366 | #else | ||
| 367 | fs::path shortcut_path = GetHomeDirectory() / "Desktop"; | ||
| 368 | if (fs::exists(shortcut_path)) { | ||
| 369 | return shortcut_path; | ||
| 370 | } | ||
| 371 | #endif | ||
| 372 | return fs::path{}; | ||
| 373 | } | ||
| 374 | |||
| 375 | fs::path GetAppsShortcutsPath() { | ||
| 376 | #if defined(_WIN32) | ||
| 377 | PWSTR AppShortcutsPath = nullptr; | ||
| 378 | |||
| 379 | if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_CommonPrograms, 0, NULL, &AppShortcutsPath))) { | ||
| 380 | std::wstring wideAppShortcutsPath(AppShortcutsPath); | ||
| 381 | CoTaskMemFree(AppShortcutsPath); | ||
| 382 | |||
| 383 | // UTF-16 filesystem lib to UTF-8 is broken, so we need to convert to UTF-8 with the with | ||
| 384 | // the Windows library (Filesystem converts the strings literally). | ||
| 385 | return fs::path{Common::UTF16ToUTF8(wideAppShortcutsPath)}; | ||
| 386 | } else { | ||
| 387 | LOG_ERROR(Common_Filesystem, | ||
| 388 | "[GetAppsShortcutsPath] Failed to get the path to the App Shortcuts directory"); | ||
| 389 | } | ||
| 390 | #else | ||
| 391 | fs::path shortcut_path = GetHomeDirectory() / ".local/share/applications"; | ||
| 392 | if (!fs::exists(shortcut_path)) { | ||
| 393 | shortcut_path = std::filesystem::path("/usr/share/applications"); | ||
| 394 | return shortcut_path; | ||
| 395 | } else { | ||
| 396 | return shortcut_path; | ||
| 397 | } | ||
| 398 | #endif | ||
| 399 | return fs::path{}; | ||
| 400 | } | ||
| 401 | |||
| 341 | // vvvvvvvvvv Deprecated vvvvvvvvvv // | 402 | // vvvvvvvvvv Deprecated vvvvvvvvvv // |
| 342 | 403 | ||
| 343 | std::string_view RemoveTrailingSlash(std::string_view path) { | 404 | std::string_view RemoveTrailingSlash(std::string_view path) { |