From b2af1e340f956c11a7c522e8c4b5900925417634 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 24 Dec 2020 09:36:04 -0500 Subject: dump nxmhandler.ini --- src/shared/appconfig.inc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/shared') diff --git a/src/shared/appconfig.inc b/src/shared/appconfig.inc index 5839c2f4..9058bf18 100644 --- a/src/shared/appconfig.inc +++ b/src/shared/appconfig.inc @@ -18,6 +18,8 @@ APPPARAM(std::wstring, proxyDLLOrig, L"steam_api_orig.dll") // needs to be ident APPPARAM(std::wstring, proxyDLLSource, L"proxy.dll") APPPARAM(std::wstring, vfs32DLLName, L"usvfs_x86.dll") APPPARAM(std::wstring, vfs64DLLName, L"usvfs_x64.dll") +APPPARAM(std::wstring, nxmHandlerExe, L"nxmhandler.exe") +APPPARAM(std::wstring, nxmHandlerIni, L"nxmhandler.ini") APPPARAM(std::wstring, portableLockFileName, L"portable.txt") APPPARAM(const wchar_t*, localSavePlaceholder, L"__MOProfileSave__\\") -- cgit v1.3.1 From c8cff6166d05e77c843bb727702607f970d3d030 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 24 Dec 2020 10:02:56 -0500 Subject: added version to dmp filename replaced QApplication calls so createVersionInfo() can be called without one, happens with dump_running_process.bat --- src/env.cpp | 35 ++++++++++++++++++++++++++++++++--- src/env.h | 4 ++++ src/shared/util.cpp | 5 +++-- 3 files changed, 39 insertions(+), 5 deletions(-) (limited to 'src/shared') diff --git a/src/env.cpp b/src/env.cpp index 98d2e6ea..edd8cd6b 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -6,6 +6,7 @@ #include "envwindows.h" #include "envdump.h" #include "settings.h" +#include "shared/util.h" #include #include @@ -1009,7 +1010,7 @@ bool registryValueExists(const QString& keyName, const QString& valueName) // returns the filename of the given process or the current one // -std::wstring processFilename(HANDLE process=INVALID_HANDLE_VALUE) +std::filesystem::path processPath(HANDLE process=INVALID_HANDLE_VALUE) { // double the buffer size 10 times const int MaxTries = 10; @@ -1045,7 +1046,7 @@ std::wstring processFilename(HANDLE process=INVALID_HANDLE_VALUE) const std::wstring s(buffer.get(), writtenSize); const std::filesystem::path path(s); - return path.filename().native(); + return path; } } @@ -1062,6 +1063,21 @@ std::wstring processFilename(HANDLE process=INVALID_HANDLE_VALUE) return {}; } +std::wstring processFilename(HANDLE process=INVALID_HANDLE_VALUE) +{ + const auto p = processPath(process); + if (p.empty()) { + return {}; + } + + return p.filename().native(); +} + +std::filesystem::path thisProcessPath() +{ + return processPath(); +} + DWORD findOtherPid() { const std::wstring defaultName = L"ModOrganizer.exe"; @@ -1126,6 +1142,19 @@ std::wstring tempDir() return std::wstring(buffer, buffer + written); } +std::wstring safeVersion() +{ + try + { + // this can throw + return MOShared::createVersionInfo().displayString(3).toStdWString() + L"-"; + } + catch(...) + { + return {}; + } +} + HandlePtr tempFile(const std::wstring dir) { // maximum tries of incrementing the counter @@ -1139,7 +1168,7 @@ HandlePtr tempFile(const std::wstring dir) // i can go until MaxTries std::wostringstream oss; oss - << L"ModOrganizer-" + << L"ModOrganizer-" << safeVersion() << std::setw(4) << (1900 + tm->tm_year) << std::setw(2) << std::setfill(L'0') << (tm->tm_mon + 1) << std::setw(2) << std::setfill(L'0') << tm->tm_mday << "T" diff --git a/src/env.h b/src/env.h index e9cb7a36..2152a40d 100644 --- a/src/env.h +++ b/src/env.h @@ -309,6 +309,10 @@ bool registryValueExists(const QString& key, const QString& value); // void deleteRegistryKeyIfEmpty(const QString& name); +// returns the path to this process +// +std::filesystem::path thisProcessPath(); + } // namespace env #endif // ENV_ENV_H diff --git a/src/shared/util.cpp b/src/shared/util.cpp index f316549e..54c6b841 100644 --- a/src/shared/util.cpp +++ b/src/shared/util.cpp @@ -210,12 +210,13 @@ std::wstring GetFileVersionString(const std::wstring &fileName) VersionInfo createVersionInfo() { - VS_FIXEDFILEINFO version = GetFileVersion(QApplication::applicationFilePath().toStdWString()); + VS_FIXEDFILEINFO version = GetFileVersion(env::thisProcessPath().native()); if (version.dwFileFlags & VS_FF_PRERELEASE) { // Pre-release builds need annotating - QString versionString = QString::fromStdWString(GetFileVersionString(QApplication::applicationFilePath().toStdWString())); + QString versionString = QString::fromStdWString( + GetFileVersionString(env::thisProcessPath().native())); // The pre-release flag can be set without the string specifying what type of pre-release bool noLetters = true; -- cgit v1.3.1 From 5183b2f47ad240174bf653b299af9e068a3b83e4 Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Thu, 24 Dec 2020 10:55:55 -0500 Subject: optimizations for download manager: - use envfs for walking directory - minimize string copies, disk access - use set of filenames to check for duplicates - use file size from envfs --- src/downloadmanager.cpp | 91 +++++++++++++++++++++++++++++++------------ src/downloadmanager.h | 4 +- src/envfs.cpp | 25 +++++++----- src/envfs.h | 5 ++- src/shared/directoryentry.cpp | 2 +- 5 files changed, 90 insertions(+), 37 deletions(-) (limited to 'src/shared') diff --git a/src/downloadmanager.cpp b/src/downloadmanager.cpp index 762e3cdb..c912464d 100644 --- a/src/downloadmanager.cpp +++ b/src/downloadmanager.cpp @@ -24,11 +24,13 @@ along with Mod Organizer. If not, see . #include "nexusinterface.h" #include "nxmaccessmanager.h" #include "iplugingame.h" +#include "envfs.h" #include #include #include "utility.h" #include "selectiondialog.h" #include "bbcode.h" +#include "shared/util.h" #include #include @@ -77,7 +79,9 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createNew(const Mo return info; } -DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta(const QString &filePath, bool showHidden, const QString outputDirectory) +DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta( + const QString &filePath, bool showHidden, const QString outputDirectory, + std::optional fileSize) { DownloadInfo *info = new DownloadInfo; @@ -113,7 +117,7 @@ DownloadManager::DownloadInfo *DownloadManager::DownloadInfo::createFromMeta(con info->m_DownloadID = s_NextDownloadID++; info->m_Output.setFileName(filePath); - info->m_TotalSize = QFileInfo(filePath).size(); + info->m_TotalSize = fileSize ? *fileSize : QFileInfo(filePath).size(); info->m_PreResumeSize = info->m_TotalSize; info->m_CurrentUrl = 0; info->m_Urls = metaFile.value("url", "").toString().split(";"); @@ -325,13 +329,15 @@ void DownloadManager::refreshList() } } - QStringList supportedExtensions = m_OrganizerCore->installationManager()->getSupportedExtensions(); - QStringList nameFilters(supportedExtensions); + const QStringList supportedExtensions = m_OrganizerCore->installationManager()->getSupportedExtensions(); + std::vector nameFilters; for (const auto& extension : supportedExtensions) { - nameFilters.append("*." + extension); + nameFilters.push_back(L"." + extension.toLower().toStdWString()); } - nameFilters.append(QString("*").append(UNFINISHED)); + nameFilters.push_back(QString(UNFINISHED).toLower().toStdWString()); + + QDir dir(QDir::fromNativeSeparators(m_OutputDirectory)); // find orphaned meta files and delete them (sounds cruel but it's better for everyone) @@ -348,28 +354,65 @@ void DownloadManager::refreshList() shellDelete(orphans, true); } - // add existing downloads to list - foreach (QString file, dir.entryList(nameFilters, QDir::Files, QDir::Time)) { - bool Exists = false; - for (QVector::const_iterator Iter = m_ActiveDownloads.begin(); Iter != m_ActiveDownloads.end() && !Exists; ++Iter) { - if (QString::compare((*Iter)->m_FileName, file, Qt::CaseInsensitive) == 0) { - Exists = true; - } else if (QString::compare(QFileInfo((*Iter)->m_Output.fileName()).fileName(), file, Qt::CaseInsensitive) == 0) { - Exists = true; - } - } - if (Exists) { - continue; - } - QString fileName = QDir::fromNativeSeparators(m_OutputDirectory) + "/" + file; + std::set seen; - DownloadInfo *info = DownloadInfo::createFromMeta(fileName, m_ShowHidden, m_OutputDirectory); - if (info != nullptr) { - m_ActiveDownloads.push_front(info); - } + struct Context + { + DownloadManager& self; + std::set& seen; + std::vector& extensions; + }; + + Context cx = {*this, seen, nameFilters}; + + for (auto&& d : m_ActiveDownloads) { + cx.seen.insert(d->m_FileName.toLower().toStdWString()); + cx.seen.insert(QFileInfo(d->m_Output.fileName()).fileName().toLower().toStdWString()); } + + env::forEachEntry( + QDir::toNativeSeparators(m_OutputDirectory).toStdWString(), &cx, nullptr, nullptr, + [](void* data, std::wstring_view f, FILETIME, uint64_t size) { + auto& cx = *static_cast(data); + + std::wstring lc = MOShared::ToLowerCopy(f); + + bool interestingExt = false; + for (auto&& ext : cx.extensions) { + if (lc.ends_with(ext)) { + interestingExt = true; + break; + } + } + + if (!interestingExt) { + return; + } + + if (cx.seen.contains(lc)) { + return; + } + + QString fileName = + QDir::fromNativeSeparators(cx.self.m_OutputDirectory) + "/" + + QString::fromWCharArray(f.data(), f.size()); + + DownloadInfo *info = DownloadInfo::createFromMeta( + fileName, cx.self.m_ShowHidden, cx.self.m_OutputDirectory, size); + + if (info == nullptr) { + return; + } + + cx.self.m_ActiveDownloads.push_front(info); + cx.seen.insert(std::move(lc)); + cx.seen.insert(QFileInfo(info->m_Output.fileName()).fileName().toLower().toStdWString()); + }); + + log::debug("saw {} downloads", m_ActiveDownloads.size()); + emit update(-1); //let watcher trigger refreshes again diff --git a/src/downloadmanager.h b/src/downloadmanager.h index 953ab88b..5e126f4b 100644 --- a/src/downloadmanager.h +++ b/src/downloadmanager.h @@ -104,7 +104,9 @@ private: bool m_Hidden; static DownloadInfo *createNew(const MOBase::ModRepositoryFileInfo *fileInfo, const QStringList &URLs); - static DownloadInfo *createFromMeta(const QString &filePath, bool showHidden, const QString outputDirectory); + static DownloadInfo *createFromMeta( + const QString &filePath, bool showHidden, const QString outputDirectory, + std::optional fileSize={}); /** * @brief rename the file diff --git a/src/envfs.cpp b/src/envfs.cpp index 20ba4229..9317eb70 100644 --- a/src/envfs.cpp +++ b/src/envfs.cpp @@ -298,14 +298,17 @@ void forEachEntryImpl( ObjectName.MaximumLength = ObjectName.Length; if (DirInfo->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - dirStartF(cx, toStringView(&oa)); - forEachEntryImpl(cx, hc, buffers, &oa, depth+1, dirStartF, dirEndF, fileF); - dirEndF(cx, toStringView(&oa)); + if (dirStartF && dirEndF) { + dirStartF(cx, toStringView(&oa)); + forEachEntryImpl(cx, hc, buffers, &oa, depth+1, dirStartF, dirEndF, fileF); + dirEndF(cx, toStringView(&oa)); + } } else { FILETIME ft; ft.dwLowDateTime = DirInfo->LastWriteTime.LowPart; ft.dwHighDateTime = DirInfo->LastWriteTime.HighPart; - fileF(cx, toStringView(&oa), ft); + + fileF(cx, toStringView(&oa), ft, DirInfo->AllocationSize.QuadPart); } } @@ -380,20 +383,20 @@ Directory getFilesAndDirs(const std::wstring& path) cx->current.pop(); }, - [](void* pcx, std::wstring_view path, FILETIME ft) { + [](void* pcx, std::wstring_view path, FILETIME ft, uint64_t s) { Context* cx = (Context*)pcx; - cx->current.top()->files.push_back(File(path, ft)); + cx->current.top()->files.push_back(File(path, ft, s)); } ); return root; } -File::File(std::wstring_view n, FILETIME ft) : +File::File(std::wstring_view n, FILETIME ft, uint64_t s) : name(n.begin(), n.end()), lcname(MOShared::ToLowerCopy(name)), - lastModified(ft) + lastModified(ft), size(s) { } @@ -429,7 +432,11 @@ void getFilesAndDirsWithFindImpl(const std::wstring& path, Directory& d) getFilesAndDirsWithFindImpl(newPath, d.dirs.back()); } } else { - d.files.push_back(File(findData.cFileName, findData.ftLastWriteTime)); + const auto size = + (findData.nFileSizeHigh * (MAXDWORD+1)) + findData.nFileSizeLow; + + d.files.push_back(File( + findData.cFileName, findData.ftLastWriteTime, size)); } result = ::FindNextFileW(searchHandle, &findData); diff --git a/src/envfs.h b/src/envfs.h index e4d98d71..62540e18 100644 --- a/src/envfs.h +++ b/src/envfs.h @@ -12,8 +12,9 @@ struct File std::wstring name; std::wstring lcname; FILETIME lastModified; + uint64_t size; - File(std::wstring_view name, FILETIME ft); + File(std::wstring_view name, FILETIME ft, uint64_t size); }; struct Directory @@ -174,7 +175,7 @@ private: using DirStartF = void (void*, std::wstring_view); using DirEndF = void (void*, std::wstring_view); -using FileF = void (void*, std::wstring_view, FILETIME); +using FileF = void (void*, std::wstring_view, FILETIME, uint64_t); void setHandleCloserThreadCount(std::size_t n); diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp index c4b467d6..0d275844 100644 --- a/src/shared/directoryentry.cpp +++ b/src/shared/directoryentry.cpp @@ -636,7 +636,7 @@ void DirectoryEntry::addFiles( onDirectoryEnd((Context*)pcx, path); }, - [](void* pcx, std::wstring_view path, FILETIME ft) + [](void* pcx, std::wstring_view path, FILETIME ft, uint64_t) { onFile((Context*)pcx, path, ft); } -- cgit v1.3.1