From 6f306121a6e7e7e846cef9c4927be4644714db19 Mon Sep 17 00:00:00 2001 From: Megamouse Date: Sat, 10 Dec 2022 18:29:44 +0100 Subject: [PATCH] Qt: fix opening folders by using util functions --- rpcs3/emucore.vcxproj.filters | 1 + rpcs3/rpcs3qt/qt_utils.cpp | 38 ++++++++++++++++++++++--- rpcs3/rpcs3qt/save_manager_dialog.cpp | 4 +-- rpcs3/rpcs3qt/trophy_manager_dialog.cpp | 4 +-- rpcs3/rpcs3qt/user_manager_dialog.cpp | 3 +- 5 files changed, 41 insertions(+), 9 deletions(-) diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index daef86ecdd..0bfea0134d 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -1101,6 +1101,7 @@ Emu\Io + Emu\Cell\Modules diff --git a/rpcs3/rpcs3qt/qt_utils.cpp b/rpcs3/rpcs3qt/qt_utils.cpp index d477a58902..3aa7b1c194 100644 --- a/rpcs3/rpcs3qt/qt_utils.cpp +++ b/rpcs3/rpcs3qt/qt_utils.cpp @@ -1,3 +1,4 @@ +#include "stdafx.h" #include "qt_utils.h" #include #include @@ -12,6 +13,8 @@ #include "Utilities/File.h" #include +LOG_CHANNEL(gui_log, "GUI"); + inline std::string sstr(const QString& _in) { return _in.toStdString(); } constexpr auto qstr = QString::fromStdString; @@ -394,7 +397,6 @@ namespace gui void open_dir(const std::string& spath) { - fs::create_dir(spath); const QString path = qstr(spath); if (fs::is_file(spath)) @@ -402,18 +404,46 @@ namespace gui // open directory and select file // https://stackoverflow.com/questions/3490336/how-to-reveal-in-finder-or-show-in-explorer-with-qt #ifdef _WIN32 - QProcess::startDetached("explorer.exe", { "/select,", QDir::toNativeSeparators(path) }); + const QString cleaned_path = QDir::toNativeSeparators(path); + gui_log.notice("gui::utils::open_dir: About to open file path '%s' (original: '%s')", cleaned_path.toStdString(), spath); + + if (!QProcess::startDetached("explorer.exe", {"/select,", cleaned_path})) + { + gui_log.error("gui::utils::open_dir: Failed to start explorer process"); + } #elif defined(__APPLE__) + gui_log.notice("gui::utils::open_dir: About to open file path '%s'", spath); + QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to reveal POSIX file \"" + path + "\"" }); QProcess::execute("/usr/bin/osascript", { "-e", "tell application \"Finder\" to activate" }); #else // open parent directory - QDesktopServices::openUrl(QUrl::fromLocalFile(qstr(fs::get_parent_dir(spath)))); + const QUrl url = QUrl::fromLocalFile(qstr(fs::get_parent_dir(spath))); + const std::string url_path = url.toString().toStdString(); + gui_log.notice("gui::utils::open_dir: About to open parent dir url '%s' for path '%s'", url_path, spath); + + if (!QDesktopServices::openUrl(url)) + { + gui_log.error("gui::utils::open_dir: Failed to open parent dir url '%s' for path '%s'", url_path, spath); + } #endif return; } - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + if (!fs::is_dir && !fs::create_path(spath)) + { + gui_log.error("gui::utils::open_dir: Failed to create path '%s' (%s)", spath, fs::g_tls_error); + return; + } + + const QUrl url = QUrl::fromLocalFile(path); + const std::string url_path = url.toString().toStdString(); + gui_log.notice("gui::utils::open_dir: About to open dir url '%s' for path '%s'", url_path, spath); + + if (!QDesktopServices::openUrl(url)) + { + gui_log.error("gui::utils::open_dir: Failed to open dir url '%s' for path '%s'", url_path, spath); + } } void open_dir(const QString& path) diff --git a/rpcs3/rpcs3qt/save_manager_dialog.cpp b/rpcs3/rpcs3qt/save_manager_dialog.cpp index 072528f9c3..cf9824c941 100644 --- a/rpcs3/rpcs3qt/save_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/save_manager_dialog.cpp @@ -210,7 +210,7 @@ void save_manager_dialog::Init() } const int idx_real = item->data(Qt::UserRole).toInt(); const QString path = qstr(m_dir + m_save_entries[idx_real].dirName + "/"); - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + gui::utils::open_dir(path); }); connect(slider_icon_size, &QAbstractSlider::valueChanged, this, &save_manager_dialog::SetIconSize); connect(m_list->horizontalHeader(), &QHeaderView::sectionClicked, this, &save_manager_dialog::OnSort); @@ -488,7 +488,7 @@ void save_manager_dialog::ShowContextMenu(const QPoint &pos) } const int idx_real = item->data(Qt::UserRole).toInt(); const QString path = qstr(m_dir + m_save_entries[idx_real].dirName + "/"); - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + gui::utils::open_dir(path); }); menu->exec(m_list->viewport()->mapToGlobal(pos)); diff --git a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp index bc66e3dfe7..f23746554c 100644 --- a/rpcs3/rpcs3qt/trophy_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/trophy_manager_dialog.cpp @@ -734,7 +734,7 @@ void trophy_manager_dialog::ShowTrophyTableContextMenu(const QPoint& pos) connect(show_trophy_dir, &QAction::triggered, this, [this, db_ind]() { const QString path = qstr(m_trophies_db[db_ind]->path); - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + gui::utils::open_dir(path); }); menu->addAction(show_trophy_dir); @@ -802,7 +802,7 @@ void trophy_manager_dialog::ShowGameTableContextMenu(const QPoint& pos) connect(show_trophy_dir, &QAction::triggered, this, [this, db_ind]() { const QString path = qstr(m_trophies_db[db_ind]->path); - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + gui::utils::open_dir(path); }); menu->addAction(show_trophy_dir); diff --git a/rpcs3/rpcs3qt/user_manager_dialog.cpp b/rpcs3/rpcs3qt/user_manager_dialog.cpp index 0ecf91da3c..c1a2f1d941 100644 --- a/rpcs3/rpcs3qt/user_manager_dialog.cpp +++ b/rpcs3/rpcs3qt/user_manager_dialog.cpp @@ -17,6 +17,7 @@ #include "main_application.h" #include "gui_settings.h" #include "persistent_settings.h" +#include "qt_utils.h" #include "Emu/System.h" #include "Emu/system_utils.hpp" @@ -426,7 +427,7 @@ void user_manager_dialog::ShowContextMenu(const QPoint &pos) connect(show_dir_act, &QAction::triggered, this, [this, key]() { const QString path = qstr(m_user_list[key].GetUserDir()); - QDesktopServices::openUrl(QUrl::fromLocalFile(path)); + gui::utils::open_dir(path); }); connect(user_id_act, &QAction::triggered, this, [this] {OnSort(0); });