From 5d4a55c3a67caec2811a2b997753adc116403d77 Mon Sep 17 00:00:00 2001 From: Tannin Date: Fri, 1 Aug 2014 12:10:49 +0200 Subject: - performance optimizations for detection of file changes in mod directories - added a workaround for download-link handling in chrome - MO will now create a profile even if the game-launcher has never been run - bugfix: files weren't cleanly removed from vfs file register --- src/shared/directoryentry.h | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) (limited to 'src/shared/directoryentry.h') diff --git a/src/shared/directoryentry.h b/src/shared/directoryentry.h index 7b656b05..1e904311 100644 --- a/src/shared/directoryentry.h +++ b/src/shared/directoryentry.h @@ -34,6 +34,11 @@ along with Mod Organizer. If not, see . #include "util.h" + +#include "error_report.h" + + + namespace MOShared { @@ -60,6 +65,8 @@ public: Index getIndex() const { return m_Index; } + time_t lastAccessed() const { return m_LastAccessed; } + void addOrigin(int origin, FILETIME fileTime, const std::wstring &archive); // 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 returned. otherwise, false is returned @@ -98,6 +105,8 @@ private: DirectoryEntry *m_Parent; mutable FILETIME m_FileTime; + time_t m_LastAccessed; + friend bool operator<(const FileEntry &lhs, const FileEntry &rhs) { return _wcsicmp(lhs.m_Name.c_str(), rhs.m_Name.c_str()) < 0; } @@ -130,7 +139,7 @@ public: std::vector getFiles() const; - void enable(bool enabled); + void enable(bool enabled, time_t notAfter = LONG_MAX); bool isDisabled() const { return m_Disabled; } void addFile(FileEntry::Index index) { m_Files.insert(index); } @@ -171,8 +180,11 @@ public: FileEntry::Ptr createFile(const std::wstring &name, DirectoryEntry *parent); FileEntry::Ptr getFile(FileEntry::Index index) const; + size_t size() const { return m_Files.size(); } + void removeFile(FileEntry::Index index); void removeOrigin(FileEntry::Index index, int originID); + void removeOriginMulti(std::set indices, int originID, time_t notAfter); void sortOrigins(); @@ -258,7 +270,7 @@ public: void removeDir(const std::wstring &path); void remove(const std::wstring &fileName, int *origin) { - auto iter = m_Files.find(fileName); + auto iter = m_Files.find(ToLower(fileName)); if (iter != m_Files.end()) { if (origin != NULL) { FileEntry::Ptr entry = m_FileRegister->getFile(iter->second); @@ -268,6 +280,8 @@ public: } } m_FileRegister->removeFile(iter->second); + } else { + log ("failed to remove %ls from %ls", fileName.c_str(), m_Name.c_str()); } } @@ -275,20 +289,23 @@ public: FilesOrigin &createOrigin(const std::wstring &originName, const std::wstring &directory, int priority); + void removeFiles(const std::set &indices); + private: DirectoryEntry(const DirectoryEntry &reference); DirectoryEntry &operator=(const DirectoryEntry &reference); void insert(const std::wstring &fileName, FilesOrigin &origin, FILETIME fileTime, const std::wstring &archive) { - auto iter = m_Files.find(fileName); + std::wstring fileNameLower = ToLower(fileName); + auto iter = m_Files.find(fileNameLower); FileEntry::Ptr file; if (iter != m_Files.end()) { file = m_FileRegister->getFile(iter->second); } else { file = m_FileRegister->createFile(fileName, this); // TODO this has been observed to cause a crash, no clue why - m_Files[fileName] = file->getIndex(); + m_Files[fileNameLower] = file->getIndex(); } file->addOrigin(origin.getID(), fileTime, archive); origin.addFile(file->getIndex()); @@ -305,22 +322,13 @@ private: void removeDirRecursive(); -private: - - struct WStrLess { - bool operator()(const std::wstring &LHS, const std::wstring &RHS) const { - return _wcsicmp(LHS.c_str(), RHS.c_str()) < 0; - } - }; - - private: boost::shared_ptr m_FileRegister; boost::shared_ptr m_OriginConnection; std::wstring m_Name; - std::map m_Files; + std::map m_Files; std::vector m_SubDirectories; DirectoryEntry *m_Parent; -- cgit v1.3.1