diff options
Diffstat (limited to 'src/mainwindow.cpp')
| -rw-r--r-- | src/mainwindow.cpp | 132 |
1 files changed, 102 insertions, 30 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 4762358e..eaa58db1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -325,6 +325,8 @@ MainWindow::MainWindow(const QString &exeName, QSettings &initSettings, Organize MainWindow::~MainWindow()
{
+ m_AboutToRun.disconnect_all_slots();
+ m_ModInstalled.disconnect_all_slots();
m_PluginContainer.setUserInterface(nullptr, nullptr);
m_OrganizerCore.setUserInterface(nullptr, nullptr);
m_IntegratedBrowser.close();
@@ -1462,7 +1464,7 @@ void MainWindow::saveModMetas() ModInfo::Ptr modInfo = ModInfo::getByIndex(i);
modInfo->saveMeta();
}
- }
+}
void MainWindow::fixCategories()
@@ -1638,7 +1640,6 @@ static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments, qCritical("failed to create IShellLink instance");
return result;
}
- if (!SUCCEEDED(result)) return result;
result = shellLink->SetPath(targetFileName);
if (!SUCCEEDED(result)) {
@@ -1646,6 +1647,7 @@ static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments, shellLink->Release();
return result;
}
+
result = shellLink->SetArguments(arguments);
if (!SUCCEEDED(result)) {
qCritical("failed to set arguments: %ls", arguments);
@@ -1671,7 +1673,7 @@ static HRESULT CreateShortcut(LPCWSTR targetFileName, LPCWSTR arguments, }
}
- IPersistFile* persistFile;
+ IPersistFile *persistFile;
result = shellLink->QueryInterface(IID_IPersistFile, (LPVOID*)&persistFile);
if (SUCCEEDED(result)) {
wchar_t linkFileNameW[MAX_PATH];
@@ -1979,7 +1981,6 @@ void MainWindow::modRenamed(const QString &oldName, const QString &newName) QFile modList(modlistName);
if (modList.exists()) {
- qDebug("rewrite modlist %s", QDir::toNativeSeparators(modlistName).toUtf8().constData());
renameModInList(modList, oldName, newName);
}
}
@@ -2236,13 +2237,13 @@ void MainWindow::reinstallMod_clicked() if (fileInfo.exists()) {
fullInstallationFile = installationFile;
} else {
- fullInstallationFile = m_OrganizerCore.downloadManager()->getOutputDirectory().append("/").append(fileInfo.fileName());
+ fullInstallationFile = m_OrganizerCore.downloadManager()->getOutputDirectory() + "/" + fileInfo.fileName();
}
} else {
- fullInstallationFile = m_OrganizerCore.downloadManager()->getOutputDirectory().append("/").append(installationFile);
+ fullInstallationFile = m_OrganizerCore.downloadManager()->getOutputDirectory() + "/" + installationFile;
}
if (QFile::exists(fullInstallationFile)) {
- installMod(fullInstallationFile);
+ installMod(fullInstallationFile, modInfo->name());
} else {
QMessageBox::information(this, tr("Failed"), tr("Installation file no longer exists"));
}
@@ -3013,22 +3014,24 @@ void MainWindow::on_modList_customContextMenuRequested(const QPoint &pos) menu->addAction(tr("Rename Mod..."), this, SLOT(renameMod_clicked()));
menu->addAction(tr("Remove Mod..."), this, SLOT(removeMod_clicked()));
menu->addAction(tr("Reinstall Mod"), this, SLOT(reinstallMod_clicked()));
- switch (info->endorsedState()) {
- case ModInfo::ENDORSED_TRUE: {
- menu->addAction(tr("Un-Endorse"), this, SLOT(unendorse_clicked()));
- } break;
- case ModInfo::ENDORSED_FALSE: {
- menu->addAction(tr("Endorse"), this, SLOT(endorse_clicked()));
- menu->addAction(tr("Won't endorse"), this, SLOT(dontendorse_clicked()));
- } break;
- case ModInfo::ENDORSED_NEVER: {
- menu->addAction(tr("Endorse"), this, SLOT(endorse_clicked()));
- } break;
- default: {
- QAction *action = new QAction(tr("Endorsement state unknown"), menu);
- action->setEnabled(false);
- menu->addAction(action);
- } break;
+ if (info->getNexusID() > 0) {
+ switch (info->endorsedState()) {
+ case ModInfo::ENDORSED_TRUE: {
+ menu->addAction(tr("Un-Endorse"), this, SLOT(unendorse_clicked()));
+ } break;
+ case ModInfo::ENDORSED_FALSE: {
+ menu->addAction(tr("Endorse"), this, SLOT(endorse_clicked()));
+ menu->addAction(tr("Won't endorse"), this, SLOT(dontendorse_clicked()));
+ } break;
+ case ModInfo::ENDORSED_NEVER: {
+ menu->addAction(tr("Endorse"), this, SLOT(endorse_clicked()));
+ } break;
+ default: {
+ QAction *action = new QAction(tr("Endorsement state unknown"), menu);
+ action->setEnabled(false);
+ menu->addAction(action);
+ } break;
+ }
}
std::vector<ModInfo::EFlag> flags = info->getFlags();
if (std::find(flags.begin(), flags.end(), ModInfo::FLAG_INVALID) != flags.end()) {
@@ -3253,6 +3256,7 @@ void MainWindow::linkDesktop() .arg(selectedExecutable.m_Arguments));
std::wstring description = ToWString(selectedExecutable.m_BinaryInfo.fileName());
std::wstring currentDirectory = ToWString(QDir::toNativeSeparators(exeInfo.absolutePath()));
+
if (CreateShortcut(targetFile.c_str()
, parameter.c_str()
, linkName.toUtf8().constData()
@@ -3405,6 +3409,7 @@ void MainWindow::installDownload(int index) try {
QString fileName = m_OrganizerCore.downloadManager()->getFilePath(index);
int modID = m_OrganizerCore.downloadManager()->getModID(index);
+ int fileID = m_OrganizerCore.downloadManager()->getFileInfo(index)->fileID;
GuessedValue<QString> modName;
// see if there already are mods with the specified mod id
@@ -3434,6 +3439,7 @@ void MainWindow::installDownload(int index) int modIndex = ModInfo::getIndex(modName);
if (modIndex != UINT_MAX) {
ModInfo::Ptr modInfo = ModInfo::getByIndex(modIndex);
+ modInfo->addInstalledFile(modID, fileID);
if (hasIniTweaks &&
(QMessageBox::question(this, tr("Configure Mod"),
@@ -3509,18 +3515,19 @@ void MainWindow::writeDataToFile() }
-int MainWindow::getBinaryExecuteInfo(const QFileInfo &targetInfo,
- QFileInfo &binaryInfo, QString &arguments)
+int MainWindow::getBinaryExecuteInfo(const QFileInfo &targetInfo, QFileInfo &binaryInfo, QString &arguments)
{
QString extension = targetInfo.completeSuffix();
- if ((extension == "exe") ||
- (extension == "cmd") ||
- (extension == "com") ||
- (extension == "bat")) {
+ if ((extension.compare("cmd", Qt::CaseInsensitive)) ||
+ (extension.compare("com", Qt::CaseInsensitive)) ||
+ (extension.compare("bat", Qt::CaseInsensitive))) {
binaryInfo = QFileInfo("C:\\Windows\\System32\\cmd.exe");
arguments = QString("/C \"%1\"").arg(QDir::toNativeSeparators(targetInfo.absoluteFilePath()));
return 1;
- } else if (extension == "jar") {
+ } else if (extension.compare("exe", Qt::CaseInsensitive) == 0) {
+ binaryInfo = targetInfo;
+ return 1;
+ } else if (extension.compare("jar", Qt::CaseInsensitive) == 0) {
// types that need to be injected into
std::wstring targetPathW = ToWString(targetInfo.absoluteFilePath());
QString binaryPath;
@@ -4383,6 +4390,12 @@ HANDLE MainWindow::startApplication(const QString &executable, const QStringList if (cwd.length() == 0) {
currentDirectory = binary.absolutePath();
}
+ try {
+ const Executable &exe = m_ExecutablesList.findByBinary(binary);
+ steamAppID = exe.m_SteamAppID;
+ } catch (const std::runtime_error&) {
+ // nop
+ }
} else {
// only a file name, search executables list
try {
@@ -4463,6 +4476,65 @@ bool MainWindow::waitForProcessOrJob(HANDLE handle, LPDWORD exitCode) return res == WAIT_OBJECT_0;
}
+
+bool MainWindow::waitForProcessOrJob(HANDLE handle, LPDWORD exitCode)
+{
+ LockedDialog *dialog = new LockedDialog(this);
+ dialog->show();
+ setEnabled(false);
+ ON_BLOCK_EXIT([&] () { dialog->hide(); dialog->deleteLater(); this->setEnabled(true); });
+
+ DWORD retLen;
+ JOBOBJECT_BASIC_PROCESS_ID_LIST info;
+
+ bool isJobHandle = true;
+
+ ULONG lastProcessID = ULONG_MAX;
+ HANDLE processHandle = handle;
+
+ DWORD res = ::MsgWaitForMultipleObjects(1, &handle, false, 500, QS_KEY | QS_MOUSE);
+ while ((res != WAIT_FAILED) && (res != WAIT_OBJECT_0) && !dialog->unlockClicked()) {
+ if (isJobHandle) {
+ if (::QueryInformationJobObject(handle, JobObjectBasicProcessIdList, &info, sizeof(info), &retLen) > 0) {
+ if (info.NumberOfProcessIdsInList == 0) {
+ // fake signaled state
+ res = WAIT_OBJECT_0;
+ break;
+ } else {
+ // this is indeed a job handle. Figure out one of the process handles as well.
+ if (lastProcessID != info.ProcessIdList[0]) {
+ lastProcessID = info.ProcessIdList[0];
+ if (processHandle != handle) {
+ ::CloseHandle(processHandle);
+ }
+ processHandle = ::OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, lastProcessID);
+ }
+ }
+ } else {
+ // the info-object I passed only provides space for 1 process id. but since this code only cares about whether there
+ // is more than one that's good enough. ERROR_MORE_DATA simply signals there are at least two processes running.
+ // any other error probably means the handle is a regular process handle, probably caused by running MO in a job without
+ // the right to break out.
+ if (::GetLastError() != ERROR_MORE_DATA) {
+ isJobHandle = false;
+ }
+ }
+ }
+
+ // keep processing events so the app doesn't appear dead
+ QCoreApplication::processEvents();
+
+ res = ::MsgWaitForMultipleObjects(1, &handle, false, 500, QS_KEY | QS_MOUSE);
+ }
+
+ if (exitCode != NULL) {
+ ::GetExitCodeProcess(processHandle, exitCode);
+ }
+ ::CloseHandle(processHandle);
+
+ return res == WAIT_OBJECT_0;
+}
+
void MainWindow::on_bossButton_clicked()
{
std::string reportURL;
|
