CString -> RString for files used by smpackage

This commit is contained in:
Chris Danford
2005-12-10 08:15:44 +00:00
parent 09d8307a83
commit ec51af900e
19 changed files with 310 additions and 310 deletions
+1 -1
View File
@@ -7,7 +7,7 @@
#include <map> #include <map>
/* Map from "&foo;" to a UTF-8 string. */ /* Map from "&foo;" to a UTF-8 string. */
typedef map<CString, wchar_t, StdStringLessNoCase> aliasmap; typedef map<CString, wchar_t, StdString::StdStringLessNoCase> aliasmap;
static aliasmap CharAliases; static aliasmap CharAliases;
static map<CString,CString> CharAliasRepl; static map<CString,CString> CharAliasRepl;
+15 -15
View File
@@ -10,7 +10,7 @@ IniFile::IniFile()
m_sName = "IniFile"; m_sName = "IniFile";
} }
bool IniFile::ReadFile( const CString &sPath ) bool IniFile::ReadFile( const RString &sPath )
{ {
m_sPath = sPath; m_sPath = sPath;
CHECKPOINT_M( ssprintf("Reading '%s'",m_sPath.c_str()) ); CHECKPOINT_M( ssprintf("Reading '%s'",m_sPath.c_str()) );
@@ -28,10 +28,10 @@ bool IniFile::ReadFile( const CString &sPath )
bool IniFile::ReadFile( RageFileBasic &f ) bool IniFile::ReadFile( RageFileBasic &f )
{ {
CString keyname; RString keyname;
while( 1 ) while( 1 )
{ {
CString line; RString line;
switch( f.GetLine(line) ) switch( f.GetLine(line) )
{ {
case -1: case -1:
@@ -61,8 +61,8 @@ bool IniFile::ReadFile( RageFileBasic &f )
int iEqualIndex = line.Find("="); int iEqualIndex = line.Find("=");
if( iEqualIndex != -1 ) if( iEqualIndex != -1 )
{ {
CString valuename = line.Left(iEqualIndex); RString valuename = line.Left(iEqualIndex);
CString value = line.Right(line.GetLength()-valuename.GetLength()-1); RString value = line.Right(line.GetLength()-valuename.GetLength()-1);
if( keyname.size() && valuename.size() ) if( keyname.size() && valuename.size() )
SetValue(keyname,valuename,value); SetValue(keyname,valuename,value);
} }
@@ -70,7 +70,7 @@ bool IniFile::ReadFile( RageFileBasic &f )
} }
} }
bool IniFile::WriteFile( const CString &sPath ) const bool IniFile::WriteFile( const RString &sPath ) const
{ {
RageFile f; RageFile f;
if( !f.Open( sPath, RageFile::WRITE ) ) if( !f.Open( sPath, RageFile::WRITE ) )
@@ -111,7 +111,7 @@ bool IniFile::WriteFile( RageFileBasic &f ) const
return true; return true;
} }
bool IniFile::GetValue( const CString &keyname, const CString &valuename, CString& value ) const bool IniFile::GetValue( const RString &keyname, const RString &valuename, RString& value ) const
{ {
const XNode* pNode = GetChild( keyname ); const XNode* pNode = GetChild( keyname );
if( pNode == NULL ) if( pNode == NULL )
@@ -119,7 +119,7 @@ bool IniFile::GetValue( const CString &keyname, const CString &valuename, CStrin
return pNode->GetAttrValue( valuename, value ); return pNode->GetAttrValue( valuename, value );
} }
void IniFile::SetValue( const CString &keyname, const CString &valuename, const CString &value ) void IniFile::SetValue( const RString &keyname, const RString &valuename, const RString &value )
{ {
XNode* pNode = GetChild( keyname ); XNode* pNode = GetChild( keyname );
if( pNode == NULL ) if( pNode == NULL )
@@ -127,7 +127,7 @@ void IniFile::SetValue( const CString &keyname, const CString &valuename, const
pNode->AppendAttr( valuename, value ); pNode->AppendAttr( valuename, value );
} }
bool IniFile::DeleteValue(const CString &keyname, const CString &valuename) bool IniFile::DeleteValue(const RString &keyname, const RString &valuename)
{ {
XNode* pNode = GetChild( keyname ); XNode* pNode = GetChild( keyname );
if( pNode == NULL ) if( pNode == NULL )
@@ -137,14 +137,14 @@ bool IniFile::DeleteValue(const CString &keyname, const CString &valuename)
#define TYPE(T) \ #define TYPE(T) \
bool IniFile::GetValue( const CString &keyname, const CString &valuename, T &value ) const \ bool IniFile::GetValue( const RString &keyname, const RString &valuename, T &value ) const \
{ \ { \
CString sValue; \ RString sValue; \
if( !GetValue(keyname,valuename,sValue) ) \ if( !GetValue(keyname,valuename,sValue) ) \
return false; \ return false; \
return FromString( sValue, value ); \ return FromString( sValue, value ); \
} \ } \
void IniFile::SetValue( const CString &keyname, const CString &valuename, T value ) \ void IniFile::SetValue( const RString &keyname, const RString &valuename, T value ) \
{ \ { \
SetValue( keyname, valuename, ToString(value) ); \ SetValue( keyname, valuename, ToString(value) ); \
} }
@@ -155,7 +155,7 @@ TYPE(float);
TYPE(bool); TYPE(bool);
bool IniFile::DeleteKey(const CString &keyname) bool IniFile::DeleteKey(const RString &keyname)
{ {
XNode* pNode = GetChild( keyname ); XNode* pNode = GetChild( keyname );
if( pNode == NULL ) if( pNode == NULL )
@@ -163,14 +163,14 @@ bool IniFile::DeleteKey(const CString &keyname)
return RemoveChild( pNode ); return RemoveChild( pNode );
} }
bool IniFile::RenameKey(const CString &from, const CString &to) bool IniFile::RenameKey(const RString &from, const RString &to)
{ {
/* If to already exists, do nothing. */ /* If to already exists, do nothing. */
XNode* pTo = GetChild( to ); XNode* pTo = GetChild( to );
if( pTo ) if( pTo )
return false; return false;
multimap<CString, XNode*>::iterator it = m_childs.find( from ); multimap<RString, XNode*>::iterator it = m_childs.find( from );
if( it == m_childs.end() ) if( it == m_childs.end() )
return false; return false;
+19 -19
View File
@@ -14,38 +14,38 @@ public:
IniFile(); IniFile();
/* Retrieve the filename of the last file loaded. */ /* Retrieve the filename of the last file loaded. */
CString GetPath() const { return m_sPath; } RString GetPath() const { return m_sPath; }
const CString &GetError() const { return m_sError; } const RString &GetError() const { return m_sError; }
bool ReadFile( const CString &sPath ); bool ReadFile( const RString &sPath );
bool ReadFile( RageFileBasic &sFile ); bool ReadFile( RageFileBasic &sFile );
bool WriteFile( const CString &sPath ) const; bool WriteFile( const RString &sPath ) const;
bool WriteFile( RageFileBasic &sFile ) const; bool WriteFile( RageFileBasic &sFile ) const;
bool GetValue( const CString &key, const CString &valuename, CString& value ) const; bool GetValue( const RString &key, const RString &valuename, RString& value ) const;
bool GetValue( const CString &key, const CString &valuename, int& value ) const; bool GetValue( const RString &key, const RString &valuename, int& value ) const;
bool GetValue( const CString &key, const CString &valuename, unsigned& value ) const; bool GetValue( const RString &key, const RString &valuename, unsigned& value ) const;
bool GetValue( const CString &key, const CString &valuename, float& value ) const; bool GetValue( const RString &key, const RString &valuename, float& value ) const;
bool GetValue( const CString &key, const CString &valuename, bool& value ) const; bool GetValue( const RString &key, const RString &valuename, bool& value ) const;
void SetValue( const CString &key, const CString &valuename, const CString &value ); void SetValue( const RString &key, const RString &valuename, const RString &value );
void SetValue( const CString &key, const CString &valuename, int value ); void SetValue( const RString &key, const RString &valuename, int value );
void SetValue( const CString &key, const CString &valuename, unsigned value ); void SetValue( const RString &key, const RString &valuename, unsigned value );
void SetValue( const CString &key, const CString &valuename, float value ); void SetValue( const RString &key, const RString &valuename, float value );
void SetValue( const CString &key, const CString &valuename, bool value ); void SetValue( const RString &key, const RString &valuename, bool value );
bool DeleteKey( const CString &keyname ); bool DeleteKey( const RString &keyname );
bool DeleteValue( const CString &keyname, const CString &valuename ); bool DeleteValue( const RString &keyname, const RString &valuename );
/* Rename a key. For example, call RenameKey("foo", "main") after /* Rename a key. For example, call RenameKey("foo", "main") after
* reading an INI where [foo] is an alias to [main]. If to already * reading an INI where [foo] is an alias to [main]. If to already
* exists, nothing happens. */ * exists, nothing happens. */
bool RenameKey( const CString &from, const CString &to ); bool RenameKey( const RString &from, const RString &to );
private: private:
CString m_sPath; RString m_sPath;
mutable CString m_sError; mutable RString m_sError;
}; };
#endif #endif
+1 -2
View File
@@ -11,11 +11,10 @@
#include "Game.h" #include "Game.h"
#include "Style.h" #include "Style.h"
const RString KEYMAPS_PATH = "Save/Keymaps.ini";
InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our program InputMapper* INPUTMAPPER = NULL; // global and accessable from anywhere in our program
#define KEYMAPS_PATH "Save/Keymaps.ini"
InputMapper::InputMapper() InputMapper::InputMapper()
{ {
ReadMappingsFromDisk(); ReadMappingsFromDisk();
-3
View File
@@ -9,11 +9,8 @@
#include "StyleInput.h" #include "StyleInput.h"
#include "GameConstantsAndTypes.h" #include "GameConstantsAndTypes.h"
const int NUM_GAME_TO_DEVICE_SLOTS = 5; // five device inputs may map to one game input const int NUM_GAME_TO_DEVICE_SLOTS = 5; // five device inputs may map to one game input
class InputMapper class InputMapper
{ {
public: public:
+5 -4
View File
@@ -12,7 +12,8 @@
#include "RageLog.h" #include "RageLog.h"
const CString DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden const CString DEFAULTS_INI_PATH = "Data/Defaults.ini"; // these can be overridden
const CString PREFERENCES_INI_PATH = "Save/Preferences.ini"; // overlay on Defaults.ini, contains the user's choices //PREFERENCES_INI_PATH // overlay on Defaults.ini, contains the user's choices
#include "SpecialFiles.h"
const CString STATIC_INI_PATH = "Data/Static.ini"; // overlay on the 2 above, can't be overridden const CString STATIC_INI_PATH = "Data/Static.ini"; // overlay on the 2 above, can't be overridden
const CString TYPE_TXT_FILE = "Data/Type.txt"; const CString TYPE_TXT_FILE = "Data/Type.txt";
@@ -463,8 +464,8 @@ void PrefsManager::RestoreGamePrefs()
void PrefsManager::ReadPrefsFromDisk() void PrefsManager::ReadPrefsFromDisk()
{ {
ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() ); ReadPrefsFromFile( DEFAULTS_INI_PATH, GetPreferencesSection() );
ReadPrefsFromFile( PREFERENCES_INI_PATH, "Options" ); ReadPrefsFromFile( SpecialFiles::PREFERENCES_INI_PATH, "Options" );
ReadGamePrefsFromIni( PREFERENCES_INI_PATH ); ReadGamePrefsFromIni( SpecialFiles::PREFERENCES_INI_PATH );
ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() ); ReadPrefsFromFile( STATIC_INI_PATH, GetPreferencesSection() );
if( !m_sCurrentGame.Get().empty() ) if( !m_sCurrentGame.Get().empty() )
@@ -542,7 +543,7 @@ void PrefsManager::SavePrefsToDisk()
{ {
IniFile ini; IniFile ini;
SavePrefsToIni( ini ); SavePrefsToIni( ini );
ini.WriteFile( PREFERENCES_INI_PATH ); ini.WriteFile( SpecialFiles::PREFERENCES_INI_PATH );
} }
void PrefsManager::SavePrefsToIni( IniFile &ini ) void PrefsManager::SavePrefsToIni( IniFile &ini )
+4 -4
View File
@@ -134,7 +134,7 @@ int RageFileObj::Read( void *pBuffer, size_t iBytes )
return ret; return ret;
} }
int RageFileObj::Read( CString &sBuffer, int iBytes ) int RageFileObj::Read( RString &sBuffer, int iBytes )
{ {
sBuffer.reserve( iBytes != -1? iBytes: this->GetFileSize() ); sBuffer.reserve( iBytes != -1? iBytes: this->GetFileSize() );
@@ -232,7 +232,7 @@ bool RageFileObj::GetCRC32( uint32_t *iRet )
/* Read up to the next \n, and return it in out. Strip the \n. If the \n is /* Read up to the next \n, and return it in out. Strip the \n. If the \n is
* preceded by a \r (DOS newline), strip that, too. */ * preceded by a \r (DOS newline), strip that, too. */
int RageFileObj::GetLine( CString &out ) int RageFileObj::GetLine( RString &out )
{ {
out = ""; out = "";
@@ -324,11 +324,11 @@ int RageFileObj::GetLine( CString &out )
//#define NEWLINE "\n" //#define NEWLINE "\n"
//#endif //#endif
int RageFileObj::PutLine( const CString &str ) int RageFileObj::PutLine( const RString &str )
{ {
if( Write(str) == -1 ) if( Write(str) == -1 )
return -1; return -1;
return Write( CString(NEWLINE) ); return Write( RString(NEWLINE) );
} }
/* Fill the internal buffer. This never marks EOF, since this is an internal, hidden /* Fill the internal buffer. This never marks EOF, since this is an internal, hidden
+14 -14
View File
@@ -11,7 +11,7 @@ class RageFileBasic
public: public:
virtual ~RageFileBasic() { } virtual ~RageFileBasic() { }
virtual CString GetError() const = 0; virtual RString GetError() const = 0;
virtual void ClearError() = 0; virtual void ClearError() = 0;
virtual bool AtEOF() const = 0; virtual bool AtEOF() const = 0;
@@ -27,12 +27,12 @@ public:
* does not necessarily mean that the end of the stream has been reached; * does not necessarily mean that the end of the stream has been reached;
* keep reading until 0 is returned. */ * keep reading until 0 is returned. */
virtual int Read( void *pBuffer, size_t iBytes ) = 0; virtual int Read( void *pBuffer, size_t iBytes ) = 0;
virtual int Read( CString &buffer, int bytes = -1 ) = 0; virtual int Read( RString &buffer, int bytes = -1 ) = 0;
virtual int Read( void *buffer, size_t bytes, int nmemb ) = 0; virtual int Read( void *buffer, size_t bytes, int nmemb ) = 0;
/* Write iSize bytes of data from pBuf. Return 0 on success, -1 on error. */ /* Write iSize bytes of data from pBuf. Return 0 on success, -1 on error. */
virtual int Write( const void *pBuffer, size_t iBytes ) = 0; virtual int Write( const void *pBuffer, size_t iBytes ) = 0;
virtual int Write( const CString &sString ) = 0; virtual int Write( const RString &sString ) = 0;
virtual int Write( const void *buffer, size_t bytes, int nmemb ) = 0; virtual int Write( const void *buffer, size_t bytes, int nmemb ) = 0;
/* Due to buffering, writing may not happen by the end of a Write() call, so not /* Due to buffering, writing may not happen by the end of a Write() call, so not
@@ -42,12 +42,12 @@ public:
virtual int Flush() = 0; virtual int Flush() = 0;
/* This returns a descriptive path for the file, or "". */ /* This returns a descriptive path for the file, or "". */
virtual CString GetDisplayPath() const { return CString(); } virtual RString GetDisplayPath() const { return RString(); }
virtual RageFileBasic *Copy() const = 0; virtual RageFileBasic *Copy() const = 0;
virtual int GetLine( CString &out ) = 0; virtual int GetLine( RString &out ) = 0;
virtual int PutLine( const CString &str ) = 0; virtual int PutLine( const RString &str ) = 0;
virtual void EnableCRC32( bool on=true ) = 0; virtual void EnableCRC32( bool on=true ) = 0;
virtual bool GetCRC32( uint32_t *iRet ) = 0; virtual bool GetCRC32( uint32_t *iRet ) = 0;
@@ -62,7 +62,7 @@ public:
RageFileObj( const RageFileObj &cpy ); RageFileObj( const RageFileObj &cpy );
virtual ~RageFileObj(); virtual ~RageFileObj();
virtual CString GetError() const { return m_sError; } virtual RString GetError() const { return m_sError; }
virtual void ClearError() { SetError(""); } virtual void ClearError() { SetError(""); }
bool AtEOF() const { return m_bEOF; } bool AtEOF() const { return m_bEOF; }
@@ -72,23 +72,23 @@ public:
int Tell() const { return m_iFilePos; } int Tell() const { return m_iFilePos; }
int Read( void *pBuffer, size_t iBytes ); int Read( void *pBuffer, size_t iBytes );
int Read( CString &buffer, int bytes = -1 ); int Read( RString &buffer, int bytes = -1 );
int Read( void *buffer, size_t bytes, int nmemb ); int Read( void *buffer, size_t bytes, int nmemb );
int Write( const void *pBuffer, size_t iBytes ); int Write( const void *pBuffer, size_t iBytes );
int Write( const CString &sString ) { return Write( sString.data(), sString.size() ); } int Write( const RString &sString ) { return Write( sString.data(), sString.size() ); }
int Write( const void *buffer, size_t bytes, int nmemb ); int Write( const void *buffer, size_t bytes, int nmemb );
int Flush(); int Flush();
int GetLine( CString &out ); int GetLine( RString &out );
int PutLine( const CString &str ); int PutLine( const RString &str );
void EnableCRC32( bool on=true ); void EnableCRC32( bool on=true );
bool GetCRC32( uint32_t *iRet ); bool GetCRC32( uint32_t *iRet );
virtual int GetFileSize() const = 0; virtual int GetFileSize() const = 0;
virtual CString GetDisplayPath() const { return CString(); } virtual RString GetDisplayPath() const { return RString(); }
virtual RageFileBasic *Copy() const { FAIL_M( "Copying unimplemented" ); } virtual RageFileBasic *Copy() const { FAIL_M( "Copying unimplemented" ); }
protected: protected:
@@ -99,8 +99,8 @@ protected:
void EnableBuffering(); void EnableBuffering();
void SetError( const CString &sError ) { m_sError = sError; } void SetError( const RString &sError ) { m_sError = sError; }
CString m_sError; RString m_sError;
private: private:
int FillBuf(); int FillBuf();
+10 -10
View File
@@ -8,12 +8,12 @@ RageFileDriver::~RageFileDriver()
delete FDB; delete FDB;
} }
int RageFileDriver::GetPathValue( const CString &path ) int RageFileDriver::GetPathValue( const RString &path )
{ {
vector<CString> parts; vector<RString> parts;
split( path, "/", parts, true ); split( path, "/", parts, true );
CString PartialPath; RString PartialPath;
for( unsigned i = 0; i < parts.size(); ++i ) for( unsigned i = 0; i < parts.size(); ++i )
{ {
@@ -42,27 +42,27 @@ int RageFileDriver::GetPathValue( const CString &path )
return 0; return 0;
} }
void RageFileDriver::GetDirListing( const CString &sPath, vector<CString> &AddTo, bool bOnlyDirs, bool bReturnPathToo ) void RageFileDriver::GetDirListing( const RString &sPath, vector<RString> &AddTo, bool bOnlyDirs, bool bReturnPathToo )
{ {
FDB->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo ); FDB->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo );
} }
RageFileManager::FileType RageFileDriver::GetFileType( const CString &sPath ) RageFileManager::FileType RageFileDriver::GetFileType( const RString &sPath )
{ {
return FDB->GetFileType( sPath ); return FDB->GetFileType( sPath );
} }
int RageFileDriver::GetFileSizeInBytes( const CString &sPath ) int RageFileDriver::GetFileSizeInBytes( const RString &sPath )
{ {
return FDB->GetFileSize( sPath ); return FDB->GetFileSize( sPath );
} }
int RageFileDriver::GetFileHash( const CString &sPath ) int RageFileDriver::GetFileHash( const RString &sPath )
{ {
return FDB->GetFileHash( sPath ); return FDB->GetFileHash( sPath );
} }
void RageFileDriver::FlushDirCache( const CString &sPath ) void RageFileDriver::FlushDirCache( const RString &sPath )
{ {
FDB->FlushDirCache(); FDB->FlushDirCache();
} }
@@ -70,7 +70,7 @@ void RageFileDriver::FlushDirCache( const CString &sPath )
const struct FileDriverEntry *g_FileDriverList = NULL; const struct FileDriverEntry *g_FileDriverList = NULL;
FileDriverEntry::FileDriverEntry( CString Type ) FileDriverEntry::FileDriverEntry( RString Type )
{ {
m_Link = g_FileDriverList; m_Link = g_FileDriverList;
g_FileDriverList = this; g_FileDriverList = this;
@@ -82,7 +82,7 @@ FileDriverEntry::~FileDriverEntry()
g_FileDriverList = NULL; /* invalidate */ g_FileDriverList = NULL; /* invalidate */
} }
RageFileDriver *MakeFileDriver( CString Type, CString Root ) RageFileDriver *MakeFileDriver( RString Type, RString Root )
{ {
for( const FileDriverEntry *p = g_FileDriverList; p; p = p->m_Link ) for( const FileDriverEntry *p = g_FileDriverList; p; p = p->m_Link )
if( !p->m_Type.CompareNoCase(Type) ) if( !p->m_Type.CompareNoCase(Type) )
+14 -14
View File
@@ -12,18 +12,18 @@ class RageFileDriver
public: public:
RageFileDriver( FilenameDB *db ) { FDB = db; } RageFileDriver( FilenameDB *db ) { FDB = db; }
virtual ~RageFileDriver(); virtual ~RageFileDriver();
virtual RageFileBasic *Open( const CString &path, int mode, int &err ) = 0; virtual RageFileBasic *Open( const RString &path, int mode, int &err ) = 0;
virtual void GetDirListing( const CString &sPath, vector<CString> &AddTo, bool bOnlyDirs, bool bReturnPathToo ); virtual void GetDirListing( const RString &sPath, vector<RString> &AddTo, bool bOnlyDirs, bool bReturnPathToo );
virtual RageFileManager::FileType GetFileType( const CString &sPath ); virtual RageFileManager::FileType GetFileType( const RString &sPath );
virtual int GetFileSizeInBytes( const CString &sFilePath ); virtual int GetFileSizeInBytes( const RString &sFilePath );
virtual int GetFileHash( const CString &sPath ); virtual int GetFileHash( const RString &sPath );
virtual int GetPathValue( const CString &path ); virtual int GetPathValue( const RString &path );
virtual void FlushDirCache( const CString &sPath ); virtual void FlushDirCache( const RString &sPath );
virtual bool Move( const CString &sOldPath, const CString &sNewPath ) { return false; } virtual bool Move( const RString &sOldPath, const RString &sNewPath ) { return false; }
virtual bool Remove( const CString &sPath ) { return false; } virtual bool Remove( const RString &sPath ) { return false; }
/* Optional: Move to a different place, as if reconstructed with a different path. */ /* Optional: Move to a different place, as if reconstructed with a different path. */
virtual bool Remount( const CString &sPath ) { return false; } virtual bool Remount( const RString &sPath ) { return false; }
/* Possible error returns from Open, in addition to standard errno.h values: */ /* Possible error returns from Open, in addition to standard errno.h values: */
enum { ERROR_WRITING_NOT_SUPPORTED = -1 }; enum { ERROR_WRITING_NOT_SUPPORTED = -1 };
@@ -34,14 +34,14 @@ public:
/* This is used to register the driver, so RageFileManager can see it. */ /* This is used to register the driver, so RageFileManager can see it. */
struct FileDriverEntry struct FileDriverEntry
{ {
FileDriverEntry( CString Type ); FileDriverEntry( RString Type );
virtual ~FileDriverEntry(); virtual ~FileDriverEntry();
virtual RageFileDriver *Create( CString Root ) const = 0; virtual RageFileDriver *Create( RString Root ) const = 0;
CString m_Type; RString m_Type;
const FileDriverEntry *m_Link; const FileDriverEntry *m_Link;
}; };
RageFileDriver *MakeFileDriver( CString Type, CString Root ); RageFileDriver *MakeFileDriver( RString Type, RString Root );
#endif #endif
+6 -6
View File
@@ -10,7 +10,7 @@ struct RageFileObjMemFile
RageFileObjMemFile(): RageFileObjMemFile():
m_iRefs(0), m_iRefs(0),
m_Mutex("RageFileObjMemFile") { } m_Mutex("RageFileObjMemFile") { }
CString m_sBuf; RString m_sBuf;
int m_iRefs; int m_iRefs;
RageMutex m_Mutex; RageMutex m_Mutex;
@@ -98,12 +98,12 @@ RageFileBasic *RageFileObjMem::Copy() const
return pRet; return pRet;
} }
const CString &RageFileObjMem::GetString() const const RString &RageFileObjMem::GetString() const
{ {
return m_pFile->m_sBuf; return m_pFile->m_sBuf;
} }
void RageFileObjMem::PutString( const CString &sBuf ) void RageFileObjMem::PutString( const RString &sBuf )
{ {
m_pFile->m_Mutex.Lock(); m_pFile->m_Mutex.Lock();
m_pFile->m_sBuf = sBuf; m_pFile->m_sBuf = sBuf;
@@ -125,7 +125,7 @@ RageFileDriverMem::~RageFileDriverMem()
} }
} }
RageFileBasic *RageFileDriverMem::Open( const CString &sPath, int mode, int &err ) RageFileBasic *RageFileDriverMem::Open( const RString &sPath, int mode, int &err )
{ {
LockMut(m_Mutex); LockMut(m_Mutex);
@@ -155,7 +155,7 @@ RageFileBasic *RageFileDriverMem::Open( const CString &sPath, int mode, int &err
return new RageFileObjMem( pFile ); return new RageFileObjMem( pFile );
} }
bool RageFileDriverMem::Remove( const CString &sPath ) bool RageFileDriverMem::Remove( const RString &sPath )
{ {
LockMut(m_Mutex); LockMut(m_Mutex);
@@ -177,7 +177,7 @@ bool RageFileDriverMem::Remove( const CString &sPath )
static struct FileDriverEntry_MEM: public FileDriverEntry static struct FileDriverEntry_MEM: public FileDriverEntry
{ {
FileDriverEntry_MEM(): FileDriverEntry( "MEM" ) { } FileDriverEntry_MEM(): FileDriverEntry( "MEM" ) { }
RageFileDriver *Create( CString Root ) const { return new RageFileDriverMem(); } RageFileDriver *Create( RString Root ) const { return new RageFileDriverMem(); }
} const g_RegisterDriver; } const g_RegisterDriver;
/* /*
+6 -6
View File
@@ -1,4 +1,4 @@
/* RageFileDriverMem: Simple memory-based "filesystem". */ /* RageFileDriverMemory: Simple memory-based "filesystem". */
#ifndef RAGE_FILE_DRIVER_MEMORY_H #ifndef RAGE_FILE_DRIVER_MEMORY_H
#define RAGE_FILE_DRIVER_MEMORY_H #define RAGE_FILE_DRIVER_MEMORY_H
@@ -22,8 +22,8 @@ public:
RageFileBasic *Copy() const; RageFileBasic *Copy() const;
/* Retrieve the contents of this file. */ /* Retrieve the contents of this file. */
const CString &GetString() const; const RString &GetString() const;
void PutString( const CString &sBuf ); void PutString( const RString &sBuf );
private: private:
RageFileObjMemFile *m_pFile; RageFileObjMemFile *m_pFile;
@@ -36,10 +36,10 @@ public:
RageFileDriverMem(); RageFileDriverMem();
~RageFileDriverMem(); ~RageFileDriverMem();
RageFileBasic *Open( const CString &sPath, int mode, int &err ); RageFileBasic *Open( const RString &sPath, int mode, int &err );
void FlushDirCache( const CString &sPath ) { } void FlushDirCache( const RString &sPath ) { }
bool Remove( const CString &sPath ); bool Remove( const RString &sPath );
private: private:
RageMutex m_Mutex; RageMutex m_Mutex;
+17 -12
View File
@@ -15,7 +15,7 @@
static struct FileDriverEntry_ZIP: public FileDriverEntry static struct FileDriverEntry_ZIP: public FileDriverEntry
{ {
FileDriverEntry_ZIP(): FileDriverEntry( "ZIP" ) { } FileDriverEntry_ZIP(): FileDriverEntry( "ZIP" ) { }
RageFileDriver *Create( CString Root ) const { return new RageFileDriverZip( Root ); } RageFileDriver *Create( RString Root ) const { return new RageFileDriverZip( Root ); }
} const g_RegisterDriver; } const g_RegisterDriver;
@@ -27,7 +27,7 @@ RageFileDriverZip::RageFileDriverZip():
m_pZip = NULL; m_pZip = NULL;
} }
RageFileDriverZip::RageFileDriverZip( CString sPath ): RageFileDriverZip::RageFileDriverZip( RString sPath ):
RageFileDriver( new NullFilenameDB ), RageFileDriver( new NullFilenameDB ),
m_Mutex( "RageFileDriverZip" ) m_Mutex( "RageFileDriverZip" )
{ {
@@ -46,7 +46,7 @@ RageFileDriverZip::RageFileDriverZip( RageFileBasic *pFile ):
Load( pFile ); Load( pFile );
} }
bool RageFileDriverZip::Load( const CString &sPath ) bool RageFileDriverZip::Load( const RString &sPath )
{ {
ASSERT( m_pZip == NULL ); /* don't load twice */ ASSERT( m_pZip == NULL ); /* don't load twice */
@@ -82,8 +82,8 @@ bool RageFileDriverZip::Load( RageFileBasic *pFile )
bool RageFileDriverZip::ReadEndCentralRecord( int &iTotalEntries, int &iCentralDirectoryOffset ) bool RageFileDriverZip::ReadEndCentralRecord( int &iTotalEntries, int &iCentralDirectoryOffset )
{ {
CString sError; RString sError;
CString sSig = FileReading::ReadString( *m_pZip, 4, sError ); RString sSig = FileReading::ReadString( *m_pZip, 4, sError );
FileReading::read_16_le( *m_pZip, sError ); /* skip number of this disk */ FileReading::read_16_le( *m_pZip, sError ); /* skip number of this disk */
FileReading::read_16_le( *m_pZip, sError ); /* skip disk with central directory */ FileReading::read_16_le( *m_pZip, sError ); /* skip disk with central directory */
FileReading::read_16_le( *m_pZip, sError ); /* skip number of entries on this disk */ FileReading::read_16_le( *m_pZip, sError ); /* skip number of entries on this disk */
@@ -176,8 +176,8 @@ bool RageFileDriverZip::ParseZipfile()
int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info ) int RageFileDriverZip::ProcessCdirFileHdr( FileInfo &info )
{ {
CString sError; RString sError;
CString sSig = FileReading::ReadString( *m_pZip, 4, sError ); RString sSig = FileReading::ReadString( *m_pZip, 4, sError );
if( sSig != "\x50\x4B\x01\x02" ) if( sSig != "\x50\x4B\x01\x02" )
{ {
LOG->Warn( "%s: central directory record signature not found", m_sPath.c_str() ); LOG->Warn( "%s: central directory record signature not found", m_sPath.c_str() );
@@ -256,8 +256,8 @@ bool RageFileDriverZip::ReadLocalFileHeader( FileInfo &info )
/* Seek to and read the local file header. */ /* Seek to and read the local file header. */
m_pZip->Seek( info.m_iOffset ); m_pZip->Seek( info.m_iOffset );
CString sError; RString sError;
CString sSig = FileReading::ReadString( *m_pZip, 4, sError ); RString sSig = FileReading::ReadString( *m_pZip, 4, sError );
if( sError != "" ) if( sError != "" )
{ {
@@ -295,12 +295,12 @@ RageFileDriverZip::~RageFileDriverZip()
delete m_pZip; delete m_pZip;
} }
const RageFileDriverZip::FileInfo *RageFileDriverZip::GetFileInfo( const CString &sPath ) const const RageFileDriverZip::FileInfo *RageFileDriverZip::GetFileInfo( const RString &sPath ) const
{ {
return (const FileInfo *) FDB->GetFilePriv( sPath ); return (const FileInfo *) FDB->GetFilePriv( sPath );
} }
RageFileBasic *RageFileDriverZip::Open( const CString &sPath, int iMode, int &iErr ) RageFileBasic *RageFileDriverZip::Open( const RString &sPath, int iMode, int &iErr )
{ {
if( iMode & RageFile::WRITE ) if( iMode & RageFile::WRITE )
{ {
@@ -352,11 +352,16 @@ RageFileBasic *RageFileDriverZip::Open( const CString &sPath, int iMode, int &iE
} }
/* NOP for now. This could check to see if the ZIP's mtime has changed, and reload. */ /* NOP for now. This could check to see if the ZIP's mtime has changed, and reload. */
void RageFileDriverZip::FlushDirCache( const CString &sPath ) void RageFileDriverZip::FlushDirCache( const RString &sPath )
{ {
} }
RString RageFileDriverZip::GetGlobalComment() const
{
ASSERT(0);
}
/* /*
* Copyright (c) 2003-2005 Glenn Maynard. All rights reserved. * Copyright (c) 2003-2005 Glenn Maynard. All rights reserved.
* All rights reserved. * All rights reserved.
+9 -7
View File
@@ -11,15 +11,15 @@ class RageFileDriverZip: public RageFileDriver
{ {
public: public:
RageFileDriverZip(); RageFileDriverZip();
RageFileDriverZip( CString sPath ); RageFileDriverZip( RString sPath );
RageFileDriverZip( RageFileBasic *pFile ); RageFileDriverZip( RageFileBasic *pFile );
bool Load( const CString &sPath ); bool Load( const RString &sPath );
bool Load( RageFileBasic *pFile ); bool Load( RageFileBasic *pFile );
virtual ~RageFileDriverZip(); virtual ~RageFileDriverZip();
RageFileBasic *Open( const CString &sPath, int iMode, int &iErr ); RageFileBasic *Open( const RString &sPath, int iMode, int &iErr );
void FlushDirCache( const CString &sPath ); void FlushDirCache( const RString &sPath );
void DeleteFileWhenFinished() { m_bFileOwned = true; } void DeleteFileWhenFinished() { m_bFileOwned = true; }
@@ -27,7 +27,7 @@ public:
enum ZipCompressionMethod { STORED = 0, DEFLATED = 8 }; enum ZipCompressionMethod { STORED = 0, DEFLATED = 8 };
struct FileInfo struct FileInfo
{ {
CString m_sName; RString m_sName;
int m_iOffset; int m_iOffset;
int m_iDataOffset; int m_iDataOffset;
@@ -38,7 +38,9 @@ public:
/* If 0, unknown. */ /* If 0, unknown. */
int m_iFilePermissions; int m_iFilePermissions;
}; };
const FileInfo *GetFileInfo( const CString &sPath ) const; const FileInfo *GetFileInfo( const RString &sPath ) const;
RString GetGlobalComment() const;
private: private:
bool m_bFileOwned; bool m_bFileOwned;
@@ -46,7 +48,7 @@ private:
RageFileBasic *m_pZip; RageFileBasic *m_pZip;
vector<FileInfo *> m_pFiles; vector<FileInfo *> m_pFiles;
CString m_sPath; RString m_sPath;
/* Open() must be threadsafe. Mutex access to "zip", since we seek /* Open() must be threadsafe. Mutex access to "zip", since we seek
* around in it when reading files. */ * around in it when reading files. */
+68 -67
View File
@@ -23,8 +23,8 @@ RageFileManager *FILEMAN = NULL;
/* Lock this before touching any of these globals (except FILEMAN itself). */ /* Lock this before touching any of these globals (except FILEMAN itself). */
static RageEvent *g_Mutex; static RageEvent *g_Mutex;
CString RageFileManagerUtil::sInitialWorkingDirectory; RString RageFileManagerUtil::sInitialWorkingDirectory;
CString RageFileManagerUtil::sDirOfExecutable; RString RageFileManagerUtil::sDirOfExecutable;
struct LoadedDriver struct LoadedDriver
{ {
@@ -34,12 +34,12 @@ struct LoadedDriver
* only send "Foo/Bar". The path "Themes/Foo" is out of the scope * only send "Foo/Bar". The path "Themes/Foo" is out of the scope
* of the driver, and GetPath returns false. */ * of the driver, and GetPath returns false. */
RageFileDriver *m_pDriver; RageFileDriver *m_pDriver;
CString m_sType, m_sRoot, m_sMountPoint; RString m_sType, m_sRoot, m_sMountPoint;
int m_iRefs; int m_iRefs;
LoadedDriver() { m_pDriver = NULL; m_iRefs = 0; } LoadedDriver() { m_pDriver = NULL; m_iRefs = 0; }
CString GetPath( const CString &sPath ) const; RString GetPath( const RString &sPath ) const;
}; };
static vector<LoadedDriver *> g_pDrivers; static vector<LoadedDriver *> g_pDrivers;
@@ -65,7 +65,7 @@ static void UnreferenceAllDrivers( vector<LoadedDriver *> &apDriverList )
apDriverList.clear(); apDriverList.clear();
} }
RageFileDriver *RageFileManager::GetFileDriver( CString sMountpoint ) RageFileDriver *RageFileManager::GetFileDriver( RString sMountpoint )
{ {
FixSlashesInPlace( sMountpoint ); FixSlashesInPlace( sMountpoint );
if( sMountpoint.size() && sMountpoint.Right(1) != "/" ) if( sMountpoint.size() && sMountpoint.Right(1) != "/" )
@@ -148,13 +148,13 @@ class RageFileDriverMountpoints: public RageFileDriver
{ {
public: public:
RageFileDriverMountpoints(): RageFileDriver( new FilenameDB ) { } RageFileDriverMountpoints(): RageFileDriver( new FilenameDB ) { }
RageFileBasic *Open( const CString &sPath, int iMode, int &iError ) RageFileBasic *Open( const RString &sPath, int iMode, int &iError )
{ {
iError = (iMode == RageFile::WRITE)? ERROR_WRITING_NOT_SUPPORTED:ENOENT; iError = (iMode == RageFile::WRITE)? ERROR_WRITING_NOT_SUPPORTED:ENOENT;
return NULL; return NULL;
} }
/* Never flush FDB, except in LoadFromDrivers. */ /* Never flush FDB, except in LoadFromDrivers. */
void FlushDirCache( const CString &sPath ) { } void FlushDirCache( const RString &sPath ) { }
void LoadFromDrivers( const vector<LoadedDriver *> &apDrivers ) void LoadFromDrivers( const vector<LoadedDriver *> &apDrivers )
{ {
@@ -169,14 +169,14 @@ public:
}; };
static RageFileDriverMountpoints *g_Mountpoints = NULL; static RageFileDriverMountpoints *g_Mountpoints = NULL;
static CString GetDirOfExecutable( CString argv0 ) static RString GetDirOfExecutable( RString argv0 )
{ {
#ifdef _XBOX #ifdef _XBOX
return "D:\\"; return "D:\\";
#else #else
/* argv[0] can be wrong in most OS's; try to avoid using it. */ /* argv[0] can be wrong in most OS's; try to avoid using it. */
CString sPath; RString sPath;
#if defined(WIN32) #if defined(WIN32)
char szBuf[MAX_PATH]; char szBuf[MAX_PATH];
GetModuleFileName( NULL, szBuf, sizeof(szBuf) ); GetModuleFileName( NULL, szBuf, sizeof(szBuf) );
@@ -212,7 +212,7 @@ static CString GetDirOfExecutable( CString argv0 )
#endif #endif
} }
static void ChangeToDirOfExecutable( CString argv0 ) static void ChangeToDirOfExecutable( RString argv0 )
{ {
RageFileManagerUtil::sInitialWorkingDirectory = GetCwd(); RageFileManagerUtil::sInitialWorkingDirectory = GetCwd();
RageFileManagerUtil::sDirOfExecutable = GetDirOfExecutable( argv0 ); RageFileManagerUtil::sDirOfExecutable = GetDirOfExecutable( argv0 );
@@ -226,7 +226,7 @@ static void ChangeToDirOfExecutable( CString argv0 )
#endif #endif
} }
RageFileManager::RageFileManager( CString argv0 ) RageFileManager::RageFileManager( RString argv0 )
{ {
CHECKPOINT_M( argv0 ); CHECKPOINT_M( argv0 );
ChangeToDirOfExecutable( argv0 ); ChangeToDirOfExecutable( argv0 );
@@ -267,24 +267,24 @@ RageFileManager::~RageFileManager()
} }
/* path must be normalized (FixSlashesInPlace, CollapsePath). */ /* path must be normalized (FixSlashesInPlace, CollapsePath). */
CString LoadedDriver::GetPath( const CString &sPath ) const RString LoadedDriver::GetPath( const RString &sPath ) const
{ {
/* If the path begins with /@, only match mountpoints that begin with /@. */ /* If the path begins with /@, only match mountpoints that begin with /@. */
if( sPath.size() >= 2 && sPath[1] == '@' ) if( sPath.size() >= 2 && sPath[1] == '@' )
{ {
if( m_sMountPoint.size() < 2 || m_sMountPoint[1] != '@' ) if( m_sMountPoint.size() < 2 || m_sMountPoint[1] != '@' )
return CString(); return RString();
} }
if( sPath.Left(m_sMountPoint.size()).CompareNoCase(m_sMountPoint) ) if( sPath.Left(m_sMountPoint.size()).CompareNoCase(m_sMountPoint) )
return CString(); /* no match */ return RString(); /* no match */
/* Add one, so we don't cut off the leading slash. */ /* Add one, so we don't cut off the leading slash. */
CString sRet = sPath.Right( sPath.size() - m_sMountPoint.size() + 1 ); RString sRet = sPath.Right( sPath.size() - m_sMountPoint.size() + 1 );
return sRet; return sRet;
} }
static void NormalizePath( CString &sPath ) static void NormalizePath( RString &sPath )
{ {
FixSlashesInPlace( sPath ); FixSlashesInPlace( sPath );
CollapsePath( sPath, true ); CollapsePath( sPath, true );
@@ -292,9 +292,9 @@ static void NormalizePath( CString &sPath )
sPath.insert( sPath.begin(), '/' ); sPath.insert( sPath.begin(), '/' );
} }
bool ilt( const CString &a, const CString &b ) { return a.CompareNoCase(b) < 0; } bool ilt( const RString &a, const RString &b ) { return a.CompareNoCase(b) < 0; }
bool ieq( const CString &a, const CString &b ) { return a.CompareNoCase(b) == 0; } bool ieq( const RString &a, const RString &b ) { return a.CompareNoCase(b) == 0; }
void RageFileManager::GetDirListing( CString sPath, vector<CString> &AddTo, bool bOnlyDirs, bool bReturnPathToo ) void RageFileManager::GetDirListing( RString sPath, vector<RString> &AddTo, bool bOnlyDirs, bool bReturnPathToo )
{ {
NormalizePath( sPath ); NormalizePath( sPath );
@@ -306,7 +306,7 @@ void RageFileManager::GetDirListing( CString sPath, vector<CString> &AddTo, bool
for( unsigned i = 0; i < apDriverList.size(); ++i ) for( unsigned i = 0; i < apDriverList.size(); ++i )
{ {
LoadedDriver *pLoadedDriver = apDriverList[i]; LoadedDriver *pLoadedDriver = apDriverList[i];
const CString p = pLoadedDriver->GetPath( sPath ); const RString p = pLoadedDriver->GetPath( sPath );
if( p.size() == 0 ) if( p.size() == 0 )
continue; continue;
@@ -322,7 +322,7 @@ void RageFileManager::GetDirListing( CString sPath, vector<CString> &AddTo, bool
for( unsigned j = OldStart; j < AddTo.size(); ++j ) for( unsigned j = OldStart; j < AddTo.size(); ++j )
{ {
/* Skip the trailing slash on the mountpoint; there's already a slash there. */ /* Skip the trailing slash on the mountpoint; there's already a slash there. */
CString &sPath = AddTo[j]; RString &sPath = AddTo[j];
sPath.insert( 0, pLoadedDriver->m_sMountPoint, pLoadedDriver->m_sMountPoint.size()-1 ); sPath.insert( 0, pLoadedDriver->m_sMountPoint, pLoadedDriver->m_sMountPoint.size()-1 );
} }
} }
@@ -334,13 +334,13 @@ void RageFileManager::GetDirListing( CString sPath, vector<CString> &AddTo, bool
{ {
/* More than one driver returned files. Remove duplicates (case-insensitively). */ /* More than one driver returned files. Remove duplicates (case-insensitively). */
sort( AddTo.begin()+iOldSize, AddTo.end(), ilt ); sort( AddTo.begin()+iOldSize, AddTo.end(), ilt );
vector<CString>::iterator it = unique( AddTo.begin()+iOldSize, AddTo.end(), ieq ); vector<RString>::iterator it = unique( AddTo.begin()+iOldSize, AddTo.end(), ieq );
AddTo.erase( it, AddTo.end() ); AddTo.erase( it, AddTo.end() );
} }
} }
/* Files may only be moved within the same file driver. */ /* Files may only be moved within the same file driver. */
bool RageFileManager::Move( CString sOldPath, CString sNewPath ) bool RageFileManager::Move( RString sOldPath, RString sNewPath )
{ {
vector<LoadedDriver *> aDriverList; vector<LoadedDriver *> aDriverList;
ReferenceAllDrivers( aDriverList ); ReferenceAllDrivers( aDriverList );
@@ -352,8 +352,8 @@ bool RageFileManager::Move( CString sOldPath, CString sNewPath )
bool Deleted = false; bool Deleted = false;
for( unsigned i = 0; i < aDriverList.size(); ++i ) for( unsigned i = 0; i < aDriverList.size(); ++i )
{ {
const CString sOldDriverPath = aDriverList[i]->GetPath( sOldPath ); const RString sOldDriverPath = aDriverList[i]->GetPath( sOldPath );
const CString sNewDriverPath = aDriverList[i]->GetPath( sNewPath ); const RString sNewDriverPath = aDriverList[i]->GetPath( sNewPath );
if( sOldDriverPath.size() == 0 || sNewDriverPath.size() == 0 ) if( sOldDriverPath.size() == 0 || sNewDriverPath.size() == 0 )
continue; continue;
@@ -367,7 +367,7 @@ bool RageFileManager::Move( CString sOldPath, CString sNewPath )
return Deleted; return Deleted;
} }
bool RageFileManager::Remove( CString sPath ) bool RageFileManager::Remove( RString sPath )
{ {
vector<LoadedDriver *> apDriverList; vector<LoadedDriver *> apDriverList;
ReferenceAllDrivers( apDriverList ); ReferenceAllDrivers( apDriverList );
@@ -378,7 +378,7 @@ bool RageFileManager::Remove( CString sPath )
bool bDeleted = false; bool bDeleted = false;
for( unsigned i = 0; i < apDriverList.size(); ++i ) for( unsigned i = 0; i < apDriverList.size(); ++i )
{ {
const CString p = apDriverList[i]->GetPath( sPath ); const RString p = apDriverList[i]->GetPath( sPath );
if( p.size() == 0 ) if( p.size() == 0 )
continue; continue;
@@ -392,9 +392,9 @@ bool RageFileManager::Remove( CString sPath )
return bDeleted; return bDeleted;
} }
void RageFileManager::CreateDir( CString sDir ) void RageFileManager::CreateDir( RString sDir )
{ {
CString sTempFile = sDir + "temp"; RString sTempFile = sDir + "temp";
RageFile f; RageFile f;
f.Open( sTempFile, RageFile::WRITE ); f.Open( sTempFile, RageFile::WRITE );
f.Close(); f.Close();
@@ -406,7 +406,7 @@ void RageFileManager::CreateDir( CString sDir )
FILEMAN->Remove( sTempFile ); FILEMAN->Remove( sTempFile );
} }
static void AdjustMountpoint( CString &sMountPoint ) static void AdjustMountpoint( RString &sMountPoint )
{ {
FixSlashesInPlace( sMountPoint ); FixSlashesInPlace( sMountPoint );
@@ -428,7 +428,7 @@ static void AddFilesystemDriver( LoadedDriver *pLoadedDriver, bool bAddToEnd )
g_Mutex->Unlock(); g_Mutex->Unlock();
} }
void RageFileManager::Mount( CString sType, CString sRoot, CString sMountPoint, bool bAddToEnd ) bool RageFileManager::Mount( RString sType, RString sRoot, RString sMountPoint, bool bAddToEnd )
{ {
FixSlashesInPlace( sRoot ); FixSlashesInPlace( sRoot );
AdjustMountpoint( sMountPoint ); AdjustMountpoint( sMountPoint );
@@ -450,7 +450,7 @@ void RageFileManager::Mount( CString sType, CString sRoot, CString sMountPoint,
LOG->Warn("Can't mount unknown VFS type \"%s\", root \"%s\"", sType.c_str(), sRoot.c_str() ); LOG->Warn("Can't mount unknown VFS type \"%s\", root \"%s\"", sType.c_str(), sRoot.c_str() );
else else
fprintf( stderr, "Can't mount unknown VFS type \"%s\", root \"%s\"\n", sType.c_str(), sRoot.c_str() ); fprintf( stderr, "Can't mount unknown VFS type \"%s\", root \"%s\"\n", sType.c_str(), sRoot.c_str() );
return; return false;
} }
CHECKPOINT; CHECKPOINT;
@@ -462,10 +462,11 @@ void RageFileManager::Mount( CString sType, CString sRoot, CString sMountPoint,
pLoadedDriver->m_sMountPoint = sMountPoint; pLoadedDriver->m_sMountPoint = sMountPoint;
AddFilesystemDriver( pLoadedDriver, bAddToEnd ); AddFilesystemDriver( pLoadedDriver, bAddToEnd );
return true;
} }
/* Mount a custom filesystem. */ /* Mount a custom filesystem. */
void RageFileManager::Mount( RageFileDriver *pDriver, CString sMountPoint, bool bAddToEnd ) void RageFileManager::Mount( RageFileDriver *pDriver, RString sMountPoint, bool bAddToEnd )
{ {
AdjustMountpoint( sMountPoint ); AdjustMountpoint( sMountPoint );
@@ -478,7 +479,7 @@ void RageFileManager::Mount( RageFileDriver *pDriver, CString sMountPoint, bool
AddFilesystemDriver( pLoadedDriver, bAddToEnd ); AddFilesystemDriver( pLoadedDriver, bAddToEnd );
} }
void RageFileManager::Unmount( CString sType, CString sRoot, CString sMountPoint ) void RageFileManager::Unmount( RString sType, RString sRoot, RString sMountPoint )
{ {
FixSlashesInPlace( sRoot ); FixSlashesInPlace( sRoot );
FixSlashesInPlace( sMountPoint ); FixSlashesInPlace( sMountPoint );
@@ -526,7 +527,7 @@ void RageFileManager::Unmount( CString sType, CString sRoot, CString sMountPoint
} }
} }
void RageFileManager::Remount( CString sMountpoint, CString sPath ) void RageFileManager::Remount( RString sMountpoint, RString sPath )
{ {
RageFileDriver *pDriver = FILEMAN->GetFileDriver( sMountpoint ); RageFileDriver *pDriver = FILEMAN->GetFileDriver( sMountpoint );
if( pDriver == NULL ) if( pDriver == NULL )
@@ -544,7 +545,7 @@ void RageFileManager::Remount( CString sMountpoint, CString sPath )
FILEMAN->ReleaseFileDriver( pDriver ); FILEMAN->ReleaseFileDriver( pDriver );
} }
bool RageFileManager::IsMounted( CString MountPoint ) bool RageFileManager::IsMounted( RString MountPoint )
{ {
LockMut( *g_Mutex ); LockMut( *g_Mutex );
@@ -569,7 +570,7 @@ void RageFileManager::GetLoadedDrivers( vector<DriverLocation> &asMounts )
} }
} }
void RageFileManager::FlushDirCache( CString sPath ) void RageFileManager::FlushDirCache( RString sPath )
{ {
LockMut( *g_Mutex ); LockMut( *g_Mutex );
@@ -584,14 +585,14 @@ void RageFileManager::FlushDirCache( CString sPath )
NormalizePath( sPath ); NormalizePath( sPath );
for( unsigned i = 0; i < g_pDrivers.size(); ++i ) for( unsigned i = 0; i < g_pDrivers.size(); ++i )
{ {
const CString &path = g_pDrivers[i]->GetPath( sPath ); const RString &path = g_pDrivers[i]->GetPath( sPath );
if( path.size() == 0 ) if( path.size() == 0 )
continue; continue;
g_pDrivers[i]->m_pDriver->FlushDirCache( path ); g_pDrivers[i]->m_pDriver->FlushDirCache( path );
} }
} }
RageFileManager::FileType RageFileManager::GetFileType( CString sPath ) RageFileManager::FileType RageFileManager::GetFileType( RString sPath )
{ {
NormalizePath( sPath ); NormalizePath( sPath );
@@ -601,7 +602,7 @@ RageFileManager::FileType RageFileManager::GetFileType( CString sPath )
RageFileManager::FileType ret = TYPE_NONE; RageFileManager::FileType ret = TYPE_NONE;
for( unsigned i = 0; i < apDriverList.size(); ++i ) for( unsigned i = 0; i < apDriverList.size(); ++i )
{ {
const CString p = apDriverList[i]->GetPath( sPath ); const RString p = apDriverList[i]->GetPath( sPath );
if( p.size() == 0 ) if( p.size() == 0 )
continue; continue;
ret = apDriverList[i]->m_pDriver->GetFileType( p ); ret = apDriverList[i]->m_pDriver->GetFileType( p );
@@ -615,7 +616,7 @@ RageFileManager::FileType RageFileManager::GetFileType( CString sPath )
} }
int RageFileManager::GetFileSizeInBytes( CString sPath ) int RageFileManager::GetFileSizeInBytes( RString sPath )
{ {
NormalizePath( sPath ); NormalizePath( sPath );
@@ -625,7 +626,7 @@ int RageFileManager::GetFileSizeInBytes( CString sPath )
int iRet = -1; int iRet = -1;
for( unsigned i = 0; i < apDriverList.size(); ++i ) for( unsigned i = 0; i < apDriverList.size(); ++i )
{ {
const CString p = apDriverList[i]->GetPath( sPath ); const RString p = apDriverList[i]->GetPath( sPath );
if( p.size() == 0 ) if( p.size() == 0 )
continue; continue;
iRet = apDriverList[i]->m_pDriver->GetFileSizeInBytes( p ); iRet = apDriverList[i]->m_pDriver->GetFileSizeInBytes( p );
@@ -637,7 +638,7 @@ int RageFileManager::GetFileSizeInBytes( CString sPath )
return iRet; return iRet;
} }
int RageFileManager::GetFileHash( CString sPath ) int RageFileManager::GetFileHash( RString sPath )
{ {
NormalizePath( sPath ); NormalizePath( sPath );
@@ -647,7 +648,7 @@ int RageFileManager::GetFileHash( CString sPath )
int iRet = -1; int iRet = -1;
for( unsigned i = 0; i < apDriverList.size(); ++i ) for( unsigned i = 0; i < apDriverList.size(); ++i )
{ {
const CString p = apDriverList[i]->GetPath( sPath ); const RString p = apDriverList[i]->GetPath( sPath );
if( p.size() == 0 ) if( p.size() == 0 )
continue; continue;
iRet = apDriverList[i]->m_pDriver->GetFileHash( p ); iRet = apDriverList[i]->m_pDriver->GetFileHash( p );
@@ -672,7 +673,7 @@ static bool SortBySecond( const pair<int,int> &a, const pair<int,int> &b )
* somewhere and not notice), and easier (don't have to pass flags down to IniFile::Write, * somewhere and not notice), and easier (don't have to pass flags down to IniFile::Write,
* etc). * etc).
*/ */
static bool PathUsesSlowFlush( const CString &sPath ) static bool PathUsesSlowFlush( const RString &sPath )
{ {
static const char *FlushPaths[] = static const char *FlushPaths[] =
{ {
@@ -686,7 +687,7 @@ static bool PathUsesSlowFlush( const CString &sPath )
} }
/* Used only by RageFile: */ /* Used only by RageFile: */
RageFileBasic *RageFileManager::Open( CString sPath, int mode, int &err ) RageFileBasic *RageFileManager::Open( RString sPath, int mode, int &err )
{ {
err = ENOENT; err = ENOENT;
@@ -703,7 +704,7 @@ RageFileBasic *RageFileManager::Open( CString sPath, int mode, int &err )
return OpenForReading( sPath, mode, err ); return OpenForReading( sPath, mode, err );
} }
RageFileBasic *RageFileManager::OpenForReading( CString sPath, int mode, int &err ) RageFileBasic *RageFileManager::OpenForReading( RString sPath, int mode, int &err )
{ {
vector<LoadedDriver *> apDriverList; vector<LoadedDriver *> apDriverList;
ReferenceAllDrivers( apDriverList ); ReferenceAllDrivers( apDriverList );
@@ -711,7 +712,7 @@ RageFileBasic *RageFileManager::OpenForReading( CString sPath, int mode, int &er
for( unsigned i = 0; i < apDriverList.size(); ++i ) for( unsigned i = 0; i < apDriverList.size(); ++i )
{ {
LoadedDriver &ld = *apDriverList[i]; LoadedDriver &ld = *apDriverList[i];
const CString path = ld.GetPath( sPath ); const RString path = ld.GetPath( sPath );
if( path.size() == 0 ) if( path.size() == 0 )
continue; continue;
int error; int error;
@@ -732,7 +733,7 @@ RageFileBasic *RageFileManager::OpenForReading( CString sPath, int mode, int &er
return NULL; return NULL;
} }
RageFileBasic *RageFileManager::OpenForWriting( CString sPath, int mode, int &iError ) RageFileBasic *RageFileManager::OpenForWriting( RString sPath, int mode, int &iError )
{ {
/* /*
* The value for a driver to open a file is the number of directories and/or files * The value for a driver to open a file is the number of directories and/or files
@@ -760,7 +761,7 @@ RageFileBasic *RageFileManager::OpenForWriting( CString sPath, int mode, int &iE
for( unsigned i = 0; i < apDriverList.size(); ++i ) for( unsigned i = 0; i < apDriverList.size(); ++i )
{ {
LoadedDriver &ld = *apDriverList[i]; LoadedDriver &ld = *apDriverList[i];
const CString path = ld.GetPath( sPath ); const RString path = ld.GetPath( sPath );
if( path.size() == 0 ) if( path.size() == 0 )
continue; continue;
@@ -778,7 +779,7 @@ RageFileBasic *RageFileManager::OpenForWriting( CString sPath, int mode, int &iE
{ {
const int iDriver = Values[i].first; const int iDriver = Values[i].first;
LoadedDriver &ld = *apDriverList[iDriver]; LoadedDriver &ld = *apDriverList[iDriver];
const CString sDriverPath = ld.GetPath( sPath ); const RString sDriverPath = ld.GetPath( sPath );
ASSERT( !sDriverPath.empty() ); ASSERT( !sDriverPath.empty() );
int iThisError; int iThisError;
@@ -803,36 +804,36 @@ RageFileBasic *RageFileManager::OpenForWriting( CString sPath, int mode, int &iE
return NULL; return NULL;
} }
bool RageFileManager::IsAFile( const CString &sPath ) { return GetFileType(sPath) == TYPE_FILE; } bool RageFileManager::IsAFile( const RString &sPath ) { return GetFileType(sPath) == TYPE_FILE; }
bool RageFileManager::IsADirectory( const CString &sPath ) { return GetFileType(sPath) == TYPE_DIR; } bool RageFileManager::IsADirectory( const RString &sPath ) { return GetFileType(sPath) == TYPE_DIR; }
bool RageFileManager::DoesFileExist( const CString &sPath ) { return GetFileType(sPath) != TYPE_NONE; } bool RageFileManager::DoesFileExist( const RString &sPath ) { return GetFileType(sPath) != TYPE_NONE; }
bool DoesFileExist( const CString &sPath ) bool DoesFileExist( const RString &sPath )
{ {
return FILEMAN->DoesFileExist( sPath ); return FILEMAN->DoesFileExist( sPath );
} }
bool IsAFile( const CString &sPath ) bool IsAFile( const RString &sPath )
{ {
return FILEMAN->IsAFile( sPath ); return FILEMAN->IsAFile( sPath );
} }
bool IsADirectory( const CString &sPath ) bool IsADirectory( const RString &sPath )
{ {
return FILEMAN->IsADirectory( sPath ); return FILEMAN->IsADirectory( sPath );
} }
unsigned GetFileSizeInBytes( const CString &sPath ) unsigned GetFileSizeInBytes( const RString &sPath )
{ {
return FILEMAN->GetFileSizeInBytes( sPath ); return FILEMAN->GetFileSizeInBytes( sPath );
} }
void GetDirListing( const CString &sPath, vector<CString> &AddTo, bool bOnlyDirs, bool bReturnPathToo ) void GetDirListing( const RString &sPath, vector<RString> &AddTo, bool bOnlyDirs, bool bReturnPathToo )
{ {
FILEMAN->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo ); FILEMAN->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo );
} }
void GetDirListingRecursive( const CString &sDir, const CString &sMatch, vector<CString> &AddTo ) void GetDirListingRecursive( const RString &sDir, const RString &sMatch, vector<RString> &AddTo )
{ {
ASSERT( sDir.Right(1) == "/" ); ASSERT( sDir.Right(1) == "/" );
GetDirListing( sDir+sMatch, AddTo, false, true ); GetDirListing( sDir+sMatch, AddTo, false, true );
@@ -849,13 +850,13 @@ void GetDirListingRecursive( const CString &sDir, const CString &sMatch, vector<
} }
} }
bool DeleteRecursive( const CString &sDir ) bool DeleteRecursive( const RString &sDir )
{ {
ASSERT( sDir.Right(1) == "/" ); ASSERT( sDir.Right(1) == "/" );
vector<CString> vsFiles; vector<RString> vsFiles;
GetDirListing( sDir+"*", vsFiles, false, true ); GetDirListing( sDir+"*", vsFiles, false, true );
FOREACH_CONST( CString, vsFiles, s ) FOREACH_CONST( RString, vsFiles, s )
{ {
if( IsADirectory(*s) ) if( IsADirectory(*s) )
DeleteRecursive( *s+"/" ); DeleteRecursive( *s+"/" );
@@ -872,22 +873,22 @@ void FlushDirCache()
} }
unsigned int GetHashForFile( const CString &sPath ) unsigned int GetHashForFile( const RString &sPath )
{ {
return FILEMAN->GetFileHash( sPath ); return FILEMAN->GetFileHash( sPath );
} }
unsigned int GetHashForDirectory( const CString &sDir ) unsigned int GetHashForDirectory( const RString &sDir )
{ {
unsigned int hash = 0; unsigned int hash = 0;
hash += GetHashForString( sDir ); hash += GetHashForString( sDir );
vector<CString> arrayFiles; vector<RString> arrayFiles;
GetDirListing( sDir+"*", arrayFiles, false ); GetDirListing( sDir+"*", arrayFiles, false );
for( unsigned i=0; i<arrayFiles.size(); i++ ) for( unsigned i=0; i<arrayFiles.size(); i++ )
{ {
const CString sFilePath = sDir + arrayFiles[i]; const RString sFilePath = sDir + arrayFiles[i];
hash += GetHashForFile( sFilePath ); hash += GetHashForFile( sFilePath );
} }
+24 -24
View File
@@ -5,8 +5,8 @@
namespace RageFileManagerUtil namespace RageFileManagerUtil
{ {
extern CString sInitialWorkingDirectory; extern RString sInitialWorkingDirectory;
extern CString sDirOfExecutable; extern RString sDirOfExecutable;
} }
class RageFileDriver; class RageFileDriver;
@@ -15,52 +15,52 @@ class RageFileBasic;
class RageFileManager class RageFileManager
{ {
public: public:
RageFileManager( CString argv0 ); RageFileManager( RString argv0 );
~RageFileManager(); ~RageFileManager();
void MountInitialFilesystems(); void MountInitialFilesystems();
void GetDirListing( CString sPath, vector<CString> &AddTo, bool bOnlyDirs, bool bReturnPathToo ); void GetDirListing( RString sPath, vector<RString> &AddTo, bool bOnlyDirs, bool bReturnPathToo );
bool Move( CString sOldPath, CString sNewPath ); bool Move( RString sOldPath, RString sNewPath );
bool Remove( CString sPath ); bool Remove( RString sPath );
void CreateDir( CString sDir ); void CreateDir( RString sDir );
enum FileType { TYPE_FILE, TYPE_DIR, TYPE_NONE }; enum FileType { TYPE_FILE, TYPE_DIR, TYPE_NONE };
FileType GetFileType( CString sPath ); FileType GetFileType( RString sPath );
bool IsAFile( const CString &sPath ); bool IsAFile( const RString &sPath );
bool IsADirectory( const CString &sPath ); bool IsADirectory( const RString &sPath );
bool DoesFileExist( const CString &sPath ); bool DoesFileExist( const RString &sPath );
int GetFileSizeInBytes( CString sPath ); int GetFileSizeInBytes( RString sPath );
int GetFileHash( CString sPath ); int GetFileHash( RString sPath );
void Mount( CString sType, CString sRealPath, CString sMountPoint, bool bAddToEnd = true ); bool Mount( RString sType, RString sRealPath, RString sMountPoint, bool bAddToEnd = true );
void Mount( RageFileDriver *pDriver, CString sMountPoint, bool bAddToEnd = true ); void Mount( RageFileDriver *pDriver, RString sMountPoint, bool bAddToEnd = true );
void Unmount( CString sType, CString sRoot, CString sMountPoint ); void Unmount( RString sType, RString sRoot, RString sMountPoint );
/* Change the root of a filesystem. Only a couple drivers support this; it's /* Change the root of a filesystem. Only a couple drivers support this; it's
* used to change memory card mountpoints without having to actually unmount * used to change memory card mountpoints without having to actually unmount
* the driver. */ * the driver. */
static void Remount( CString sMountpoint, CString sPath ); static void Remount( RString sMountpoint, RString sPath );
bool IsMounted( CString MountPoint ); bool IsMounted( RString MountPoint );
struct DriverLocation struct DriverLocation
{ {
CString Type, Root, MountPoint; RString Type, Root, MountPoint;
}; };
void GetLoadedDrivers( vector<DriverLocation> &asMounts ); void GetLoadedDrivers( vector<DriverLocation> &asMounts );
void FlushDirCache( CString sPath ); void FlushDirCache( RString sPath );
/* Used only by RageFile: */ /* Used only by RageFile: */
RageFileBasic *Open( CString sPath, int iMode, int &iError ); RageFileBasic *Open( RString sPath, int iMode, int &iError );
/* Retrieve or release a reference to the low-level driver for a mountpoint. */ /* Retrieve or release a reference to the low-level driver for a mountpoint. */
RageFileDriver *GetFileDriver( CString sMountpoint ); RageFileDriver *GetFileDriver( RString sMountpoint );
void ReleaseFileDriver( RageFileDriver *pDriver ); void ReleaseFileDriver( RageFileDriver *pDriver );
private: private:
RageFileBasic *OpenForReading( CString sPath, int iMode, int &iError ); RageFileBasic *OpenForReading( RString sPath, int iMode, int &iError );
RageFileBasic *OpenForWriting( CString sPath, int iMode, int &iError ); RageFileBasic *OpenForWriting( RString sPath, int iMode, int &iError );
}; };
extern RageFileManager *FILEMAN; extern RageFileManager *FILEMAN;
-8
View File
@@ -148,10 +148,6 @@ CString SecondsToMSSMsMs( float fSecs )
return sReturn; return sReturn;
} }
#include "LuaFunctions.h"
#include "LuaManager.h"
LuaFunction( SecondsToMSSMsMs, SecondsToMSSMsMs( FArg(1) ) )
CString SecondsToMMSSMsMsMs( float fSecs ) CString SecondsToMMSSMsMsMs( float fSecs )
{ {
const int iMinsDisplay = (int)fSecs/60; const int iMinsDisplay = (int)fSecs/60;
@@ -180,8 +176,6 @@ CString Commify( int iNum )
return sReturn; return sReturn;
} }
LuaFunction( FormatNumberAndSuffix, FormatNumberAndSuffix( IArg(1) ) )
CString FormatNumberAndSuffix( int i ) CString FormatNumberAndSuffix( int i )
{ {
CString sSuffix; CString sSuffix;
@@ -1596,8 +1590,6 @@ CString Basename( const CString &dir )
return dir.substr( start, end-start+1 ); return dir.substr( start, end-start+1 );
} }
LuaFunction( Basename, Basename( SArg(1) ) )
/* Return all but the last named component of dir: /* Return all but the last named component of dir:
* a/b/c -> a/b/ * a/b/c -> a/b/
* a/b/c/ -> a/b/ * a/b/c/ -> a/b/
+92 -92
View File
@@ -227,29 +227,29 @@ void fapproach( float& val, float other_val, float to_move );
float fmodfp( float x, float y ); float fmodfp( float x, float y );
int power_of_two( int input ); int power_of_two( int input );
bool IsAnInt( const CString &s ); bool IsAnInt( const RString &s );
bool IsHexVal( const CString &s ); bool IsHexVal( const RString &s );
float HHMMSSToSeconds( const CString &sHMS ); float HHMMSSToSeconds( const RString &sHMS );
CString SecondsToHHMMSS( float fSecs ); RString SecondsToHHMMSS( float fSecs );
CString SecondsToMSSMsMs( float fSecs ); RString SecondsToMSSMsMs( float fSecs );
CString SecondsToMMSSMsMs( float fSecs ); RString SecondsToMMSSMsMs( float fSecs );
CString SecondsToMMSSMsMsMs( float fSecs ); RString SecondsToMMSSMsMsMs( float fSecs );
CString PrettyPercent( float fNumerator, float fDenominator ); RString PrettyPercent( float fNumerator, float fDenominator );
inline CString PrettyPercent( int fNumerator, int fDenominator ) { return PrettyPercent( float(fNumerator), float(fDenominator) ); } inline RString PrettyPercent( int fNumerator, int fDenominator ) { return PrettyPercent( float(fNumerator), float(fDenominator) ); }
CString Commify( int iNum ); RString Commify( int iNum );
CString FormatNumberAndSuffix( int i ); RString FormatNumberAndSuffix( int i );
struct tm GetLocalTime(); struct tm GetLocalTime();
CString ssprintf( const char *fmt, ...) PRINTF(1,2); RString ssprintf( const char *fmt, ...) PRINTF(1,2);
CString vssprintf( const char *fmt, va_list argList ); RString vssprintf( const char *fmt, va_list argList );
#ifdef WIN32 #ifdef WIN32
CString hr_ssprintf( int hr, const char *fmt, ...); RString hr_ssprintf( int hr, const char *fmt, ...);
CString werr_ssprintf( int err, const char *fmt, ...); RString werr_ssprintf( int err, const char *fmt, ...);
CString ConvertWstringToACP( wstring s ); RString ConvertWstringToACP( wstring s );
CString ConvertUTF8ToACP( CString s ); RString ConvertUTF8ToACP( RString s );
#endif #endif
/* /*
@@ -257,61 +257,61 @@ CString ConvertUTF8ToACP( CString s );
* If Path is a directory (eg. c:\games\stepmania"), append a slash so the last * If Path is a directory (eg. c:\games\stepmania"), append a slash so the last
* element will end up in Dir, not FName: "c:\games\stepmania\". * element will end up in Dir, not FName: "c:\games\stepmania\".
* */ * */
void splitpath( const CString &Path, CString &Dir, CString &Filename, CString &Ext ); void splitpath( const RString &Path, RString &Dir, RString &Filename, RString &Ext );
CString SetExtension( const CString &path, const CString &ext ); RString SetExtension( const RString &path, const RString &ext );
CString GetExtension( const CString &sPath ); RString GetExtension( const RString &sPath );
CString GetFileNameWithoutExtension( const CString &sPath ); RString GetFileNameWithoutExtension( const RString &sPath );
typedef int longchar; typedef int longchar;
extern const wchar_t INVALID_CHAR; extern const wchar_t INVALID_CHAR;
int utf8_get_char_len( char p ); int utf8_get_char_len( char p );
bool utf8_to_wchar( const CString &s, unsigned &start, wchar_t &ch ); bool utf8_to_wchar( const RString &s, unsigned &start, wchar_t &ch );
bool utf8_to_wchar_ec( const CString &s, unsigned &start, wchar_t &ch ); bool utf8_to_wchar_ec( const RString &s, unsigned &start, wchar_t &ch );
void wchar_to_utf8( wchar_t ch, CString &out ); void wchar_to_utf8( wchar_t ch, RString &out );
wchar_t utf8_get_char( const CString &s ); wchar_t utf8_get_char( const RString &s );
bool utf8_is_valid( const CString &s ); bool utf8_is_valid( const RString &s );
void utf8_remove_bom( CString &s ); void utf8_remove_bom( RString &s );
CString WStringToCString( const wstring &sString ); RString WStringToCString( const wstring &sString );
CString WcharToUTF8( wchar_t c ); RString WcharToUTF8( wchar_t c );
wstring CStringToWstring( const CString &sString ); wstring CStringToWstring( const RString &sString );
CString GetLanguageNameFromISO639Code( CString sName ); RString GetLanguageNameFromISO639Code( RString sName );
// Splits a CString into an vector<CString> according the Delimitor. // Splits a RString into an vector<RString> according the Delimitor.
void split( const CString &sSource, const CString &sDelimitor, vector<CString>& asAddIt, const bool bIgnoreEmpty = true ); void split( const RString &sSource, const RString &sDelimitor, vector<RString>& asAddIt, const bool bIgnoreEmpty = true );
void split( const wstring &sSource, const wstring &sDelimitor, vector<wstring> &asAddIt, const bool bIgnoreEmpty = true ); void split( const wstring &sSource, const wstring &sDelimitor, vector<wstring> &asAddIt, const bool bIgnoreEmpty = true );
/* In-place split. */ /* In-place split. */
void split( const CString &sSource, const CString &sDelimitor, int &iBegin, int &iSize, const bool bIgnoreEmpty = true ); void split( const RString &sSource, const RString &sDelimitor, int &iBegin, int &iSize, const bool bIgnoreEmpty = true );
void split( const wstring &sSource, const wstring &sDelimitor, int &iBegin, int &iSize, const bool bIgnoreEmpty = true ); void split( const wstring &sSource, const wstring &sDelimitor, int &iBegin, int &iSize, const bool bIgnoreEmpty = true );
/* In-place split of partial string. */ /* In-place split of partial string. */
void split( const CString &sSource, const CString &sDelimitor, int &iBegin, int &iSize, int iLen, const bool bIgnoreEmpty ); /* no default to avoid ambiguity */ void split( const RString &sSource, const RString &sDelimitor, int &iBegin, int &iSize, int iLen, const bool bIgnoreEmpty ); /* no default to avoid ambiguity */
void split( const wstring &sSource, const wstring &sDelimitor, int &iBegin, int &iSize, int iLen, const bool bIgnoreEmpty ); void split( const wstring &sSource, const wstring &sDelimitor, int &iBegin, int &iSize, int iLen, const bool bIgnoreEmpty );
// Joins a vector<CString> to create a CString according the Deliminator. // Joins a vector<RString> to create a RString according the Deliminator.
CString join( const CString &sDelimitor, const vector<CString>& sSource ); RString join( const RString &sDelimitor, const vector<RString>& sSource );
CString join( const CString &sDelimitor, vector<CString>::const_iterator begin, vector<CString>::const_iterator end ); RString join( const RString &sDelimitor, vector<RString>::const_iterator begin, vector<RString>::const_iterator end );
CString GetCwd(); RString GetCwd();
void SetCommandlineArguments( int argc, char **argv ); void SetCommandlineArguments( int argc, char **argv );
bool GetCommandlineArgument( const CString &option, CString *argument=NULL, int iIndex=0 ); bool GetCommandlineArgument( const RString &option, RString *argument=NULL, int iIndex=0 );
extern int g_argc; extern int g_argc;
extern char **g_argv; extern char **g_argv;
void CRC32( unsigned int &iCRC, const void *pBuffer, size_t iSize ); void CRC32( unsigned int &iCRC, const void *pBuffer, size_t iSize );
unsigned int GetHashForString( const CString &s ); unsigned int GetHashForString( const RString &s );
unsigned int GetHashForFile( const CString &sPath ); unsigned int GetHashForFile( const RString &sPath );
unsigned int GetHashForDirectory( const CString &sDir ); // a hash value that remains the same as long as nothing in the directory has changed unsigned int GetHashForDirectory( const RString &sDir ); // a hash value that remains the same as long as nothing in the directory has changed
bool DirectoryIsEmpty( const CString &sPath ); bool DirectoryIsEmpty( const RString &sPath );
bool CompareCStringsAsc( const CString &sStr1, const CString &sStr2 ); bool CompareCStringsAsc( const RString &sStr1, const RString &sStr2 );
bool CompareCStringsDesc( const CString &sStr1, const CString &sStr2 ); bool CompareCStringsDesc( const RString &sStr1, const RString &sStr2 );
void SortCStringArray( vector<CString> &asAddTo, const bool bSortAscending = true ); void SortCStringArray( vector<RString> &asAddTo, const bool bSortAscending = true );
/* Find the mean and standard deviation of all numbers in [start,end). */ /* Find the mean and standard deviation of all numbers in [start,end). */
float calc_mean( const float *pStart, const float *pEnd ); float calc_mean( const float *pStart, const float *pEnd );
@@ -332,47 +332,47 @@ inline T Increment( T a ) { ++a; return a; }
template<class T> template<class T>
inline T Decrement( T a ) { --a; return a; } inline T Decrement( T a ) { --a; return a; }
void TrimLeft( CString &sStr, const char *szTrim = "\r\n\t " ); void TrimLeft( RString &sStr, const char *szTrim = "\r\n\t " );
void TrimRight( CString &sStr, const char *szTrim = "\r\n\t " ); void TrimRight( RString &sStr, const char *szTrim = "\r\n\t " );
void StripCrnl( CString &sStr ); void StripCrnl( RString &sStr );
bool BeginsWith( const CString &sTestThis, const CString &sBeginning ); bool BeginsWith( const RString &sTestThis, const RString &sBeginning );
bool EndsWith( const CString &sTestThis, const CString &sEnding ); bool EndsWith( const RString &sTestThis, const RString &sEnding );
void StripCvs( vector<CString> &vs ); // remove all items that end in "cvs" void StripCvs( vector<RString> &vs ); // remove all items that end in "cvs"
CString DerefRedir( const CString &sPath ); RString DerefRedir( const RString &sPath );
bool GetFileContents( const CString &sPath, CString &sOut, bool bOneLine = false ); bool GetFileContents( const RString &sPath, RString &sOut, bool bOneLine = false );
class Regex class Regex
{ {
public: public:
Regex( const CString &sPat = "" ); Regex( const RString &sPat = "" );
Regex( const Regex &rhs ); Regex( const Regex &rhs );
Regex &operator=( const Regex &rhs ); Regex &operator=( const Regex &rhs );
~Regex(); ~Regex();
bool IsSet() const { return !pattern.empty(); } bool IsSet() const { return !pattern.empty(); }
void Set( const CString &str ); void Set( const RString &str );
bool Compare( const CString &sStr ); bool Compare( const RString &sStr );
bool Compare( const CString &sStr, vector<CString> &asMatches ); bool Compare( const RString &sStr, vector<RString> &asMatches );
bool Replace( const CString &sReplacement, const CString &sSubject, CString &sOut ); bool Replace( const RString &sReplacement, const RString &sSubject, RString &sOut );
private: private:
void *reg; void *reg;
unsigned backrefs; unsigned backrefs;
CString pattern; RString pattern;
void Compile(); void Compile();
void Release(); void Release();
}; };
void ReplaceEntityText( CString &sText, const map<CString,CString> &m ); void ReplaceEntityText( RString &sText, const map<RString,RString> &m );
void ReplaceEntityText( CString &sText, const map<char,CString> &m ); void ReplaceEntityText( RString &sText, const map<char,RString> &m );
void Replace_Unicode_Markers( CString &Text ); void Replace_Unicode_Markers( RString &Text );
CString WcharDisplayText( wchar_t c ); RString WcharDisplayText( wchar_t c );
CString Basename( const CString &dir ); RString Basename( const RString &dir );
CString Dirname( const CString &dir ); RString Dirname( const RString &dir );
CString Capitalize( const CString &s ); RString Capitalize( const RString &s );
#ifndef WIN32 #ifndef WIN32
#include <unistd.h> /* correct place with correct definitions */ #include <unistd.h> /* correct place with correct definitions */
@@ -424,45 +424,45 @@ typedef basic_string<char,char_traits_char_nocase> istring;
/* Compatibility/convenience shortcuts. These are actually defined in RageFileManager.h, but /* Compatibility/convenience shortcuts. These are actually defined in RageFileManager.h, but
* declared here since they're used in many places. */ * declared here since they're used in many places. */
void GetDirListing( const CString &sPath, vector<CString> &AddTo, bool bOnlyDirs=false, bool bReturnPathToo=false ); void GetDirListing( const RString &sPath, vector<RString> &AddTo, bool bOnlyDirs=false, bool bReturnPathToo=false );
void GetDirListingRecursive( const CString &sDir, const CString &sMatch, vector<CString> &AddTo ); /* returns path too */ void GetDirListingRecursive( const RString &sDir, const RString &sMatch, vector<RString> &AddTo ); /* returns path too */
bool DeleteRecursive( const CString &sDir ); /* delete the dir and all files/subdirs inside it */ bool DeleteRecursive( const RString &sDir ); /* delete the dir and all files/subdirs inside it */
bool DoesFileExist( const CString &sPath ); bool DoesFileExist( const RString &sPath );
bool IsAFile( const CString &sPath ); bool IsAFile( const RString &sPath );
bool IsADirectory( const CString &sPath ); bool IsADirectory( const RString &sPath );
unsigned GetFileSizeInBytes( const CString &sFilePath ); unsigned GetFileSizeInBytes( const RString &sFilePath );
void FlushDirCache(); void FlushDirCache();
// call FixSlashes on any path that came from the user // call FixSlashes on any path that came from the user
void FixSlashesInPlace( CString &sPath ); void FixSlashesInPlace( RString &sPath );
CString FixSlashes( CString sPath ); RString FixSlashes( RString sPath );
void CollapsePath( CString &sPath, bool bRemoveLeadingDot=false ); void CollapsePath( RString &sPath, bool bRemoveLeadingDot=false );
bool FromString( const CString &sValue, int &out ); bool FromString( const RString &sValue, int &out );
bool FromString( const CString &sValue, unsigned &out ); bool FromString( const RString &sValue, unsigned &out );
bool FromString( const CString &sValue, float &out ); bool FromString( const RString &sValue, float &out );
bool FromString( const CString &sValue, bool &out ); bool FromString( const RString &sValue, bool &out );
inline bool FromString( const CString &sValue, CString &out ) { out = sValue; return true; } inline bool FromString( const RString &sValue, RString &out ) { out = sValue; return true; }
CString ToString( int value ); RString ToString( int value );
CString ToString( unsigned value ); RString ToString( unsigned value );
CString ToString( float value ); RString ToString( float value );
CString ToString( bool value ); RString ToString( bool value );
inline CString ToString( const CString &value ) { return value; } inline RString ToString( const RString &value ) { return value; }
// helper file functions used by Bookkeeper and ProfileManager // helper file functions used by Bookkeeper and ProfileManager
class RageFileBasic; class RageFileBasic;
bool FileRead( RageFileBasic& f, CString& sOut ); bool FileRead( RageFileBasic& f, RString& sOut );
bool FileRead( RageFileBasic& f, int& iOut ); bool FileRead( RageFileBasic& f, int& iOut );
bool FileRead( RageFileBasic& f, unsigned& uOut ); bool FileRead( RageFileBasic& f, unsigned& uOut );
bool FileRead( RageFileBasic& f, float& fOut ); bool FileRead( RageFileBasic& f, float& fOut );
void FileWrite( RageFileBasic& f, const CString& sWrite ); void FileWrite( RageFileBasic& f, const RString& sWrite );
void FileWrite( RageFileBasic& f, int iWrite ); void FileWrite( RageFileBasic& f, int iWrite );
void FileWrite( RageFileBasic& f, size_t uWrite ); void FileWrite( RageFileBasic& f, size_t uWrite );
void FileWrite( RageFileBasic& f, float fWrite ); void FileWrite( RageFileBasic& f, float fWrite );
bool FileCopy( CString sSrcFile, CString sDstFile ); bool FileCopy( RString sSrcFile, RString sDstFile );
bool FileCopy( RageFileBasic &in, RageFileBasic &out, CString &sError, bool *bReadError = NULL ); bool FileCopy( RageFileBasic &in, RageFileBasic &out, RString &sError, bool *bReadError = NULL );
#endif #endif
+5 -2
View File
@@ -101,7 +101,9 @@ void NORETURN sm_crash( const char *reason = "Internal error" );
* we do expect, such as DSound init failure.) */ * we do expect, such as DSound init failure.) */
#define FAIL_M(MESSAGE) { CHECKPOINT_M(MESSAGE); sm_crash(MESSAGE); } #define FAIL_M(MESSAGE) { CHECKPOINT_M(MESSAGE); sm_crash(MESSAGE); }
#define ASSERT_M(COND, MESSAGE) { if(unlikely(!(COND))) { FAIL_M(MESSAGE); } } #define ASSERT_M(COND, MESSAGE) { if(unlikely(!(COND))) { FAIL_M(MESSAGE); } }
#if !defined(CO_EXIST_WITH_MFC)
#define ASSERT(COND) ASSERT_M((COND), "Assertion '" #COND "' failed") #define ASSERT(COND) ASSERT_M((COND), "Assertion '" #COND "' failed")
#endif
void ShowWarning( const char *file, int line, const char *message ); // don't pull in LOG here void ShowWarning( const char *file, int line, const char *message ); // don't pull in LOG here
#define WARN(MESSAGE) (ShowWarning(__FILE__, __LINE__, MESSAGE)) #define WARN(MESSAGE) (ShowWarning(__FILE__, __LINE__, MESSAGE))
@@ -134,9 +136,10 @@ void ShowWarning( const char *file, int line, const char *message ); // don't pu
/* Use CStdString: */ /* Use CStdString: */
#include "StdString.h" #include "StdString.h"
using namespace StdString; typedef StdString::CStdString RString;
//#define CString CStdString #if !defined(CO_EXIST_WITH_MFC)
typedef StdString::CStdString CString; typedef StdString::CStdString CString;
#endif
/* Include this here to make sure our assertion handler is always /* Include this here to make sure our assertion handler is always
* used. (This file is a dependency of most everything anyway, * used. (This file is a dependency of most everything anyway,