handle "SLASH" stuff at a low level

This commit is contained in:
Glenn Maynard
2003-12-10 09:43:31 +00:00
parent f4a3640b0d
commit cd7ab704cb
+47 -13
View File
@@ -21,6 +21,43 @@
#define O_BINARY 0 #define O_BINARY 0
#endif #endif
/* Wrappers for low-level file functions, to work around Xbox issues: */
static int DoMkdir( const CString &sPath, int perm )
{
#if defined(XBOX)
CString TempPath = sPath;
TempPath.Replace( "/", "\\" ); /* just for mkdir */
return mkdir( TempPath, perm );
#else
return mkdir( sPath, perm );
#endif
}
static int DoOpen( const CString &sPath, int flags, int perm )
{
#if defined(XBOX)
CString TempPath = sPath;
TempPath.Replace( "/", "\\" ); /* just for mkdir */
return open( TempPath, flags, perm );
#else
return open( sPath, flags, perm );
#endif
}
#if defined(WIN32)
static HANDLE DoFindFirstFile( const CString &sPath, WIN32_FIND_DATA *fd )
{
#if defined(XBOX)
CString TempPath = sPath;
TempPath.Replace( "/", "\\" ); /* just for mkdir */
return FindFirstFile( TempPath, fd );
#else
return FindFirstFile( sPath, fd );
#endif
}
#endif
/* This driver handles direct file access. */ /* This driver handles direct file access. */
class DirectFilenameDB: public FilenameDB class DirectFilenameDB: public FilenameDB
{ {
@@ -40,6 +77,7 @@ public:
} }
}; };
void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path ) void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path )
{ {
CString sPath = path; CString sPath = path;
@@ -53,10 +91,10 @@ void DirectFilenameDB::PopulateFileSet( FileSet &fs, const CString &path )
#if defined(WIN32) #if defined(WIN32)
WIN32_FIND_DATA fd; WIN32_FIND_DATA fd;
if ( sPath.size() > 0 && sPath.Right(1) == SLASH ) if ( sPath.size() > 0 && sPath.Right(1) == "/" )
sPath.erase( sPath.size() - 1 ); sPath.erase( sPath.size() - 1 );
HANDLE hFind = FindFirstFile( root+sPath+SLASH "*", &fd ); HANDLE hFind = DoFindFirstFile( root+sPath+"/*", &fd );
if( hFind == INVALID_HANDLE_VALUE ) if( hFind == INVALID_HANDLE_VALUE )
return; return;
@@ -156,12 +194,12 @@ static bool CreateDirectories( CString Path )
{ {
CStringArray parts; CStringArray parts;
CString curpath; CString curpath;
split(Path, SLASH, parts); split(Path, "/", parts);
for(unsigned i = 0; i < parts.size(); ++i) for(unsigned i = 0; i < parts.size(); ++i)
{ {
curpath += parts[i] + SLASH; curpath += parts[i] + "/";
if( mkdir(curpath, 0755) == 0 ) if( DoMkdir(curpath, 0755) == 0 )
continue; continue;
if(errno == EEXIST) if(errno == EEXIST)
@@ -193,7 +231,9 @@ static bool CreateDirectories( CString Path )
return true; return true;
} }
RageFileObj *MakeFileObjDirect( const CString &sPath, RageFile::OpenMode mode, RageFile &p, int &err )
RageFileObj *MakeFileObjDirect( CString sPath, RageFile::OpenMode mode, RageFile &p, int &err )
{ {
int flags = O_BINARY; int flags = O_BINARY;
if( mode == RageFile::READ ) if( mode == RageFile::READ )
@@ -203,11 +243,7 @@ RageFileObj *MakeFileObjDirect( const CString &sPath, RageFile::OpenMode mode, R
flags |= O_WRONLY|O_CREAT|O_TRUNC; flags |= O_WRONLY|O_CREAT|O_TRUNC;
} }
#if defined(XBOX) int fd = DoOpen( sPath, flags, 0644 );
sPath.Replace( "/", "\\" );
#endif
int fd = open( sPath, flags, 0644 );
if( fd == -1 ) if( fd == -1 )
{ {
err = errno; err = errno;
@@ -230,9 +266,7 @@ RageFileObj *RageFileDriverDirect::Open( const CString &path, RageFile::OpenMode
{ {
const CString dir = Dirname(sPath); const CString dir = Dirname(sPath);
if( this->GetFileType(dir) != RageFileManager::TYPE_DIR ) if( this->GetFileType(dir) != RageFileManager::TYPE_DIR )
{
CreateDirectories( dir ); CreateDirectories( dir );
}
} }
return MakeFileObjDirect( sPath, mode, p, err ); return MakeFileObjDirect( sPath, mode, p, err );