diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-05-26 06:52:45 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-05-26 06:52:45 -0400 |
| commit | fce3c9f8c3058d9975ccc634be3572a431c1a50d (patch) | |
| tree | 09cf0f21afe1352452ce2b1d58892b9044a8e2f5 /src | |
| parent | 2caa688e5581849441b1c96e4a2d357e9241f74a (diff) | |
moved shell functions to uibase
Diffstat (limited to 'src')
| -rw-r--r-- | src/motddialog.cpp | 3 | ||||
| -rw-r--r-- | src/organizercore.cpp | 163 | ||||
| -rw-r--r-- | src/organizercore.h | 13 |
3 files changed, 3 insertions, 176 deletions
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 <http://www.gnu.org/licenses/>. #include "utility.h"
#include "ui_motddialog.h"
#include "organizercore.h"
+#include <utility.h>
#include <Shlwapi.h>
+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<int>(reinterpret_cast<std::size_t>(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<HINSTANCE>(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
{
|
