summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar DanielSvoboda2023-10-13 12:57:49 -0300
committerGravatar GitHub2023-10-13 09:57:49 -0600
commit56e5d996846e72b3ffa8bf8a462e0ee81f3e2c1f (patch)
treef33506b4a74270ff153e486f99f3a4a8efab36b7 /src
parentMerge pull request #11769 from liamwhite/qt-ownership-issue (diff)
downloadyuzu-56e5d996846e72b3ffa8bf8a462e0ee81f3e2c1f.tar.gz
yuzu-56e5d996846e72b3ffa8bf8a462e0ee81f3e2c1f.tar.xz
yuzu-56e5d996846e72b3ffa8bf8a462e0ee81f3e2c1f.zip
Improvement in Directory Path Detection for Shortcuts (#11749)
* Improvement in Directory Path Detection for Shortcuts This pull request updates how the directory path for shortcuts is determined. The main changes are: 1. Replaced the use of environment variables to determine the path of the desktop and applications menu with `QStandardPaths::writableLocation`. This change addresses an issue where the desktop path was not correctly identified when its location was customized, as shown in the attached screenshot. 2. Added conversion from `QString` to `std::string` using `toUtf8()`, which correctly handles non-ASCII characters in directory paths. This change ensures that directory paths containing Portuguese words like "Área de trabalho" are supported. 3. Replaced directory checking using `Common::FS::IsDir()` with `QDir::exists()`. These changes should improve cross-platform compatibility and code robustness. Because it couldn't locate my desktop, which wasn't on the C drive, but on the F, and even though localization wouldn't work because it was setting it to find the 'Desktop' folder and in the computer's language it says 'Área de trabalho', that will fix for other languages too. * Update main.cpp * formatting * Update src/yuzu/main.cpp Co-authored-by: Tobias <thm.frey@gmail.com> * Update src/yuzu/main.cpp Co-authored-by: Tobias <thm.frey@gmail.com> * Update main.cpp * Update main.cpp * Update main.cpp desktopPath > desktop_Path applicationsPath > applications_Path * Update main.cpp * formatting * Update main.cpp This code will attempt to use QStandardPaths to find the applications directory. If that fails, it will resort to using the ~/.local/share/applications directory, which is a common location for application shortcuts in Linux. * Update main.cpp * formatting --------- Co-authored-by: Tobias <thm.frey@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/yuzu/main.cpp68
1 files changed, 38 insertions, 30 deletions
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index 5427758c1..1a6b63856 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -67,6 +67,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
67#define QT_NO_OPENGL 67#define QT_NO_OPENGL
68#include <QClipboard> 68#include <QClipboard>
69#include <QDesktopServices> 69#include <QDesktopServices>
70#include <QDir>
70#include <QFile> 71#include <QFile>
71#include <QFileDialog> 72#include <QFileDialog>
72#include <QInputDialog> 73#include <QInputDialog>
@@ -76,6 +77,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual
76#include <QPushButton> 77#include <QPushButton>
77#include <QScreen> 78#include <QScreen>
78#include <QShortcut> 79#include <QShortcut>
80#include <QStandardPaths>
79#include <QStatusBar> 81#include <QStatusBar>
80#include <QString> 82#include <QString>
81#include <QSysInfo> 83#include <QSysInfo>
@@ -2869,44 +2871,50 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
2869#endif // __linux__ 2871#endif // __linux__
2870 2872
2871 std::filesystem::path target_directory{}; 2873 std::filesystem::path target_directory{};
2872 // Determine target directory for shortcut
2873#if defined(WIN32)
2874 const char* home = std::getenv("USERPROFILE");
2875#else
2876 const char* home = std::getenv("HOME");
2877#endif
2878 const std::filesystem::path home_path = (home == nullptr ? "~" : home);
2879 const char* xdg_data_home = std::getenv("XDG_DATA_HOME");
2880 2874
2881 if (target == GameListShortcutTarget::Desktop) { 2875 switch (target) {
2882 target_directory = home_path / "Desktop"; 2876 case GameListShortcutTarget::Desktop: {
2883 if (!Common::FS::IsDir(target_directory)) { 2877 const QString desktop_path =
2884 QMessageBox::critical( 2878 QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
2885 this, tr("Create Shortcut"), 2879 target_directory = desktop_path.toUtf8().toStdString();
2886 tr("Cannot create shortcut on desktop. Path \"%1\" does not exist.") 2880 break;
2887 .arg(QString::fromStdString(target_directory.generic_string())), 2881 }
2888 QMessageBox::StandardButton::Ok); 2882 case GameListShortcutTarget::Applications: {
2889 return; 2883 const QString applications_path =
2890 } 2884 QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
2891 } else if (target == GameListShortcutTarget::Applications) { 2885 if (applications_path.isEmpty()) {
2892 target_directory = (xdg_data_home == nullptr ? home_path / ".local/share" : xdg_data_home) / 2886 const char* home = std::getenv("HOME");
2893 "applications"; 2887 if (home != nullptr) {
2894 if (!Common::FS::CreateDirs(target_directory)) { 2888 target_directory = std::filesystem::path(home) / ".local/share/applications";
2895 QMessageBox::critical( 2889 }
2896 this, tr("Create Shortcut"), 2890 } else {
2897 tr("Cannot create shortcut in applications menu. Path \"%1\" " 2891 target_directory = applications_path.toUtf8().toStdString();
2898 "does not exist and cannot be created.")
2899 .arg(QString::fromStdString(target_directory.generic_string())),
2900 QMessageBox::StandardButton::Ok);
2901 return;
2902 } 2892 }
2893 break;
2894 }
2895 default:
2896 return;
2897 }
2898
2899 const QDir dir(QString::fromStdString(target_directory.generic_string()));
2900 if (!dir.exists()) {
2901 QMessageBox::critical(this, tr("Create Shortcut"),
2902 tr("Cannot create shortcut. Path \"%1\" does not exist.")
2903 .arg(QString::fromStdString(target_directory.generic_string())),
2904 QMessageBox::StandardButton::Ok);
2905 return;
2903 } 2906 }
2904 2907
2905 const std::string game_file_name = std::filesystem::path(game_path).filename().string(); 2908 const std::string game_file_name = std::filesystem::path(game_path).filename().string();
2906 // Determine full paths for icon and shortcut 2909 // Determine full paths for icon and shortcut
2907#if defined(__linux__) || defined(__FreeBSD__) 2910#if defined(__linux__) || defined(__FreeBSD__)
2911 const char* home = std::getenv("HOME");
2912 const std::filesystem::path home_path = (home == nullptr ? "~" : home);
2913 const char* xdg_data_home = std::getenv("XDG_DATA_HOME");
2914
2908 std::filesystem::path system_icons_path = 2915 std::filesystem::path system_icons_path =
2909 (xdg_data_home == nullptr ? home_path / ".local/share/" : xdg_data_home) / 2916 (xdg_data_home == nullptr ? home_path / ".local/share/"
2917 : std::filesystem::path(xdg_data_home)) /
2910 "icons/hicolor/256x256"; 2918 "icons/hicolor/256x256";
2911 if (!Common::FS::CreateDirs(system_icons_path)) { 2919 if (!Common::FS::CreateDirs(system_icons_path)) {
2912 QMessageBox::critical( 2920 QMessageBox::critical(