From c82c7af678c088a6b94fc8a4a0f31fc9498e8220 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sun, 26 May 2019 04:00:54 -0400 Subject: changed rest of ShellExecuteW() calls to use shell::Execute(), shell::OpenLink() or shell::OpenFile() --- src/motddialog.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/motddialog.cpp') diff --git a/src/motddialog.cpp b/src/motddialog.cpp index 96d88542..9be41d96 100644 --- a/src/motddialog.cpp +++ b/src/motddialog.cpp @@ -21,6 +21,7 @@ along with Mod Organizer. If not, see . #include "bbcode.h" #include "utility.h" #include "ui_motddialog.h" +#include "organizercore.h" #include MotDDialog::MotDDialog(const QString &message, QWidget *parent) @@ -43,5 +44,5 @@ void MotDDialog::on_okButton_clicked() void MotDDialog::linkClicked(const QUrl &url) { - ::ShellExecuteW(nullptr, L"open", MOBase::ToWString(url.toString()).c_str(), nullptr, nullptr, SW_SHOWNORMAL); + shell::OpenLink(url); } -- cgit v1.3.1 From fce3c9f8c3058d9975ccc634be3572a431c1a50d Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Sun, 26 May 2019 06:52:45 -0400 Subject: moved shell functions to uibase --- src/motddialog.cpp | 3 + src/organizercore.cpp | 163 -------------------------------------------------- src/organizercore.h | 13 ---- 3 files changed, 3 insertions(+), 176 deletions(-) (limited to 'src/motddialog.cpp') diff --git a/src/motddialog.cpp b/src/motddialog.cpp index 9be41d96..ca1e60ad 100644 --- a/src/motddialog.cpp +++ b/src/motddialog.cpp @@ -22,8 +22,11 @@ along with Mod Organizer. If not, see . #include "utility.h" #include "ui_motddialog.h" #include "organizercore.h" +#include #include +using namespace MOBase; + MotDDialog::MotDDialog(const QString &message, QWidget *parent) : QDialog(parent), ui(new Ui::MotDDialog) { diff --git a/src/organizercore.cpp b/src/organizercore.cpp index d3de3e01..19b53b8d 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -269,169 +269,6 @@ bool checkService() } -const char* ShellExecuteError(int i) -{ - switch (i) { - case 0: - return "The operating system is out of memory or resources"; - - case ERROR_FILE_NOT_FOUND: - return "The specified file was not found"; - - case ERROR_PATH_NOT_FOUND: - return "The specified path was not found"; - - case ERROR_BAD_FORMAT: - return "The .exe file is invalid (non-Win32 .exe or error in .exe image)"; - - case SE_ERR_ACCESSDENIED: - return "The operating system denied access to the specified file"; - - case SE_ERR_ASSOCINCOMPLETE: - return "The file name association is incomplete or invalid"; - - case SE_ERR_DDEBUSY: - return "The DDE transaction could not be completed because other DDE " - "transactions were being processed"; - - case SE_ERR_DDEFAIL: - return "The DDE transaction failed"; - - case SE_ERR_DDETIMEOUT: - return "The DDE transaction could not be completed because the request " - "timed out"; - - case SE_ERR_DLLNOTFOUND: - return "The specified DLL was not found"; - - case SE_ERR_NOASSOC: - return "There is no application associated with the given file name " - "extension"; - - case SE_ERR_OOM: - return "There was not enough memory to complete the operation"; - - case SE_ERR_SHARE: - return "A sharing violation occurred"; - - default: - return "Unknown error"; - } -} - -void LogShellFailure( - const wchar_t* operation, const wchar_t* file, const wchar_t* params, - HINSTANCE h) -{ - const auto code = static_cast(reinterpret_cast(h)); - - QString s = "failed to invoke"; - - if (operation) { - s += " " + QString::fromWCharArray(operation); - } - - if (file) { - s += " " + QString::fromWCharArray(file); - } - - if (params) { - s += " " + QString::fromWCharArray(params); - } - - qCritical( - "failed to invoke %s: %s (error %d)", - s, ShellExecuteError(code), code); -} - -bool ShellExecuteWrapper( - const wchar_t* operation, const wchar_t* file, const wchar_t* params) -{ - const auto h = ::ShellExecuteW( - 0, operation, file, params, nullptr, SW_SHOWNORMAL); - - // anything <= 32 is not an actual HINSTANCE and signals failure - if (h <= reinterpret_cast(32)) - { - LogShellFailure(operation, file, params, h); - return false; - } - - return true; -} - -bool ExploreDirectory(const QFileInfo& info) -{ - const auto path = QDir::toNativeSeparators(info.absoluteFilePath()); - const auto ws_path = path.toStdWString(); - - return ShellExecuteWrapper(L"explore", ws_path.c_str(), nullptr); -} - -bool ExploreFileInDirectory(const QFileInfo& info) -{ - const auto path = QDir::toNativeSeparators(info.absoluteFilePath()); - const auto params = "/select,\"" + path + "\""; - const auto ws_params = params.toStdWString(); - - return ShellExecuteWrapper(nullptr, L"explorer", ws_params.c_str()); -} - - -namespace shell -{ - -bool ExploreFile(const QFileInfo& info) -{ - if (info.isFile()) { - return ExploreFileInDirectory(info); - } else if (info.isDir()) { - return ExploreDirectory(info); - } else { - // try the parent directory - const auto parent = info.dir(); - - if (parent.exists()) { - return ExploreDirectory(parent.absolutePath()); - } - } - - return false; -} - -bool ExploreFile(const QString& path) -{ - return ExploreFile(QFileInfo(path)); -} - -bool ExploreFile(const QDir& dir) -{ - return ExploreFile(QFileInfo(dir.absolutePath())); -} - -bool OpenFile(const QString& path) -{ - const auto ws_path = path.toStdWString(); - return ShellExecuteWrapper(L"open", ws_path.c_str(), nullptr); -} - -bool OpenLink(const QUrl& url) -{ - const auto ws_url = url.toString().toStdWString(); - return ShellExecuteWrapper(L"open", ws_url.c_str(), nullptr); -} - -bool Execute(const QString& program, const QString& params) -{ - const auto program_ws = program.toStdWString(); - const auto params_ws = params.toStdWString(); - - return ShellExecuteWrapper(L"open", program_ws.c_str(), params_ws.c_str()); -} - -} // namespace shell - - OrganizerCore::OrganizerCore(const QSettings &initSettings) : m_UserInterface(nullptr) , m_PluginContainer(nullptr) diff --git a/src/organizercore.h b/src/organizercore.h index 9c4e3ae2..e24227b7 100644 --- a/src/organizercore.h +++ b/src/organizercore.h @@ -57,19 +57,6 @@ namespace MOBase { } -namespace shell -{ - bool ExploreFile(const QFileInfo& info); - bool ExploreFile(const QString& path); - bool ExploreFile(const QDir& dir); - - bool OpenFile(const QString& path); - bool OpenLink(const QUrl& url); - - bool Execute(const QString& program, const QString& params); -} - - class OrganizerCore : public QObject, public MOBase::IPluginDiagnose { -- cgit v1.3.1