summaryrefslogtreecommitdiff
path: root/src/organizercore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/organizercore.cpp')
-rw-r--r--src/organizercore.cpp150
1 files changed, 86 insertions, 64 deletions
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index bdaf4ffc..2542545f 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -267,6 +267,91 @@ bool checkService()
return serviceRunning;
}
+
+bool GetFileExecutionContext(
+ QWidget* parent, const QFileInfo &targetInfo,
+ QFileInfo &binaryInfo, QString &arguments, FileExecutionTypes& type)
+{
+ QString extension = targetInfo.suffix();
+ if ((extension.compare("cmd", Qt::CaseInsensitive) == 0) ||
+ (extension.compare("com", Qt::CaseInsensitive) == 0) ||
+ (extension.compare("bat", Qt::CaseInsensitive) == 0)) {
+ binaryInfo = QFileInfo("C:\\Windows\\System32\\cmd.exe");
+ arguments = QString("/C \"%1\"").arg(QDir::toNativeSeparators(targetInfo.absoluteFilePath()));
+ type = FileExecutionTypes::executable;
+ return true;
+ } else if (extension.compare("exe", Qt::CaseInsensitive) == 0) {
+ binaryInfo = targetInfo;
+ type = FileExecutionTypes::executable;
+ return true;
+ } else if (extension.compare("jar", Qt::CaseInsensitive) == 0) {
+ // types that need to be injected into
+ std::wstring targetPathW = targetInfo.absoluteFilePath().toStdWString();
+ QString binaryPath;
+
+ { // try to find java automatically
+ WCHAR buffer[MAX_PATH];
+ if (::FindExecutableW(targetPathW.c_str(), nullptr, buffer) > (HINSTANCE)32) {
+ DWORD binaryType = 0UL;
+ if (!::GetBinaryTypeW(buffer, &binaryType)) {
+ qDebug("failed to determine binary type of \"%ls\": %lu", buffer, ::GetLastError());
+ } else if (binaryType == SCS_32BIT_BINARY) {
+ binaryPath = QString::fromWCharArray(buffer);
+ }
+ }
+ }
+ if (binaryPath.isEmpty() && (extension == "jar")) {
+ // second attempt: look to the registry
+ QSettings javaReg("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment", QSettings::NativeFormat);
+ if (javaReg.contains("CurrentVersion")) {
+ QString currentVersion = javaReg.value("CurrentVersion").toString();
+ binaryPath = javaReg.value(QString("%1/JavaHome").arg(currentVersion)).toString().append("\\bin\\javaw.exe");
+ }
+ }
+ if (binaryPath.isEmpty()) {
+ binaryPath = QFileDialog::getOpenFileName(
+ parent, QObject::tr("Select binary"), QString(), QObject::tr("Binary") + " (*.exe)");
+ }
+ if (binaryPath.isEmpty()) {
+ return false;
+ }
+ binaryInfo = QFileInfo(binaryPath);
+ if (extension == "jar") {
+ arguments = QString("-jar \"%1\"").arg(QDir::toNativeSeparators(targetInfo.absoluteFilePath()));
+ } else {
+ arguments = QString("\"%1\"").arg(QDir::toNativeSeparators(targetInfo.absoluteFilePath()));
+ }
+
+ type = FileExecutionTypes::executable;
+ return true;
+ } else {
+ type = FileExecutionTypes::other;
+ return true;
+ }
+}
+
+bool ExploreFile(const QString& path)
+{
+ const auto ws = path.toStdWString();
+
+ const auto h = ::ShellExecuteW(
+ nullptr, L"explore", ws.c_str(), nullptr, nullptr, SW_SHOWNORMAL);
+
+ // anything <= 32 is not an actual HINSTANCE and signals failure
+ return (h > reinterpret_cast<HINSTANCE>(32));
+}
+
+bool ExploreFile(const QFileInfo& info)
+{
+ return ExploreFile(info.absolutePath());
+}
+
+bool ExploreFile(const QDir& dir)
+{
+ return ExploreFile(dir.absolutePath());
+}
+
+
OrganizerCore::OrganizerCore(const QSettings &initSettings)
: m_UserInterface(nullptr)
, m_PluginContainer(nullptr)
@@ -1220,76 +1305,13 @@ QStringList OrganizerCore::modsSortedByProfilePriority() const
return res;
}
-
-bool OrganizerCore::getFileExecutionContext(
- QWidget* parent, const QFileInfo &targetInfo,
- QFileInfo &binaryInfo, QString &arguments, FileExecutionTypes& type)
-{
- QString extension = targetInfo.suffix();
- if ((extension.compare("cmd", Qt::CaseInsensitive) == 0) ||
- (extension.compare("com", Qt::CaseInsensitive) == 0) ||
- (extension.compare("bat", Qt::CaseInsensitive) == 0)) {
- binaryInfo = QFileInfo("C:\\Windows\\System32\\cmd.exe");
- arguments = QString("/C \"%1\"").arg(QDir::toNativeSeparators(targetInfo.absoluteFilePath()));
- type = FileExecutionTypes::executable;
- return true;
- } else if (extension.compare("exe", Qt::CaseInsensitive) == 0) {
- binaryInfo = targetInfo;
- type = FileExecutionTypes::executable;
- return true;
- } else if (extension.compare("jar", Qt::CaseInsensitive) == 0) {
- // types that need to be injected into
- std::wstring targetPathW = ToWString(targetInfo.absoluteFilePath());
- QString binaryPath;
-
- { // try to find java automatically
- WCHAR buffer[MAX_PATH];
- if (::FindExecutableW(targetPathW.c_str(), nullptr, buffer) > (HINSTANCE)32) {
- DWORD binaryType = 0UL;
- if (!::GetBinaryTypeW(buffer, &binaryType)) {
- qDebug("failed to determine binary type of \"%ls\": %lu", buffer, ::GetLastError());
- } else if (binaryType == SCS_32BIT_BINARY) {
- binaryPath = ToQString(buffer);
- }
- }
- }
- if (binaryPath.isEmpty() && (extension == "jar")) {
- // second attempt: look to the registry
- QSettings javaReg("HKEY_LOCAL_MACHINE\\Software\\JavaSoft\\Java Runtime Environment", QSettings::NativeFormat);
- if (javaReg.contains("CurrentVersion")) {
- QString currentVersion = javaReg.value("CurrentVersion").toString();
- binaryPath = javaReg.value(QString("%1/JavaHome").arg(currentVersion)).toString().append("\\bin\\javaw.exe");
- }
- }
- if (binaryPath.isEmpty()) {
- binaryPath = QFileDialog::getOpenFileName(
- parent, QObject::tr("Select binary"), QString(), QObject::tr("Binary") + " (*.exe)");
- }
- if (binaryPath.isEmpty()) {
- return false;
- }
- binaryInfo = QFileInfo(binaryPath);
- if (extension == "jar") {
- arguments = QString("-jar \"%1\"").arg(QDir::toNativeSeparators(targetInfo.absoluteFilePath()));
- } else {
- arguments = QString("\"%1\"").arg(QDir::toNativeSeparators(targetInfo.absoluteFilePath()));
- }
-
- type = FileExecutionTypes::executable;
- return true;
- } else {
- type = FileExecutionTypes::other;
- return true;
- }
-}
-
bool OrganizerCore::executeFile(QWidget* parent, const QFileInfo& targetInfo)
{
QFileInfo binaryInfo;
QString arguments;
FileExecutionTypes type;
- if (!getFileExecutionContext(parent, targetInfo, binaryInfo, arguments, type)) {
+ if (!GetFileExecutionContext(parent, targetInfo, binaryInfo, arguments, type)) {
return false;
}