commit 32a1aa6b4fd2cc31787c1ecd4026f491b4a5284f
parent 4d4e7b88152760c76fd7941932e5f9865be7d4d0
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 7 Dec 2015 22:31:29 -0500
don't access the name of downloads once they may have been freed from memory
downloads may finish in any order, so we can't assume the last started one will be the last to finish
Diffstat:
2 files changed, 11 insertions(+), 11 deletions(-)
diff --git a/src/progress.cpp b/src/progress.cpp
@@ -10,8 +10,8 @@ using namespace std;
Progress::Progress()
: Dialog(IDD_PROGRESS_DIALOG),
- m_transaction(nullptr), m_current(nullptr), m_label(nullptr),
- m_progress(nullptr), m_done(0), m_total(0)
+ m_transaction(nullptr), m_label(nullptr), m_progress(nullptr),
+ m_done(0), m_total(0)
{
}
@@ -21,6 +21,7 @@ void Progress::setTransaction(Transaction *t)
m_done = 0;
m_total = 0;
+ m_currentName.clear();
if(!m_transaction)
return;
@@ -29,7 +30,6 @@ void Progress::setTransaction(Transaction *t)
m_transaction->downloadQueue()->onPush(
bind(&Progress::addDownload, this, placeholders::_1));
- m_transaction->onFinish([=] { m_current = nullptr; });
}
void Progress::onInit()
@@ -60,7 +60,7 @@ void Progress::addDownload(Download *dl)
updateProgress();
dl->onStart([=] {
- m_current = dl;
+ m_currentName = dl->name();
updateProgress();
});
@@ -72,13 +72,11 @@ void Progress::addDownload(Download *dl)
void Progress::updateProgress()
{
- if(m_current) {
- const string text = "Downloading " +
- to_string(min(m_done + 1, m_total)) + " of " +
- to_string(m_total) + ": " + m_current->name();
+ const string text = "Downloading " +
+ to_string(min(m_done + 1, m_total)) + " of " +
+ to_string(m_total) + ": " + m_currentName;
- SetWindowText(m_label, text.c_str());
- }
+ SetWindowText(m_label, text.c_str());
const double pos = (double)m_done / m_total;
const int percent = (int)(pos * 100);
diff --git a/src/progress.hpp b/src/progress.hpp
@@ -3,6 +3,8 @@
#include "dialog.hpp"
+#include <string>
+
class Download;
class Transaction;
@@ -21,7 +23,7 @@ private:
void updateProgress();
Transaction *m_transaction;
- Download *m_current;
+ std::string m_currentName;
HWND m_label;
HWND m_progress;