diff options
| author | Brian Munro <brian.alexander.munro@gmail.com> | 2018-04-13 11:56:36 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-04-13 11:56:36 +0200 |
| commit | bc75009169ecbf378fa90891dc8183a8cb3ef499 (patch) | |
| tree | 221f74cbaeea3750bd705a6a37ff8242e4cef192 /src/downloadmanager.cpp | |
| parent | d6aab781ee1d5b927ccf06100e74539a980ee83f (diff) | |
| parent | 8be73d2e3b0af9cb99616d31418a0d9c74aca466 (diff) | |
Merge pull request #294 from Modorganizer2/Develop
Release 2.1.2
Diffstat (limited to 'src/downloadmanager.cpp')
| -rw-r--r-- | src/downloadmanager.cpp | 79 |
1 files changed, 61 insertions, 18 deletions
diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index a4fde093..569a7d31 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -460,7 +460,29 @@ void DownloadManager::addNXMDownload(const QString &url) return;
}
+ for (auto pair : m_PendingDownloads) {
+ if (pair.first == nxmInfo.modId() && pair.second == nxmInfo.fileId()) {
+ qDebug("download requested is already started (mod id: %s, file id: %s)", qPrintable(QString(nxmInfo.modId())), qPrintable(QString(nxmInfo.fileId())));
+ QMessageBox::information(nullptr, tr("Already Started"), tr("A download for this mod file has already been queued."), QMessageBox::Ok);
+ return;
+ }
+ }
+
+ for (DownloadInfo *download : m_ActiveDownloads) {
+ if (download->m_FileInfo->modID == nxmInfo.modId() && download->m_FileInfo->fileID == nxmInfo.fileId()) {
+ if (download->m_State == STATE_DOWNLOADING || download->m_State == STATE_PAUSED || download->m_State == STATE_STARTED) {
+ qDebug("download requested is already started (mod: %s, file: %s)", qPrintable(download->m_FileInfo->modName),
+ qPrintable(download->m_FileInfo->fileName));
+
+ QMessageBox::information(nullptr, tr("Already Started"), tr("There is already a download started for this file (%2).")
+ .arg(download->m_FileInfo->modName).arg(download->m_FileInfo->name), QMessageBox::Ok);
+ return;
+ }
+ }
+ }
+
emit aboutToUpdate();
+
m_PendingDownloads.append(std::make_pair(nxmInfo.modId(), nxmInfo.fileId()));
emit update(-1);
@@ -558,36 +580,20 @@ void DownloadManager::removeDownload(int index, bool deleteFile) emit aboutToUpdate();
if (index < 0) {
- if (index == -1) {
- DownloadState minState = STATE_READY;
+ DownloadState minState = index == -1 ? STATE_READY : STATE_INSTALLED;
index = 0;
for (QVector<DownloadInfo*>::iterator iter = m_ActiveDownloads.begin(); iter != m_ActiveDownloads.end();) {
if ((*iter)->m_State >= minState) {
removeFile(index, deleteFile);
delete *iter;
iter = m_ActiveDownloads.erase(iter);
+ QCoreApplication::processEvents();
}
else {
++iter;
++index;
}
}
- }
- else {
- DownloadState minState = STATE_INSTALLED;
- index = 0;
- for (QVector<DownloadInfo*>::iterator iter = m_ActiveDownloads.begin(); iter != m_ActiveDownloads.end();) {
- if ((*iter)->m_State == minState) {
- removeFile(index, deleteFile);
- delete *iter;
- iter = m_ActiveDownloads.erase(iter);
- }
- else {
- ++iter;
- ++index;
- }
- }
- }
} else {
if (index >= m_ActiveDownloads.size()) {
reportError(tr("remove: invalid download index %1").arg(index));
@@ -896,6 +902,26 @@ void DownloadManager::markInstalled(int index) setState(m_ActiveDownloads.at(index), STATE_INSTALLED);
}
+void DownloadManager::markInstalled(QString fileName)
+{
+ int index = indexByName(fileName);
+ if (index >= 0) {
+ markInstalled(index);
+ } else {
+ DownloadInfo *info = getDownloadInfo(fileName);
+ if (info != nullptr) {
+ QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat);
+ metaFile.setValue("installed", true);
+ metaFile.setValue("uninstalled", false);
+ }
+ delete info;
+ }
+}
+
+DownloadManager::DownloadInfo* DownloadManager::getDownloadInfo(QString fileName)
+{
+ return DownloadInfo::createFromMeta(fileName, true);
+}
void DownloadManager::markUninstalled(int index)
{
@@ -911,6 +937,23 @@ void DownloadManager::markUninstalled(int index) }
+void DownloadManager::markUninstalled(QString fileName)
+{
+ int index = indexByName(fileName);
+ if (index >= 0) {
+ markUninstalled(index);
+ } else {
+ QString filePath = QDir::fromNativeSeparators(m_OutputDirectory) + "/" + fileName;
+ DownloadInfo *info = getDownloadInfo(filePath);
+ if (info != nullptr) {
+ QSettings metaFile(info->m_Output.fileName() + ".meta", QSettings::IniFormat);
+ metaFile.setValue("uninstalled", true);
+ }
+ delete info;
+ }
+}
+
+
QString DownloadManager::getDownloadFileName(const QString &baseName) const
{
QString fullPath = m_OutputDirectory + "/" + baseName;
|
