diff options
Diffstat (limited to 'src/organizercore.cpp')
| -rw-r--r-- | src/organizercore.cpp | 163 |
1 files changed, 0 insertions, 163 deletions
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) |
