From bfe6e0076d124fd2bab5536c8a92cb90ae6b6093 Mon Sep 17 00:00:00 2001 From: Jason Felds Date: Wed, 15 Jun 2011 22:36:58 -0400 Subject: [PATCH] Port ResolvePath from OpenITG. Also, forgot to [sqlite] this earlier. --- src/RageFileManager.cpp | 36 ++++++++++++++++++++++++++++++++++++ src/RageFileManager.h | 6 ++++++ 2 files changed, 42 insertions(+) diff --git a/src/RageFileManager.cpp b/src/RageFileManager.cpp index 6219b6288c..b107a27a51 100644 --- a/src/RageFileManager.cpp +++ b/src/RageFileManager.cpp @@ -731,6 +731,42 @@ int RageFileManager::GetFileHash( const RString &sPath_ ) return iRet; } +RString RageFileManager::ResolvePath(const RString &path) +{ + RString tmpPath = path; + NormalizePath(tmpPath); + + RString resolvedPath = tmpPath; + + vector apDriverList; + ReferenceAllDrivers( apDriverList ); + + for( unsigned i = 0; i < apDriverList.size(); ++i ) + { + LoadedDriver *pDriver = apDriverList[i]; + const RString driverPath = pDriver->GetPath( tmpPath ); + + if ( driverPath.empty() || pDriver->m_sRoot.empty() ) + continue; + + if ( pDriver->m_sType != "dir" && pDriver->m_sType != "dirro" ) + continue; + + int iMountPointLen = pDriver->m_sMountPoint.length(); + if( tmpPath.substr(0, iMountPointLen) != pDriver->m_sMountPoint ) + continue; + + resolvedPath = pDriver->m_sRoot + "/" + RString(tmpPath.substr(iMountPointLen)); + break; + } + + UnreferenceAllDrivers( apDriverList ); + + NormalizePath( resolvedPath ); + + return resolvedPath; +} + static bool SortBySecond( const pair &a, const pair &b ) { return a.second < b.second; diff --git a/src/RageFileManager.h b/src/RageFileManager.h index 12c6ca1fe0..7eaa445852 100644 --- a/src/RageFileManager.h +++ b/src/RageFileManager.h @@ -37,6 +37,12 @@ public: int GetFileSizeInBytes( const RString &sPath ); int GetFileHash( const RString &sPath ); + + /** + * @brief Get the absolte path from the VPS. + * @param path the VPS path. + * @return the absolute path. */ + RString ResolvePath(const RString &path); bool Mount( const RString &sType, const RString &sRealPath, const RString &sMountPoint, bool bAddToEnd = true ); void Mount( RageFileDriver *pDriver, const RString &sMountPoint, bool bAddToEnd = true );