summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-05-26 06:18:11 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-05-26 06:18:11 -0400
commit21185182c6551d053cccdcf087e0c219a3785cf8 (patch)
tree6994b9a2436f23b2765c557f133387c8e6b82d5e /src
parent0439e18fe4cd2500c4ab6b3ff219c53153cf2175 (diff)
moved getFileExecutionContext() and its enum into OrganizerCore
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp4
-rw-r--r--src/organizercore.cpp127
-rw-r--r--src/organizercore.h20
3 files changed, 76 insertions, 75 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index b1728617..810caa01 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -5152,12 +5152,14 @@ void MainWindow::addAsExecutable()
return;
}
+ using FileExecutionTypes = OrganizerCore::FileExecutionTypes;
+
QFileInfo targetInfo(m_ContextItem->data(0, Qt::UserRole).toString());
QFileInfo binaryInfo;
QString arguments;
FileExecutionTypes type;
- if (!GetFileExecutionContext(this, targetInfo, binaryInfo, arguments, type)) {
+ if (!OrganizerCore::getFileExecutionContext(this, targetInfo, binaryInfo, arguments, type)) {
return;
}
diff --git a/src/organizercore.cpp b/src/organizercore.cpp
index 04c94164..d3de3e01 100644
--- a/src/organizercore.cpp
+++ b/src/organizercore.cpp
@@ -269,69 +269,6 @@ bool checkService()
}
-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;
- }
-}
-
-
const char* ShellExecuteError(int i)
{
switch (i) {
@@ -1448,6 +1385,68 @@ 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 = 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 OrganizerCore::executeFileVirtualized(
QWidget* parent, const QFileInfo& targetInfo)
{
@@ -1455,7 +1454,7 @@ bool OrganizerCore::executeFileVirtualized(
QString arguments;
FileExecutionTypes type;
- if (!GetFileExecutionContext(parent, targetInfo, binaryInfo, arguments, type)) {
+ if (!getFileExecutionContext(parent, targetInfo, binaryInfo, arguments, type)) {
return false;
}
diff --git a/src/organizercore.h b/src/organizercore.h
index 6f9defc2..9c4e3ae2 100644
--- a/src/organizercore.h
+++ b/src/organizercore.h
@@ -57,16 +57,6 @@ namespace MOBase {
}
-enum class FileExecutionTypes
-{
- Executable = 1,
- Other = 2
-};
-
-bool GetFileExecutionContext(
- QWidget* parent, const QFileInfo &targetInfo,
- QFileInfo &binaryInfo, QString &arguments, FileExecutionTypes& type);
-
namespace shell
{
bool ExploreFile(const QFileInfo& info);
@@ -111,6 +101,12 @@ private:
typedef boost::signals2::signal<void (const QString&)> SignalModInstalled;
public:
+ enum class FileExecutionTypes
+ {
+ Executable = 1,
+ Other = 2
+ };
+
static bool isNxmLink(const QString &link) { return link.startsWith("nxm://", Qt::CaseInsensitive); }
OrganizerCore(const QSettings &initSettings);
@@ -164,6 +160,10 @@ public:
void doAfterLogin(const std::function<void()> &function) { m_PostLoginTasks.append(function); }
+ static bool getFileExecutionContext(
+ QWidget* parent, const QFileInfo &targetInfo,
+ QFileInfo &binaryInfo, QString &arguments, FileExecutionTypes& type);
+
bool executeFileVirtualized(QWidget* parent, const QFileInfo& targetInfo);
bool previewFileWithAlternatives(QWidget* parent, QString filename);
bool previewFile(QWidget* parent, const QString& originName, const QString& path);