diff --git a/stepmania/src/RageFileDriver.cpp b/stepmania/src/RageFileDriver.cpp index 196a11e4a8..eaea572593 100644 --- a/stepmania/src/RageFileDriver.cpp +++ b/stepmania/src/RageFileDriver.cpp @@ -115,9 +115,9 @@ int RageFileDriver::GetFileSizeInBytes( const CString &sPath ) return FDB->GetFileSize( sPath ); } -int RageFileDriver::GetFileModTime( const CString &sPath ) +int RageFileDriver::GetFileHash( const CString &sPath ) { - return FDB->GetFileModTime( sPath ); + return FDB->GetFileHash( sPath ); } void RageFileDriver::FlushDirCache( const CString &sPath ) diff --git a/stepmania/src/RageFileDriver.h b/stepmania/src/RageFileDriver.h index 89959d9684..ec4dc94e37 100644 --- a/stepmania/src/RageFileDriver.h +++ b/stepmania/src/RageFileDriver.h @@ -15,7 +15,7 @@ public: virtual void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ); virtual RageFileManager::FileType GetFileType( const CString &sPath ); virtual int GetFileSizeInBytes( const CString &sFilePath ); - virtual int GetFileModTime( const CString &sPath ); + virtual int GetFileHash( const CString &sPath ); virtual int GetPathValue( const CString &path ); virtual bool Ready() { return true; } /* see RageFileManager::MountpointIsReady */ virtual void FlushDirCache( const CString &sPath ); diff --git a/stepmania/src/RageFileDriverDirect.cpp b/stepmania/src/RageFileDriverDirect.cpp index b27cd605a0..a198db8583 100644 --- a/stepmania/src/RageFileDriverDirect.cpp +++ b/stepmania/src/RageFileDriverDirect.cpp @@ -69,7 +69,7 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path ) f.SetName( fd.cFileName ); f.dir = !!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY); f.size = fd.nFileSizeLow; - f.mtime = fd.ftLastWriteTime.dwLowDateTime; + f.hash = fd.ftLastWriteTime.dwLowDateTime; fs.files.insert(f); } while( FindNextFile( hFind, &fd ) ); @@ -112,7 +112,7 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path ) } else { f.dir = (st.st_mode & S_IFDIR); f.size = st.st_size; - f.mtime = st.st_mtime; + f.hash = st.st_mtime; } fs.files.insert(f); diff --git a/stepmania/src/RageFileManager.cpp b/stepmania/src/RageFileManager.cpp index 2c10f10033..8023779387 100644 --- a/stepmania/src/RageFileManager.cpp +++ b/stepmania/src/RageFileManager.cpp @@ -18,7 +18,7 @@ public: RageFileDriverMountpoints(): RageFileDriver( new FilenameDB ) { } RageFileObj *Open( const CString &path, RageFile::OpenMode mode, RageFile &p, int &err ) { - err = EINVAL; + err = (mode == RageFile::WRITE)? EINVAL:ENOENT; return NULL; } void FlushDirCache( const CString &sPath ) { } @@ -257,14 +257,14 @@ int RageFileManager::GetFileSizeInBytes( const CString &sPath ) return -1; } -int RageFileManager::GetFileModTime( const CString &sPath ) +int RageFileManager::GetFileHash( const CString &sPath ) { for( unsigned i = 0; i < g_Drivers.size(); ++i ) { const CString p = g_Drivers[i].GetPath( sPath ); if( p.size() == 0 ) continue; - int ret = g_Drivers[i].driver->GetFileModTime( p ); + int ret = g_Drivers[i].driver->GetFileHash( p ); if( ret != -1 ) return ret; } @@ -288,7 +288,6 @@ RageFileObj *RageFileManager::Open( const CString &sPath, RageFile::OpenMode mod if( mode == RageFile::WRITE ) return OpenForWriting( sPath, mode, p, err ); - /* XXX: WRITE logic */ for( unsigned i = 0; i < g_Drivers.size(); ++i ) { const CString path = g_Drivers[i].GetPath( sPath ); @@ -393,11 +392,6 @@ unsigned GetFileSizeInBytes( const CString &sPath ) return FILEMAN->GetFileSizeInBytes( sPath ); } -int GetFileModTime( const CString &sPath ) -{ - return FILEMAN->GetFileModTime( sPath ); -} - void GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) { FILEMAN->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo ); @@ -408,3 +402,25 @@ void FlushDirCache() FILEMAN->FlushDirCache( "" ); } + +unsigned int GetHashForFile( const CString &sPath ) +{ + return GetHashForString( sPath ) + FILEMAN->GetFileHash( sPath ); +} + +unsigned int GetHashForDirectory( const CString &sDir ) +{ + unsigned int hash = 0; + + hash += GetHashForFile( sDir ); + + CStringArray arrayFiles; + GetDirListing( sDir+"*", arrayFiles, false ); + for( unsigned i=0; isize; } -int FileSet::GetFileModTime(const CString &path) const +int FileSet::GetFileHash(const CString &path) const { set::const_iterator i = files.find( File(path) ); if(i == files.end()) return -1; - return i->mtime; + return i->hash + i->size; } /* Given "foo/bar/baz/" or "foo/bar/baz", return "foo/bar/" and "baz". */ @@ -117,12 +117,12 @@ int FilenameDB::GetFileSize( const CString &sPath ) return fs.GetFileSize(Name); } -int FilenameDB::GetFileModTime( const CString &sPath ) +int FilenameDB::GetFileHash( const CString &sPath ) { CString Dir, Name; SplitPath(sPath, Dir, Name); FileSet &fs = GetFileSet( Dir ); - return fs.GetFileModTime(Name); + return fs.GetFileHash(Name); } /* XXX: this won't work right for URIs, eg \\foo\bar */ @@ -243,7 +243,7 @@ void FilenameDB::AddFileSet( CString sPath, FileSet *fs ) /* Add the file or directory "sPath". sPath is a directory if it ends with * a slash. */ -void FilenameDB::AddFile( const CString &sPath, int size, int mtime, void *priv ) +void FilenameDB::AddFile( const CString &sPath, int size, int hash, void *priv ) { vector parts; split( sPath, "/", parts, false ); @@ -272,7 +272,7 @@ void FilenameDB::AddFile( const CString &sPath, int size, int mtime, void *priv if( !IsDir ) { f.size = size; - f.mtime = mtime; + f.hash = hash; f.priv = priv; } fs.files.insert( f ); @@ -347,22 +347,3 @@ void FilenameDB::GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDi bool ResolvePath(CString &path) { return true; } // XXX - -#if 0 -bool DoesFileExist( const CString &sPath ) { return FDB.GetFileType( sPath ) != TTYPE_NONE; } -bool IsAFile( const CString &sPath ) { return FDB.GetFileType( sPath ) == TTYPE_FILE; } -bool IsADirectory( const CString &sPath ) { return FDB.GetFileType( sPath ) == TTYPE_DIR; } -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); - if( ret == -1 ) - return 0; - return ret; -} -void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ) -{ - FDB.GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo ); -} -#endif diff --git a/stepmania/src/RageUtil_FileDB.h b/stepmania/src/RageUtil_FileDB.h index 84d2134604..4e192181f5 100644 --- a/stepmania/src/RageUtil_FileDB.h +++ b/stepmania/src/RageUtil_FileDB.h @@ -23,15 +23,15 @@ struct File 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; + int hash; /* Private data, for RageFileDrivers. */ void *priv; - File() { dir=false; size=-1; mtime=-1; priv=NULL;} + File() { dir=false; size=-1; hash=-1; priv=NULL;} File( const CString &fn ) { SetName( fn ); - dir=false; size=-1; mtime=-1; priv=NULL; + dir=false; size=-1; hash=-1; priv=NULL; } bool operator== (const File &rhs) const { return lname==rhs.lname; } @@ -58,7 +58,7 @@ struct FileSet FileType GetFileType( const CString &path ) const; int GetFileSize(const CString &path) const; - int GetFileModTime(const CString &path) const; + int GetFileHash(const CString &path) const; }; class FilenameDB @@ -85,7 +85,7 @@ public: ExpireSeconds( -1 ) { } virtual FilenameDB::~FilenameDB() { FlushDirCache(); } - void AddFile( const CString &sPath, int size, int mtime, void *priv=NULL ); + void AddFile( const CString &sPath, int size, int hash, void *priv=NULL ); File *GetFile( const CString &path ); /* This handles at most two * wildcards. If we need anything more complicated, @@ -98,7 +98,7 @@ public: FileType GetFileType( const CString &path ); int GetFileSize(const CString &path); - int GetFileModTime( const CString &sFilePath ); + int GetFileHash( const CString &sFilePath ); void GetDirListing( CString sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo ); void FlushDirCache();