diff options
| -rw-r--r-- | src/yuzu/main.cpp | 68 |
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( |