From 47293827bbd92ce227e5188c10b66deb9f85d5bf Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 28 Sep 2013 21:13:57 +0200 Subject: - download progress is now visible in task bar - esp-tooltip now lists all masters, highlighting the missing ones - python plugin will now report a problem if the path contains a semicolon - leak detection now (somewaht) works around the fact that we don't always get a stack trace - bugfix: mod meta-file is now reliably created if it was missing - bugfix: parser for nxm-links didn't handle numbers in the mod name - bugfix: small memory leak --- src/downloadmanager.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/downloadmanager.h') diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 92ba3143..0d49aa35 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -98,6 +98,8 @@ private: int m_Tries; bool m_ReQueried; + quint32 m_TaskProgressId; + NexusInfo m_NexusInfo; static DownloadInfo *createNew(const NexusInfo &nexusInfo, int modID, int fileID, const QStringList &URLs); -- cgit v1.3.1 From 54c7131a5e2fa282369e25344ac190d51676c383 Mon Sep 17 00:00:00 2001 From: Tannin Date: Thu, 10 Oct 2013 19:32:01 +0200 Subject: - new toggle to display hidden downloads - hidden downloads can be un-hidden - the installation manager now more thoroughly cleans up the temporary directory after installation - added SkyrimLauncher.exe to the list of auto-detected executables - bugfix: shutting down MO while downloads where active in some occasions didn't work - bugfix: when canceling the only active download the taskbar icon didn't return to normal --- src/downloadlistwidget.cpp | 20 ++++++++--- src/downloadlistwidget.h | 2 ++ src/downloadlistwidgetcompact.cpp | 20 ++++++++--- src/downloadlistwidgetcompact.h | 2 ++ src/downloadmanager.cpp | 58 ++++++++++++++++++++++++++----- src/downloadmanager.h | 24 ++++++++++++- src/installationmanager.cpp | 72 +++++++++++++-------------------------- src/installationmanager.h | 5 +-- src/main.cpp | 5 ++- src/mainwindow.cpp | 6 ++++ src/mainwindow.h | 1 + src/mainwindow.ui | 9 ++++- src/moapplication.cpp | 6 +++- src/moapplication.h | 60 ++++++++++++++++---------------- src/shared/skyriminfo.cpp | 1 + src/version.rc | 4 +-- 16 files changed, 189 insertions(+), 106 deletions(-) (limited to 'src/downloadmanager.h') diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index b657ca69..b4d40799 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -208,6 +208,11 @@ void DownloadListWidgetDelegate::issueRemoveFromView() emit removeDownload(m_ContextRow, false); } +void DownloadListWidgetDelegate::issueRestoreToView() +{ + emit restoreDownload(m_ContextRow); +} + void DownloadListWidgetDelegate::issueCancel() { emit cancelDownload(m_ContextRow); @@ -277,13 +282,18 @@ bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel * QMenu menu(m_View); m_ContextRow = qobject_cast(model)->mapToSource(index).row(); DownloadManager::DownloadState state = m_Manager->getState(m_ContextRow); + bool hidden = m_Manager->isHidden(m_ContextRow); if (state >= DownloadManager::STATE_READY) { menu.addAction(tr("Install"), this, SLOT(issueInstall())); if (m_Manager->isInfoIncomplete(m_ContextRow)) { menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo())); } menu.addAction(tr("Delete"), this, SLOT(issueDelete())); - menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); + if (hidden) { + menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); + } else { + menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); + } } else if (state == DownloadManager::STATE_DOWNLOADING){ menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); menu.addAction(tr("Pause"), this, SLOT(issuePause())); @@ -295,9 +305,11 @@ bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel * menu.addSeparator(); menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted())); menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll())); - menu.addSeparator(); - menu.addAction(tr("Remove Installed..."), this, SLOT(issueRemoveFromViewCompleted())); - menu.addAction(tr("Remove All..."), this, SLOT(issueRemoveFromViewAll())); + if (!hidden) { + menu.addSeparator(); + menu.addAction(tr("Remove Installed..."), this, SLOT(issueRemoveFromViewCompleted())); + menu.addAction(tr("Remove All..."), this, SLOT(issueRemoveFromViewAll())); + } menu.exec(mouseEvent->globalPos()); event->accept(); diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h index c80200fb..f5bfdbaa 100644 --- a/src/downloadlistwidget.h +++ b/src/downloadlistwidget.h @@ -65,6 +65,7 @@ signals: void installDownload(int index); void queryInfo(int index); void removeDownload(int index, bool deleteFile); + void restoreDownload(int index); void cancelDownload(int index); void pauseDownload(int index); void resumeDownload(int index); @@ -83,6 +84,7 @@ private slots: void issueInstall(); void issueDelete(); void issueRemoveFromView(); + void issueRestoreToView(); void issueCancel(); void issuePause(); void issueResume(); diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp index 8dd6e275..d2a71dd5 100644 --- a/src/downloadlistwidgetcompact.cpp +++ b/src/downloadlistwidgetcompact.cpp @@ -195,6 +195,11 @@ void DownloadListWidgetCompactDelegate::issueRemoveFromView() emit removeDownload(m_ContextIndex.row(), false); } +void DownloadListWidgetCompactDelegate::issueRestoreToView() +{ + emit restoreDownload(m_ContextIndex.row()); +} + void DownloadListWidgetCompactDelegate::issueCancel() { emit cancelDownload(m_ContextIndex.row()); @@ -265,13 +270,18 @@ bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItem QMenu menu; m_ContextIndex = qobject_cast(model)->mapToSource(index); DownloadManager::DownloadState state = m_Manager->getState(m_ContextIndex.row()); + bool hidden = m_Manager->isHidden(m_ContextIndex.row()); if (state >= DownloadManager::STATE_READY) { menu.addAction(tr("Install"), this, SLOT(issueInstall())); if (m_Manager->isInfoIncomplete(m_ContextIndex.row())) { menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo())); } menu.addAction(tr("Delete"), this, SLOT(issueDelete())); - menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); + if (hidden) { + menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); + } else { + menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); + } } else if (state == DownloadManager::STATE_DOWNLOADING){ menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); menu.addAction(tr("Pause"), this, SLOT(issuePause())); @@ -283,9 +293,11 @@ bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItem menu.addSeparator(); menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted())); menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll())); - menu.addSeparator(); - menu.addAction(tr("Remove Installed..."), this, SLOT(issueRemoveFromViewCompleted())); - menu.addAction(tr("Remove All..."), this, SLOT(issueRemoveFromViewAll())); + if (!hidden) { + menu.addSeparator(); + menu.addAction(tr("Remove Installed..."), this, SLOT(issueRemoveFromViewCompleted())); + menu.addAction(tr("Remove All..."), this, SLOT(issueRemoveFromViewAll())); + } menu.exec(mouseEvent->globalPos()); event->accept(); diff --git a/src/downloadlistwidgetcompact.h b/src/downloadlistwidgetcompact.h index 78f51840..05d00b9d 100644 --- a/src/downloadlistwidgetcompact.h +++ b/src/downloadlistwidgetcompact.h @@ -65,6 +65,7 @@ signals: void installDownload(int index); void queryInfo(int index); void removeDownload(int index, bool deleteFile); + void restoreDownload(int index); void cancelDownload(int index); void pauseDownload(int index); void resumeDownload(int index); @@ -83,6 +84,7 @@ private slots: void issueInstall(); void issueDelete(); void issueRemoveFromView(); + void issueRestoreToView(); void issueCancel(); void issuePause(); void issueResume(); diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index b965d598..eca5600a 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -69,14 +69,16 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const Ne return info; } -DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta(const QString &filePath) +DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta(const QString &filePath, bool showHidden) { DownloadInfo *info = new DownloadInfo; QString metaFileName = filePath + ".meta"; QSettings metaFile(metaFileName, QSettings::IniFormat); - if (metaFile.value("removed", false).toBool()) { + if (!showHidden && metaFile.value("removed", false).toBool()) { return NULL; + } else { + info->m_Hidden = metaFile.value("removed", false).toBool(); } QString fileName = QFileInfo(filePath).fileName(); @@ -151,7 +153,7 @@ QString DownloadManager::DownloadInfo::currentURL() DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent) - : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher() + : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false) { connect(&m_DirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); } @@ -188,13 +190,15 @@ void DownloadManager::pauseAll() ::Sleep(100); bool done = false; + QTime startTime = QTime::currentTime(); // further loops: busy waiting for all downloads to complete. This could be neater... - while (!done) { + while (!done && (startTime.secsTo(QTime::currentTime()) < 5)) { QCoreApplication::processEvents(); done = true; foreach (DownloadInfo *info, m_ActiveDownloads) { if ((info->m_State < STATE_CANCELED) || - (info->m_State != STATE_FETCHINGFILEINFO) || (info->m_State != STATE_FETCHINGMODINFO)) { + (info->m_State == STATE_FETCHINGFILEINFO) || + (info->m_State == STATE_FETCHINGMODINFO)) { done = false; break; } @@ -230,6 +234,12 @@ void DownloadManager::setSupportedExtensions(const QStringList &extensions) refreshList(); } +void DownloadManager::setShowHidden(bool showHidden) +{ + m_ShowHidden = showHidden; + refreshList(); +} + void DownloadManager::refreshList() { // remove finished downloads @@ -267,7 +277,7 @@ void DownloadManager::refreshList() QString fileName = QDir::fromNativeSeparators(m_OutputDirectory) + "/" + file; - DownloadInfo *info = DownloadInfo::createFromMeta(fileName); + DownloadInfo *info = DownloadInfo::createFromMeta(fileName, m_ShowHidden); if (info != NULL) { m_ActiveDownloads.push_front(info); } @@ -437,6 +447,22 @@ void DownloadManager::refreshAlphabeticalTranslation() } +void DownloadManager::restoreDownload(int index) +{ + if ((index < 0) || (index >= m_ActiveDownloads.size())) { + throw MyException(tr("invalid index")); + } + + DownloadInfo *download = m_ActiveDownloads.at(index); + download->m_Hidden = false; + + QString filePath = m_OutputDirectory + "/" + download->m_FileName; + + QSettings metaSettings(filePath.append(".meta"), QSettings::IniFormat); + metaSettings.setValue("removed", false); +} + + void DownloadManager::removeDownload(int index, bool deleteFile) { try { @@ -492,9 +518,13 @@ void DownloadManager::pauseDownload(int index) return; } - if (m_ActiveDownloads.at(index)->m_State == STATE_DOWNLOADING) { - setState(m_ActiveDownloads.at(index), STATE_PAUSING); - qDebug("pausing %d - %s", index, m_ActiveDownloads[index]->m_FileName.toUtf8().constData()); + DownloadInfo *info = m_ActiveDownloads.at(index); + + if (info->m_State == STATE_DOWNLOADING) { + setState(info, STATE_PAUSING); + qDebug("pausing %d - %s", index, info->m_FileName.toUtf8().constData()); + } else if ((info->m_State == STATE_FETCHINGMODINFO) || (info->m_State == STATE_FETCHINGFILEINFO)) { + setState(info, STATE_READY); } } @@ -671,6 +701,14 @@ int DownloadManager::getModID(int index) const return m_ActiveDownloads.at(index)->m_ModID; } +bool DownloadManager::isHidden(int index) const +{ + if ((index < 0) || (index >= m_ActiveDownloads.size())) { + throw MyException(tr("invalid index")); + } + return m_ActiveDownloads.at(index)->m_Hidden; +} + NexusInfo DownloadManager::getNexusInfo(int index) const { @@ -843,6 +881,7 @@ void DownloadManager::createMetaFile(DownloadInfo *info) metaFile.setValue("uninstalled", info->m_State == DownloadManager::STATE_UNINSTALLED); metaFile.setValue("paused", (info->m_State == DownloadManager::STATE_PAUSED) || (info->m_State == DownloadManager::STATE_ERROR)); + metaFile.setValue("removed", info->m_Hidden); // slightly hackish... for (int i = 0; i < m_ActiveDownloads.size(); ++i) { @@ -1110,6 +1149,7 @@ void DownloadManager::downloadFinished() QByteArray data = info->m_Reply->readAll(); info->m_Output.write(data); info->m_Output.close(); + TaskProgressManager::instance().forgetMe(info->m_TaskProgressId); bool error = false; diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 0d49aa35..a42ac073 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -102,8 +102,10 @@ private: NexusInfo m_NexusInfo; + bool m_Hidden; + static DownloadInfo *createNew(const NexusInfo &nexusInfo, int modID, int fileID, const QStringList &URLs); - static DownloadInfo *createFromMeta(const QString &filePath); + static DownloadInfo *createFromMeta(const QString &filePath, bool showHidden); /** * @brief rename the file @@ -168,6 +170,11 @@ public: */ void setSupportedExtensions(const QStringList &extensions); + /** + * @brief sets whether hidden files are to be shown after all + */ + void setShowHidden(bool showHidden); + /** * @brief download from an already open network connection * @@ -263,6 +270,13 @@ public: **/ int getModID(int index) const; + /** + * @brief determine if the specified file is supposed to be hidden + * @param index index of the file to look up + * @return true if the specified file is supposed to be hidden + */ + bool isHidden(int index) const; + /** * @brief retrieve all nexus info of the download specified by index * @@ -352,6 +366,12 @@ public slots: **/ void removeDownload(int index, bool deleteFile); + /** + * @brief restores the specified download to view (which was previously hidden + * @param index index of the download to restore + */ + void restoreDownload(int index); + /** * @brief cancel the specified download. This will lead to the corresponding file to be deleted * @@ -436,6 +456,8 @@ private: std::map m_DownloadFails; + bool m_ShowHidden; + }; #endif // DOWNLOADMANAGER_H diff --git a/src/installationmanager.cpp b/src/installationmanager.cpp index 87efecf1..6b430eea 100644 --- a/src/installationmanager.cpp +++ b/src/installationmanager.cpp @@ -184,11 +184,7 @@ bool InstallationManager::unpackSingleFile(const QString &fileName) QString InstallationManager::extractFile(const QString &fileName) { if (unpackSingleFile(fileName)) { - QString tempFileName = QDir::tempPath().append("/").append(QFileInfo(fileName).fileName()); - - m_FilesToDelete.insert(tempFileName); - - return tempFileName; + return QDir::tempPath().append("/").append(QFileInfo(fileName).fileName()); } else { return QString(); } @@ -571,49 +567,36 @@ bool InstallationManager::doInstall(GuessedValue &modName, int modID, } -void InstallationManager::openFile(const QString &fileName) +bool InstallationManager::wasCancelled() { - unpackSingleFile(fileName); + return m_CurrentArchive->getLastError() == Archive::ERROR_EXTRACT_CANCELLED; +} - QString tempFileName = QDir::tempPath().append("/").append(QFileInfo(fileName).fileName()); - SHELLEXECUTEINFOW execInfo; - memset(&execInfo, 0, sizeof(SHELLEXECUTEINFOW)); - execInfo.cbSize = sizeof(SHELLEXECUTEINFOW); - execInfo.fMask = SEE_MASK_NOCLOSEPROCESS; - execInfo.lpVerb = L"open"; - std::wstring fileNameW = ToWString(tempFileName); - execInfo.lpFile = fileNameW.c_str(); - execInfo.nShow = SW_SHOWNORMAL; - if (!::ShellExecuteExW(&execInfo)) { - qCritical("failed to spawn %s: %d", tempFileName.toUtf8().constData(), ::GetLastError()); - } +void InstallationManager::postInstallCleanup() const +{ + m_CurrentArchive->close(); - m_FilesToDelete.insert(tempFileName); -} + // directories we may want to remove. sorted from longest to shortest to ensure we remove subdirectories first. + auto longestFirst = [](const QString &LHS, const QString &RHS) -> bool { + if (LHS.size() != RHS.size()) return LHS.size() > RHS.size(); + else return LHS < RHS; + }; + std::set> directoriesToRemove(longestFirst); -// copy and pasted from mo_dll -bool EndsWith(LPCWSTR string, LPCWSTR subString) -{ - size_t slen = wcslen(string); - size_t len = wcslen(subString); - if (slen < len) { - return false; + // clean up temp files + // TODO: this doesn't yet remove directories. Also, the files may be left there if this point isn't reached + foreach (const QString &tempFile, m_TempFilesToDelete) { + QFileInfo fileInfo(QDir::tempPath() + "/" + tempFile); + QFile::remove(fileInfo.absoluteFilePath()); + directoriesToRemove.insert(fileInfo.absolutePath()); } - for (size_t i = 0; i < len; ++i) { - if (towlower(string[slen - len + i]) != towlower(subString[i])) { - return false; - } + // try to delete each directory we had temporary files in. the call fails for non-empty directories which is ok + foreach (const QString &dir, directoriesToRemove) { + QDir().rmdir(dir); } - return true; -} - - -bool InstallationManager::wasCancelled() -{ - return m_CurrentArchive->getLastError() == Archive::ERROR_EXTRACT_CANCELLED; } @@ -675,9 +658,7 @@ bool InstallationManager::install(const QString &fileName, GuessedValue bool archiveOpen = m_CurrentArchive->open(ToWString(QDir::toNativeSeparators(fileName)).c_str(), new MethodCallback(this, &InstallationManager::queryPassword)); - ON_BLOCK_EXIT([this] { - this->m_CurrentArchive->close(); - }); + ON_BLOCK_EXIT(std::bind(&InstallationManager::postInstallCleanup, this)); QScopedPointer filesTree(archiveOpen ? createFilesTree() : NULL); IPluginInstaller::EInstallResult installResult = IPluginInstaller::RESULT_NOTATTEMPTED; @@ -729,13 +710,6 @@ bool InstallationManager::install(const QString &fileName, GuessedValue qPrintable(installer->name()), e.what()); } - // clean up temp files - // TODO: this doesn't yet remove directories. Also, the files may be left there if this point isn't reached - foreach (const QString &tempFile, m_TempFilesToDelete) { - QFile::remove(QDir::tempPath() + "/" + tempFile); - } - - // act upon the installation result. at this point the files have already been // extracted to the correct location switch (installResult) { diff --git a/src/installationmanager.h b/src/installationmanager.h index 0e43a15d..1c6f9f19 100644 --- a/src/installationmanager.h +++ b/src/installationmanager.h @@ -168,9 +168,7 @@ private: bool ensureValidModName(MOBase::GuessedValue &name) const; -private slots: - - void openFile(const QString &fileName); + void postInstallCleanup() const; private: @@ -202,7 +200,6 @@ private: QProgressDialog m_InstallationProgress; - std::set m_FilesToDelete; std::set m_TempFilesToDelete; }; diff --git a/src/main.cpp b/src/main.cpp index c4431ac4..7c2a9b0e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -433,7 +433,10 @@ int main(int argc, char *argv[]) qDebug("initializing tutorials"); TutorialManager::init(QDir::fromNativeSeparators(ToQString(GameInfo::instance().getTutorialDir())).append("/")); - application.setStyleFile(settings.value("Settings/style", "").toString()); + if (!application.setStyleFile(settings.value("Settings/style", "").toString())) { + // disable invalid stylesheet + settings.setValue("Settings/style", ""); + } int res = 1; { // scope to control lifetime of mainwindow diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 57201db9..33dc75ed 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -4265,6 +4265,7 @@ void MainWindow::updateDownloadListDelegate() connect(ui->downloadView->itemDelegate(), SIGNAL(installDownload(int)), this, SLOT(installDownload(int))); connect(ui->downloadView->itemDelegate(), SIGNAL(queryInfo(int)), &m_DownloadManager, SLOT(queryInfo(int))); connect(ui->downloadView->itemDelegate(), SIGNAL(removeDownload(int, bool)), &m_DownloadManager, SLOT(removeDownload(int, bool))); + connect(ui->downloadView->itemDelegate(), SIGNAL(restoreDownload(int)), &m_DownloadManager, SLOT(restoreDownload(int))); connect(ui->downloadView->itemDelegate(), SIGNAL(cancelDownload(int)), &m_DownloadManager, SLOT(cancelDownload(int))); connect(ui->downloadView->itemDelegate(), SIGNAL(pauseDownload(int)), &m_DownloadManager, SLOT(pauseDownload(int))); connect(ui->downloadView->itemDelegate(), SIGNAL(resumeDownload(int)), &m_DownloadManager, SLOT(resumeDownload(int))); @@ -4735,3 +4736,8 @@ void MainWindow::on_linkButton_pressed() ui->linkButton->menu()->actions().at(1)->setIcon(linkDesktopFile.exists() ? removeIcon : addIcon); ui->linkButton->menu()->actions().at(2)->setIcon(linkMenuFile.exists() ? removeIcon : addIcon); } + +void MainWindow::on_showHiddenBox_toggled(bool checked) +{ + m_DownloadManager.setShowHidden(checked); +} diff --git a/src/mainwindow.h b/src/mainwindow.h index dfec5f49..ad4ed82e 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -502,6 +502,7 @@ private slots: // ui slots void on_groupCombo_currentIndexChanged(int index); void on_categoriesList_itemSelectionChanged(); void on_linkButton_pressed(); + void on_showHiddenBox_toggled(bool checked); }; #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 923df17c..b29136ff 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -968,7 +968,7 @@ p, li { white-space: pre-wrap; } - + @@ -976,6 +976,13 @@ p, li { white-space: pre-wrap; } + + + + Show Hidden + + + diff --git a/src/moapplication.cpp b/src/moapplication.cpp index efb0b615..ac660c6c 100644 --- a/src/moapplication.cpp +++ b/src/moapplication.cpp @@ -32,7 +32,7 @@ MOApplication::MOApplication(int argc, char **argv) } -void MOApplication::setStyleFile(const QString &styleName) +bool MOApplication::setStyleFile(const QString &styleName) { // remove all files from watch QStringList currentWatch = m_StyleWatcher.files(); @@ -42,11 +42,15 @@ void MOApplication::setStyleFile(const QString &styleName) // set new stylesheet or clear it if (styleName.length() != 0) { QString styleSheetName = applicationDirPath() + "/" + MOBase::ToQString(AppConfig::stylesheetsPath()) + "/" + styleName; + if (!QFile::exists(styleSheetName)) { + return false; + } m_StyleWatcher.addPath(styleSheetName); updateStyle(styleSheetName); } else { setStyleSheet(""); } + return true; } diff --git a/src/moapplication.h b/src/moapplication.h index 3d74031d..dd7f5eab 100644 --- a/src/moapplication.h +++ b/src/moapplication.h @@ -17,33 +17,33 @@ You should have received a copy of the GNU General Public License along with Mod Organizer. If not, see . */ -#ifndef MOAPPLICATION_H -#define MOAPPLICATION_H - -#include -#include - - -class MOApplication : public QApplication { -Q_OBJECT -public: - - MOApplication(int argc, char **argv); - - virtual bool notify (QObject *receiver, QEvent *event); - -public slots: - - void setStyleFile(const QString &style); - -private slots: - - void updateStyle(const QString &fileName); - -private: - - QFileSystemWatcher m_StyleWatcher; -}; - - -#endif // MOAPPLICATION_H +#ifndef MOAPPLICATION_H +#define MOAPPLICATION_H + +#include +#include + + +class MOApplication : public QApplication { +Q_OBJECT +public: + + MOApplication(int argc, char **argv); + + virtual bool notify (QObject *receiver, QEvent *event); + +public slots: + + bool setStyleFile(const QString &style); + +private slots: + + void updateStyle(const QString &fileName); + +private: + + QFileSystemWatcher m_StyleWatcher; +}; + + +#endif // MOAPPLICATION_H diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp index 8c6b79ef..71d791f5 100644 --- a/src/shared/skyriminfo.cpp +++ b/src/shared/skyriminfo.cpp @@ -295,6 +295,7 @@ std::vector SkyrimInfo::getExecutables() result.push_back(ExecutableInfo(L"SKSE", L"skse_loader.exe", L"", L"", DEFAULT_CLOSE)); result.push_back(ExecutableInfo(L"SBW", L"SBW.exe", L"", L"", DEFAULT_CLOSE)); result.push_back(ExecutableInfo(L"Skyrim", L"TESV.exe", L"", L"", DEFAULT_CLOSE)); + result.push_back(ExecutableInfo(L"Skyrim Launcher", L"SkyrimLauncher.exe", L"", L"", DEFAULT_CLOSE)); result.push_back(ExecutableInfo(L"BOSS", L"BOSS/BOSS.exe", L"", L"", DEFAULT_STAY)); result.push_back(ExecutableInfo(L"Creation Kit", L"CreationKit.exe", L"", L"", DEFAULT_STAY, L"202480")); diff --git a/src/version.rc b/src/version.rc index 16669011..e71bc1b5 100644 --- a/src/version.rc +++ b/src/version.rc @@ -1,7 +1,7 @@ #include "Winver.h" -#define VER_FILEVERSION 1,0,4,0 -#define VER_FILEVERSION_STR "1,0,4,0\0" +#define VER_FILEVERSION 1,0,5,0 +#define VER_FILEVERSION_STR "1,0,5,0\0" VS_VERSION_INFO VERSIONINFO FILEVERSION VER_FILEVERSION -- cgit v1.3.1 From bdf04f516ca7c5274ff50104662e372ed29aea6b Mon Sep 17 00:00:00 2001 From: Tannin Date: Thu, 10 Oct 2013 21:23:25 +0200 Subject: - MO now warns if a nxm-link for a wrong game was attempted instead of downloading the wrong file - bugfix: in nxmhandler adding a new line with different game but same executable didn't work (the change was silently dropped) --- src/downloadmanager.cpp | 17 +++++++++++++++-- src/downloadmanager.h | 2 +- src/nexusinterface.cpp | 4 +--- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src/downloadmanager.h') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index eca5600a..779b052c 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -376,6 +376,15 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl void DownloadManager::addNXMDownload(const QString &url) { NXMUrl nxmInfo(url); + + QString managedGame = ToQString(MOShared::GameInfo::instance().getGameShortName()); + + if (nxmInfo.game().compare(managedGame, Qt::CaseInsensitive) != 0) { + QMessageBox::information(NULL, tr("Wrong Game"), tr("The download link is for a mod for \"%1\" but this instance of MO " + "has been set up for \"%2\".").arg(nxmInfo.game()).arg(managedGame), QMessageBox::Ok); + return; + } + m_RequestIDs.insert(m_NexusInterface->requestFileInfo(nxmInfo.getModId(), nxmInfo.getFileId(), this, QVariant())); } @@ -990,7 +999,7 @@ void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultD } -void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant, QVariant resultData, int requestID) +void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant userData, QVariant resultData, int requestID) { std::set::iterator idIter = m_RequestIDs.find(requestID); if (idIter == m_RequestIDs.end()) { @@ -1007,7 +1016,11 @@ void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant, QVar info.m_Version = result["version"].toString(); info.m_FileName = result["uri"].toString(); - m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(info))); + if (userData.isValid()) { + m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(info), userData.toString())); + } else { + m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(info))); + } } diff --git a/src/downloadmanager.h b/src/downloadmanager.h index a42ac073..e82ea064 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -125,7 +125,7 @@ private: private: static unsigned int s_NextDownloadID; private: - DownloadInfo() : m_TotalSize(0), m_ReQueried(false) {} + DownloadInfo() : m_TotalSize(0), m_ReQueried(false), m_Hidden(false) {} }; public: diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index bee0bb44..936ff400 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -397,7 +397,7 @@ void NexusInterface::nextRequest() QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/xml"); #pragma message("automatically insert the correct version number") - request.setRawHeader("User-Agent", QString("Mod Organizer v0.99.0 (compatible to Nexus Client v%1)").arg(m_NMMVersion).toUtf8()); + request.setRawHeader("User-Agent", QString("Mod Organizer v1.0.5 (compatible to Nexus Client v%1)").arg(m_NMMVersion).toUtf8()); info.m_Reply = m_AccessManager->get(request); @@ -414,8 +414,6 @@ void NexusInterface::downloadRequestedNXM(const QString &url) emit requestNXMDownload(url); } -#include - void NexusInterface::requestFinished(std::list::iterator iter) { QNetworkReply *reply = iter->m_Reply; -- cgit v1.3.1 From 469cc2d945afebb1291a825339642b5e95f0e223 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 7 Dec 2013 12:48:18 +0100 Subject: - download manager now saves the file times on nexus, for potential later use in version check - nexus interface now supports 301 redirects - now using the new nexus url format - bugfix: "visit on nexus" used an outdated url scheme and thus caused unnecessary redirection --- src/downloadmanager.cpp | 26 ++++++++++++++++--- src/downloadmanager.h | 5 ++++ src/mainwindow.cpp | 2 +- src/nexusinterface.cpp | 59 ++++++++++++++++++++++++++------------------ src/nexusinterface.h | 7 +++--- src/shared/fallout3info.cpp | 4 +-- src/shared/fallout3info.h | 1 + src/shared/falloutnvinfo.cpp | 4 +-- src/shared/falloutnvinfo.h | 1 + src/shared/gameinfo.h | 1 + src/shared/oblivioninfo.cpp | 4 +-- src/shared/oblivioninfo.h | 1 + src/shared/skyriminfo.cpp | 4 +-- src/shared/skyriminfo.h | 1 + 14 files changed, 80 insertions(+), 40 deletions(-) (limited to 'src/downloadmanager.h') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 779b052c..48484d24 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -153,7 +153,8 @@ QString DownloadManager::DownloadInfo::currentURL() DownloadManager::DownloadManager(NexusInterface *nexusInterface, QObject *parent) - : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false) + : IDownloadManager(parent), m_NexusInterface(nexusInterface), m_DirWatcher(), m_ShowHidden(false), + m_DateExpression("/Date\\((\\d+)\\)/") { connect(&m_DirWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(directoryChanged(QString))); } @@ -851,7 +852,6 @@ void DownloadManager::downloadProgress(qint64 bytesReceived, qint64 bytesTotal) setState(info, STATE_PAUSED); } else { if (bytesTotal > info->m_TotalSize) { - qDebug("file size %s: %lld", qPrintable(info->m_FileName), bytesTotal); info->m_TotalSize = bytesTotal; } int oldProgress = info->m_Progress; @@ -883,6 +883,7 @@ void DownloadManager::createMetaFile(DownloadInfo *info) metaFile.setValue("name", info->m_NexusInfo.m_Name); metaFile.setValue("modName", info->m_NexusInfo.m_ModName); metaFile.setValue("version", info->m_NexusInfo.m_Version); + metaFile.setValue("fileTime", info->m_NexusInfo.m_FileTime); metaFile.setValue("fileCategory", info->m_NexusInfo.m_FileCategory); metaFile.setValue("newestVersion", info->m_NexusInfo.m_NewestVersion); metaFile.setValue("category", info->m_NexusInfo.m_Category); @@ -914,11 +915,9 @@ void DownloadManager::nxmDescriptionAvailable(int, QVariant userData, QVariant r DownloadInfo *info = downloadInfoByID(userData.toInt()); if (info == NULL) return; - info->m_NexusInfo.m_Category = result["category_id"].toInt(); info->m_NexusInfo.m_ModName = result["name"].toString().trimmed(); info->m_NexusInfo.m_NewestVersion = result["version"].toString(); - if (info->m_FileID != 0) { setState(info, STATE_READY); } else { @@ -927,6 +926,17 @@ void DownloadManager::nxmDescriptionAvailable(int, QVariant userData, QVariant r } +QDateTime DownloadManager::matchDate(const QString &timeString) +{ + if (m_DateExpression.exactMatch(timeString)) { + return QDateTime::fromMSecsSinceEpoch(m_DateExpression.cap(1).toLongLong()); + } else { + qWarning("date not matched: %s", qPrintable(timeString)); + return QDateTime::currentDateTime(); + } +} + + void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultData, int requestID) { std::set::iterator idIter = m_RequestIDs.find(requestID); @@ -960,7 +970,11 @@ void DownloadManager::nxmFilesAvailable(int, QVariant userData, QVariant resultD (fileNameVariant == info->m_FileName) || (fileNameVariant == alternativeLocalName)) { info->m_NexusInfo.m_Name = fileInfo["name"].toString(); info->m_NexusInfo.m_Version = fileInfo["version"].toString(); + if (info->m_NexusInfo.m_Version.isEmpty()) { + info->m_NexusInfo.m_Version = info->m_NexusInfo.m_NewestVersion; + } info->m_NexusInfo.m_FileCategory = fileInfo["category_id"].toInt(); + info->m_NexusInfo.m_FileTime = matchDate(fileInfo["date"].toString()); info->m_FileID = fileInfo["id"].toInt(); found = true; break; @@ -1014,7 +1028,11 @@ void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant userD info.m_Name = result["name"].toString(); info.m_Version = result["version"].toString(); + if (info.m_Version.isEmpty()) { + info.m_Version = info.m_NewestVersion; + } info.m_FileName = result["uri"].toString(); + info.m_FileTime = matchDate(result["date"].toString()); if (userData.isValid()) { m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(info), userData.toString())); diff --git a/src/downloadmanager.h b/src/downloadmanager.h index e82ea064..099e6084 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -46,6 +46,7 @@ struct NexusInfo { QString m_NewestVersion; QString m_FileName; QVariantList m_DownloadMap; + QDateTime m_FileTime; bool m_Set; }; Q_DECLARE_METATYPE(NexusInfo) @@ -437,6 +438,8 @@ private: DownloadInfo *downloadInfoByID(unsigned int id); + QDateTime matchDate(const QString &timeString); + private: static const int AUTOMATIC_RETRIES = 3; @@ -458,6 +461,8 @@ private: bool m_ShowHidden; + QRegExp m_DateExpression; + }; #endif // DOWNLOADMANAGER_H diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d5330017..cca10279 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3214,7 +3214,7 @@ void MainWindow::visitOnNexus_clicked() { int modID = m_ModList.data(m_ModList.index(m_ContextRow, 0), Qt::UserRole).toInt(); if (modID > 0) { - nexusLinkActivated(QString("%1/downloads/file.php?id=%2").arg(ToQString(GameInfo::instance().getNexusPage())).arg(modID)); + nexusLinkActivated(QString("%1/mods/%2").arg(ToQString(GameInfo::instance().getNexusPage())).arg(modID)); } else { MessageDialog::showMessage(tr("Nexus ID for this Mod is unknown"), this); } diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index 6a4ae046..6b5cf19c 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -380,29 +380,33 @@ void NexusInterface::nextRequest() info.m_Timeout->setInterval(60000); QString url; - switch (info.m_Type) { - case NXMRequestInfo::TYPE_DESCRIPTION: { - url = QString("%1/Mods/%2/").arg(info.m_URL).arg(info.m_ModID); - } break; - case NXMRequestInfo::TYPE_FILES: { - url = QString("%1/Files/indexfrommod/%2/").arg(info.m_URL).arg(info.m_ModID); - } break; - case NXMRequestInfo::TYPE_FILEINFO: { - url = QString("%1/Files/%2/").arg(info.m_URL).arg(info.m_FileID); - } break; - case NXMRequestInfo::TYPE_DOWNLOADURL: { - url = QString("%1/Files/download/%2").arg(info.m_URL).arg(info.m_FileID); - } break; - case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: { - url = QString("%1/Mods/toggleendorsement/%2?lvote=%3").arg(info.m_URL).arg(info.m_ModID).arg(!info.m_Endorse); - } break; - case NXMRequestInfo::TYPE_GETUPDATES: { - QString modIDList = VectorJoin(info.m_ModIDList, ","); - modIDList = "[" + modIDList + "]"; - url = QString("%1/Mods/GetUpdates?ModList=%2").arg(info.m_URL).arg(modIDList); - } break; + if (!info.m_Reroute) { + switch (info.m_Type) { + case NXMRequestInfo::TYPE_DESCRIPTION: { + url = QString("%1/Mods/%2/").arg(info.m_URL).arg(info.m_ModID); + } break; + case NXMRequestInfo::TYPE_FILES: { + url = QString("%1/Files/indexfrommod/%2/").arg(info.m_URL).arg(info.m_ModID); + } break; + case NXMRequestInfo::TYPE_FILEINFO: { + url = QString("%1/Files/%2/").arg(info.m_URL).arg(info.m_FileID); + } break; + case NXMRequestInfo::TYPE_DOWNLOADURL: { + url = QString("%1/Files/download/%2").arg(info.m_URL).arg(info.m_FileID); + } break; + case NXMRequestInfo::TYPE_TOGGLEENDORSEMENT: { + url = QString("%1/Mods/toggleendorsement/%2?lvote=%3").arg(info.m_URL).arg(info.m_ModID).arg(!info.m_Endorse); + } break; + case NXMRequestInfo::TYPE_GETUPDATES: { + QString modIDList = VectorJoin(info.m_ModIDList, ","); + modIDList = "[" + modIDList + "]"; + url = QString("%1/Mods/GetUpdates?ModList=%2").arg(info.m_URL).arg(modIDList); + } break; + } + url.append(QString("?game_id=%1").arg(GameInfo::instance().getNexusGameID())); + } else { + url = info.m_URL; } - QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/xml"); request.setRawHeader("User-Agent", @@ -433,13 +437,21 @@ void NexusInterface::requestFinished(std::list::iterator iter) qWarning("request failed: %s", reply->errorString().toUtf8().constData()); emit nxmRequestFailed(iter->m_ModID, iter->m_UserData, iter->m_ID, reply->errorString()); } else { + int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); + if (statusCode == 301) { + // redirect request, return request to queue + iter->m_URL = reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toString(); + iter->m_Reroute = true; + m_RequestQueue.enqueue(*iter); + nextRequest(); + return; + } QByteArray data = reply->readAll(); if (data.isNull() || data.isEmpty() || (strcmp(data.constData(), "null") == 0)) { QString nexusError(reply->rawHeader("NexusErrorInfo")); if (nexusError.length() == 0) { nexusError = tr("empty response"); } - emit nxmRequestFailed(iter->m_ModID, iter->m_UserData, iter->m_ID, nexusError); } else { bool ok; @@ -509,7 +521,6 @@ void NexusInterface::requestTimeout() qWarning("invalid sender type"); return; } - qWarning("request timeout"); for (std::list::iterator iter = m_ActiveRequest.begin(); iter != m_ActiveRequest.end(); ++iter) { if (iter->m_Timeout == timer) { // this abort causes a "request failed" which cleans up the rest diff --git a/src/nexusinterface.h b/src/nexusinterface.h index da5fe02a..e7a01b0f 100644 --- a/src/nexusinterface.h +++ b/src/nexusinterface.h @@ -270,18 +270,19 @@ private: QVariant m_UserData; QTimer *m_Timeout; QString m_URL; + bool m_Reroute; int m_ID; int m_Endorse; NXMRequestInfo(int modID, Type type, QVariant userData, const QString &url) : m_ModID(modID), m_FileID(0), m_Reply(NULL), m_Type(type), m_UserData(userData), - m_Timeout(NULL), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} + m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} NXMRequestInfo(std::vector modIDList, Type type, QVariant userData, const QString &url) : m_ModID(-1), m_ModIDList(modIDList), m_FileID(0), m_Reply(NULL), m_Type(type), m_UserData(userData), - m_Timeout(NULL), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} + m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} NXMRequestInfo(int modID, int fileID, Type type, QVariant userData, const QString &url) : m_ModID(modID), m_FileID(fileID), m_Reply(NULL), m_Type(type), m_UserData(userData), - m_Timeout(NULL), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} + m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} private: static QAtomicInt s_NextID; diff --git a/src/shared/fallout3info.cpp b/src/shared/fallout3info.cpp index c673fa1b..864a67be 100644 --- a/src/shared/fallout3info.cpp +++ b/src/shared/fallout3info.cpp @@ -155,13 +155,13 @@ std::wstring Fallout3Info::getSEName() std::wstring Fallout3Info::getNexusPage() { - return L"http://fallout3.nexusmods.com"; + return L"http://www.nexusmods.com/fallout3"; } std::wstring Fallout3Info::getNexusInfoUrlStatic() { - return L"http://fallout3.nexusmods.com"; + return L"http://www.nexusmods.com/fallout3"; } diff --git a/src/shared/fallout3info.h b/src/shared/fallout3info.h index 0fa97d41..4bcb9d37 100644 --- a/src/shared/fallout3info.h +++ b/src/shared/fallout3info.h @@ -76,6 +76,7 @@ public: virtual std::wstring getNexusInfoUrl() { return Fallout3Info::getNexusInfoUrlStatic(); } static int getNexusModIDStatic(); virtual int getNexusModID() { return Fallout3Info::getNexusModIDStatic(); } + virtual int getNexusGameID() { return 120; } virtual void createProfile(const std::wstring &directory, bool useDefaults); virtual void repairProfile(const std::wstring &directory); diff --git a/src/shared/falloutnvinfo.cpp b/src/shared/falloutnvinfo.cpp index 7d7f0098..8df9607d 100644 --- a/src/shared/falloutnvinfo.cpp +++ b/src/shared/falloutnvinfo.cpp @@ -209,13 +209,13 @@ std::wstring FalloutNVInfo::getSEName() std::wstring FalloutNVInfo::getNexusPage() { - return L"http://newvegas.nexusmods.com"; + return L"http://www.nexusmods.com/newvegas"; } std::wstring FalloutNVInfo::getNexusInfoUrlStatic() { - return L"http://newvegas.nexusmods.com"; + return L"http://www.nexusmods.com/newvegas"; } diff --git a/src/shared/falloutnvinfo.h b/src/shared/falloutnvinfo.h index 3960c951..e25d2e02 100644 --- a/src/shared/falloutnvinfo.h +++ b/src/shared/falloutnvinfo.h @@ -77,6 +77,7 @@ public: virtual std::wstring getNexusInfoUrl() { return FalloutNVInfo::getNexusInfoUrlStatic(); } static int getNexusModIDStatic(); virtual int getNexusModID() { return FalloutNVInfo::getNexusModIDStatic(); } + virtual int getNexusGameID() { return 130; } virtual void createProfile(const std::wstring &directory, bool useDefaults); virtual void repairProfile(const std::wstring &directory); diff --git a/src/shared/gameinfo.h b/src/shared/gameinfo.h index 0221dd1b..d517fc1b 100644 --- a/src/shared/gameinfo.h +++ b/src/shared/gameinfo.h @@ -145,6 +145,7 @@ public: virtual std::wstring getNexusPage() = 0; virtual std::wstring getNexusInfoUrl() = 0; virtual int getNexusModID() = 0; + virtual int getNexusGameID() = 0; // clone relevant files to the specified directory virtual void createProfile(const std::wstring &directory, bool useDefaults) = 0; diff --git a/src/shared/oblivioninfo.cpp b/src/shared/oblivioninfo.cpp index b3e65e59..1438de0a 100644 --- a/src/shared/oblivioninfo.cpp +++ b/src/shared/oblivioninfo.cpp @@ -191,13 +191,13 @@ std::wstring OblivionInfo::getSEName() std::wstring OblivionInfo::getNexusPage() { - return L"http://oblivion.nexusmods.com"; + return L"http://www.nexusmods.com/oblivion"; } std::wstring OblivionInfo::getNexusInfoUrlStatic() { - return L"http://oblivion.nexusmods.com"; + return L"http://www.nexusmods.com/oblivion"; } diff --git a/src/shared/oblivioninfo.h b/src/shared/oblivioninfo.h index 6a9f56ca..dfa53575 100644 --- a/src/shared/oblivioninfo.h +++ b/src/shared/oblivioninfo.h @@ -73,6 +73,7 @@ public: virtual std::wstring getNexusInfoUrl() { return OblivionInfo::getNexusInfoUrlStatic(); } static int getNexusModIDStatic(); virtual int getNexusModID() { return OblivionInfo::getNexusModIDStatic(); } + virtual int getNexusGameID() { return 101; } virtual void createProfile(const std::wstring &directory, bool useDefaults); virtual void repairProfile(const std::wstring &directory); diff --git a/src/shared/skyriminfo.cpp b/src/shared/skyriminfo.cpp index 0a0dd98d..a8b9a433 100644 --- a/src/shared/skyriminfo.cpp +++ b/src/shared/skyriminfo.cpp @@ -183,13 +183,13 @@ std::wstring SkyrimInfo::getSEName() std::wstring SkyrimInfo::getNexusPage() { - return L"http://skyrim.nexusmods.com"; + return L"http://www.nexusmods.com/skyrim"; } std::wstring SkyrimInfo::getNexusInfoUrlStatic() { - return L"http://skyrim.nexusmods.com"; + return L"http://www.nexusmods.com/skyrim"; } diff --git a/src/shared/skyriminfo.h b/src/shared/skyriminfo.h index ae5ab81f..7da523a1 100644 --- a/src/shared/skyriminfo.h +++ b/src/shared/skyriminfo.h @@ -81,6 +81,7 @@ public: virtual std::wstring getNexusInfoUrl() { return SkyrimInfo::getNexusInfoUrlStatic(); } static int getNexusModIDStatic(); virtual int getNexusModID() { return SkyrimInfo::getNexusModIDStatic(); } + virtual int getNexusGameID() { return 110; } virtual void createProfile(const std::wstring &directory, bool useDefaults); virtual void repairProfile(const std::wstring &directory); -- cgit v1.3.1 From 4dc3538a7d14dd0f1aaa2e6c172745b63e251c86 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 4 Jan 2014 15:57:14 +0100 Subject: - nxmhandler will now ask before registering itself - downloads from nexus are now displayed before file information is retrieved - logging from the ui is now a bit more informative - download list now scrolls to bottom automatically --- src/downloadlist.cpp | 19 ++-- src/downloadlistsortproxy.cpp | 22 +++-- src/downloadlistwidget.cpp | 179 +++++++++++++++++++++----------------- src/downloadlistwidget.h | 3 + src/downloadlistwidgetcompact.cpp | 148 ++++++++++++++++++------------- src/downloadlistwidgetcompact.h | 2 + src/downloadmanager.cpp | 49 ++++++++++- src/downloadmanager.h | 25 ++++++ src/logbuffer.cpp | 15 +++- src/logbuffer.h | 2 + src/mainwindow.cpp | 12 ++- src/messagedialog.cpp | 1 + src/settings.cpp | 9 ++ src/settings.h | 7 ++ src/settingsdialog.cpp | 6 ++ src/settingsdialog.h | 2 + src/settingsdialog.ui | 44 +++++++--- 17 files changed, 368 insertions(+), 177 deletions(-) (limited to 'src/downloadmanager.h') diff --git a/src/downloadlist.cpp b/src/downloadlist.cpp index fe021a27..d280cdb6 100644 --- a/src/downloadlist.cpp +++ b/src/downloadlist.cpp @@ -34,9 +34,10 @@ DownloadList::DownloadList(DownloadManager *manager, QObject *parent) int DownloadList::rowCount(const QModelIndex&) const { - return m_Manager->numTotalDownloads(); + return m_Manager->numTotalDownloads() + m_Manager->numPendingDownloads(); } + int DownloadList::columnCount(const QModelIndex&) const { return 3; @@ -75,14 +76,18 @@ QVariant DownloadList::data(const QModelIndex &index, int role) const if (role == Qt::DisplayRole) { return index.row(); } else if (role == Qt::ToolTipRole) { - QString text = m_Manager->getFileName(index.row()) + "\n"; - if (m_Manager->isInfoIncomplete(index.row())) { - text += tr("Information missing, please select \"Query Info\" from the context menu to re-retrieve."); + if (index.row() < m_Manager->numTotalDownloads()) { + QString text = m_Manager->getFileName(index.row()) + "\n"; + if (m_Manager->isInfoIncomplete(index.row())) { + text += tr("Information missing, please select \"Query Info\" from the context menu to re-retrieve."); + } else { + NexusInfo info = m_Manager->getNexusInfo(index.row()); + text += QString("%1 (ID %2) %3").arg(info.m_ModName).arg(m_Manager->getModID(index.row())).arg(info.m_Version); + } + return text; } else { - NexusInfo info = m_Manager->getNexusInfo(index.row()); - text += QString("%1 (ID %2) %3").arg(info.m_ModName).arg(m_Manager->getModID(index.row())).arg(info.m_Version); + return tr("pending download"); } - return text; } else { return QVariant(); } diff --git a/src/downloadlistsortproxy.cpp b/src/downloadlistsortproxy.cpp index fc743574..7abe8579 100644 --- a/src/downloadlistsortproxy.cpp +++ b/src/downloadlistsortproxy.cpp @@ -37,13 +37,16 @@ bool DownloadListSortProxy::lessThan(const QModelIndex &left, { int leftIndex = sourceModel()->data(left).toInt(); int rightIndex = sourceModel()->data(right).toInt(); - - if (left.column() == DownloadList::COL_NAME) { - return m_Manager->getFileName(leftIndex).compare(m_Manager->getFileName(rightIndex), Qt::CaseInsensitive) < 0; - } else if (left.column() == DownloadList::COL_FILETIME) { - return m_Manager->getFileTime(leftIndex) < m_Manager->getFileTime(rightIndex); - } else if (left.column() == DownloadList::COL_STATUS) { - return m_Manager->getState(leftIndex) < m_Manager->getState(rightIndex); + if (leftIndex < m_Manager->numTotalDownloads()) { + if (left.column() == DownloadList::COL_NAME) { + return m_Manager->getFileName(leftIndex).compare(m_Manager->getFileName(rightIndex), Qt::CaseInsensitive) < 0; + } else if (left.column() == DownloadList::COL_FILETIME) { + return m_Manager->getFileTime(leftIndex) < m_Manager->getFileTime(rightIndex); + } else if (left.column() == DownloadList::COL_STATUS) { + return m_Manager->getState(leftIndex) < m_Manager->getState(rightIndex); + } else { + return leftIndex < rightIndex; + } } else { return leftIndex < rightIndex; } @@ -54,6 +57,9 @@ bool DownloadListSortProxy::filterAcceptsRow(int source_row, const QModelIndex&) { if (m_CurrentFilter.length() == 0) { return true; + } else if (source_row < m_Manager->numTotalDownloads()) { + return m_Manager->getFileName(source_row).contains(m_CurrentFilter, Qt::CaseInsensitive); + } else { + return false; } - return m_Manager->getFileName(source_row).contains(m_CurrentFilter, Qt::CaseInsensitive); } diff --git a/src/downloadlistwidget.cpp b/src/downloadlistwidget.cpp index b4d40799..68dd2adf 100644 --- a/src/downloadlistwidget.cpp +++ b/src/downloadlistwidget.cpp @@ -82,80 +82,100 @@ void DownloadListWidgetDelegate::drawCache(QPainter *painter, const QStyleOption } -void DownloadListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +void DownloadListWidgetDelegate::paintPendingDownload(int downloadIndex) const { - try { - auto iter = m_Cache.find(index.row()); - if (iter != m_Cache.end()) { - drawCache(painter, option, *iter); - return; - } - - m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2), option.rect.height())); + std::pair nexusids = m_Manager->getPendingDownload(downloadIndex); + m_NameLabel->setText(tr("< mod %1 file %2 >").arg(nexusids.first).arg(nexusids.second)); + m_SizeLabel->setText("???"); + m_InstallLabel->setVisible(true); + m_InstallLabel->setText(tr("Pending")); + m_Progress->setVisible(false); +} - int downloadIndex = index.data().toInt(); - QString name = m_Manager->getFileName(downloadIndex); - if (name.length() > 53) { - name.truncate(50); - name.append("..."); - } - m_NameLabel->setText(name); - m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1024)); - DownloadManager::DownloadState state = m_Manager->getState(downloadIndex); - if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { - QPalette labelPalette; - m_InstallLabel->setVisible(true); - m_Progress->setVisible(false); +void DownloadListWidgetDelegate::paintRegularDownload(int downloadIndex) const +{ + QString name = m_Manager->getFileName(downloadIndex); + if (name.length() > 53) { + name.truncate(50); + name.append("..."); + } + m_NameLabel->setText(name); + m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1024)); + DownloadManager::DownloadState state = m_Manager->getState(downloadIndex); + if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { + QPalette labelPalette; + m_InstallLabel->setVisible(true); + m_Progress->setVisible(false); #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Paused - Double Click to resume", 0)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Paused - Double Click to resume", 0)); #else - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Paused - Double Click to resume", 0, QApplication::UnicodeUTF8)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Paused - Double Click to resume", 0, QApplication::UnicodeUTF8)); #endif - labelPalette.setColor(QPalette::WindowText, Qt::darkRed); - m_InstallLabel->setPalette(labelPalette); - } else if (state == DownloadManager::STATE_FETCHINGMODINFO) { - m_InstallLabel->setText(tr("Fetching Info 1")); - m_Progress->setVisible(false); - } else if (state == DownloadManager::STATE_FETCHINGFILEINFO) { - m_InstallLabel->setText(tr("Fetching Info 2")); - m_Progress->setVisible(false); - } else if (state >= DownloadManager::STATE_READY) { - QPalette labelPalette; - m_InstallLabel->setVisible(true); - m_Progress->setVisible(false); - if (state == DownloadManager::STATE_INSTALLED) { - // the tr-macro doesn't work here, maybe because the translation is actually associated with DownloadListWidget instead - // of DownloadListWidgetDelegate? + labelPalette.setColor(QPalette::WindowText, Qt::darkRed); + m_InstallLabel->setPalette(labelPalette); + } else if (state == DownloadManager::STATE_FETCHINGMODINFO) { + m_InstallLabel->setText(tr("Fetching Info 1")); + m_Progress->setVisible(false); + } else if (state == DownloadManager::STATE_FETCHINGFILEINFO) { + m_InstallLabel->setText(tr("Fetching Info 2")); + m_Progress->setVisible(false); + } else if (state >= DownloadManager::STATE_READY) { + QPalette labelPalette; + m_InstallLabel->setVisible(true); + m_Progress->setVisible(false); + if (state == DownloadManager::STATE_INSTALLED) { + // the tr-macro doesn't work here, maybe because the translation is actually associated with DownloadListWidget instead + // of DownloadListWidgetDelegate? #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Installed - Double Click to re-install", 0)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Installed - Double Click to re-install", 0)); #else - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Installed - Double Click to re-install", 0, QApplication::UnicodeUTF8)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Installed - Double Click to re-install", 0, QApplication::UnicodeUTF8)); #endif - labelPalette.setColor(QPalette::WindowText, Qt::darkGray); - } else if (state == DownloadManager::STATE_UNINSTALLED) { + labelPalette.setColor(QPalette::WindowText, Qt::darkGray); + } else if (state == DownloadManager::STATE_UNINSTALLED) { #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Uninstalled - Double Click to re-install", 0)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Uninstalled - Double Click to re-install", 0)); #else - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Uninstalled - Double Click to re-install", 0, QApplication::UnicodeUTF8)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Uninstalled - Double Click to re-install", 0, QApplication::UnicodeUTF8)); #endif - labelPalette.setColor(QPalette::WindowText, Qt::lightGray); - } else { + labelPalette.setColor(QPalette::WindowText, Qt::lightGray); + } else { #if QT_VERSION >= QT_VERSION_CHECK(5,0,0) - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Done - Double Click to install", 0)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Done - Double Click to install", 0)); #else - m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Done - Double Click to install", 0, QApplication::UnicodeUTF8)); + m_InstallLabel->setText(QApplication::translate("DownloadListWidget", "Done - Double Click to install", 0, QApplication::UnicodeUTF8)); #endif - labelPalette.setColor(QPalette::WindowText, Qt::darkGreen); - } - m_InstallLabel->setPalette(labelPalette); - if (m_Manager->isInfoIncomplete(downloadIndex)) { - m_NameLabel->setText(" " + m_NameLabel->text()); - } + labelPalette.setColor(QPalette::WindowText, Qt::darkGreen); + } + m_InstallLabel->setPalette(labelPalette); + if (m_Manager->isInfoIncomplete(downloadIndex)) { + m_NameLabel->setText(" " + m_NameLabel->text()); + } + } else { + m_InstallLabel->setVisible(false); + m_Progress->setVisible(true); + m_Progress->setValue(m_Manager->getProgress(downloadIndex)); + } +} + +void DownloadListWidgetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const +{ + try { + auto iter = m_Cache.find(index.row()); + if (iter != m_Cache.end()) { + drawCache(painter, option, *iter); + return; + } + + m_ItemWidget->resize(QSize(m_View->columnWidth(0) + m_View->columnWidth(1) + m_View->columnWidth(2), option.rect.height())); + + int downloadIndex = index.data().toInt(); + + if (downloadIndex >= m_Manager->numTotalDownloads()) { + paintPendingDownload(downloadIndex - m_Manager->numTotalDownloads()); } else { - m_InstallLabel->setVisible(false); - m_Progress->setVisible(true); - m_Progress->setValue(m_Manager->getProgress(downloadIndex)); + paintRegularDownload(downloadIndex); } #pragma message("caching disabled because changes in the list (including resorting) doesn't work correctly") @@ -280,29 +300,32 @@ bool DownloadListWidgetDelegate::editorEvent(QEvent *event, QAbstractItemModel * QMouseEvent *mouseEvent = static_cast(event); if (mouseEvent->button() == Qt::RightButton) { QMenu menu(m_View); + bool hidden = false; m_ContextRow = qobject_cast(model)->mapToSource(index).row(); - DownloadManager::DownloadState state = m_Manager->getState(m_ContextRow); - bool hidden = m_Manager->isHidden(m_ContextRow); - if (state >= DownloadManager::STATE_READY) { - menu.addAction(tr("Install"), this, SLOT(issueInstall())); - if (m_Manager->isInfoIncomplete(m_ContextRow)) { - menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo())); + if (m_ContextRow < m_Manager->numTotalDownloads()) { + DownloadManager::DownloadState state = m_Manager->getState(m_ContextRow); + hidden = m_Manager->isHidden(m_ContextRow); + if (state >= DownloadManager::STATE_READY) { + menu.addAction(tr("Install"), this, SLOT(issueInstall())); + if (m_Manager->isInfoIncomplete(m_ContextRow)) { + menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo())); + } + menu.addAction(tr("Delete"), this, SLOT(issueDelete())); + if (hidden) { + menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); + } else { + menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); + } + } else if (state == DownloadManager::STATE_DOWNLOADING){ + menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); + menu.addAction(tr("Pause"), this, SLOT(issuePause())); + } else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { + menu.addAction(tr("Remove"), this, SLOT(issueDelete())); + menu.addAction(tr("Resume"), this, SLOT(issueResume())); } - menu.addAction(tr("Delete"), this, SLOT(issueDelete())); - if (hidden) { - menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); - } else { - menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); - } - } else if (state == DownloadManager::STATE_DOWNLOADING){ - menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); - menu.addAction(tr("Pause"), this, SLOT(issuePause())); - } else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { - menu.addAction(tr("Remove"), this, SLOT(issueDelete())); - menu.addAction(tr("Resume"), this, SLOT(issueResume())); - } - menu.addSeparator(); + menu.addSeparator(); + } menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted())); menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll())); if (!hidden) { diff --git a/src/downloadlistwidget.h b/src/downloadlistwidget.h index f5bfdbaa..80c4430a 100644 --- a/src/downloadlistwidget.h +++ b/src/downloadlistwidget.h @@ -60,6 +60,9 @@ public: virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; + void paintPendingDownload(int downloadIndex) const; + void paintRegularDownload(int downloadIndex) const; + signals: void installDownload(int index); diff --git a/src/downloadlistwidgetcompact.cpp b/src/downloadlistwidgetcompact.cpp index d2a71dd5..e2fbcd24 100644 --- a/src/downloadlistwidgetcompact.cpp +++ b/src/downloadlistwidgetcompact.cpp @@ -82,6 +82,66 @@ void DownloadListWidgetCompactDelegate::drawCache(QPainter *painter, const QStyl } +void DownloadListWidgetCompactDelegate::paintPendingDownload(int downloadIndex) const +{ + std::pair nexusids = m_Manager->getPendingDownload(downloadIndex); + m_NameLabel->setText(tr("< mod %1 file %2 >").arg(nexusids.first).arg(nexusids.second)); + if (m_SizeLabel != NULL) { + m_SizeLabel->setText("???"); + } + m_DoneLabel->setVisible(true); + m_DoneLabel->setText(tr("Pending")); + m_Progress->setVisible(false); +} + + +void DownloadListWidgetCompactDelegate::paintRegularDownload(int downloadIndex) const +{ + QString name = m_Manager->getFileName(downloadIndex); + if (name.length() > 53) { + name.truncate(50); + name.append("..."); + } + m_NameLabel->setText(name); + + DownloadManager::DownloadState state = m_Manager->getState(downloadIndex); + + if ((m_SizeLabel != NULL) && (state >= DownloadManager::STATE_READY)) { + m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1048576)); + } + + if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { + m_DoneLabel->setVisible(true); + m_Progress->setVisible(false); + m_DoneLabel->setText(tr("Paused")); + m_DoneLabel->setForegroundRole(QPalette::Link); + } else if (state == DownloadManager::STATE_FETCHINGMODINFO) { + m_DoneLabel->setText(tr("Fetching Info 1")); + } else if (state == DownloadManager::STATE_FETCHINGFILEINFO) { + m_DoneLabel->setText(tr("Fetching Info 2")); + } else if (state >= DownloadManager::STATE_READY) { + m_DoneLabel->setVisible(true); + m_Progress->setVisible(false); + if (state == DownloadManager::STATE_INSTALLED) { + m_DoneLabel->setText(tr("Installed")); + m_DoneLabel->setForegroundRole(QPalette::Mid); + } else if (state == DownloadManager::STATE_UNINSTALLED) { + m_DoneLabel->setText(tr("Uninstalled")); + m_DoneLabel->setForegroundRole(QPalette::Dark); + } else { + m_DoneLabel->setText(tr("Done")); + m_DoneLabel->setForegroundRole(QPalette::WindowText); + } + if (m_Manager->isInfoIncomplete(downloadIndex)) { + m_NameLabel->setText(" " + m_NameLabel->text()); + } + } else { + m_DoneLabel->setVisible(false); + m_Progress->setVisible(true); + m_Progress->setValue(m_Manager->getProgress(downloadIndex)); + } +} + void DownloadListWidgetCompactDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { #pragma message("This is quite costy - room for optimization?") @@ -100,49 +160,10 @@ void DownloadListWidgetCompactDelegate::paint(QPainter *painter, const QStyleOpt } int downloadIndex = index.data().toInt(); - - QString name = m_Manager->getFileName(downloadIndex); - if (name.length() > 53) { - name.truncate(50); - name.append("..."); - } - m_NameLabel->setText(name); - - DownloadManager::DownloadState state = m_Manager->getState(downloadIndex); - - if ((m_SizeLabel != NULL) && (state >= DownloadManager::STATE_READY)) { - m_SizeLabel->setText(QString::number(m_Manager->getFileSize(downloadIndex) / 1048576)); - } - - if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { - m_DoneLabel->setVisible(true); - m_Progress->setVisible(false); - m_DoneLabel->setText(tr("Paused")); - m_DoneLabel->setForegroundRole(QPalette::Link); - } else if (state == DownloadManager::STATE_FETCHINGMODINFO) { - m_DoneLabel->setText(tr("Fetching Info 1")); - } else if (state == DownloadManager::STATE_FETCHINGFILEINFO) { - m_DoneLabel->setText(tr("Fetching Info 2")); - } else if (state >= DownloadManager::STATE_READY) { - m_DoneLabel->setVisible(true); - m_Progress->setVisible(false); - if (state == DownloadManager::STATE_INSTALLED) { - m_DoneLabel->setText(tr("Installed")); - m_DoneLabel->setForegroundRole(QPalette::Mid); - } else if (state == DownloadManager::STATE_UNINSTALLED) { - m_DoneLabel->setText(tr("Uninstalled")); - m_DoneLabel->setForegroundRole(QPalette::Dark); - } else { - m_DoneLabel->setText(tr("Done")); - m_DoneLabel->setForegroundRole(QPalette::WindowText); - } - if (m_Manager->isInfoIncomplete(downloadIndex)) { - m_NameLabel->setText(" " + m_NameLabel->text()); - } + if (downloadIndex >= m_Manager->numTotalDownloads()) { + paintPendingDownload(downloadIndex - m_Manager->numTotalDownloads()); } else { - m_DoneLabel->setVisible(false); - m_Progress->setVisible(true); - m_Progress->setValue(m_Manager->getProgress(downloadIndex)); + paintRegularDownload(downloadIndex); } #pragma message("caching disabled because changes in the list (including resorting) doesn't work correctly") @@ -268,29 +289,32 @@ bool DownloadListWidgetCompactDelegate::editorEvent(QEvent *event, QAbstractItem QMouseEvent *mouseEvent = static_cast(event); if (mouseEvent->button() == Qt::RightButton) { QMenu menu; + bool hidden = false; m_ContextIndex = qobject_cast(model)->mapToSource(index); - DownloadManager::DownloadState state = m_Manager->getState(m_ContextIndex.row()); - bool hidden = m_Manager->isHidden(m_ContextIndex.row()); - if (state >= DownloadManager::STATE_READY) { - menu.addAction(tr("Install"), this, SLOT(issueInstall())); - if (m_Manager->isInfoIncomplete(m_ContextIndex.row())) { - menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo())); - } - menu.addAction(tr("Delete"), this, SLOT(issueDelete())); - if (hidden) { - menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); - } else { - menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); + if (m_ContextIndex.row() < m_Manager->numTotalDownloads()) { + DownloadManager::DownloadState state = m_Manager->getState(m_ContextIndex.row()); + hidden = m_Manager->isHidden(m_ContextIndex.row()); + if (state >= DownloadManager::STATE_READY) { + menu.addAction(tr("Install"), this, SLOT(issueInstall())); + if (m_Manager->isInfoIncomplete(m_ContextIndex.row())) { + menu.addAction(tr("Query Info"), this, SLOT(issueQueryInfo())); + } + menu.addAction(tr("Delete"), this, SLOT(issueDelete())); + if (hidden) { + menu.addAction(tr("Un-Hide"), this, SLOT(issueRestoreToView())); + } else { + menu.addAction(tr("Remove from View"), this, SLOT(issueRemoveFromView())); + } + } else if (state == DownloadManager::STATE_DOWNLOADING){ + menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); + menu.addAction(tr("Pause"), this, SLOT(issuePause())); + } else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { + menu.addAction(tr("Remove"), this, SLOT(issueDelete())); + menu.addAction(tr("Resume"), this, SLOT(issueResume())); } - } else if (state == DownloadManager::STATE_DOWNLOADING){ - menu.addAction(tr("Cancel"), this, SLOT(issueCancel())); - menu.addAction(tr("Pause"), this, SLOT(issuePause())); - } else if ((state == DownloadManager::STATE_PAUSED) || (state == DownloadManager::STATE_ERROR)) { - menu.addAction(tr("Remove"), this, SLOT(issueDelete())); - menu.addAction(tr("Resume"), this, SLOT(issueResume())); - } - menu.addSeparator(); + menu.addSeparator(); + } menu.addAction(tr("Delete Installed..."), this, SLOT(issueDeleteCompleted())); menu.addAction(tr("Delete All..."), this, SLOT(issueDeleteAll())); if (!hidden) { diff --git a/src/downloadlistwidgetcompact.h b/src/downloadlistwidgetcompact.h index 05d00b9d..4d7f40de 100644 --- a/src/downloadlistwidgetcompact.h +++ b/src/downloadlistwidgetcompact.h @@ -78,6 +78,8 @@ protected: private: void drawCache(QPainter *painter, const QStyleOptionViewItem &option, const QPixmap &cache) const; + void paintPendingDownload(int downloadIndex) const; + void paintRegularDownload(int downloadIndex) const; private slots: diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 48484d24..61c5113c 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -323,6 +323,7 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs, (QMessageBox::question(NULL, tr("Download again?"), tr("A file with the same name has already been downloaded. " "Do you want to download it again? The new file will receive a different name."), QMessageBox::Yes | QMessageBox::No) == QMessageBox::No)) { + removePending(modID, fileID); delete newDownload; return false; } @@ -331,11 +332,24 @@ bool DownloadManager::addDownload(QNetworkReply *reply, const QStringList &URLs, startDownload(reply, newDownload, false); - emit update(-1); +// emit update(-1); return true; } +void DownloadManager::removePending(int modID, int fileID) +{ + emit aboutToUpdate(); + for (auto iter = m_PendingDownloads.begin(); iter != m_PendingDownloads.end(); ++iter) { + if ((iter->first == modID) && (iter->second == fileID)) { + m_PendingDownloads.erase(iter); + break; + } + } + emit update(-1); +} + + void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownload, bool resume) { newDownload->m_Reply = reply; @@ -365,11 +379,14 @@ void DownloadManager::startDownload(QNetworkReply *reply, DownloadInfo *newDownl if (!resume) { newDownload->m_PreResumeSize = newDownload->m_Output.size(); + removePending(newDownload->m_ModID, newDownload->m_FileID); + emit aboutToUpdate(); m_ActiveDownloads.append(newDownload); emit update(-1); + emit downloadAdded(); } } @@ -379,14 +396,21 @@ void DownloadManager::addNXMDownload(const QString &url) NXMUrl nxmInfo(url); QString managedGame = ToQString(MOShared::GameInfo::instance().getGameShortName()); - + qDebug("add nxm download", qPrintable(url)); if (nxmInfo.game().compare(managedGame, Qt::CaseInsensitive) != 0) { + qDebug("download requested for wrong game (game: %s, url: %s)", qPrintable(managedGame), qPrintable(nxmInfo.game())); QMessageBox::information(NULL, tr("Wrong Game"), tr("The download link is for a mod for \"%1\" but this instance of MO " "has been set up for \"%2\".").arg(nxmInfo.game()).arg(managedGame), QMessageBox::Ok); return; } - m_RequestIDs.insert(m_NexusInterface->requestFileInfo(nxmInfo.getModId(), nxmInfo.getFileId(), this, QVariant())); + emit aboutToUpdate(); + + m_PendingDownloads.append(std::make_pair(nxmInfo.modId(), nxmInfo.fileId())); + + emit update(-1); + emit downloadAdded(); + m_RequestIDs.insert(m_NexusInterface->requestFileInfo(nxmInfo.modId(), nxmInfo.fileId(), this, QVariant())); } @@ -628,6 +652,19 @@ int DownloadManager::numTotalDownloads() const return m_ActiveDownloads.size(); } +int DownloadManager::numPendingDownloads() const +{ + return m_PendingDownloads.size(); +} + +std::pair DownloadManager::getPendingDownload(int index) +{ + if ((index < 0) || (index >= m_PendingDownloads.size())) { + throw MyException(tr("invalid index")); + } + + return m_PendingDownloads.at(index); +} QString DownloadManager::getFilePath(int index) const { @@ -1025,8 +1062,8 @@ void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant userD NexusInfo info; QVariantMap result = resultData.toMap(); - info.m_Name = result["name"].toString(); + qDebug("file info received for %s", qPrintable(info.m_Name)); info.m_Version = result["version"].toString(); if (info.m_Version.isEmpty()) { info.m_Version = info.m_NewestVersion; @@ -1121,9 +1158,12 @@ void DownloadManager::nxmDownloadURLsAvailable(int modID, int fileID, QVariant u m_RequestIDs.erase(idIter); } + qDebug("download urls received (modid %d, fileid %d)", modID, fileID); + NexusInfo info = userData.value(); QVariantList resultList = resultData.toList(); if (resultList.length() == 0) { + removePending(modID, fileID); emit showMessage(tr("No download server available. Please try again later.")); return; } @@ -1282,3 +1322,4 @@ void DownloadManager::directoryChanged(const QString&) { refreshList(); } + diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 099e6084..62396666 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -205,6 +205,19 @@ public: **/ int numTotalDownloads() const; + /** + * @brief retrieve number of pending downloads (nexus downloads for which we don't know the name and url yet) + * @return number of pending downloads + */ + int numPendingDownloads() const; + + /** + * @brief retrieve the info of a pending download + * @param index index of the pending download (index in the range [0, numPendingDownloads()[) + * @return pair of modid, fileid + */ + std::pair getPendingDownload(int index); + /** * @brief retrieve the full path to the download specified by index * @@ -357,6 +370,11 @@ signals: */ void downloadSpeed(const QString &serverName, int bytesPerSecond); + /** + * @brief emitted whenever a new download is added to the list + */ + void downloadAdded(); + public slots: /** @@ -440,6 +458,8 @@ private: QDateTime matchDate(const QString &timeString); + void removePending(int modID, int fileID); + private: static const int AUTOMATIC_RETRIES = 3; @@ -447,6 +467,9 @@ private: private: NexusInterface *m_NexusInterface; + + QVector > m_PendingDownloads; + QVector m_ActiveDownloads; QString m_OutputDirectory; @@ -465,4 +488,6 @@ private: }; + + #endif // DOWNLOADMANAGER_H diff --git a/src/logbuffer.cpp b/src/logbuffer.cpp index a3b6f1b5..f930cf10 100644 --- a/src/logbuffer.cpp +++ b/src/logbuffer.cpp @@ -112,13 +112,26 @@ void LogBuffer::log(QtMsgType type, const QMessageLogContext &context, const QSt #else + +char LogBuffer::msgTypeID(QtMsgType type) +{ + switch (type) { + case QtDebugMsg: return 'D'; + case QtWarningMsg: return 'W'; + case QtCriticalMsg: return 'C'; + case QtFatalMsg: return 'F'; + } +} + +#include + void LogBuffer::log(QtMsgType type, const char *message) { QMutexLocker guard(&s_Mutex); if (!s_Instance.isNull()) { s_Instance->logMessage(type, message); } - fprintf(stdout, "%s\n", message); + fprintf(stdout, "[%c] %s: %s\n", msgTypeID(type), qPrintable(QTime::currentTime().toString()), message); fflush(stdout); } diff --git a/src/logbuffer.h b/src/logbuffer.h index de5e887f..68753996 100644 --- a/src/logbuffer.h +++ b/src/logbuffer.h @@ -60,6 +60,8 @@ private: void write() const; + static char msgTypeID(QtMsgType type); + private: static QScopedPointer s_Instance; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3a543e0b..ee7ee139 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -230,9 +230,9 @@ MainWindow::MainWindow(const QString &exeName, QSettings &initSettings, QWidget ui->savegameList->installEventFilter(this); ui->savegameList->setMouseTracking(true); - connect(&m_DownloadManager, SIGNAL(showMessage(QString)), this, SLOT(showMessage(QString))); connect(&m_DownloadManager, SIGNAL(downloadSpeed(QString,int)), this, SLOT(downloadSpeed(QString,int))); + connect(&m_DownloadManager, SIGNAL(downloadAdded()), ui->downloadView, SLOT(scrollToBottom())); connect(ui->savegameList, SIGNAL(itemEntered(QListWidgetItem*)), this, SLOT(saveSelectionChanged(QListWidgetItem*))); @@ -780,6 +780,8 @@ void MainWindow::showEvent(QShowEvent *event) ui->groupCombo->setCurrentIndex(grouping); allowListResize(); + + m_Settings.registerAsNXMHandler(false); } @@ -4024,15 +4026,10 @@ void MainWindow::on_actionSettings_triggered() NexusInterface::instance()->setNMMVersion(m_Settings.getNMMVersion()); } + void MainWindow::on_actionNexus_triggered() { - std::wstring nxmPath = ToWString(QApplication::applicationDirPath() + "/nxmhandler.exe"); - std::wstring executable = ToWString(QApplication::applicationFilePath()); - ::ShellExecuteW(NULL, L"open", nxmPath.c_str(), - (std::wstring(L"reg ") + GameInfo::instance().getGameShortName() + L" \"" + executable + L"\"").c_str(), NULL, SW_SHOWNORMAL); - ::ShellExecuteW(NULL, L"open", GameInfo::instance().getNexusPage(false).c_str(), NULL, NULL, SW_SHOWNORMAL); - ui->tabWidget->setCurrentIndex(4); } @@ -4052,6 +4049,7 @@ void MainWindow::linkClicked(const QString &url) void MainWindow::downloadRequestedNXM(const QString &url) { QString username, password; + qDebug("download requested: %s", qPrintable(url)); if (!m_LoginAttempted && !NexusInterface::instance()->getAccessManager()->loggedIn() && (m_Settings.getNexusLogin(username, password) || diff --git a/src/messagedialog.cpp b/src/messagedialog.cpp index 4a1ef0d6..8cef1b7c 100644 --- a/src/messagedialog.cpp +++ b/src/messagedialog.cpp @@ -81,6 +81,7 @@ void MessageDialog::resizeEvent(QResizeEvent *event) void MessageDialog::showMessage(const QString &text, QWidget *reference) { + qDebug("%s", qPrintable(text)); if (reference != NULL) { MessageDialog *dialog = new MessageDialog(text, reference); dialog->show(); diff --git a/src/settings.cpp b/src/settings.cpp index 8086672a..895094f7 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -102,6 +102,15 @@ bool Settings::pluginBlacklisted(const QString &fileName) const return m_PluginBlacklist.contains(fileName); } +void Settings::registerAsNXMHandler(bool force) +{ + std::wstring nxmPath = ToWString(QCoreApplication::applicationDirPath() + "/nxmhandler.exe"); + std::wstring executable = ToWString(QCoreApplication::applicationFilePath()); + std::wstring mode = force ? L"forcereg" : L"reg"; + ::ShellExecuteW(NULL, L"open", nxmPath.c_str(), + (mode + L" " + GameInfo::instance().getGameShortName() + L" \"" + executable + L"\"").c_str(), NULL, SW_SHOWNORMAL); +} + void Settings::registerPlugin(IPlugin *plugin) { m_Plugins.push_back(plugin); diff --git a/src/settings.h b/src/settings.h index abffc94b..81174440 100644 --- a/src/settings.h +++ b/src/settings.h @@ -256,6 +256,13 @@ public: */ std::vector plugins() const { return m_Plugins; } + /** + * @brief register MO as the handler for nxm links + * @param force set to true to enforce the registration dialog to show up, + * even if the user said earlier not to + */ + void registerAsNXMHandler(bool force); + private: QString obfuscate(const QString &password) const; diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp index c8908ddb..bf1f95dc 100644 --- a/src/settingsdialog.cpp +++ b/src/settingsdialog.cpp @@ -29,6 +29,7 @@ along with Mod Organizer. If not, see . #include #define WIN32_LEAN_AND_MEAN #include +#include "settings.h" using namespace MOBase; @@ -165,3 +166,8 @@ void SettingsDialog::deleteBlacklistItem() { ui->pluginBlacklist->takeItem(ui->pluginBlacklist->currentIndex().row()); } + +void SettingsDialog::on_associateButton_clicked() +{ + Settings::instance().registerAsNXMHandler(true); +} diff --git a/src/settingsdialog.h b/src/settingsdialog.h index 718574a0..0bd9fd23 100644 --- a/src/settingsdialog.h +++ b/src/settingsdialog.h @@ -75,6 +75,8 @@ private slots: void deleteBlacklistItem(); + void on_associateButton_clicked(); + private: Ui::SettingsDialog *ui; }; diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui index 39d49a39..bda6726c 100644 --- a/src/settingsdialog.ui +++ b/src/settingsdialog.ui @@ -275,32 +275,29 @@ p, li { white-space: pre-wrap; } - - - QFormLayout::AllNonFixedFieldsGrow - - + + Username - + false - + Password - + false @@ -342,13 +339,40 @@ p, li { white-space: pre-wrap; } - + + + + + Associate with "Download with manager" links + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + 4 + - Known Servers (Dynamically updated every download) + Known Servers (updated on download) -- cgit v1.3.1 From e69210b3a78c4a6c63086d84e6bdb2c3b47d8944 Mon Sep 17 00:00:00 2001 From: Tannin Date: Sat, 18 Jan 2014 19:51:58 +0100 Subject: - when a download server returns a text file, it's assumed to be an error and the text displayed as an error - save games can now be deleted from inside MO - bugfix: removing the pending download entry failed if the download-url request failed - bugfix: download manager didn't stop automatically resuming failed downloads under certain circumstances - bugfix: uninstalled downloads were treated as not-finished when refreshing the download list - bugfix: updating the filesystem watcher on the saves directory didn't work correctly --- src/aboutdialog.cpp | 1 - src/downloadmanager.cpp | 33 ++++++++++++++++----------------- src/downloadmanager.h | 2 +- src/mainwindow.cpp | 23 ++++++++++++++++++++++- src/mainwindow.h | 3 ++- src/modinfo.cpp | 4 ++-- src/modinfo.h | 2 +- src/nexusinterface.cpp | 34 +++++++++++++++++----------------- src/nexusinterface.h | 8 ++++---- src/pluginlist.cpp | 1 - src/selfupdater.cpp | 2 +- src/selfupdater.h | 2 +- 12 files changed, 67 insertions(+), 48 deletions(-) (limited to 'src/downloadmanager.h') diff --git a/src/aboutdialog.cpp b/src/aboutdialog.cpp index 94e4e54c..c7f95640 100644 --- a/src/aboutdialog.cpp +++ b/src/aboutdialog.cpp @@ -73,7 +73,6 @@ void AboutDialog::on_creditsList_currentItemChanged(QListWidgetItem *current, QL auto iter = m_LicenseFiles.find(current->data(Qt::UserRole).toInt()); if (iter != m_LicenseFiles.end()) { QString filePath = qApp->applicationDirPath() + "/license/" + iter->second; -qDebug("%s", qPrintable(filePath)); QString text = MOBase::readFileText(filePath); ui->licenseText->setText(text); } else { diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index dd320f70..31d8bcec 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -26,15 +26,16 @@ along with Mod Organizer. If not, see . #include "utility.h" #include "json.h" #include "selectiondialog.h" +#include #include #include #include #include #include -#include -#include #include #include +#include +#include using namespace MOBase; @@ -246,7 +247,7 @@ void DownloadManager::refreshList() // remove finished downloads for (QVector::iterator Iter = m_ActiveDownloads.begin(); Iter != m_ActiveDownloads.end();) { - if (((*Iter)->m_State == STATE_READY) || ((*Iter)->m_State == STATE_INSTALLED)) { + if (((*Iter)->m_State == STATE_READY) || ((*Iter)->m_State == STATE_INSTALLED) || ((*Iter)->m_State == STATE_UNINSTALLED)) { delete *Iter; Iter = m_ActiveDownloads.erase(Iter); } else { @@ -414,7 +415,7 @@ void DownloadManager::addNXMDownload(const QString &url) NXMUrl nxmInfo(url); QString managedGame = ToQString(MOShared::GameInfo::instance().getGameShortName()); - qDebug("add nxm download", qPrintable(url)); + qDebug("add nxm download: %s", qPrintable(url)); if (nxmInfo.game().compare(managedGame, Qt::CaseInsensitive) != 0) { qDebug("download requested for wrong game (game: %s, url: %s)", qPrintable(managedGame), qPrintable(nxmInfo.game())); QMessageBox::information(NULL, tr("Wrong Game"), tr("The download link is for a mod for \"%1\" but this instance of MO " @@ -1089,11 +1090,7 @@ void DownloadManager::nxmFileInfoAvailable(int modID, int fileID, QVariant userD info.m_FileName = result["uri"].toString(); info.m_FileTime = matchDate(result["date"].toString()); - if (userData.isValid()) { - m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(info), userData.toString())); - } else { - m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, qVariantFromValue(info))); - } + m_RequestIDs.insert(m_NexusInterface->requestDownloadURL(modID, fileID, this, QVariant::fromValue(info))); } @@ -1176,8 +1173,6 @@ void DownloadManager::nxmDownloadURLsAvailable(int modID, int fileID, QVariant u m_RequestIDs.erase(idIter); } - qDebug("download urls received (modid %d, fileid %d)", modID, fileID); - NexusInfo info = userData.value(); QVariantList resultList = resultData.toList(); if (resultList.length() == 0) { @@ -1200,7 +1195,7 @@ void DownloadManager::nxmDownloadURLsAvailable(int modID, int fileID, QVariant u } -void DownloadManager::nxmRequestFailed(int modID, QVariant userData, int requestID, const QString &errorString) +void DownloadManager::nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorString) { std::set::iterator idIter = m_RequestIDs.find(requestID); if (idIter == m_RequestIDs.end()) { @@ -1225,7 +1220,7 @@ void DownloadManager::nxmRequestFailed(int modID, QVariant userData, int request } } - removePending(modID, userData.toInt()); + removePending(modID, fileID); emit showMessage(tr("Failed to request file info from nexus: %1").arg(errorString)); } @@ -1243,14 +1238,18 @@ void DownloadManager::downloadFinished() TaskProgressManager::instance().forgetMe(info->m_TaskProgressId); bool error = false; - if ((info->m_State != STATE_CANCELING) && (info->m_State != STATE_PAUSING)) { + bool textData = reply->header(QNetworkRequest::ContentTypeHeader).toString().startsWith("text", Qt::CaseInsensitive); if ((info->m_Output.size() == 0) || ((reply->error() != QNetworkReply::NoError) && (reply->error() != QNetworkReply::OperationCanceledError)) || - reply->header(QNetworkRequest::ContentTypeHeader).toString().startsWith("text", Qt::CaseInsensitive)) { + textData) { if (info->m_Tries == 0) { - emit showMessage(tr("Download failed: %1 (%2)").arg(reply->errorString()).arg(reply->error())); + if (textData && (reply->error() == QNetworkReply::NoError)) { + emit showMessage(tr("Download failed. Server reported: %1").arg(readFileText(info->m_Output.fileName()))); + } else { + emit showMessage(tr("Download failed: %1 (%2)").arg(reply->errorString()).arg(reply->error())); + } } error = true; setState(info, STATE_PAUSING); @@ -1310,7 +1309,7 @@ void DownloadManager::downloadFinished() if ((info->m_Tries > 0) && error) { --info->m_Tries; - resumeDownload(index); + resumeDownloadInt(index); } } else { qWarning("no download index %d", index); diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 62396666..80b99ad2 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -412,7 +412,7 @@ public slots: void nxmDownloadURLsAvailable(int modID, int fileID, QVariant userData, QVariant resultData, int requestID); - void nxmRequestFailed(int modID, QVariant userData, int requestID, const QString &errorString); + void nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorString); private slots: diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 14e27e76..582bc283 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -66,6 +66,7 @@ along with Mod Organizer. If not, see . #include #include #include +#include #include #include #include @@ -1737,6 +1738,9 @@ void MainWindow::refreshSaveList() savesDir.setPath(QDir::fromNativeSeparators(ToQString(GameInfo::instance().getDocumentsDir() + L"\\" + path))); } + if (m_SavesWatcher.directories().length() > 0) { + m_SavesWatcher.removePaths(m_SavesWatcher.directories()); + } m_SavesWatcher.addPath(savesDir.absolutePath()); QStringList filters; @@ -3868,6 +3872,22 @@ void MainWindow::on_categoriesList_itemSelectionChanged() } +void MainWindow::deleteSavegame_clicked() +{ + QListWidgetItem *selectedItem = ui->savegameList->item(m_SelectedSaveGame); + if (selectedItem == NULL) { + return; + } + + QString fileName = selectedItem->data(Qt::UserRole).toString(); + + if (QMessageBox::question(this, tr("Confirm"), tr("Really delete \"%1\"?").arg(selectedItem->text()), + QMessageBox::Yes | QMessageBox::No) == QMessageBox::Yes) { + shellDelete(QStringList() << fileName); + } +} + + void MainWindow::fixMods_clicked() { QListWidgetItem *selectedItem = ui->savegameList->item(m_SelectedSaveGame); @@ -3973,6 +3993,7 @@ void MainWindow::on_savegameList_customContextMenuRequested(const QPoint &pos) QMenu menu; menu.addAction(tr("Fix Mods..."), this, SLOT(fixMods_clicked())); + menu.addAction(tr("Delete"), this, SLOT(deleteSavegame_clicked())); menu.exec(ui->savegameList->mapToGlobal(pos)); } @@ -4721,7 +4742,7 @@ void MainWindow::nxmDownloadURLs(int, int, QVariant, QVariant resultData, int) } -void MainWindow::nxmRequestFailed(int modID, QVariant, int, const QString &errorString) +void MainWindow::nxmRequestFailed(int modID, int, QVariant, int, const QString &errorString) { if (modID == -1) { // must be the update-check that failed diff --git a/src/mainwindow.h b/src/mainwindow.h index e7b3f7e1..c01ce767 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -398,6 +398,7 @@ private slots: void openExplorer_clicked(); void information_clicked(); // savegame context menu + void deleteSavegame_clicked(); void fixMods_clicked(); // data-tree context menu void writeDataToFile(); @@ -464,7 +465,7 @@ private slots: void nxmUpdatesAvailable(const std::vector &modIDs, QVariant userData, QVariant resultData, int requestID); // void nxmEndorsementToggled(int, QVariant, QVariant resultData, int); void nxmDownloadURLs(int modID, int fileID, QVariant userData, QVariant resultData, int requestID); - void nxmRequestFailed(int modID, QVariant userData, int requestID, const QString &errorString); + void nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorString); void editCategories(); diff --git a/src/modinfo.cpp b/src/modinfo.cpp index 6569f897..85612b32 100644 --- a/src/modinfo.cpp +++ b/src/modinfo.cpp @@ -345,7 +345,7 @@ ModInfoRegular::ModInfoRegular(const QDir &path, DirectoryEntry **directoryStruc connect(&m_NexusBridge, SIGNAL(descriptionAvailable(int,QVariant,QVariant)), this, SLOT(nxmDescriptionAvailable(int,QVariant,QVariant))); connect(&m_NexusBridge, SIGNAL(endorsementToggled(int,QVariant,QVariant)), this, SLOT(nxmEndorsementToggled(int,QVariant,QVariant))); - connect(&m_NexusBridge, SIGNAL(requestFailed(int,QVariant,QString)), this, SLOT(nxmRequestFailed(int,QVariant,QString))); + connect(&m_NexusBridge, SIGNAL(requestFailed(int,int,QVariant,QString)), this, SLOT(nxmRequestFailed(int,int,QVariant,QString))); } @@ -439,7 +439,7 @@ void ModInfoRegular::nxmEndorsementToggled(int, QVariant, QVariant resultData) } -void ModInfoRegular::nxmRequestFailed(int, QVariant userData, const QString &errorMessage) +void ModInfoRegular::nxmRequestFailed(int, int, QVariant userData, const QString &errorMessage) { QString fullMessage = errorMessage; if (userData.canConvert() && (userData.toInt() == 1)) { diff --git a/src/modinfo.h b/src/modinfo.h index 677d8a82..83654c7e 100644 --- a/src/modinfo.h +++ b/src/modinfo.h @@ -762,7 +762,7 @@ private slots: void nxmDescriptionAvailable(int modID, QVariant userData, QVariant resultData); void nxmEndorsementToggled(int, QVariant userData, QVariant resultData); - void nxmRequestFailed(int modID, QVariant userData, const QString &errorMessage); + void nxmRequestFailed(int modID, int fileID, QVariant userData, const QString &errorMessage); private: diff --git a/src/nexusinterface.cpp b/src/nexusinterface.cpp index 6b87822a..64dd6272 100644 --- a/src/nexusinterface.cpp +++ b/src/nexusinterface.cpp @@ -128,12 +128,12 @@ void NexusBridge::nxmEndorsementToggled(int modID, QVariant userData, QVariant r } } -void NexusBridge::nxmRequestFailed(int modID, QVariant userData, int requestID, const QString &errorMessage) +void NexusBridge::nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorMessage) { std::set::iterator iter = m_RequestIDs.find(requestID); if (iter != m_RequestIDs.end()) { m_RequestIDs.erase(iter); - emit requestFailed(modID, userData, errorMessage); + emit requestFailed(modID, fileID, userData, errorMessage); } } @@ -257,8 +257,8 @@ int NexusInterface::requestDescription(int modID, QObject *receiver, QVariant us connect(this, SIGNAL(nxmDescriptionAvailable(int,QVariant,QVariant,int)), receiver, SLOT(nxmDescriptionAvailable(int,QVariant,QVariant,int)), Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(int,QVariant,int,QString)), - receiver, SLOT(nxmRequestFailed(int,QVariant,int,QString)), Qt::UniqueConnection); + connect(this, SIGNAL(nxmRequestFailed(int,int,QVariant,int,QString)), + receiver, SLOT(nxmRequestFailed(int,int,QVariant,int,QString)), Qt::UniqueConnection); nextRequest(); return requestInfo.m_ID; @@ -273,8 +273,8 @@ int NexusInterface::requestUpdates(const std::vector &modIDs, QObject *rece connect(this, SIGNAL(nxmUpdatesAvailable(std::vector,QVariant,QVariant,int)), receiver, SLOT(nxmUpdatesAvailable(std::vector,QVariant,QVariant,int)), Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(int,QVariant,int,QString)), - receiver, SLOT(nxmRequestFailed(int,QVariant,int,QString)), Qt::UniqueConnection); + connect(this, SIGNAL(nxmRequestFailed(int,int,QVariant,int,QString)), + receiver, SLOT(nxmRequestFailed(int,int,QVariant,int,QString)), Qt::UniqueConnection); nextRequest(); return requestInfo.m_ID; @@ -307,8 +307,8 @@ int NexusInterface::requestFiles(int modID, QObject *receiver, QVariant userData connect(this, SIGNAL(nxmFilesAvailable(int,QVariant,QVariant,int)), receiver, SLOT(nxmFilesAvailable(int,QVariant,QVariant,int)), Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(int,QVariant,int,QString)), - receiver, SLOT(nxmRequestFailed(int,QVariant,int,QString)), Qt::UniqueConnection); + connect(this, SIGNAL(nxmRequestFailed(int,int,QVariant,int,QString)), + receiver, SLOT(nxmRequestFailed(int,int,QVariant,int,QString)), Qt::UniqueConnection); // QTimer::singleShot(1000, this, SLOT(fakeFiles())); // static int fID = 42; @@ -327,8 +327,8 @@ int NexusInterface::requestFileInfo(int modID, int fileID, QObject *receiver, QV connect(this, SIGNAL(nxmFileInfoAvailable(int,int,QVariant,QVariant,int)), receiver, SLOT(nxmFileInfoAvailable(int,int,QVariant,QVariant,int)), Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(int,QVariant,int,QString)), - receiver, SLOT(nxmRequestFailed(int,QVariant,int,QString)), Qt::UniqueConnection); + connect(this, SIGNAL(nxmRequestFailed(int,int,QVariant,int,QString)), + receiver, SLOT(nxmRequestFailed(int,int,QVariant,int,QString)), Qt::UniqueConnection); nextRequest(); return requestInfo.m_ID; @@ -343,8 +343,8 @@ int NexusInterface::requestDownloadURL(int modID, int fileID, QObject *receiver, connect(this, SIGNAL(nxmDownloadURLsAvailable(int,int,QVariant,QVariant,int)), receiver, SLOT(nxmDownloadURLsAvailable(int,int,QVariant,QVariant,int)), Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(int,QVariant,int,QString)), - receiver, SLOT(nxmRequestFailed(int,QVariant,int,QString)), Qt::UniqueConnection); + connect(this, SIGNAL(nxmRequestFailed(int,int,QVariant,int,QString)), + receiver, SLOT(nxmRequestFailed(int,int,QVariant,int,QString)), Qt::UniqueConnection); nextRequest(); return requestInfo.m_ID; @@ -360,8 +360,8 @@ int NexusInterface::requestToggleEndorsement(int modID, bool endorse, QObject *r connect(this, SIGNAL(nxmEndorsementToggled(int,QVariant,QVariant,int)), receiver, SLOT(nxmEndorsementToggled(int,QVariant,QVariant,int)), Qt::UniqueConnection); - connect(this, SIGNAL(nxmRequestFailed(int,QVariant,int,QString)), - receiver, SLOT(nxmRequestFailed(int,QVariant,int,QString)), Qt::UniqueConnection); + connect(this, SIGNAL(nxmRequestFailed(int,int,QVariant,int,QString)), + receiver, SLOT(nxmRequestFailed(int,int,QVariant,int,QString)), Qt::UniqueConnection); nextRequest(); return requestInfo.m_ID; @@ -437,7 +437,7 @@ void NexusInterface::requestFinished(std::list::iterator iter) if (reply->error() != QNetworkReply::NoError) { qWarning("request failed: %s", reply->errorString().toUtf8().constData()); - emit nxmRequestFailed(iter->m_ModID, iter->m_UserData, iter->m_ID, reply->errorString()); + emit nxmRequestFailed(iter->m_ModID, iter->m_FileID, iter->m_UserData, iter->m_ID, reply->errorString()); } else { int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); if (statusCode == 301) { @@ -454,7 +454,7 @@ void NexusInterface::requestFinished(std::list::iterator iter) if (nexusError.length() == 0) { nexusError = tr("empty response"); } - emit nxmRequestFailed(iter->m_ModID, iter->m_UserData, iter->m_ID, nexusError); + emit nxmRequestFailed(iter->m_ModID, iter->m_FileID, iter->m_UserData, iter->m_ID, nexusError); } else { bool ok; QVariant result = QtJson::parse(data, ok); @@ -480,7 +480,7 @@ void NexusInterface::requestFinished(std::list::iterator iter) } break; } } else { - emit nxmRequestFailed(iter->m_ModID, iter->m_UserData, iter->m_ID, tr("invalid response")); + emit nxmRequestFailed(iter->m_ModID, iter->m_FileID, iter->m_UserData, iter->m_ID, tr("invalid response")); } } } diff --git a/src/nexusinterface.h b/src/nexusinterface.h index e7a01b0f..7b709e1c 100644 --- a/src/nexusinterface.h +++ b/src/nexusinterface.h @@ -105,7 +105,7 @@ public slots: void nxmFileInfoAvailable(int modID, int fileID, QVariant userData, QVariant resultData, int requestID); void nxmDownloadURLsAvailable(int modID, int fileID, QVariant userData, QVariant resultData, int requestID); void nxmEndorsementToggled(int modID, QVariant userData, QVariant resultData, int requestID); - void nxmRequestFailed(int modID, QVariant userData, int requestID, const QString &errorMessage); + void nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorMessage); private: @@ -240,7 +240,7 @@ signals: void nxmFileInfoAvailable(int modID, int fileID, QVariant userData, QVariant resultData, int requestID); void nxmDownloadURLsAvailable(int modID, int fileID, QVariant userData, QVariant resultData, int requestID); void nxmEndorsementToggled(int modID, QVariant userData, QVariant resultData, int requestID); - void nxmRequestFailed(int modID, QVariant userData, int requestID, const QString &errorString); + void nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorString); private slots: @@ -276,13 +276,13 @@ private: NXMRequestInfo(int modID, Type type, QVariant userData, const QString &url) : m_ModID(modID), m_FileID(0), m_Reply(NULL), m_Type(type), m_UserData(userData), - m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} + m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} NXMRequestInfo(std::vector modIDList, Type type, QVariant userData, const QString &url) : m_ModID(-1), m_ModIDList(modIDList), m_FileID(0), m_Reply(NULL), m_Type(type), m_UserData(userData), m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} NXMRequestInfo(int modID, int fileID, Type type, QVariant userData, const QString &url) : m_ModID(modID), m_FileID(fileID), m_Reply(NULL), m_Type(type), m_UserData(userData), - m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} + m_Timeout(NULL), m_Reroute(false), m_ID(s_NextID.fetchAndAddAcquire(1)), m_URL(url) {} private: static QAtomicInt s_NextID; diff --git a/src/pluginlist.cpp b/src/pluginlist.cpp index a0045ab3..85137390 100644 --- a/src/pluginlist.cpp +++ b/src/pluginlist.cpp @@ -312,7 +312,6 @@ bool PluginList::readLoadOrder(const QString &fileName) void PluginList::readEnabledFrom(const QString &fileName) { -qDebug("read enabled from %s", qPrintable(fileName)); for (std::vector::iterator iter = m_ESPs.begin(); iter != m_ESPs.end(); ++iter) { if (!iter->m_ForceEnabled) { iter->m_Enabled = false; diff --git a/src/selfupdater.cpp b/src/selfupdater.cpp index 2a9ca893..3a0db83f 100644 --- a/src/selfupdater.cpp +++ b/src/selfupdater.cpp @@ -428,7 +428,7 @@ void SelfUpdater::nxmFilesAvailable(int, QVariant userData, QVariant resultData, } -void SelfUpdater::nxmRequestFailed(int, QVariant, int requestID, const QString &errorMessage) +void SelfUpdater::nxmRequestFailed(int, int, QVariant, int requestID, const QString &errorMessage) { if (requestID == m_UpdateRequestID) { m_UpdateRequestID = -1; diff --git a/src/selfupdater.h b/src/selfupdater.h index 2c4c1ecd..14f7e90a 100644 --- a/src/selfupdater.h +++ b/src/selfupdater.h @@ -87,7 +87,7 @@ public slots: void nxmDescriptionAvailable(int modID, QVariant userData, QVariant resultData, int requestID); void nxmFilesAvailable(int modID, QVariant userData, QVariant resultData, int requestID); - void nxmRequestFailed(int modID, QVariant userData, int requestID, const QString &errorMessage); + void nxmRequestFailed(int modID, int fileID, QVariant userData, int requestID, const QString &errorMessage); void nxmDownloadURLsAvailable(int modID, int fileID, QVariant userData, QVariant resultData, int requestID); signals: -- cgit v1.3.1