diff --git a/stepmania/src/RageUtil.cpp b/stepmania/src/RageUtil.cpp index b3e5234e92..3960d3dc62 100644 --- a/stepmania/src/RageUtil.cpp +++ b/stepmania/src/RageUtil.cpp @@ -437,12 +437,8 @@ unsigned int GetHashForFile( CString sPath ) unsigned int hash = 0; hash += GetHashForString( sPath ); - hash += GetFileSizeInBytes( sPath ); - - struct stat st; - if( DoStat(sPath, &st)) - hash += st.st_mtime; + hash += GetFileModTime( sPath ); return hash; } diff --git a/stepmania/src/RageUtil_FileDB.cpp b/stepmania/src/RageUtil_FileDB.cpp index 29b3b8d5ed..199f409de1 100644 --- a/stepmania/src/RageUtil_FileDB.cpp +++ b/stepmania/src/RageUtil_FileDB.cpp @@ -22,9 +22,12 @@ struct File { istring name; bool dir; int size; + /* Modification time of the file. The contents of this is undefined, except that + * when the file has been modified, this value will change. */ + int mtime; - File() { dir=false; size=-1; } - File( istring fn ): name(fn) { dir=false; size=-1; } + File() { dir=false; size=-1; mtime=-1; } + File( istring fn ): name(fn) { dir=false; size=-1; mtime=-1; } bool operator== (const File &rhs) const { return name==rhs.name; } bool operator< (const File &rhs) const { return namesize; } +int FileSet::GetFileModTime(const CString &path) const +{ + set::const_iterator i = files.find(File(path.c_str())); + if(i == files.end()) + return -1; + return i->mtime; +} + /* Given "foo/bar/baz/" or "foo/bar/baz", return "foo/bar/" and "baz". */ static void SplitPath( CString Path, CString &Dir, CString &Name ) { @@ -241,6 +255,7 @@ public: bool IsAFile(const CString &path); bool IsADirectory(const CString &path); int GetFileSize(const CString &path); + int GetFileModTime( const CString &sFilePath ); void FlushDirCache(); }; @@ -277,6 +292,13 @@ int FilenameDB::GetFileSize( const CString &sPath ) return fs.GetFileSize(Name); } +int FilenameDB::GetFileModTime( const CString &sPath ) +{ + CString Dir, Name; + SplitPath(sPath, Dir, Name); + FileSet &fs = GetFileSet(Dir.c_str()); + return fs.GetFileModTime(Name); +} /* XXX: this won't work right for URIs, eg \\foo\bar */ bool FilenameDB::ResolvePath(CString &path) @@ -462,15 +484,21 @@ void FlushDirCache() bool DoesFileExist( const CString &sPath ) { return FDB.DoesFileExist(sPath); } bool IsAFile( const CString &sPath ) { return FDB.IsAFile(sPath); } bool IsADirectory( const CString &sPath ) { return FDB.IsADirectory(sPath); } +int GetFileModTime( const CString &sPath ) { return FDB.GetFileModTime(sPath); } unsigned GetFileSizeInBytes( const CString &sPath ) { int ret = FDB.GetFileSize(sPath); - LOG->Trace("file '%s' size %i", sPath.c_str(), ret); +// LOG->Trace("file '%s' size %i", sPath.c_str(), ret); if( ret == -1 ) return 0; return ret; } #else +static bool DoStat(CString sPath, struct stat *st) +{ + TrimRight(sPath, "/\\"); + return stat(sPath.c_str(), st) != -1; +} bool DoesFileExist( const CString &sPath ) { if(sPath.empty()) return false; @@ -501,11 +529,13 @@ unsigned GetFileSizeInBytes( const CString &sFilePath ) return st.st_size; } -#endif -/* XXX */ -bool DoStat(CString sPath, struct stat *st) +int GetFileModTime( const CString &sPath ) { - TrimRight(sPath, "/\\"); - return stat(sPath.c_str(), st) != -1; + struct stat st; + if(!DoStat(sFilePath, &st)) + return -1; + + return st.st_mtime; } +#endif diff --git a/stepmania/src/RageUtil_FileDB.h b/stepmania/src/RageUtil_FileDB.h index 538c1558b3..c35b35a5bd 100644 --- a/stepmania/src/RageUtil_FileDB.h +++ b/stepmania/src/RageUtil_FileDB.h @@ -6,7 +6,7 @@ bool IsAFile( const CString &sPath ); bool IsADirectory( const CString &sPath ); bool ResolvePath(CString &path); unsigned GetFileSizeInBytes( const CString &sFilePath ); -bool DoStat(CString sPath, struct stat *st); +int GetFileModTime( const CString &sPath ); void FlushDirCache();