updater: Deduplicate Downloads

This commit is contained in:
derrod 2023-01-12 01:35:48 +01:00 committed by Jim
parent ace518804b
commit 807c0c386d

View file

@ -24,6 +24,7 @@
#include <vector>
#include <string>
#include <mutex>
#include <unordered_set>
using namespace std;
using namespace json11;
@ -246,6 +247,7 @@ enum state_t {
STATE_PENDING_DOWNLOAD,
STATE_DOWNLOADING,
STATE_DOWNLOADED,
STATE_ALREADY_DOWNLOADED,
STATE_INSTALL_FAILED,
STATE_INSTALLED,
};
@ -1564,6 +1566,24 @@ static bool Update(wchar_t *cmdLine)
source.c_str(), size);
}
/* ------------------------------------- *
* Deduplicate Downloads */
unordered_set<wstring> tempFiles;
for (update_t &update : updates) {
if (update.patchable)
continue;
if (tempFiles.count(update.tempPath)) {
update.state = STATE_ALREADY_DOWNLOADED;
totalFileSize -= update.fileSize;
completedUpdates++;
continue;
}
tempFiles.insert(update.tempPath);
}
/* ------------------------------------- *
* Download Updates */