summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorMikaël Capelle <capelle.mikael@gmail.com>2022-05-17 11:47:01 +0200
committerMikaël Capelle <capelle.mikael@gmail.com>2023-07-09 17:20:40 +0200
commitd13f6bb870cdda71257f665367be8ef9fca86255 (patch)
tree52e214718478f1e52856572f5aa1a2ac58537f9f /src/shared
parent86bb01ba9eac879d3685c439ac9da0028bc4bc80 (diff)
Apply clang-format.
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/appconfig.cpp16
-rw-r--r--src/shared/appconfig.h15
-rw-r--r--src/shared/directoryentry.cpp348
-rw-r--r--src/shared/directoryentry.h201
-rw-r--r--src/shared/fileentry.cpp104
-rw-r--r--src/shared/fileentry.h75
-rw-r--r--src/shared/fileregister.cpp30
-rw-r--r--src/shared/fileregister.h12
-rw-r--r--src/shared/fileregisterfwd.h45
-rw-r--r--src/shared/filesorigin.cpp32
-rw-r--r--src/shared/filesorigin.h41
-rw-r--r--src/shared/originconnection.cpp62
-rw-r--r--src/shared/originconnection.h40
-rw-r--r--src/shared/util.cpp155
-rw-r--r--src/shared/util.h26
-rw-r--r--src/shared/windows_error.cpp15
-rw-r--r--src/shared/windows_error.h15
17 files changed, 557 insertions, 675 deletions
diff --git a/src/shared/appconfig.cpp b/src/shared/appconfig.cpp
index d2fc386c..221732de 100644
--- a/src/shared/appconfig.cpp
+++ b/src/shared/appconfig.cpp
@@ -19,15 +19,21 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "appconfig.h"
-namespace AppConfig {
+namespace AppConfig
+{
#define PARWSTRING wstring
-#define APPPARAM(partype, parid, value) partype parid () { return value; }
+#define APPPARAM(partype, parid, value) \
+ partype parid() \
+ { \
+ return value; \
+ }
#include "appconfig.inc"
-namespace MOShared {
+namespace MOShared
+{
#undef PARWSTRING
#undef APPPARAM
-}
-} // namespace MOShared
+} // namespace MOShared
+} // namespace AppConfig
diff --git a/src/shared/appconfig.h b/src/shared/appconfig.h
index cca5b0f5..598ee19c 100644
--- a/src/shared/appconfig.h
+++ b/src/shared/appconfig.h
@@ -22,19 +22,20 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <string>
-namespace AppConfig {
-
+namespace AppConfig
+{
#define PARWSTRING wstring
-#define APPPARAM(partype, parid, value) partype parid ();
+#define APPPARAM(partype, parid, value) partype parid();
#include "appconfig.inc"
-namespace MOShared {
+namespace MOShared
+{
#undef PARWSTRING
#undef APPPARAM
-}
+} // namespace MOShared
-} // namespace MOShared
+} // namespace AppConfig
-#endif // APPCONFIG_H
+#endif // APPCONFIG_H
diff --git a/src/shared/directoryentry.cpp b/src/shared/directoryentry.cpp
index 48ff7aa3..84da66e2 100644
--- a/src/shared/directoryentry.cpp
+++ b/src/shared/directoryentry.cpp
@@ -18,10 +18,10 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "directoryentry.h"
-#include "originconnection.h"
-#include "filesorigin.h"
-#include "fileentry.h"
#include "../envfs.h"
+#include "fileentry.h"
+#include "filesorigin.h"
+#include "originconnection.h"
#include "util.h"
#include "windows_error.h"
#include <log.h>
@@ -49,46 +49,45 @@ void elapsedImpl(std::chrono::nanoseconds& out, F&& f)
// elapsed() is not optimized out when EnableInstrumentation is false even
// though it's equivalent that this macro
#define elapsed(OUT, F) (F)();
-//#define elapsed(OUT, F) elapsedImpl(OUT, F);
+// #define elapsed(OUT, F) elapsedImpl(OUT, F);
static bool SupportOptimizedFind()
{
- // large fetch and basic info for FindFirstFileEx is supported on win server 2008 r2, win 7 and newer
+ // large fetch and basic info for FindFirstFileEx is supported on win server 2008 r2,
+ // win 7 and newer
OSVERSIONINFOEX versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
- versionInfo.dwMajorVersion = 6;
- versionInfo.dwMinorVersion = 1;
+ versionInfo.dwMajorVersion = 6;
+ versionInfo.dwMinorVersion = 1;
ULONGLONG mask = ::VerSetConditionMask(
- ::VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL),
- VER_MINORVERSION, VER_GREATER_EQUAL);
+ ::VerSetConditionMask(0, VER_MAJORVERSION, VER_GREATER_EQUAL), VER_MINORVERSION,
+ VER_GREATER_EQUAL);
- return (::VerifyVersionInfo(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION, mask) == TRUE);
+ return (::VerifyVersionInfo(&versionInfo, VER_MAJORVERSION | VER_MINORVERSION,
+ mask) == TRUE);
}
-bool DirCompareByName::operator()(
- const DirectoryEntry* lhs, const DirectoryEntry* rhs) const
+bool DirCompareByName::operator()(const DirectoryEntry* lhs,
+ const DirectoryEntry* rhs) const
{
return _wcsicmp(lhs->getName().c_str(), rhs->getName().c_str()) < 0;
}
-
-DirectoryEntry::DirectoryEntry(
- std::wstring name, DirectoryEntry* parent, int originID) :
- m_OriginConnection(new OriginConnection),
- m_Name(std::move(name)), m_Parent(parent), m_Populated(false), m_TopLevel(true)
+DirectoryEntry::DirectoryEntry(std::wstring name, DirectoryEntry* parent, int originID)
+ : m_OriginConnection(new OriginConnection), m_Name(std::move(name)),
+ m_Parent(parent), m_Populated(false), m_TopLevel(true)
{
m_FileRegister.reset(new FileRegister(m_OriginConnection));
m_Origins.insert(originID);
}
-DirectoryEntry::DirectoryEntry(
- std::wstring name, DirectoryEntry* parent, int originID,
- boost::shared_ptr<FileRegister> fileRegister,
- boost::shared_ptr<OriginConnection> originConnection) :
- m_FileRegister(fileRegister), m_OriginConnection(originConnection),
- m_Name(std::move(name)), m_Parent(parent), m_Populated(false), m_TopLevel(false)
+DirectoryEntry::DirectoryEntry(std::wstring name, DirectoryEntry* parent, int originID,
+ boost::shared_ptr<FileRegister> fileRegister,
+ boost::shared_ptr<OriginConnection> originConnection)
+ : m_FileRegister(fileRegister), m_OriginConnection(originConnection),
+ m_Name(std::move(name)), m_Parent(parent), m_Populated(false), m_TopLevel(false)
{
m_Origins.insert(originID);
}
@@ -100,7 +99,7 @@ DirectoryEntry::~DirectoryEntry()
void DirectoryEntry::clear()
{
- for (auto itor=m_SubDirectories.rbegin(); itor!=m_SubDirectories.rend(); ++itor) {
+ for (auto itor = m_SubDirectories.rbegin(); itor != m_SubDirectories.rend(); ++itor) {
delete *itor;
}
@@ -110,19 +109,20 @@ void DirectoryEntry::clear()
m_SubDirectoriesLookup.clear();
}
-void DirectoryEntry::addFromOrigin(
- const std::wstring &originName, const std::wstring &directory, int priority,
- DirectoryStats& stats)
+void DirectoryEntry::addFromOrigin(const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ DirectoryStats& stats)
{
env::DirectoryWalker walker;
addFromOrigin(walker, originName, directory, priority, stats);
}
-void DirectoryEntry::addFromOrigin(
- env::DirectoryWalker& walker, const std::wstring &originName,
- const std::wstring &directory, int priority, DirectoryStats& stats)
+void DirectoryEntry::addFromOrigin(env::DirectoryWalker& walker,
+ const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ DirectoryStats& stats)
{
- FilesOrigin &origin = createOrigin(originName, directory, priority, stats);
+ FilesOrigin& origin = createOrigin(originName, directory, priority, stats);
if (!directory.empty()) {
addFiles(walker, origin, directory, stats);
@@ -131,27 +131,27 @@ void DirectoryEntry::addFromOrigin(
m_Populated = true;
}
-void DirectoryEntry::addFromList(
- const std::wstring &originName, const std::wstring &directory,
- env::Directory& root, int priority, DirectoryStats& stats)
+void DirectoryEntry::addFromList(const std::wstring& originName,
+ const std::wstring& directory, env::Directory& root,
+ int priority, DirectoryStats& stats)
{
stats = {};
- FilesOrigin &origin = createOrigin(originName, directory, priority, stats);
+ FilesOrigin& origin = createOrigin(originName, directory, priority, stats);
addDir(origin, root, stats);
}
-void DirectoryEntry::addDir(
- FilesOrigin& origin, env::Directory& d, DirectoryStats& stats)
+void DirectoryEntry::addDir(FilesOrigin& origin, env::Directory& d,
+ DirectoryStats& stats)
{
- elapsed(stats.dirTimes, [&]{
+ elapsed(stats.dirTimes, [&] {
for (auto& sd : d.dirs) {
auto* sdirEntry = getSubDirectory(sd, true, stats, origin.getID());
sdirEntry->addDir(origin, sd, stats);
}
});
- elapsed(stats.fileTimes, [&]{
+ elapsed(stats.fileTimes, [&] {
for (auto& f : d.files) {
insert(f, origin, L"", -1, stats);
}
@@ -160,12 +160,12 @@ void DirectoryEntry::addDir(
m_Populated = true;
}
-void DirectoryEntry::addFromAllBSAs(
- const std::wstring& originName, const std::wstring& directory,
- int priority, const std::vector<std::wstring>& archives,
- const std::set<std::wstring>& enabledArchives,
- const std::vector<std::wstring>& loadOrder,
- DirectoryStats& stats)
+void DirectoryEntry::addFromAllBSAs(const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ const std::vector<std::wstring>& archives,
+ const std::set<std::wstring>& enabledArchives,
+ const std::vector<std::wstring>& loadOrder,
+ DirectoryStats& stats)
{
for (const auto& archive : archives) {
const std::filesystem::path archivePath(archive);
@@ -179,10 +179,9 @@ void DirectoryEntry::addFromAllBSAs(
int order = -1;
- for (auto plugin : loadOrder)
- {
+ for (auto plugin : loadOrder) {
const auto pluginNameLc =
- ToLowerCopy(std::filesystem::path(plugin).stem().native());
+ ToLowerCopy(std::filesystem::path(plugin).stem().native());
if (filenameLc.starts_with(pluginNameLc + L" - ") ||
filenameLc.starts_with(pluginNameLc + L".")) {
@@ -193,17 +192,16 @@ void DirectoryEntry::addFromAllBSAs(
}
}
- addFromBSA(
- originName, directory, archivePath.native(),
- priority, order, stats);
+ addFromBSA(originName, directory, archivePath.native(), priority, order, stats);
}
}
-void DirectoryEntry::addFromBSA(
- const std::wstring& originName, const std::wstring& directory,
- const std::wstring& archivePath, int priority, int order, DirectoryStats& stats)
+void DirectoryEntry::addFromBSA(const std::wstring& originName,
+ const std::wstring& directory,
+ const std::wstring& archivePath, int priority,
+ int order, DirectoryStats& stats)
{
- FilesOrigin& origin = createOrigin(originName, directory, priority, stats);
+ FilesOrigin& origin = createOrigin(originName, directory, priority, stats);
const auto archiveName = std::filesystem::path(archivePath).filename().native();
if (containsArchive(archiveName)) {
@@ -213,14 +211,11 @@ void DirectoryEntry::addFromBSA(
BSA::Archive archive;
BSA::EErrorCode res = BSA::ERROR_NONE;
- try
- {
+ try {
// read() can return an error, but it can also throw if the file is not a
// valid bsa
res = archive.read(ToString(archivePath, false).c_str(), false);
- }
- catch(std::exception& e)
- {
+ } catch (std::exception& e) {
log::error("invalid bsa '{}', error {}", archivePath, e.what());
return;
}
@@ -232,12 +227,11 @@ void DirectoryEntry::addFromBSA(
std::error_code ec;
const auto lwt = std::filesystem::last_write_time(archivePath, ec);
- FILETIME ft = {};
+ FILETIME ft = {};
if (ec) {
- log::warn(
- "failed to get last modified date for '{}', {}",
- archivePath, ec.message());
+ log::warn("failed to get last modified date for '{}', {}", archivePath,
+ ec.message());
} else {
ft = ToFILETIME(lwt);
}
@@ -259,17 +253,17 @@ void DirectoryEntry::propagateOrigin(int origin)
}
}
-bool DirectoryEntry::originExists(const std::wstring &name) const
+bool DirectoryEntry::originExists(const std::wstring& name) const
{
return m_OriginConnection->exists(name);
}
-FilesOrigin &DirectoryEntry::getOriginByID(int ID) const
+FilesOrigin& DirectoryEntry::getOriginByID(int ID) const
{
return m_OriginConnection->getByID(ID);
}
-FilesOrigin &DirectoryEntry::getOriginByName(const std::wstring &name) const
+FilesOrigin& DirectoryEntry::getOriginByName(const std::wstring& name) const
{
return m_OriginConnection->getByName(name);
}
@@ -290,11 +284,11 @@ int DirectoryEntry::anyOrigin() const
}
}
- // if we got here, no file directly within this directory is a valid indicator for a mod, thus
- // we continue looking in subdirectories
+ // if we got here, no file directly within this directory is a valid indicator for a
+ // mod, thus we continue looking in subdirectories
for (DirectoryEntry* entry : m_SubDirectories) {
int res = entry->anyOrigin();
- if (res != InvalidOriginID){
+ if (res != InvalidOriginID) {
return res;
}
}
@@ -313,8 +307,8 @@ std::vector<FileEntryPtr> DirectoryEntry::getFiles() const
return result;
}
-DirectoryEntry* DirectoryEntry::findSubDirectory(
- const std::wstring &name, bool alreadyLowerCase) const
+DirectoryEntry* DirectoryEntry::findSubDirectory(const std::wstring& name,
+ bool alreadyLowerCase) const
{
SubDirectoriesLookup::const_iterator itor;
@@ -331,14 +325,14 @@ DirectoryEntry* DirectoryEntry::findSubDirectory(
return itor->second;
}
-DirectoryEntry* DirectoryEntry::findSubDirectoryRecursive(const std::wstring &path)
+DirectoryEntry* DirectoryEntry::findSubDirectoryRecursive(const std::wstring& path)
{
DirectoryStats dummy;
return getSubDirectoryRecursive(path, false, dummy, InvalidOriginID);
}
-const FileEntryPtr DirectoryEntry::findFile(
- const std::wstring &name, bool alreadyLowerCase) const
+const FileEntryPtr DirectoryEntry::findFile(const std::wstring& name,
+ bool alreadyLowerCase) const
{
FilesLookup::const_iterator iter;
@@ -383,8 +377,8 @@ bool DirectoryEntry::containsArchive(std::wstring archiveName)
return false;
}
-const FileEntryPtr DirectoryEntry::searchFile(
- const std::wstring &path, const DirectoryEntry** directory) const
+const FileEntryPtr DirectoryEntry::searchFile(const std::wstring& path,
+ const DirectoryEntry** directory) const
{
if (directory != nullptr) {
*directory = nullptr;
@@ -399,7 +393,7 @@ const FileEntryPtr DirectoryEntry::searchFile(
return FileEntryPtr();
}
- const size_t len = path.find_first_of(L"\\/");
+ const size_t len = path.find_first_of(L"\\/");
if (len == std::string::npos) {
// no more path components
@@ -416,7 +410,7 @@ const FileEntryPtr DirectoryEntry::searchFile(
} else {
// file is in a subdirectory, recurse into the matching subdirectory
std::wstring pathComponent = path.substr(0, len);
- DirectoryEntry* temp = findSubDirectory(pathComponent);
+ DirectoryEntry* temp = findSubDirectory(pathComponent);
if (temp != nullptr) {
if (len >= path.size()) {
@@ -436,7 +430,7 @@ void DirectoryEntry::removeFile(FileIndex index)
removeFileFromList(index);
}
-bool DirectoryEntry::removeFile(const std::wstring &filePath, int* origin)
+bool DirectoryEntry::removeFile(const std::wstring& filePath, int* origin)
{
size_t pos = filePath.find_first_of(L"\\/");
@@ -445,7 +439,7 @@ bool DirectoryEntry::removeFile(const std::wstring &filePath, int* origin)
}
std::wstring dirName = filePath.substr(0, pos);
- std::wstring rest = filePath.substr(pos + 1);
+ std::wstring rest = filePath.substr(pos + 1);
DirectoryStats dummy;
DirectoryEntry* entry = getSubDirectoryRecursive(dirName, false, dummy);
@@ -457,7 +451,7 @@ bool DirectoryEntry::removeFile(const std::wstring &filePath, int* origin)
}
}
-void DirectoryEntry::removeDir(const std::wstring &path)
+void DirectoryEntry::removeDir(const std::wstring& path)
{
size_t pos = path.find_first_of(L"\\/");
@@ -474,7 +468,7 @@ void DirectoryEntry::removeDir(const std::wstring &path)
}
} else {
std::wstring dirName = path.substr(0, pos);
- std::wstring rest = path.substr(pos + 1);
+ std::wstring rest = path.substr(pos + 1);
DirectoryStats dummy;
DirectoryEntry* entry = getSubDirectoryRecursive(dirName, false, dummy);
@@ -485,12 +479,12 @@ void DirectoryEntry::removeDir(const std::wstring &path)
}
}
-bool DirectoryEntry::remove(const std::wstring &fileName, int* origin)
+bool DirectoryEntry::remove(const std::wstring& fileName, int* origin)
{
const auto lcFileName = ToLowerCopy(fileName);
auto iter = m_Files.find(lcFileName);
- bool b = false;
+ bool b = false;
if (iter != m_Files.end()) {
if (origin != nullptr) {
@@ -512,13 +506,12 @@ bool DirectoryEntry::hasContentsFromOrigin(int originID) const
return m_Origins.find(originID) != m_Origins.end();
}
-FilesOrigin &DirectoryEntry::createOrigin(
- const std::wstring &originName, const std::wstring &directory, int priority,
- DirectoryStats& stats)
+FilesOrigin& DirectoryEntry::createOrigin(const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ DirectoryStats& stats)
{
- auto r = m_OriginConnection->getOrCreate(
- originName, directory, priority,
- m_FileRegister, m_OriginConnection, stats);
+ auto r = m_OriginConnection->getOrCreate(originName, directory, priority,
+ m_FileRegister, m_OriginConnection, stats);
if (r.second) {
++stats.originCreate;
@@ -529,14 +522,14 @@ FilesOrigin &DirectoryEntry::createOrigin(
return r.first;
}
-void DirectoryEntry::removeFiles(const std::set<FileIndex> &indices)
+void DirectoryEntry::removeFiles(const std::set<FileIndex>& indices)
{
removeFilesFromList(indices);
}
-FileEntryPtr DirectoryEntry::insert(
- std::wstring_view fileName, FilesOrigin &origin, FILETIME fileTime,
- std::wstring_view archive, int order, DirectoryStats& stats)
+FileEntryPtr DirectoryEntry::insert(std::wstring_view fileName, FilesOrigin& origin,
+ FILETIME fileTime, std::wstring_view archive,
+ int order, DirectoryStats& stats)
{
std::wstring fileNameLower = ToLowerCopy(fileName);
FileEntryPtr fe;
@@ -548,7 +541,7 @@ FileEntryPtr DirectoryEntry::insert(
FilesLookup::iterator itor;
- elapsed(stats.filesLookupTimes, [&]{
+ elapsed(stats.filesLookupTimes, [&] {
itor = m_FilesLookup.find(key);
});
@@ -558,8 +551,8 @@ FileEntryPtr DirectoryEntry::insert(
fe = m_FileRegister->getFile(itor->second);
} else {
++stats.fileCreate;
- fe = m_FileRegister->createFile(
- std::wstring(fileName.begin(), fileName.end()), this, stats);
+ fe = m_FileRegister->createFile(std::wstring(fileName.begin(), fileName.end()),
+ this, stats);
elapsed(stats.addFileTimes, [&] {
addFileToList(std::move(key.value), fe->getIndex());
@@ -569,20 +562,20 @@ FileEntryPtr DirectoryEntry::insert(
}
}
- elapsed(stats.addOriginToFileTimes, [&]{
+ elapsed(stats.addOriginToFileTimes, [&] {
fe->addOrigin(origin.getID(), fileTime, archive, order);
});
- elapsed(stats.addFileToOriginTimes, [&]{
+ elapsed(stats.addFileToOriginTimes, [&] {
origin.addFile(fe->getIndex());
});
return fe;
}
-FileEntryPtr DirectoryEntry::insert(
- env::File& file, FilesOrigin &origin, std::wstring_view archive, int order,
- DirectoryStats& stats)
+FileEntryPtr DirectoryEntry::insert(env::File& file, FilesOrigin& origin,
+ std::wstring_view archive, int order,
+ DirectoryStats& stats)
{
FileEntryPtr fe;
@@ -591,7 +584,7 @@ FileEntryPtr DirectoryEntry::insert(
FilesMap::iterator itor;
- elapsed(stats.filesLookupTimes, [&]{
+ elapsed(stats.filesLookupTimes, [&] {
itor = m_Files.find(file.lcname);
});
@@ -604,7 +597,7 @@ FileEntryPtr DirectoryEntry::insert(
fe = m_FileRegister->createFile(std::move(file.name), this, stats);
// file.name has been moved from this point
- elapsed(stats.addFileTimes, [&]{
+ elapsed(stats.addFileTimes, [&] {
addFileToList(std::move(file.lcname), fe->getIndex());
});
@@ -612,11 +605,11 @@ FileEntryPtr DirectoryEntry::insert(
}
}
- elapsed(stats.addOriginToFileTimes, [&]{
+ elapsed(stats.addOriginToFileTimes, [&] {
fe->addOrigin(origin.getID(), file.lastModified, archive, order);
});
- elapsed(stats.addFileToOriginTimes, [&]{
+ elapsed(stats.addFileToOriginTimes, [&] {
origin.addFile(fe->getIndex());
});
@@ -630,36 +623,32 @@ struct DirectoryEntry::Context
std::stack<DirectoryEntry*> current;
};
-void DirectoryEntry::addFiles(
- env::DirectoryWalker& walker, FilesOrigin &origin,
- const std::wstring& path, DirectoryStats& stats)
+void DirectoryEntry::addFiles(env::DirectoryWalker& walker, FilesOrigin& origin,
+ const std::wstring& path, DirectoryStats& stats)
{
Context cx = {origin, stats};
cx.current.push(this);
- walker.forEachEntry(path, &cx,
- [](void* pcx, std::wstring_view path)
- {
- onDirectoryStart((Context*)pcx, path);
- },
+ walker.forEachEntry(
+ path, &cx,
+ [](void* pcx, std::wstring_view path) {
+ onDirectoryStart((Context*)pcx, path);
+ },
- [](void* pcx, std::wstring_view path)
- {
- onDirectoryEnd((Context*)pcx, path);
- },
+ [](void* pcx, std::wstring_view path) {
+ onDirectoryEnd((Context*)pcx, path);
+ },
- [](void* pcx, std::wstring_view path, FILETIME ft, uint64_t)
- {
- onFile((Context*)pcx, path, ft);
- }
- );
+ [](void* pcx, std::wstring_view path, FILETIME ft, uint64_t) {
+ onFile((Context*)pcx, path, ft);
+ });
}
void DirectoryEntry::onDirectoryStart(Context* cx, std::wstring_view path)
{
elapsed(cx->stats.dirTimes, [&] {
- auto* sd = cx->current.top()->getSubDirectory(
- path, true, cx->stats, cx->origin.getID());
+ auto* sd =
+ cx->current.top()->getSubDirectory(path, true, cx->stats, cx->origin.getID());
cx->current.push(sd);
});
@@ -674,23 +663,22 @@ void DirectoryEntry::onDirectoryEnd(Context* cx, std::wstring_view path)
void DirectoryEntry::onFile(Context* cx, std::wstring_view path, FILETIME ft)
{
- elapsed(cx->stats.fileTimes, [&]{
+ elapsed(cx->stats.fileTimes, [&] {
cx->current.top()->insert(path, cx->origin, ft, L"", -1, cx->stats);
});
}
-void DirectoryEntry::addFiles(
- FilesOrigin& origin, const BSA::Folder::Ptr archiveFolder, FILETIME fileTime,
- const std::wstring& archiveName, int order, DirectoryStats& stats)
+void DirectoryEntry::addFiles(FilesOrigin& origin, const BSA::Folder::Ptr archiveFolder,
+ FILETIME fileTime, const std::wstring& archiveName,
+ int order, DirectoryStats& stats)
{
// add files
const auto fileCount = archiveFolder->getNumFiles();
- for (unsigned int i=0; i<fileCount; ++i) {
+ for (unsigned int i = 0; i < fileCount; ++i) {
const BSA::File::Ptr file = archiveFolder->getFile(i);
- auto f = insert(
- ToWString(file->getName(), true), origin, fileTime,
- archiveName, order, stats);
+ auto f = insert(ToWString(file->getName(), true), origin, fileTime, archiveName,
+ order, stats);
if (f) {
if (file->getUncompressedFileSize() > 0) {
@@ -703,18 +691,18 @@ void DirectoryEntry::addFiles(
// recurse into subdirectories
const auto dirCount = archiveFolder->getNumSubFolders();
- for (unsigned int i=0; i<dirCount; ++i) {
+ for (unsigned int i = 0; i < dirCount; ++i) {
const BSA::Folder::Ptr folder = archiveFolder->getSubFolder(i);
DirectoryEntry* folderEntry = getSubDirectoryRecursive(
- ToWString(folder->getName(), true), true, stats, origin.getID());
+ ToWString(folder->getName(), true), true, stats, origin.getID());
folderEntry->addFiles(origin, folder, fileTime, archiveName, order, stats);
}
}
-DirectoryEntry* DirectoryEntry::getSubDirectory(
- std::wstring_view name, bool create, DirectoryStats& stats, int originID)
+DirectoryEntry* DirectoryEntry::getSubDirectory(std::wstring_view name, bool create,
+ DirectoryStats& stats, int originID)
{
std::wstring nameLc = ToLowerCopy(name);
@@ -733,9 +721,8 @@ DirectoryEntry* DirectoryEntry::getSubDirectory(
if (create) {
++stats.subdirCreate;
- auto* entry = new DirectoryEntry(
- std::wstring(name.begin(), name.end()), this, originID,
- m_FileRegister, m_OriginConnection);
+ auto* entry = new DirectoryEntry(std::wstring(name.begin(), name.end()), this,
+ originID, m_FileRegister, m_OriginConnection);
elapsed(stats.addDirectoryTimes, [&] {
addDirectoryToList(entry, std::move(nameLc));
@@ -748,8 +735,8 @@ DirectoryEntry* DirectoryEntry::getSubDirectory(
}
}
-DirectoryEntry* DirectoryEntry::getSubDirectory(
- env::Directory& dir, bool create, DirectoryStats& stats, int originID)
+DirectoryEntry* DirectoryEntry::getSubDirectory(env::Directory& dir, bool create,
+ DirectoryStats& stats, int originID)
{
SubDirectoriesLookup::iterator itor;
@@ -767,12 +754,11 @@ DirectoryEntry* DirectoryEntry::getSubDirectory(
if (create) {
++stats.subdirCreate;
- auto* entry = new DirectoryEntry(
- std::move(dir.name), this, originID,
- m_FileRegister, m_OriginConnection);
+ auto* entry = new DirectoryEntry(std::move(dir.name), this, originID,
+ m_FileRegister, m_OriginConnection);
// dir.name is moved from this point
- elapsed(stats.addDirectoryTimes, [&]{
+ elapsed(stats.addDirectoryTimes, [&] {
addDirectoryToList(entry, std::move(dir.lcname));
});
@@ -784,8 +770,10 @@ DirectoryEntry* DirectoryEntry::getSubDirectory(
}
}
-DirectoryEntry* DirectoryEntry::getSubDirectoryRecursive(
- const std::wstring& path, bool create, DirectoryStats& stats, int originID)
+DirectoryEntry* DirectoryEntry::getSubDirectoryRecursive(const std::wstring& path,
+ bool create,
+ DirectoryStats& stats,
+ int originID)
{
if (path.length() == 0) {
// path ended with a backslash?
@@ -797,14 +785,14 @@ DirectoryEntry* DirectoryEntry::getSubDirectoryRecursive(
if (pos == std::wstring::npos) {
return getSubDirectory(path, create, stats);
} else {
- DirectoryEntry* nextChild = getSubDirectory(
- path.substr(0, pos), create, stats, originID);
+ DirectoryEntry* nextChild =
+ getSubDirectory(path.substr(0, pos), create, stats, originID);
if (nextChild == nullptr) {
return nullptr;
} else {
- return nextChild->getSubDirectoryRecursive(
- path.substr(pos + 1), create, stats, originID);
+ return nextChild->getSubDirectoryRecursive(path.substr(pos + 1), create, stats,
+ originID);
}
}
}
@@ -837,9 +825,10 @@ void DirectoryEntry::removeDirectoryFromList(SubDirectories::iterator itor)
const auto* entry = *itor;
{
- auto itor2 = std::find_if(
- m_SubDirectoriesLookup.begin(), m_SubDirectoriesLookup.end(),
- [&](auto&& d) { return (d.second == entry); });
+ auto itor2 = std::find_if(m_SubDirectoriesLookup.begin(),
+ m_SubDirectoriesLookup.end(), [&](auto&& d) {
+ return (d.second == entry);
+ });
if (itor2 == m_SubDirectoriesLookup.end()) {
log::error("entry {} not in sub directories map", entry->getName());
@@ -854,23 +843,20 @@ void DirectoryEntry::removeDirectoryFromList(SubDirectories::iterator itor)
void DirectoryEntry::removeFileFromList(FileIndex index)
{
auto removeFrom = [&](auto& list) {
- auto iter = std::find_if(
- list.begin(), list.end(),
- [&index](auto&& pair) { return (pair.second == index); }
- );
+ auto iter = std::find_if(list.begin(), list.end(), [&index](auto&& pair) {
+ return (pair.second == index);
+ });
if (iter == list.end()) {
auto f = m_FileRegister->getFile(index);
if (f) {
- log::error(
- "can't remove file '{}', not in directory entry '{}'",
- f->getName(), getName());
+ log::error("can't remove file '{}', not in directory entry '{}'", f->getName(),
+ getName());
} else {
- log::error(
- "can't remove file with index {}, not in directory entry '{}' and "
- "not in register",
- index, getName());
+ log::error("can't remove file with index {}, not in directory entry '{}' and "
+ "not in register",
+ index, getName());
}
} else {
list.erase(iter);
@@ -914,25 +900,22 @@ struct DumpFailed : public std::runtime_error
void DirectoryEntry::dump(const std::wstring& file) const
{
- try
- {
+ try {
std::FILE* f = nullptr;
- auto e = _wfopen_s(&f, file.c_str(), L"wb");
+ auto e = _wfopen_s(&f, file.c_str(), L"wb");
if (e != 0 || !f) {
- throw DumpFailed(fmt::format(
- "failed to open, {} ({})", std::strerror(e), e));
+ throw DumpFailed(fmt::format("failed to open, {} ({})", std::strerror(e), e));
}
- Guard g([&]{ std::fclose(f); });
+ Guard g([&] {
+ std::fclose(f);
+ });
dump(f, L"Data");
- }
- catch(DumpFailed& e)
- {
- log::error(
- "failed to write list to '{}': {}",
- QString::fromStdWString(file).toStdString(), e.what());
+ } catch (DumpFailed& e) {
+ log::error("failed to write list to '{}': {}",
+ QString::fromStdWString(file).toStdString(), e.what());
}
}
@@ -952,7 +935,7 @@ void DirectoryEntry::dump(std::FILE* f, const std::wstring& parentPath) const
continue;
}
- const auto& o = m_OriginConnection->getByID(file->getOrigin());
+ const auto& o = m_OriginConnection->getByID(file->getOrigin());
const auto path = parentPath + L"\\" + file->getName();
const auto line = path + L"\t(" + o.getName() + L")\r\n";
@@ -960,8 +943,7 @@ void DirectoryEntry::dump(std::FILE* f, const std::wstring& parentPath) const
if (std::fwrite(lineu8.data(), lineu8.size(), 1, f) != 1) {
const auto e = errno;
- throw DumpFailed(fmt::format(
- "failed to write, {} ({})", std::strerror(e), e));
+ throw DumpFailed(fmt::format("failed to write, {} ({})", std::strerror(e), e));
}
}
}
@@ -975,4 +957,4 @@ void DirectoryEntry::dump(std::FILE* f, const std::wstring& parentPath) const
}
}
-} // namespace MOShared
+} // namespace MOShared
diff --git a/src/shared/directoryentry.h b/src/shared/directoryentry.h
index f7ab2b90..42aef8c7 100644
--- a/src/shared/directoryentry.h
+++ b/src/shared/directoryentry.h
@@ -25,116 +25,87 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
namespace env
{
- class DirectoryWalker;
- struct Directory;
- struct File;
-}
+class DirectoryWalker;
+struct Directory;
+struct File;
+} // namespace env
namespace std
{
- template <>
- struct hash<MOShared::DirectoryEntryFileKey>
- {
- using argument_type = MOShared::DirectoryEntryFileKey;
- using result_type = std::size_t;
-
- inline result_type operator()(const argument_type& key) const;
- };
-}
+template <>
+struct hash<MOShared::DirectoryEntryFileKey>
+{
+ using argument_type = MOShared::DirectoryEntryFileKey;
+ using result_type = std::size_t;
+ inline result_type operator()(const argument_type& key) const;
+};
+} // namespace std
namespace MOShared
{
struct DirCompareByName
{
- bool operator()(const DirectoryEntry* a, const DirectoryEntry* b) const;
+ bool operator()(const DirectoryEntry* a, const DirectoryEntry* b) const;
};
-
class DirectoryEntry
{
public:
- using SubDirectories = std::set<DirectoryEntry*, DirCompareByName>;
+ using SubDirectories = std::set<DirectoryEntry*, DirCompareByName>;
- DirectoryEntry(
- std::wstring name, DirectoryEntry* parent, OriginID originID);
+ DirectoryEntry(std::wstring name, DirectoryEntry* parent, OriginID originID);
- DirectoryEntry(
- std::wstring name, DirectoryEntry* parent, OriginID originID,
- boost::shared_ptr<FileRegister> fileRegister,
- boost::shared_ptr<OriginConnection> originConnection);
+ DirectoryEntry(std::wstring name, DirectoryEntry* parent, OriginID originID,
+ boost::shared_ptr<FileRegister> fileRegister,
+ boost::shared_ptr<OriginConnection> originConnection);
~DirectoryEntry();
// noncopyable
- DirectoryEntry(const DirectoryEntry&) = delete;
+ DirectoryEntry(const DirectoryEntry&) = delete;
DirectoryEntry& operator=(const DirectoryEntry&) = delete;
void clear();
- bool isPopulated() const
- {
- return m_Populated;
- }
+ bool isPopulated() const { return m_Populated; }
- bool isTopLevel() const
- {
- return m_TopLevel;
- }
+ bool isTopLevel() const { return m_TopLevel; }
- bool isEmpty() const
- {
- return m_Files.empty() && m_SubDirectories.empty();
- }
+ bool isEmpty() const { return m_Files.empty() && m_SubDirectories.empty(); }
- bool hasFiles() const
- {
- return !m_Files.empty();
- }
+ bool hasFiles() const { return !m_Files.empty(); }
- const DirectoryEntry* getParent() const
- {
- return m_Parent;
- }
+ const DirectoryEntry* getParent() const { return m_Parent; }
// add files to this directory (and subdirectories) from the specified origin.
// That origin may exist or not
- void addFromOrigin(
- const std::wstring& originName,
- const std::wstring& directory, int priority, DirectoryStats& stats);
+ void addFromOrigin(const std::wstring& originName, const std::wstring& directory,
+ int priority, DirectoryStats& stats);
- void addFromOrigin(
- env::DirectoryWalker& walker, const std::wstring& originName,
- const std::wstring& directory, int priority, DirectoryStats& stats);
+ void addFromOrigin(env::DirectoryWalker& walker, const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ DirectoryStats& stats);
- void addFromAllBSAs(
- const std::wstring& originName, const std::wstring& directory,
- int priority, const std::vector<std::wstring>& archives,
- const std::set<std::wstring>& enabledArchives,
- const std::vector<std::wstring>& loadOrder,
- DirectoryStats& stats);
+ void addFromAllBSAs(const std::wstring& originName, const std::wstring& directory,
+ int priority, const std::vector<std::wstring>& archives,
+ const std::set<std::wstring>& enabledArchives,
+ const std::vector<std::wstring>& loadOrder,
+ DirectoryStats& stats);
- void addFromBSA(
- const std::wstring& originName, const std::wstring& directory,
- const std::wstring& archivePath, int priority, int order,
- DirectoryStats& stats);
+ void addFromBSA(const std::wstring& originName, const std::wstring& directory,
+ const std::wstring& archivePath, int priority, int order,
+ DirectoryStats& stats);
- void addFromList(
- const std::wstring& originName, const std::wstring& directory,
- env::Directory& root, int priority, DirectoryStats& stats);
+ void addFromList(const std::wstring& originName, const std::wstring& directory,
+ env::Directory& root, int priority, DirectoryStats& stats);
void propagateOrigin(OriginID origin);
- const std::wstring& getName() const
- {
- return m_Name;
- }
+ const std::wstring& getName() const { return m_Name; }
- boost::shared_ptr<FileRegister> getFileRegister()
- {
- return m_FileRegister;
- }
+ boost::shared_ptr<FileRegister> getFileRegister() { return m_FileRegister; }
bool originExists(const std::wstring& name) const;
FilesOrigin& getOriginByID(OriginID ID) const;
@@ -145,10 +116,7 @@ public:
std::vector<FileEntryPtr> getFiles() const;
- const SubDirectories& getSubDirectories() const
- {
- return m_SubDirectories;
- }
+ const SubDirectories& getSubDirectories() const { return m_SubDirectories; }
template <class F>
void forEachDirectory(F&& f) const
@@ -164,7 +132,7 @@ public:
void forEachFile(F&& f) const
{
for (auto&& p : m_Files) {
- if (auto file=m_FileRegister->getFile(p.second)) {
+ if (auto file = m_FileRegister->getFile(p.second)) {
if (!f(*file)) {
break;
}
@@ -187,16 +155,17 @@ public:
return m_FileRegister->getFile(index);
}
- DirectoryEntry* findSubDirectory(
- const std::wstring& name, bool alreadyLowerCase=false) const;
+ DirectoryEntry* findSubDirectory(const std::wstring& name,
+ bool alreadyLowerCase = false) const;
DirectoryEntry* findSubDirectoryRecursive(const std::wstring& path);
/** retrieve a file in this directory by name.
- * @param name name of the file
- * @return fileentry object for the file or nullptr if no file matches
- */
- const FileEntryPtr findFile(const std::wstring& name, bool alreadyLowerCase=false) const;
+ * @param name name of the file
+ * @return fileentry object for the file or nullptr if no file matches
+ */
+ const FileEntryPtr findFile(const std::wstring& name,
+ bool alreadyLowerCase = false) const;
const FileEntryPtr findFile(const DirectoryEntryFileKey& key) const;
bool hasFile(const std::wstring& name) const;
@@ -208,8 +177,8 @@ public:
// if directory is not nullptr, the referenced variable will be set to the
// path containing the file
//
- const FileEntryPtr searchFile(
- const std::wstring& path, const DirectoryEntry** directory=nullptr) const;
+ const FileEntryPtr searchFile(const std::wstring& path,
+ const DirectoryEntry** directory = nullptr) const;
void removeFile(FileIndex index);
@@ -227,17 +196,17 @@ public:
bool hasContentsFromOrigin(OriginID originID) const;
- FilesOrigin& createOrigin(
- const std::wstring& originName,
- const std::wstring& directory, int priority, DirectoryStats& stats);
+ FilesOrigin& createOrigin(const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ DirectoryStats& stats);
void removeFiles(const std::set<FileIndex>& indices);
void dump(const std::wstring& file) const;
private:
- using FilesMap = std::map<std::wstring, FileIndex>;
- using FilesLookup = std::unordered_map<DirectoryEntryFileKey, FileIndex>;
+ using FilesMap = std::map<std::wstring, FileIndex>;
+ using FilesLookup = std::unordered_map<DirectoryEntryFileKey, FileIndex>;
using SubDirectoriesLookup = std::unordered_map<std::wstring, DirectoryEntry*>;
boost::shared_ptr<FileRegister> m_FileRegister;
@@ -257,36 +226,32 @@ private:
mutable std::mutex m_FilesMutex;
mutable std::mutex m_OriginsMutex;
+ FileEntryPtr insert(std::wstring_view fileName, FilesOrigin& origin,
+ FILETIME fileTime, std::wstring_view archive, int order,
+ DirectoryStats& stats);
- FileEntryPtr insert(
- std::wstring_view fileName, FilesOrigin& origin, FILETIME fileTime,
- std::wstring_view archive, int order, DirectoryStats& stats);
+ FileEntryPtr insert(env::File& file, FilesOrigin& origin, std::wstring_view archive,
+ int order, DirectoryStats& stats);
- FileEntryPtr insert(
- env::File& file, FilesOrigin& origin,
- std::wstring_view archive, int order, DirectoryStats& stats);
+ void addFiles(env::DirectoryWalker& walker, FilesOrigin& origin,
+ const std::wstring& path, DirectoryStats& stats);
- void addFiles(
- env::DirectoryWalker& walker, FilesOrigin& origin,
- const std::wstring& path, DirectoryStats& stats);
-
- void addFiles(
- FilesOrigin& origin, BSA::Folder::Ptr archiveFolder, FILETIME fileTime,
- const std::wstring& archiveName, int order, DirectoryStats& stats);
+ void addFiles(FilesOrigin& origin, BSA::Folder::Ptr archiveFolder, FILETIME fileTime,
+ const std::wstring& archiveName, int order, DirectoryStats& stats);
void addDir(FilesOrigin& origin, env::Directory& d, DirectoryStats& stats);
- DirectoryEntry* getSubDirectory(
- std::wstring_view name, bool create, DirectoryStats& stats,
- OriginID originID = InvalidOriginID);
+ DirectoryEntry* getSubDirectory(std::wstring_view name, bool create,
+ DirectoryStats& stats,
+ OriginID originID = InvalidOriginID);
- DirectoryEntry* getSubDirectory(
- env::Directory& dir, bool create, DirectoryStats& stats,
- OriginID originID = InvalidOriginID);
+ DirectoryEntry* getSubDirectory(env::Directory& dir, bool create,
+ DirectoryStats& stats,
+ OriginID originID = InvalidOriginID);
- DirectoryEntry* getSubDirectoryRecursive(
- const std::wstring& path, bool create, DirectoryStats& stats,
- OriginID originID = InvalidOriginID);
+ DirectoryEntry* getSubDirectoryRecursive(const std::wstring& path, bool create,
+ DirectoryStats& stats,
+ OriginID originID = InvalidOriginID);
void removeDirRecursive();
@@ -305,17 +270,15 @@ private:
void dump(std::FILE* f, const std::wstring& parentPath) const;
};
-} // namespace MOShared
-
+} // namespace MOShared
namespace std
{
- hash<MOShared::DirectoryEntryFileKey>::result_type
- hash<MOShared::DirectoryEntryFileKey>::operator()(
- const argument_type& key) const
- {
- return key.hash;
- }
+hash<MOShared::DirectoryEntryFileKey>::result_type
+hash<MOShared::DirectoryEntryFileKey>::operator()(const argument_type& key) const
+{
+ return key.hash;
}
+} // namespace std
-#endif // MO_REGISTER_DIRECTORYENTRY_INCLUDED
+#endif // MO_REGISTER_DIRECTORYENTRY_INCLUDED
diff --git a/src/shared/fileentry.cpp b/src/shared/fileentry.cpp
index 5be9a9dc..48670617 100644
--- a/src/shared/fileentry.cpp
+++ b/src/shared/fileentry.cpp
@@ -5,20 +5,18 @@
namespace MOShared
{
-FileEntry::FileEntry() :
- m_Index(InvalidFileIndex), m_Name(), m_Origin(-1), m_Parent(nullptr),
- m_FileSize(NoFileSize), m_CompressedFileSize(NoFileSize)
-{
-}
+FileEntry::FileEntry()
+ : m_Index(InvalidFileIndex), m_Name(), m_Origin(-1), m_Parent(nullptr),
+ m_FileSize(NoFileSize), m_CompressedFileSize(NoFileSize)
+{}
-FileEntry::FileEntry(FileIndex index, std::wstring name, DirectoryEntry *parent) :
- m_Index(index), m_Name(std::move(name)), m_Origin(-1), m_Archive(L"", -1), m_Parent(parent),
- m_FileSize(NoFileSize), m_CompressedFileSize(NoFileSize)
-{
-}
+FileEntry::FileEntry(FileIndex index, std::wstring name, DirectoryEntry* parent)
+ : m_Index(index), m_Name(std::move(name)), m_Origin(-1), m_Archive(L"", -1),
+ m_Parent(parent), m_FileSize(NoFileSize), m_CompressedFileSize(NoFileSize)
+{}
-void FileEntry::addOrigin(
- OriginID origin, FILETIME fileTime, std::wstring_view archive, int order)
+void FileEntry::addOrigin(OriginID origin, FILETIME fileTime, std::wstring_view archive,
+ int order)
{
std::scoped_lock lock(m_OriginsMutex);
@@ -29,32 +27,30 @@ void FileEntry::addOrigin(
if (m_Origin == -1) {
// If this file has no previous origin, this mod is now the origin with no
// alternatives
- m_Origin = origin;
+ m_Origin = origin;
m_FileTime = fileTime;
- m_Archive = DataArchiveOrigin(std::wstring(archive.begin(), archive.end()), order);
- }
- else if (
- (m_Parent != nullptr) && (
- (m_Parent->getOriginByID(origin).getPriority() > m_Parent->getOriginByID(m_Origin).getPriority()) ||
- (archive.size() == 0 && m_Archive.isValid()))
- ) {
+ m_Archive = DataArchiveOrigin(std::wstring(archive.begin(), archive.end()), order);
+ } else if ((m_Parent != nullptr) &&
+ ((m_Parent->getOriginByID(origin).getPriority() >
+ m_Parent->getOriginByID(m_Origin).getPriority()) ||
+ (archive.size() == 0 && m_Archive.isValid()))) {
// If this mod has a higher priority than the origin mod OR
// this mod has a loose file and the origin mod has an archived file,
// this mod is now the origin and the previous origin is the first alternative
- auto itor = std::find_if(
- m_Alternatives.begin(), m_Alternatives.end(),
- [&](auto&& i) { return i.originID() == m_Origin; });
+ auto itor =
+ std::find_if(m_Alternatives.begin(), m_Alternatives.end(), [&](auto&& i) {
+ return i.originID() == m_Origin;
+ });
if (itor == m_Alternatives.end()) {
m_Alternatives.push_back({m_Origin, m_Archive});
}
- m_Origin = origin;
+ m_Origin = origin;
m_FileTime = fileTime;
- m_Archive = DataArchiveOrigin(std::wstring(archive.begin(), archive.end()), order);
- }
- else {
+ m_Archive = DataArchiveOrigin(std::wstring(archive.begin(), archive.end()), order);
+ } else {
// This mod is just an alternative
bool found = false;
@@ -70,15 +66,18 @@ void FileEntry::addOrigin(
}
if ((m_Parent != nullptr) &&
- (m_Parent->getOriginByID(iter->originID()).getPriority() < m_Parent->getOriginByID(origin).getPriority())) {
- m_Alternatives.insert(iter, {origin, {std::wstring(archive.begin(), archive.end()), order}});
+ (m_Parent->getOriginByID(iter->originID()).getPriority() <
+ m_Parent->getOriginByID(origin).getPriority())) {
+ m_Alternatives.insert(
+ iter, {origin, {std::wstring(archive.begin(), archive.end()), order}});
found = true;
break;
}
}
if (!found) {
- m_Alternatives.push_back({origin, {std::wstring(archive.begin(), archive.end()), order}});
+ m_Alternatives.push_back(
+ {origin, {std::wstring(archive.begin(), archive.end()), order}});
}
}
}
@@ -93,21 +92,21 @@ bool FileEntry::removeOrigin(OriginID origin)
auto currentIter = m_Alternatives.begin();
for (auto iter = m_Alternatives.begin(); iter != m_Alternatives.end(); ++iter) {
if (iter->originID() != origin) {
- //Both files are not from archives.
+ // Both files are not from archives.
if (!iter->isFromArchive() && !currentIter->isFromArchive()) {
- if ((m_Parent->getOriginByID(iter->originID()).getPriority() > m_Parent->getOriginByID(currentIter->originID()).getPriority())) {
+ if ((m_Parent->getOriginByID(iter->originID()).getPriority() >
+ m_Parent->getOriginByID(currentIter->originID()).getPriority())) {
currentIter = iter;
}
- }
- else {
- //Both files are from archives
+ } else {
+ // Both files are from archives
if (iter->isFromArchive() && currentIter->isFromArchive()) {
if (iter->archive().order() > currentIter->archive().order()) {
currentIter = iter;
}
- }
- else {
- //Only one of the two is an archive, so we change currentIter only if he is the archive one.
+ } else {
+ // Only one of the two is an archive, so we change currentIter only if he
+ // is the archive one.
if (currentIter->isFromArchive()) {
currentIter = iter;
}
@@ -117,19 +116,20 @@ bool FileEntry::removeOrigin(OriginID origin)
}
OriginID currentID = currentIter->originID();
- m_Archive = currentIter->archive();
+ m_Archive = currentIter->archive();
m_Alternatives.erase(currentIter);
m_Origin = currentID;
} else {
- m_Origin = -1;
+ m_Origin = -1;
m_Archive = DataArchiveOrigin(L"", -1);
return true;
}
} else {
- auto newEnd = std::remove_if(
- m_Alternatives.begin(), m_Alternatives.end(),
- [&](auto &i) { return i.originID() == origin; });
+ auto newEnd =
+ std::remove_if(m_Alternatives.begin(), m_Alternatives.end(), [&](auto& i) {
+ return i.originID() == origin;
+ });
if (newEnd != m_Alternatives.end()) {
m_Alternatives.erase(newEnd, m_Alternatives.end());
@@ -160,8 +160,12 @@ void FileEntry::sortOrigins()
}
if (LHS.isFromArchive() && RHS.isFromArchive()) {
- int l = LHS.archive().order(); if (l < 0) l = INT_MAX;
- int r = RHS.archive().order(); if (r < 0) r = INT_MAX;
+ int l = LHS.archive().order();
+ if (l < 0)
+ l = INT_MAX;
+ int r = RHS.archive().order();
+ if (r < 0)
+ r = INT_MAX;
return l < r;
}
@@ -171,10 +175,10 @@ void FileEntry::sortOrigins()
}
return true;
- });
+ });
if (!m_Alternatives.empty()) {
- m_Origin = m_Alternatives.back().originID();
+ m_Origin = m_Alternatives.back().originID();
m_Archive = m_Alternatives.back().archive();
m_Alternatives.pop_back();
}
@@ -207,7 +211,7 @@ std::wstring FileEntry::getFullPath(OriginID originID) const
if (originID == InvalidOriginID) {
bool ignore = false;
- originID = getOrigin(ignore);
+ originID = getOrigin(ignore);
}
// base directory for origin
@@ -234,7 +238,7 @@ std::wstring FileEntry::getRelativePath() const
return result + L"\\" + m_Name;
}
-bool FileEntry::recurseParents(std::wstring &path, const DirectoryEntry *parent) const
+bool FileEntry::recurseParents(std::wstring& path, const DirectoryEntry* parent) const
{
if (parent == nullptr) {
return false;
@@ -248,4 +252,4 @@ bool FileEntry::recurseParents(std::wstring &path, const DirectoryEntry *parent)
}
}
-} // namespace
+} // namespace MOShared
diff --git a/src/shared/fileentry.h b/src/shared/fileentry.h
index 31655bb1..80d8b292 100644
--- a/src/shared/fileentry.h
+++ b/src/shared/fileentry.h
@@ -9,23 +9,19 @@ namespace MOShared
class FileEntry
{
public:
- static constexpr uint64_t NoFileSize =
- std::numeric_limits<uint64_t>::max();
+ static constexpr uint64_t NoFileSize = std::numeric_limits<uint64_t>::max();
FileEntry();
- FileEntry(FileIndex index, std::wstring name, DirectoryEntry *parent);
+ FileEntry(FileIndex index, std::wstring name, DirectoryEntry* parent);
// noncopyable
- FileEntry(const FileEntry&) = delete;
+ FileEntry(const FileEntry&) = delete;
FileEntry& operator=(const FileEntry&) = delete;
- FileIndex getIndex() const
- {
- return m_Index;
- }
+ FileIndex getIndex() const { return m_Index; }
- void addOrigin(
- OriginID origin, FILETIME fileTime, std::wstring_view archive, int order);
+ void addOrigin(OriginID origin, FILETIME fileTime, std::wstring_view archive,
+ int order);
// remove the specified origin from the list of origins that contain this
// file. if no origin is left, the file is effectively deleted and true is
@@ -37,71 +33,44 @@ public:
// gets the list of alternative origins (origins with lower priority than
// the primary one). if sortOrigins has been called, it is sorted by priority
// (ascending)
- const AlternativesVector &getAlternatives() const
- {
- return m_Alternatives;
- }
+ const AlternativesVector& getAlternatives() const { return m_Alternatives; }
- const std::wstring &getName() const
- {
- return m_Name;
- }
+ const std::wstring& getName() const { return m_Name; }
- OriginID getOrigin() const
- {
- return m_Origin;
- }
+ OriginID getOrigin() const { return m_Origin; }
- OriginID getOrigin(bool &archive) const
+ OriginID getOrigin(bool& archive) const
{
archive = m_Archive.isValid();
return m_Origin;
}
- const DataArchiveOrigin &getArchive() const
- {
- return m_Archive;
- }
+ const DataArchiveOrigin& getArchive() const { return m_Archive; }
bool isFromArchive(std::wstring archiveName = L"") const;
// if originID is -1, uses the main origin; if this file doesn't exist in the
// given origin, returns an empty string
//
- std::wstring getFullPath(OriginID originID=InvalidOriginID) const;
+ std::wstring getFullPath(OriginID originID = InvalidOriginID) const;
std::wstring getRelativePath() const;
- DirectoryEntry *getParent()
- {
- return m_Parent;
- }
+ DirectoryEntry* getParent() { return m_Parent; }
- void setFileTime(FILETIME fileTime) const
- {
- m_FileTime = fileTime;
- }
+ void setFileTime(FILETIME fileTime) const { m_FileTime = fileTime; }
- FILETIME getFileTime() const
- {
- return m_FileTime;
- }
+ FILETIME getFileTime() const { return m_FileTime; }
void setFileSize(uint64_t size, uint64_t compressedSize)
{
- m_FileSize = size;
+ m_FileSize = size;
m_CompressedFileSize = compressedSize;
}
- uint64_t getFileSize() const
- {
- return m_FileSize;
- }
+ uint64_t getFileSize() const { return m_FileSize; }
- uint64_t getCompressedFileSize() const
- {
- return m_CompressedFileSize;
- }
+ uint64_t getCompressedFileSize() const { return m_CompressedFileSize; }
private:
FileIndex m_Index;
@@ -109,14 +78,14 @@ private:
OriginID m_Origin;
DataArchiveOrigin m_Archive;
AlternativesVector m_Alternatives;
- DirectoryEntry *m_Parent;
+ DirectoryEntry* m_Parent;
mutable FILETIME m_FileTime;
uint64_t m_FileSize, m_CompressedFileSize;
mutable std::mutex m_OriginsMutex;
- bool recurseParents(std::wstring &path, const DirectoryEntry *parent) const;
+ bool recurseParents(std::wstring& path, const DirectoryEntry* parent) const;
};
-} // namespace
+} // namespace MOShared
-#endif // MO_REGISTER_FILEENTRY_INCLUDED
+#endif // MO_REGISTER_FILEENTRY_INCLUDED
diff --git a/src/shared/fileregister.cpp b/src/shared/fileregister.cpp
index 98e49452..ab94367f 100644
--- a/src/shared/fileregister.cpp
+++ b/src/shared/fileregister.cpp
@@ -1,8 +1,8 @@
#include "fileregister.h"
-#include "fileentry.h"
#include "directoryentry.h"
-#include "originconnection.h"
+#include "fileentry.h"
#include "filesorigin.h"
+#include "originconnection.h"
#include <log.h>
namespace MOShared
@@ -11,9 +11,8 @@ namespace MOShared
using namespace MOBase;
FileRegister::FileRegister(boost::shared_ptr<OriginConnection> originConnection)
- : m_OriginConnection(originConnection), m_NextIndex(0)
-{
-}
+ : m_OriginConnection(originConnection), m_NextIndex(0)
+{}
bool FileRegister::indexValid(FileIndex index) const
{
@@ -26,11 +25,11 @@ bool FileRegister::indexValid(FileIndex index) const
return false;
}
-FileEntryPtr FileRegister::createFile(
- std::wstring name, DirectoryEntry *parent, DirectoryStats& stats)
+FileEntryPtr FileRegister::createFile(std::wstring name, DirectoryEntry* parent,
+ DirectoryStats& stats)
{
const auto index = generateIndex();
- auto p = FileEntryPtr(new FileEntry(index, std::move(name), parent));
+ auto p = FileEntryPtr(new FileEntry(index, std::move(name), parent));
{
std::scoped_lock lock(m_Mutex);
@@ -96,18 +95,19 @@ void FileRegister::removeOrigin(FileIndex index, OriginID originID)
}
}
- log::error(QObject::tr("invalid file index for remove (for origin): {}").toStdString(), index);
+ log::error(
+ QObject::tr("invalid file index for remove (for origin): {}").toStdString(),
+ index);
}
-void FileRegister::removeOriginMulti(
- std::set<FileIndex> indices, OriginID originID)
+void FileRegister::removeOriginMulti(std::set<FileIndex> indices, OriginID originID)
{
std::vector<FileEntryPtr> removedFiles;
{
std::scoped_lock lock(m_Mutex);
- for (auto iter = indices.begin(); iter != indices.end(); ) {
+ for (auto iter = indices.begin(); iter != indices.end();) {
const auto index = *iter;
if (index < m_Files.size()) {
@@ -140,13 +140,13 @@ void FileRegister::removeOriginMulti(
// frequently the case
std::set<DirectoryEntry*> parents;
- for (const FileEntryPtr &file : removedFiles) {
+ for (const FileEntryPtr& file : removedFiles) {
if (file->getParent() != nullptr) {
parents.insert(file->getParent());
}
}
- for (DirectoryEntry *parent : parents) {
+ for (DirectoryEntry* parent : parents) {
parent->removeFiles(indices);
}
}
@@ -181,4 +181,4 @@ void FileRegister::unregisterFile(FileEntryPtr file)
}
}
-} // namespace
+} // namespace MOShared
diff --git a/src/shared/fileregister.h b/src/shared/fileregister.h
index c27dc93b..aeb2c5b7 100644
--- a/src/shared/fileregister.h
+++ b/src/shared/fileregister.h
@@ -2,8 +2,8 @@
#define MO_REGISTER_FILESREGISTER_INCLUDED
#include "fileregisterfwd.h"
-#include <mutex>
#include <boost/shared_ptr.hpp>
+#include <mutex>
namespace MOShared
{
@@ -14,13 +14,13 @@ public:
FileRegister(boost::shared_ptr<OriginConnection> originConnection);
// noncopyable
- FileRegister(const FileRegister&) = delete;
+ FileRegister(const FileRegister&) = delete;
FileRegister& operator=(const FileRegister&) = delete;
bool indexValid(FileIndex index) const;
- FileEntryPtr createFile(
- std::wstring name, DirectoryEntry *parent, DirectoryStats& stats);
+ FileEntryPtr createFile(std::wstring name, DirectoryEntry* parent,
+ DirectoryStats& stats);
FileEntryPtr getFile(FileIndex index) const;
@@ -48,6 +48,6 @@ private:
FileIndex generateIndex();
};
-} // namespace
+} // namespace MOShared
-#endif // MO_REGISTER_FILESREGISTER_INCLUDED
+#endif // MO_REGISTER_FILESREGISTER_INCLUDED
diff --git a/src/shared/fileregisterfwd.h b/src/shared/fileregisterfwd.h
index 57b3715a..dce40ab5 100644
--- a/src/shared/fileregisterfwd.h
+++ b/src/shared/fileregisterfwd.h
@@ -8,15 +8,9 @@ namespace MOShared
struct DirectoryEntryFileKey
{
- DirectoryEntryFileKey(std::wstring v)
- : value(std::move(v)), hash(getHash(value))
- {
- }
+ DirectoryEntryFileKey(std::wstring v) : value(std::move(v)), hash(getHash(value)) {}
- bool operator==(const DirectoryEntryFileKey& o) const
- {
- return (value == o.value);
- }
+ bool operator==(const DirectoryEntryFileKey& o) const { return (value == o.value); }
static std::size_t getHash(const std::wstring& value)
{
@@ -27,7 +21,6 @@ struct DirectoryEntryFileKey
const std::size_t hash;
};
-
class DirectoryEntry;
class OriginConnection;
class FileRegister;
@@ -36,11 +29,11 @@ class FileEntry;
struct DirectoryStats;
using FileEntryPtr = boost::shared_ptr<FileEntry>;
-using FileIndex = unsigned int;
-using OriginID = int;
+using FileIndex = unsigned int;
+using OriginID = int;
constexpr FileIndex InvalidFileIndex = UINT_MAX;
-constexpr OriginID InvalidOriginID = -1;
+constexpr OriginID InvalidOriginID = -1;
// if a file is in an archive, name is the name of the bsa and order
// is the order of the associated plugin in the plugins list
@@ -49,19 +42,17 @@ constexpr OriginID InvalidOriginID = -1;
class DataArchiveOrigin
{
std::wstring name_ = L"";
- int order_ = -1;
-
-public:
+ int order_ = -1;
+public:
int order() const { return order_; }
const std::wstring& name() const { return name_; }
-
- bool isValid() const {
- return name_.size() > 0;
- }
+
+ bool isValid() const { return name_.size() > 0; }
DataArchiveOrigin(std::wstring name, int order)
- : name_(std::move(name)), order_(order) {}
+ : name_(std::move(name)), order_(order)
+ {}
DataArchiveOrigin() = default;
};
@@ -72,18 +63,16 @@ class FileAlternative
DataArchiveOrigin archive_;
public:
-
OriginID originID() const { return originID_; }
const DataArchiveOrigin& archive() const { return archive_; }
- bool isFromArchive() const {
- return archive_.isValid();
- }
+ bool isFromArchive() const { return archive_.isValid(); }
FileAlternative() = default;
- FileAlternative(OriginID originID, DataArchiveOrigin archive)
- : originID_(originID), archive_(std::move(archive)) {}
+ FileAlternative(OriginID originID, DataArchiveOrigin archive)
+ : originID_(originID), archive_(std::move(archive))
+ {}
};
using AlternativesVector = std::vector<FileAlternative>;
@@ -127,6 +116,6 @@ struct DirectoryStats
std::string toCsv() const;
};
-} // namespace
+} // namespace MOShared
-#endif // MO_REGISTER_FILEREGISTERFWD_INCLUDED
+#endif // MO_REGISTER_FILEREGISTERFWD_INCLUDED
diff --git a/src/shared/filesorigin.cpp b/src/shared/filesorigin.cpp
index 049e4258..dd1aec61 100644
--- a/src/shared/filesorigin.cpp
+++ b/src/shared/filesorigin.cpp
@@ -1,12 +1,12 @@
#include "filesorigin.h"
-#include "originconnection.h"
-#include "fileregister.h"
#include "fileentry.h"
+#include "fileregister.h"
+#include "originconnection.h"
namespace MOShared
{
-std::wstring tail(const std::wstring &source, const size_t count)
+std::wstring tail(const std::wstring& source, const size_t count)
{
if (count >= source.length()) {
return source;
@@ -15,28 +15,24 @@ std::wstring tail(const std::wstring &source, const size_t count)
return source.substr(source.length() - count);
}
-
FilesOrigin::FilesOrigin()
- : m_ID(0), m_Disabled(false), m_Name(), m_Path(), m_Priority(0)
-{
-}
+ : m_ID(0), m_Disabled(false), m_Name(), m_Path(), m_Priority(0)
+{}
-FilesOrigin::FilesOrigin(
- OriginID ID, const std::wstring &name, const std::wstring &path, int priority,
- boost::shared_ptr<MOShared::FileRegister> fileRegister,
- boost::shared_ptr<MOShared::OriginConnection> originConnection) :
- m_ID(ID), m_Disabled(false), m_Name(name), m_Path(path),
- m_Priority(priority), m_FileRegister(fileRegister),
- m_OriginConnection(originConnection)
-{
-}
+FilesOrigin::FilesOrigin(OriginID ID, const std::wstring& name,
+ const std::wstring& path, int priority,
+ boost::shared_ptr<MOShared::FileRegister> fileRegister,
+ boost::shared_ptr<MOShared::OriginConnection> originConnection)
+ : m_ID(ID), m_Disabled(false), m_Name(name), m_Path(path), m_Priority(priority),
+ m_FileRegister(fileRegister), m_OriginConnection(originConnection)
+{}
void FilesOrigin::setPriority(int priority)
{
m_Priority = priority;
}
-void FilesOrigin::setName(const std::wstring &name)
+void FilesOrigin::setName(const std::wstring& name)
{
m_OriginConnection.lock()->changeNameLookup(m_Name, name);
@@ -121,4 +117,4 @@ bool FilesOrigin::containsArchive(std::wstring archiveName)
return false;
}
-} // namespace
+} // namespace MOShared
diff --git a/src/shared/filesorigin.h b/src/shared/filesorigin.h
index 1aa4c645..92fe12ef 100644
--- a/src/shared/filesorigin.h
+++ b/src/shared/filesorigin.h
@@ -12,40 +12,26 @@ class FilesOrigin
public:
FilesOrigin();
- FilesOrigin(
- OriginID ID, const std::wstring &name, const std::wstring &path,
- int priority,
- boost::shared_ptr<FileRegister> fileRegister,
- boost::shared_ptr<OriginConnection> originConnection);
+ FilesOrigin(OriginID ID, const std::wstring& name, const std::wstring& path,
+ int priority, boost::shared_ptr<FileRegister> fileRegister,
+ boost::shared_ptr<OriginConnection> originConnection);
// noncopyable
- FilesOrigin(const FilesOrigin&) = delete;
+ FilesOrigin(const FilesOrigin&) = delete;
FilesOrigin& operator=(const FilesOrigin&) = delete;
// sets priority for this origin (does not automatically refresh
// the structure)
void setPriority(int priority);
- int getPriority() const
- {
- return m_Priority;
- }
+ int getPriority() const { return m_Priority; }
- void setName(const std::wstring &name);
- const std::wstring &getName() const
- {
- return m_Name;
- }
+ void setName(const std::wstring& name);
+ const std::wstring& getName() const { return m_Name; }
- OriginID getID() const
- {
- return m_ID;
- }
+ OriginID getID() const { return m_ID; }
- const std::wstring &getPath() const
- {
- return m_Path;
- }
+ const std::wstring& getPath() const { return m_Path; }
std::vector<FileEntryPtr> getFiles() const;
FileEntryPtr findFile(FileIndex index) const;
@@ -53,10 +39,7 @@ public:
void enable(bool enabled, DirectoryStats& stats);
void enable(bool enabled);
- bool isDisabled() const
- {
- return m_Disabled;
- }
+ bool isDisabled() const { return m_Disabled; }
void addFile(FileIndex index)
{
@@ -80,6 +63,6 @@ private:
mutable std::mutex m_Mutex;
};
-} // namespace
+} // namespace MOShared
-#endif // MO_REGISTER_FILESORIGIN_INCLUDED
+#endif // MO_REGISTER_FILESORIGIN_INCLUDED
diff --git a/src/shared/originconnection.cpp b/src/shared/originconnection.cpp
index 2830e8e3..e433891c 100644
--- a/src/shared/originconnection.cpp
+++ b/src/shared/originconnection.cpp
@@ -8,24 +8,20 @@ namespace MOShared
using namespace MOBase;
-OriginConnection::OriginConnection()
- : m_NextID(0)
-{
-}
+OriginConnection::OriginConnection() : m_NextID(0) {}
std::pair<FilesOrigin&, bool> OriginConnection::getOrCreate(
- const std::wstring &originName, const std::wstring &directory, int priority,
- const boost::shared_ptr<FileRegister>& fileRegister,
- const boost::shared_ptr<OriginConnection>& originConnection,
- DirectoryStats& stats)
+ const std::wstring& originName, const std::wstring& directory, int priority,
+ const boost::shared_ptr<FileRegister>& fileRegister,
+ const boost::shared_ptr<OriginConnection>& originConnection, DirectoryStats& stats)
{
std::unique_lock lock(m_Mutex);
auto itor = m_OriginsNameMap.find(originName);
if (itor == m_OriginsNameMap.end()) {
- FilesOrigin& origin = createOriginNoLock(
- originName, directory, priority, fileRegister, originConnection);
+ FilesOrigin& origin = createOriginNoLock(originName, directory, priority,
+ fileRegister, originConnection);
return {origin, true};
} else {
@@ -37,18 +33,19 @@ std::pair<FilesOrigin&, bool> OriginConnection::getOrCreate(
}
}
-FilesOrigin& OriginConnection::createOrigin(
- const std::wstring &originName, const std::wstring &directory, int priority,
- boost::shared_ptr<FileRegister> fileRegister,
- boost::shared_ptr<OriginConnection> originConnection)
+FilesOrigin&
+OriginConnection::createOrigin(const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ boost::shared_ptr<FileRegister> fileRegister,
+ boost::shared_ptr<OriginConnection> originConnection)
{
std::scoped_lock lock(m_Mutex);
- return createOriginNoLock(
- originName, directory, priority, fileRegister, originConnection);
+ return createOriginNoLock(originName, directory, priority, fileRegister,
+ originConnection);
}
-bool OriginConnection::exists(const std::wstring &name)
+bool OriginConnection::exists(const std::wstring& name)
{
std::scoped_lock lock(m_Mutex);
return m_OriginsNameMap.find(name) != m_OriginsNameMap.end();
@@ -73,7 +70,7 @@ const FilesOrigin* OriginConnection::findByID(OriginID ID) const
}
}
-FilesOrigin& OriginConnection::getByName(const std::wstring &name)
+FilesOrigin& OriginConnection::getByName(const std::wstring& name)
{
std::scoped_lock lock(m_Mutex);
@@ -83,12 +80,14 @@ FilesOrigin& OriginConnection::getByName(const std::wstring &name)
return m_Origins[iter->second];
} else {
std::ostringstream stream;
- stream << QObject::tr("invalid origin name: ").toStdString() << ToString(name, true);
+ stream << QObject::tr("invalid origin name: ").toStdString()
+ << ToString(name, true);
throw std::runtime_error(stream.str());
}
}
-void OriginConnection::changeNameLookup(const std::wstring &oldName, const std::wstring &newName)
+void OriginConnection::changeNameLookup(const std::wstring& oldName,
+ const std::wstring& newName)
{
std::scoped_lock lock(m_Mutex);
@@ -99,7 +98,8 @@ void OriginConnection::changeNameLookup(const std::wstring &oldName, const std::
m_OriginsNameMap.erase(iter);
m_OriginsNameMap[newName] = idx;
} else {
- log::error(QObject::tr("failed to change name lookup from {} to {}").toStdString(), oldName, newName);
+ log::error(QObject::tr("failed to change name lookup from {} to {}").toStdString(),
+ oldName, newName);
}
}
@@ -109,23 +109,21 @@ OriginID OriginConnection::createID()
}
FilesOrigin& OriginConnection::createOriginNoLock(
- const std::wstring &originName, const std::wstring &directory, int priority,
- boost::shared_ptr<FileRegister> fileRegister,
- boost::shared_ptr<OriginConnection> originConnection)
+ const std::wstring& originName, const std::wstring& directory, int priority,
+ boost::shared_ptr<FileRegister> fileRegister,
+ boost::shared_ptr<OriginConnection> originConnection)
{
OriginID newID = createID();
- auto itor = m_Origins.emplace(
- std::piecewise_construct,
- std::forward_as_tuple(newID),
- std::forward_as_tuple(
- newID, originName, directory, priority,
- fileRegister, originConnection))
- .first;
+ auto itor = m_Origins
+ .emplace(std::piecewise_construct, std::forward_as_tuple(newID),
+ std::forward_as_tuple(newID, originName, directory, priority,
+ fileRegister, originConnection))
+ .first;
m_OriginsNameMap.insert({originName, newID});
return itor->second;
}
-} // namespace
+} // namespace MOShared
diff --git a/src/shared/originconnection.h b/src/shared/originconnection.h
index ef8692bb..d8a67648 100644
--- a/src/shared/originconnection.h
+++ b/src/shared/originconnection.h
@@ -12,29 +12,29 @@ public:
OriginConnection();
// noncopyable
- OriginConnection(const OriginConnection&) = delete;
+ OriginConnection(const OriginConnection&) = delete;
OriginConnection& operator=(const OriginConnection&) = delete;
- std::pair<FilesOrigin&, bool> getOrCreate(
- const std::wstring &originName, const std::wstring &directory, int priority,
- const boost::shared_ptr<FileRegister>& fileRegister,
- const boost::shared_ptr<OriginConnection>& originConnection,
- DirectoryStats& stats);
+ std::pair<FilesOrigin&, bool>
+ getOrCreate(const std::wstring& originName, const std::wstring& directory,
+ int priority, const boost::shared_ptr<FileRegister>& fileRegister,
+ const boost::shared_ptr<OriginConnection>& originConnection,
+ DirectoryStats& stats);
- FilesOrigin& createOrigin(
- const std::wstring &originName, const std::wstring &directory, int priority,
- boost::shared_ptr<FileRegister> fileRegister,
- boost::shared_ptr<OriginConnection> originConnection);
+ FilesOrigin& createOrigin(const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ boost::shared_ptr<FileRegister> fileRegister,
+ boost::shared_ptr<OriginConnection> originConnection);
- bool exists(const std::wstring &name);
+ bool exists(const std::wstring& name);
- FilesOrigin &getByID(OriginID ID);
+ FilesOrigin& getByID(OriginID ID);
const FilesOrigin* findByID(OriginID ID) const;
- FilesOrigin &getByName(const std::wstring &name);
+ FilesOrigin& getByName(const std::wstring& name);
void changePriorityLookup(int oldPriority, int newPriority);
- void changeNameLookup(const std::wstring &oldName, const std::wstring &newName);
+ void changeNameLookup(const std::wstring& oldName, const std::wstring& newName);
private:
std::atomic<OriginID> m_NextID;
@@ -44,12 +44,12 @@ private:
OriginID createID();
- FilesOrigin& createOriginNoLock(
- const std::wstring &originName, const std::wstring &directory, int priority,
- boost::shared_ptr<FileRegister> fileRegister,
- boost::shared_ptr<OriginConnection> originConnection);
+ FilesOrigin& createOriginNoLock(const std::wstring& originName,
+ const std::wstring& directory, int priority,
+ boost::shared_ptr<FileRegister> fileRegister,
+ boost::shared_ptr<OriginConnection> originConnection);
};
-} // namespace
+} // namespace MOShared
-#endif // MO_REGISTER_ORIGINCONNECTION_INCLUDED
+#endif // MO_REGISTER_ORIGINCONNECTION_INCLUDED
diff --git a/src/shared/util.cpp b/src/shared/util.cpp
index e2faaec5..c3b4d7aa 100644
--- a/src/shared/util.cpp
+++ b/src/shared/util.cpp
@@ -18,9 +18,9 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
*/
#include "util.h"
-#include "windows_error.h"
-#include "../mainwindow.h"
#include "../env.h"
+#include "../mainwindow.h"
+#include "windows_error.h"
#include <log.h>
#include <usvfs.h>
#include <usvfs_version.h>
@@ -30,28 +30,28 @@ using namespace MOBase;
namespace MOShared
{
-bool FileExists(const std::string &filename)
+bool FileExists(const std::string& filename)
{
DWORD dwAttrib = ::GetFileAttributesA(filename.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES);
}
-bool FileExists(const std::wstring &filename)
+bool FileExists(const std::wstring& filename)
{
DWORD dwAttrib = ::GetFileAttributesW(filename.c_str());
return (dwAttrib != INVALID_FILE_ATTRIBUTES);
}
-bool FileExists(const std::wstring &searchPath, const std::wstring &filename)
+bool FileExists(const std::wstring& searchPath, const std::wstring& filename)
{
std::wstringstream stream;
stream << searchPath << "\\" << filename;
return FileExists(stream.str());
}
-std::string ToString(const std::wstring &source, bool utf8)
+std::string ToString(const std::wstring& source, bool utf8)
{
std::string result;
if (source.length() > 0) {
@@ -59,20 +59,23 @@ std::string ToString(const std::wstring &source, bool utf8)
if (!utf8) {
codepage = AreFileApisANSI() ? GetACP() : GetOEMCP();
}
- int sizeRequired = ::WideCharToMultiByte(codepage, 0, &source[0], -1, nullptr, 0, nullptr, nullptr);
+ int sizeRequired = ::WideCharToMultiByte(codepage, 0, &source[0], -1, nullptr, 0,
+ nullptr, nullptr);
if (sizeRequired == 0) {
throw windows_error("failed to convert string to multibyte");
}
- // the size returned by WideCharToMultiByte contains zero termination IF -1 is specified for the length.
- // we don't want that \0 in the string because then the length field would be wrong. Because madness
+ // the size returned by WideCharToMultiByte contains zero termination IF -1 is
+ // specified for the length. we don't want that \0 in the string because then the
+ // length field would be wrong. Because madness
result.resize(sizeRequired - 1, '\0');
- ::WideCharToMultiByte(codepage, 0, &source[0], (int)source.size(), &result[0], sizeRequired, nullptr, nullptr);
+ ::WideCharToMultiByte(codepage, 0, &source[0], (int)source.size(), &result[0],
+ sizeRequired, nullptr, nullptr);
}
return result;
}
-std::wstring ToWString(const std::string &source, bool utf8)
+std::wstring ToWString(const std::string& source, bool utf8)
{
std::wstring result;
if (source.length() > 0) {
@@ -80,53 +83,51 @@ std::wstring ToWString(const std::string &source, bool utf8)
if (!utf8) {
codepage = AreFileApisANSI() ? GetACP() : GetOEMCP();
}
- int sizeRequired
- = ::MultiByteToWideChar(codepage, 0, source.c_str(),
- static_cast<int>(source.length()), nullptr, 0);
+ int sizeRequired = ::MultiByteToWideChar(
+ codepage, 0, source.c_str(), static_cast<int>(source.length()), nullptr, 0);
if (sizeRequired == 0) {
throw windows_error("failed to convert string to wide character");
}
result.resize(sizeRequired, L'\0');
::MultiByteToWideChar(codepage, 0, source.c_str(),
- static_cast<int>(source.length()), &result[0],
- sizeRequired);
+ static_cast<int>(source.length()), &result[0], sizeRequired);
}
return result;
}
static std::locale loc("");
-static auto locToLowerW = [] (wchar_t in) -> wchar_t {
+static auto locToLowerW = [](wchar_t in) -> wchar_t {
return std::tolower(in, loc);
};
-static auto locToLower = [] (char in) -> char {
+static auto locToLower = [](char in) -> char {
return std::tolower(in, loc);
};
std::string& ToLowerInPlace(std::string& text)
{
- CharLowerBuffA(const_cast<CHAR *>(text.c_str()), static_cast<DWORD>(text.size()));
+ CharLowerBuffA(const_cast<CHAR*>(text.c_str()), static_cast<DWORD>(text.size()));
return text;
}
std::string ToLowerCopy(const std::string& text)
{
std::string result(text);
- CharLowerBuffA(const_cast<CHAR *>(result.c_str()), static_cast<DWORD>(result.size()));
+ CharLowerBuffA(const_cast<CHAR*>(result.c_str()), static_cast<DWORD>(result.size()));
return result;
}
std::wstring& ToLowerInPlace(std::wstring& text)
{
- CharLowerBuffW(const_cast<WCHAR *>(text.c_str()), static_cast<DWORD>(text.size()));
+ CharLowerBuffW(const_cast<WCHAR*>(text.c_str()), static_cast<DWORD>(text.size()));
return text;
}
std::wstring ToLowerCopy(const std::wstring& text)
{
std::wstring result(text);
- CharLowerBuffW(const_cast<WCHAR *>(result.c_str()), static_cast<DWORD>(result.size()));
+ CharLowerBuffW(const_cast<WCHAR*>(result.c_str()), static_cast<DWORD>(result.size()));
return result;
}
@@ -142,20 +143,19 @@ bool CaseInsenstiveComparePred(wchar_t lhs, wchar_t rhs)
return std::tolower(lhs, loc) == std::tolower(rhs, loc);
}
-bool CaseInsensitiveEqual(const std::wstring &lhs, const std::wstring &rhs)
+bool CaseInsensitiveEqual(const std::wstring& lhs, const std::wstring& rhs)
{
- return (lhs.length() == rhs.length())
- && std::equal(lhs.begin(), lhs.end(),
- rhs.begin(),
- [] (wchar_t lhs, wchar_t rhs) -> bool {
+ return (lhs.length() == rhs.length()) &&
+ std::equal(lhs.begin(), lhs.end(), rhs.begin(),
+ [](wchar_t lhs, wchar_t rhs) -> bool {
return std::tolower(lhs, loc) == std::tolower(rhs, loc);
});
}
-VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName)
+VS_FIXEDFILEINFO GetFileVersion(const std::wstring& fileName)
{
DWORD handle = 0UL;
- DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
+ DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
if (size == 0) {
throw windows_error("failed to determine file version info size");
}
@@ -167,7 +167,7 @@ VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName)
throw windows_error("failed to determine file version info");
}
- void *versionInfoPtr = nullptr;
+ void* versionInfoPtr = nullptr;
UINT versionInfoLength = 0;
if (!::VerQueryValue(buffer.get(), L"\\", &versionInfoPtr, &versionInfoLength)) {
throw windows_error("failed to determine file version");
@@ -180,10 +180,10 @@ VS_FIXEDFILEINFO GetFileVersion(const std::wstring &fileName)
}
}
-std::wstring GetFileVersionString(const std::wstring &fileName)
+std::wstring GetFileVersionString(const std::wstring& fileName)
{
DWORD handle = 0UL;
- DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
+ DWORD size = ::GetFileVersionInfoSizeW(fileName.c_str(), &handle);
if (size == 0) {
throw windows_error("failed to determine file version info size");
}
@@ -196,14 +196,14 @@ std::wstring GetFileVersionString(const std::wstring &fileName)
}
LPVOID strBuffer = nullptr;
- UINT strLength = 0;
- if (!::VerQueryValue(buffer.get(), L"\\StringFileInfo\\040904B0\\ProductVersion", &strBuffer, &strLength)) {
+ UINT strLength = 0;
+ if (!::VerQueryValue(buffer.get(), L"\\StringFileInfo\\040904B0\\ProductVersion",
+ &strBuffer, &strLength)) {
throw windows_error("failed to determine file version");
}
return std::wstring((LPCTSTR)strBuffer);
- }
- catch (...) {
+ } catch (...) {
throw;
}
}
@@ -212,45 +212,35 @@ VersionInfo createVersionInfo()
{
VS_FIXEDFILEINFO version = GetFileVersion(env::thisProcessPath().native());
- if (version.dwFileFlags & VS_FF_PRERELEASE)
- {
+ if (version.dwFileFlags & VS_FF_PRERELEASE) {
// Pre-release builds need annotating
- QString versionString = QString::fromStdWString(
- GetFileVersionString(env::thisProcessPath().native()));
+ QString versionString =
+ QString::fromStdWString(GetFileVersionString(env::thisProcessPath().native()));
- // The pre-release flag can be set without the string specifying what type of pre-release
+ // The pre-release flag can be set without the string specifying what type of
+ // pre-release
bool noLetters = true;
- for (QChar character : versionString)
- {
- if (character.isLetter())
- {
+ for (QChar character : versionString) {
+ if (character.isLetter()) {
noLetters = false;
break;
}
}
- if (noLetters)
- {
+ if (noLetters) {
// Default to pre-alpha when release type is unspecified
- return VersionInfo(version.dwFileVersionMS >> 16,
- version.dwFileVersionMS & 0xFFFF,
- version.dwFileVersionLS >> 16,
- version.dwFileVersionLS & 0xFFFF,
- VersionInfo::RELEASE_PREALPHA);
- }
- else
- {
+ return VersionInfo(
+ version.dwFileVersionMS >> 16, version.dwFileVersionMS & 0xFFFF,
+ version.dwFileVersionLS >> 16, version.dwFileVersionLS & 0xFFFF,
+ VersionInfo::RELEASE_PREALPHA);
+ } else {
// Trust the string to make sense
return VersionInfo(versionString);
}
- }
- else
- {
+ } else {
// Non-pre-release builds just need their version numbers reading
- return VersionInfo(version.dwFileVersionMS >> 16,
- version.dwFileVersionMS & 0xFFFF,
- version.dwFileVersionLS >> 16,
- version.dwFileVersionLS & 0xFFFF);
+ return VersionInfo(version.dwFileVersionMS >> 16, version.dwFileVersionMS & 0xFFFF,
+ version.dwFileVersionLS >> 16, version.dwFileVersionLS & 0xFFFF);
}
}
@@ -260,7 +250,7 @@ QString getUsvfsDLLVersion()
// directly; until then, using GetProcAddress() allows for mixing up devbuilds
// and usvfs dlls
- using USVFSVersionStringType = const char* WINAPI ();
+ using USVFSVersionStringType = const char* WINAPI();
QString s;
@@ -268,7 +258,7 @@ QString getUsvfsDLLVersion()
if (m) {
auto* f = reinterpret_cast<USVFSVersionStringType*>(
- ::GetProcAddress(m, "USVFSVersionString"));
+ ::GetProcAddress(m, "USVFSVersionString"));
if (f) {
s = f();
@@ -286,7 +276,7 @@ QString getUsvfsDLLVersion()
QString getUsvfsVersionString()
{
- const QString dll = getUsvfsDLLVersion();
+ const QString dll = getUsvfsDLLVersion();
const QString header = USVFS_VERSION_STRING;
QString usvfsVersion;
@@ -300,10 +290,7 @@ QString getUsvfsVersionString()
void SetThisThreadName(const QString& s)
{
- using SetThreadDescriptionType = HRESULT (
- HANDLE hThread,
- PCWSTR lpThreadDescription
- );
+ using SetThreadDescriptionType = HRESULT(HANDLE hThread, PCWSTR lpThreadDescription);
static SetThreadDescriptionType* SetThreadDescription = [] {
SetThreadDescriptionType* p = nullptr;
@@ -314,7 +301,7 @@ void SetThisThreadName(const QString& s)
}
p = reinterpret_cast<SetThreadDescriptionType*>(
- GetProcAddress(kernel32.get(), "SetThreadDescription"));
+ GetProcAddress(kernel32.get(), "SetThreadDescription"));
return p;
}();
@@ -324,13 +311,12 @@ void SetThisThreadName(const QString& s)
}
}
-
char shortcutChar(const QAction* a)
{
const auto text = a->text();
- char shortcut = 0;
+ char shortcut = 0;
- for (int i=0; i<text.size(); ++i) {
+ for (int i = 0; i < text.size(); ++i) {
const auto c = text[i];
if (c == '&') {
if (i >= (text.size() - 1)) {
@@ -350,7 +336,7 @@ void checkDuplicateShortcuts(const QMenu& m)
{
const auto actions = m.actions();
- for (int i=0; i<actions.size(); ++i) {
+ for (int i = 0; i < actions.size(); ++i) {
const auto* action1 = actions[i];
if (action1->isSeparator()) {
continue;
@@ -361,7 +347,7 @@ void checkDuplicateShortcuts(const QMenu& m)
continue;
}
- for (int j=i+1; j<actions.size(); ++j) {
+ for (int j = i + 1; j < actions.size(); ++j) {
const auto* action2 = actions[j];
if (action2->isSeparator()) {
continue;
@@ -370,9 +356,8 @@ void checkDuplicateShortcuts(const QMenu& m)
const char shortcut2 = shortcutChar(action2);
if (shortcut1 == shortcut2) {
- log::error(
- "duplicate shortcut {} for {} and {}",
- shortcut1, action1->text(), action2->text());
+ log::error("duplicate shortcut {} for {} and {}", shortcut1, action1->text(),
+ action2->text());
break;
}
@@ -380,16 +365,15 @@ void checkDuplicateShortcuts(const QMenu& m)
}
}
-} // namespace MOShared
-
+} // namespace MOShared
-static bool g_exiting = false;
+static bool g_exiting = false;
static bool g_canClose = false;
MainWindow* findMainWindow()
{
for (auto* tl : qApp->topLevelWidgets()) {
- if (auto* mw=dynamic_cast<MainWindow*>(tl)) {
+ if (auto* mw = dynamic_cast<MainWindow*>(tl)) {
return mw;
}
}
@@ -404,10 +388,12 @@ bool ExitModOrganizer(ExitFlags e)
}
g_exiting = true;
- Guard g([&]{ g_exiting = false; });
+ Guard g([&] {
+ g_exiting = false;
+ });
if (!e.testFlag(Exit::Force)) {
- if (auto* mw=findMainWindow()) {
+ if (auto* mw = findMainWindow()) {
if (!mw->canExit()) {
return false;
}
@@ -437,7 +423,6 @@ void ResetExitFlag()
g_exiting = false;
}
-
bool isNxmLink(const QString& link)
{
return link.startsWith("nxm://", Qt::CaseInsensitive);
diff --git a/src/shared/util.h b/src/shared/util.h
index 87ec5bf2..1bc6bd47 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -20,23 +20,24 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#ifndef UTIL_H
#define UTIL_H
+#include <filesystem>
#include <log.h>
#include <string>
-#include <filesystem>
#include <versioninfo.h>
class Executable;
-namespace MOShared {
+namespace MOShared
+{
/// Test if a file (or directory) by the specified name exists
-bool FileExists(const std::string &filename);
-bool FileExists(const std::wstring &filename);
+bool FileExists(const std::string& filename);
+bool FileExists(const std::wstring& filename);
-bool FileExists(const std::wstring &searchPath, const std::wstring &filename);
+bool FileExists(const std::wstring& searchPath, const std::wstring& filename);
-std::string ToString(const std::wstring &source, bool utf8);
-std::wstring ToWString(const std::string &source, bool utf8);
+std::string ToString(const std::wstring& source, bool utf8);
+std::wstring ToWString(const std::string& source, bool utf8);
std::string& ToLowerInPlace(std::string& text);
std::string ToLowerCopy(const std::string& text);
@@ -45,7 +46,7 @@ std::wstring& ToLowerInPlace(std::wstring& text);
std::wstring ToLowerCopy(const std::wstring& text);
std::wstring ToLowerCopy(std::wstring_view text);
-bool CaseInsensitiveEqual(const std::wstring &lhs, const std::wstring &rhs);
+bool CaseInsensitiveEqual(const std::wstring& lhs, const std::wstring& rhs);
MOBase::VersionInfo createVersionInfo();
QString getUsvfsVersionString();
@@ -62,8 +63,7 @@ inline FILETIME ToFILETIME(std::filesystem::file_time_type t)
return ft;
}
-} // namespace MOShared
-
+} // namespace MOShared
enum class Exit
{
@@ -73,17 +73,17 @@ enum class Exit
Force = 0x04
};
-const int RestartExitCode = INT_MAX;
+const int RestartExitCode = INT_MAX;
const int ReselectExitCode = INT_MAX - 1;
using ExitFlags = QFlags<Exit>;
Q_DECLARE_OPERATORS_FOR_FLAGS(ExitFlags);
-bool ExitModOrganizer(ExitFlags e=Exit::Normal);
+bool ExitModOrganizer(ExitFlags e = Exit::Normal);
bool ModOrganizerExiting();
bool ModOrganizerCanCloseNow();
void ResetExitFlag();
bool isNxmLink(const QString& link);
-#endif // UTIL_H
+#endif // UTIL_H
diff --git a/src/shared/windows_error.cpp b/src/shared/windows_error.cpp
index 49fb9bc7..f0add1da 100644
--- a/src/shared/windows_error.cpp
+++ b/src/shared/windows_error.cpp
@@ -20,7 +20,8 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include "windows_error.h"
#include <sstream>
-namespace MOShared {
+namespace MOShared
+{
std::string windows_error::constructMessage(const std::string& input, int inErrorCode)
{
@@ -33,17 +34,19 @@ std::string windows_error::constructMessage(const std::string& input, int inErro
// TODO: the message is not english?
if (FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- nullptr, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&buffer, 0, nullptr) == 0) {
+ nullptr, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPSTR)&buffer, 0, nullptr) == 0) {
finalMessage << " (errorcode " << errorCode << ")";
} else {
LPSTR lastChar = buffer + strlen(buffer) - 2;
- *lastChar = '\0';
+ *lastChar = '\0';
finalMessage << " (" << buffer << " [" << errorCode << "])";
- LocalFree(buffer); // allocated by FormatMessage
+ LocalFree(buffer); // allocated by FormatMessage
}
- ::SetLastError(errorCode); // restore error code because FormatMessage might have modified it
+ ::SetLastError(
+ errorCode); // restore error code because FormatMessage might have modified it
return finalMessage.str();
}
-} // namespace MOShared
+} // namespace MOShared
diff --git a/src/shared/windows_error.h b/src/shared/windows_error.h
index ea506dc1..2bdd6392 100644
--- a/src/shared/windows_error.h
+++ b/src/shared/windows_error.h
@@ -20,25 +20,28 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#ifndef WINDOWS_ERROR_H
#define WINDOWS_ERROR_H
-
#include <stdexcept>
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
-namespace MOShared {
+namespace MOShared
+{
-class windows_error : public std::runtime_error {
+class windows_error : public std::runtime_error
+{
public:
windows_error(const std::string& message, int errorcode = ::GetLastError())
- : runtime_error(constructMessage(message, errorcode)), m_ErrorCode(errorcode)
+ : runtime_error(constructMessage(message, errorcode)), m_ErrorCode(errorcode)
{}
int getErrorCode() const { return m_ErrorCode; }
+
private:
std::string constructMessage(const std::string& input, int errorcode);
+
private:
int m_ErrorCode;
};
-} // namespace MOShared
+} // namespace MOShared
-#endif // WINDOWS_ERROR_H
+#endif // WINDOWS_ERROR_H