summaryrefslogtreecommitdiff
path: root/src/directoryrefresher.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2020-02-16 18:57:38 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2020-02-18 17:25:05 -0500
commitd3fe9ff1faed52da8f647d9294e9ce371b0361e4 (patch)
tree18aee61a71ae07a26d5746a36e48dfc77319cb0d /src/directoryrefresher.cpp
parent528fa988b54342d3d5372ecf9613b60fc7287613 (diff)
moved TimeThis to uibase
fixed progress bar
Diffstat (limited to 'src/directoryrefresher.cpp')
-rw-r--r--src/directoryrefresher.cpp34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/directoryrefresher.cpp b/src/directoryrefresher.cpp
index 5e1c05a8..599dd815 100644
--- a/src/directoryrefresher.cpp
+++ b/src/directoryrefresher.cpp
@@ -326,8 +326,10 @@ void DirectoryRefresher::addModToStructure(DirectoryEntry *directoryStructure
}
}
+
struct ModThread
{
+ DirectoryRefreshProgress* progress = nullptr;
DirectoryEntry* ds = nullptr;
std::wstring modName;
std::wstring path;
@@ -375,6 +377,11 @@ struct ModThread
modName, path, prio, archives, enabledArchives, lo, *stats);
}
+ if (progress) {
+ progress->addDone();
+ }
+
+ SetThisThreadName(QString::fromStdWString(L"idle refresher"));
ready = false;
}
};
@@ -382,13 +389,22 @@ struct ModThread
env::ThreadPool<ModThread> g_threads;
+void DirectoryRefresher::updateProgress(const DirectoryRefreshProgress* p)
+{
+ // careful: called from multiple threads
+ emit progress(p);
+}
void DirectoryRefresher::addMultipleModsFilesToStructure(
MOShared::DirectoryEntry *directoryStructure,
- const std::vector<EntryInfo>& entries, bool emitProgress)
+ const std::vector<EntryInfo>& entries, DirectoryRefreshProgress* progress)
{
std::vector<DirectoryStats> stats(entries.size());
+ if (progress) {
+ progress->start(entries.size());
+ }
+
log::debug("refresher: using {} threads", m_threadCount);
g_threads.setMax(m_threadCount);
@@ -405,9 +421,14 @@ void DirectoryRefresher::addMultipleModsFilesToStructure(
if (e.stealFiles.length() > 0) {
stealModFilesIntoStructure(
directoryStructure, e.modName, prio, e.absolutePath, e.stealFiles);
+
+ if (progress) {
+ progress->addDone();
+ }
} else {
auto& mt = g_threads.request();
+ mt.progress = progress;
mt.ds = directoryStructure;
mt.modName = e.modName.toStdWString();
mt.path = QDir::toNativeSeparators(e.absolutePath).toStdWString();
@@ -430,10 +451,6 @@ void DirectoryRefresher::addMultipleModsFilesToStructure(
} catch (const std::exception& ex) {
emit error(tr("failed to read mod (%1): %2").arg(e.modName, ex.what()));
}
-
- if (emitProgress) {
- emit progress((static_cast<int>(i) * 100) / static_cast<int>(entries.size()) + 1);
- }
}
g_threads.waitForAll();
@@ -447,6 +464,7 @@ void DirectoryRefresher::refresh()
{
SetThisThreadName("DirectoryRefresher");
TimeThis tt("refresh");
+ auto* p = new DirectoryRefreshProgress(this);
{
QMutexLocker locker(&m_RefreshLock);
@@ -468,7 +486,7 @@ void DirectoryRefresher::refresh()
return lhs.priority < rhs.priority;
});
- addMultipleModsFilesToStructure(m_Root.get(), m_Mods, true);
+ addMultipleModsFilesToStructure(m_Root.get(), m_Mods, p);
m_Root->getFileRegister()->sortOrigins();
@@ -478,6 +496,8 @@ void DirectoryRefresher::refresh()
log::debug("refresher saw {} files", m_lastFileCount);
}
- emit progress(100);
+ p->finish();
+
+ emit progress(p);
emit refreshed();
}