27 #include "precompiled.h"
39 : m_name(name), m_size(size), m_mtime(mtime), m_priority(priority), m_loader(loader)
63 const double howMuchNewer = difftime(newFile.
MTime(), previousFile.
MTime());
64 const double threshold = 2.0;
65 if(howMuchNewer > threshold)
67 if(howMuchNewer < -threshold)
74 if(newFile.
Loader()->Precedence() < previousFile.
Loader()->Precedence())
83 std::pair<VfsPath, VfsFile> value = std::make_pair(file.
Name(), file);
84 std::pair<VfsFiles::iterator, bool> ret =
m_files.insert(value);
87 VfsFile& previousFile = ret.first->second;
88 const VfsFile& newFile = value.second;
90 previousFile = newFile;
97 return &(*ret.first).second;
105 std::pair<VfsPath, VfsDirectory> value = std::make_pair(name.
string(),
VfsDirectory());
106 std::pair<VfsSubdirectories::iterator, bool> ret =
m_subdirectories.insert(value);
107 return &(*ret.first).second;
168 wchar_t timestamp[25];
169 const time_t mtime = file.
MTime();
170 wcsftime(timestamp,
ARRAY_SIZE(timestamp), L
"%a %b %d %H:%M:%S %Y", localtime(&mtime));
182 std::wstring descriptions;
183 descriptions.reserve(100*files.size());
185 const std::wstring indentation(4*indentLevel,
' ');
186 for(VfsDirectory::VfsFiles::const_iterator it = files.begin(); it != files.end(); ++it)
188 const VfsFile& file = it->second;
189 descriptions += indentation;
191 descriptions += L
"\n";
200 const std::wstring indentation(4*indentLevel,
' ');
203 for(VfsDirectory::VfsSubdirectories::const_iterator it = subdirectories.begin(); it != subdirectories.end(); ++it)
205 const VfsPath& name = it->first;
207 descriptions += indentation;
208 descriptions += std::wstring(L
"[") + name.
string() + L
"]\n";
VfsFile * AddFile(const VfsFile &file)
const VfsPath & Name() const
void RemoveFile(const VfsPath &name)
remove the given file from the virtual directory (no effect on the physical file).
void DirectoryDescriptionR(std::wstring &descriptions, const VfsDirectory &directory, size_t indentLevel)
append each directory's files' description to the given string.
volatile intptr_t m_shouldPopulate
PRealDirectory m_realDirectory
const VfsFiles & Files() const
int swprintf_s(wchar_t *buf, size_t max_chars, const wchar_t *fmt,...) WPRINTF_ARGS(3)
std::wstring FileDescriptions(const VfsDirectory &directory, size_t indentLevel)
void SetAssociatedDirectory(const PRealDirectory &realDirectory)
side effect: the next ShouldPopulate() will return true.
VfsFile * GetFile(const VfsPath &name)
const VfsSubdirectories & Subdirectories() const
std::wstring FileDescription(const VfsFile &file)
shared_ptr< RealDirectory > PRealDirectory
const String & string() const
VfsSubdirectories m_subdirectories
shared_ptr< IFileLoader > PIFileLoader
const PIFileLoader & Loader() const
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
static bool ShouldReplaceWith(const VfsFile &previousFile, const VfsFile &newFile)
void Clear()
empty file and subdirectory lists (e.g.
bool cpu_CAS(volatile intptr_t *location, intptr_t expected, intptr_t newValue)
atomic "compare and swap".
std::map< VfsPath, VfsFile > VfsFiles
void RequestRepopulate()
ensure the next ShouldPopulate returns true.
std::map< VfsPath, VfsDirectory > VfsSubdirectories
#define stats_vfs_file_add(file_size)
VfsDirectory * GetSubdirectory(const VfsPath &name)
VfsFile(const VfsPath &name, size_t size, time_t mtime, size_t priority, const PIFileLoader &provider)
VfsDirectory * AddSubdirectory(const VfsPath &name)