diff options
| author | Tannin <devnull@localhost> | 2014-12-09 18:35:32 +0100 |
|---|---|---|
| committer | Tannin <devnull@localhost> | 2014-12-09 18:35:32 +0100 |
| commit | 116a36b9439b27fe3ea7a5bed1f462792634d50d (patch) | |
| tree | c75da86255c446c6eec557f5b756961f7bff5791 /src | |
| parent | 479fdb3dcd47fb8d951dc9aa9f558878d880ca04 (diff) | |
searching for steam process will no longer fail when more than 1024 processes are running (and steam is past the 1024th)
Diffstat (limited to 'src')
| -rw-r--r-- | src/installationmanager.cpp | 4 | ||||
| -rw-r--r-- | src/mainwindow.cpp | 30 |
2 files changed, 22 insertions, 12 deletions
diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 25866cb9..b19978a4 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -524,7 +524,7 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID, return false;
}
- QString targetDirectoryNative = m_ModsDirectory.mid(0).append("\\").append(modName);
+ QString targetDirectoryNative = m_ModsDirectory + "\\" + modName;
QString targetDirectory = QDir::fromNativeSeparators(targetDirectoryNative);
qDebug("installing to \"%s\"", targetDirectoryNative.toUtf8().constData());
@@ -548,7 +548,7 @@ bool InstallationManager::doInstall(GuessedValue<QString> &modName, int modID, m_InstallationProgress.hide();
- QSettings settingsFile(targetDirectory.mid(0).append("/meta.ini"), QSettings::IniFormat);
+ QSettings settingsFile(targetDirectory + "/meta.ini", QSettings::IniFormat);
// overwrite settings only if they are actually are available or haven't been set before
if ((modID != 0) || !settingsFile.contains("modid")) {
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index b4f709d3..630184c9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1001,18 +1001,28 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) bool MainWindow::testForSteam() { - DWORD processIDs[1024]; + size_t currentSize = 1024; + std::unique_ptr<DWORD[]> processIDs; DWORD bytesReturned; - if (!::EnumProcesses(processIDs, sizeof(processIDs), &bytesReturned)) { - qWarning("failed to determine if steam is running"); - return true; + bool success = false; + while (!success) { + processIDs.reset(new DWORD[currentSize]); + if (!::EnumProcesses(processIDs.get(), currentSize * sizeof(DWORD), &bytesReturned)) { + qWarning("failed to determine if steam is running"); + return true; + } + if (bytesReturned == (currentSize * sizeof(DWORD))) { + // maximum size used, list probably truncated + currentSize *= 2; + } else { + success = true; + } } - TCHAR processName[MAX_PATH]; for (unsigned int i = 0; i < bytesReturned / sizeof(DWORD); ++i) { memset(processName, '\0', sizeof(TCHAR) * MAX_PATH); if (processIDs[i] != 0) { - HANDLE process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processIDs[i]); + HANDLE process = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, processIDs[i]); if (process != NULL) { HMODULE module; @@ -1020,12 +1030,14 @@ bool MainWindow::testForSteam() // first module in a process is always the binary if (EnumProcessModules(process, &module, sizeof(HMODULE) * 1, &ignore)) { - GetModuleBaseName(process, module, processName, MAX_PATH); + ::GetModuleBaseName(process, module, processName, MAX_PATH); if ((_tcsicmp(processName, TEXT("steam.exe")) == 0) || (_tcsicmp(processName, TEXT("steamservice.exe")) == 0)) { return true; } } + } else { + qDebug("can't open process %lu: %lu", processIDs[i], ::GetLastError()); } } } @@ -2105,7 +2117,7 @@ void MainWindow::saveModMetas() ModInfo::Ptr modInfo = ModInfo::getByIndex(i); modInfo->saveMeta(); } - } +} void MainWindow::fixCategories() @@ -2962,7 +2974,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); } } @@ -4394,7 +4405,6 @@ void MainWindow::installDownload(int index) } m_CurrentProfile->writeModlistNow(); - bool hasIniTweaks = false; m_InstallationManager.setModsDirectory(m_Settings.getModDirectory()); if (m_InstallationManager.install(fileName, modName, hasIniTweaks)) { |
