Update main.cpp

This commit is contained in:
DanielSvoboda 2023-10-11 19:54:30 -03:00 committed by GitHub
commit 7961fe6189
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2872,36 +2872,31 @@ void GMainWindow::OnGameListCreateShortcut(u64 program_id, const std::string& ga
std::filesystem::path target_directory{}; std::filesystem::path target_directory{};
// Determine target directory for shortcut switch (target) {
if (target == GameListShortcutTarget::Desktop) { case GameListShortcutTarget::Desktop: {
const auto desktop_path = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation); const QString desktopPath =
target_directory = desktop_path.toUtf8().toStdString(); QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
const QDir dir(QString::fromStdString(target_directory.generic_string())); target_directory = desktopPath.toUtf8().toStdString();
if (!dir.exists()) { break;
QMessageBox::critical(
this, tr("Create Shortcut"),
tr("Cannot create shortcut on desktop. Path \"%1\" does not exist.")
.arg(QString::fromStdString(target_directory.generic_string())),
QMessageBox::StandardButton::Ok);
return;
} }
} else if (target == GameListShortcutTarget::Applications) { case GameListShortcutTarget::Applications: {
#if defined(__linux__) const QString applicationsPath =
QString applicationsPath =
QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation); QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation);
target_directory = applicationsPath.toUtf8().toStdString(); target_directory = applicationsPath.toUtf8().toStdString();
QDir dir(QString::fromStdString(target_directory.generic_string())); break;
}
default:
return;
}
const QDir dir(QString::fromStdString(target_directory.generic_string()));
if (!dir.exists()) { if (!dir.exists()) {
QMessageBox::critical( QMessageBox::critical(this, tr("Create Shortcut"),
this, tr("Create Shortcut"), tr("Cannot create shortcut. Path \"%1\" does not exist.")
tr("Cannot create shortcut in applications menu. Path \"%1\" "
"does not exist and cannot be created.")
.arg(QString::fromStdString(target_directory.generic_string())), .arg(QString::fromStdString(target_directory.generic_string())),
QMessageBox::StandardButton::Ok); QMessageBox::StandardButton::Ok);
return; return;
} }
#endif
}
const std::string game_file_name = std::filesystem::path(game_path).filename().string(); const std::string game_file_name = std::filesystem::path(game_path).filename().string();
// Determine full paths for icon and shortcut // Determine full paths for icon and shortcut