2003-12-04 08:25:59 +00:00
|
|
|
#include "global.h"
|
|
|
|
|
#include "RageFileDriver.h"
|
2003-12-05 02:25:32 +00:00
|
|
|
#include "RageUtil.h"
|
2003-12-07 22:22:27 +00:00
|
|
|
#include "RageUtil_FileDB.h"
|
|
|
|
|
|
|
|
|
|
RageFileDriver::~RageFileDriver()
|
|
|
|
|
{
|
|
|
|
|
delete FDB;
|
|
|
|
|
}
|
2003-12-04 08:25:59 +00:00
|
|
|
|
|
|
|
|
void RageFileObj::SetError( const CString &err )
|
|
|
|
|
{
|
|
|
|
|
parent.SetError( err );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RageFileObj::Seek( int offset )
|
|
|
|
|
{
|
|
|
|
|
const int OldPos = parent.Tell();
|
|
|
|
|
if( offset < OldPos )
|
|
|
|
|
parent.Rewind();
|
|
|
|
|
else
|
|
|
|
|
offset -= OldPos;
|
|
|
|
|
|
2003-12-10 05:01:22 +00:00
|
|
|
char buf[1024*4];
|
2003-12-04 08:25:59 +00:00
|
|
|
while( offset )
|
|
|
|
|
{
|
|
|
|
|
/* Must call parent.Read: */
|
|
|
|
|
int got = parent.Read( buf, min( (int) sizeof(buf), offset ) );
|
|
|
|
|
if( got == -1 )
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
if( got == 0 )
|
|
|
|
|
break;
|
|
|
|
|
offset -= got;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return parent.Tell();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RageFileObj::SeekCur( int offset )
|
|
|
|
|
{
|
|
|
|
|
return Seek( parent.Tell() + offset );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int RageFileObj::GetFileSize()
|
|
|
|
|
{
|
|
|
|
|
int OldPos = parent.Tell();
|
|
|
|
|
parent.Rewind();
|
|
|
|
|
char buf[256];
|
|
|
|
|
int ret = 0;
|
|
|
|
|
while( 1 )
|
|
|
|
|
{
|
|
|
|
|
/* Must call parent.Read: */
|
|
|
|
|
int got = parent.Read( buf, sizeof(buf) );
|
|
|
|
|
if( got == -1 )
|
|
|
|
|
{
|
|
|
|
|
ret = -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if( got == 0 )
|
|
|
|
|
break;
|
|
|
|
|
ret += got;
|
|
|
|
|
}
|
|
|
|
|
Seek( OldPos );
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 00:05:55 +00:00
|
|
|
int RageFileDriver::GetPathValue( const CString &path )
|
2003-12-05 02:25:32 +00:00
|
|
|
{
|
|
|
|
|
vector<CString> parts;
|
2003-12-10 09:44:16 +00:00
|
|
|
split( path, "/", parts, true );
|
2003-12-05 02:25:32 +00:00
|
|
|
|
|
|
|
|
CString PartialPath;
|
|
|
|
|
|
|
|
|
|
for( unsigned i = 0; i < parts.size(); ++i )
|
|
|
|
|
{
|
|
|
|
|
PartialPath += parts[i];
|
|
|
|
|
if( i+1 < parts.size() )
|
2003-12-10 09:44:16 +00:00
|
|
|
PartialPath += "/";
|
2003-12-05 02:25:32 +00:00
|
|
|
|
|
|
|
|
const RageFileManager::FileType Type = GetFileType( PartialPath );
|
|
|
|
|
switch( Type )
|
|
|
|
|
{
|
|
|
|
|
case RageFileManager::TYPE_NONE:
|
|
|
|
|
return parts.size()-i;
|
|
|
|
|
|
|
|
|
|
/* If this is the last part (the whole path), it needs to be a file; otherwise a directory. */
|
|
|
|
|
case RageFileManager::TYPE_FILE:
|
|
|
|
|
if( i != parts.size()-1 )
|
|
|
|
|
return -1;
|
|
|
|
|
break;
|
|
|
|
|
case RageFileManager::TYPE_DIR:
|
|
|
|
|
if( i == parts.size()-1 )
|
|
|
|
|
return -1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 00:05:55 +00:00
|
|
|
void RageFileDriver::GetDirListing( const CString &sPath, CStringArray &AddTo, bool bOnlyDirs, bool bReturnPathToo )
|
2003-12-07 22:22:27 +00:00
|
|
|
{
|
|
|
|
|
FDB->GetDirListing( sPath, AddTo, bOnlyDirs, bReturnPathToo );
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-08 00:05:55 +00:00
|
|
|
RageFileManager::FileType RageFileDriver::GetFileType( const CString &sPath )
|
2003-12-07 22:22:27 +00:00
|
|
|
{
|
2004-01-16 22:33:01 +00:00
|
|
|
return FDB->GetFileType( sPath );
|
2003-12-07 22:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
2003-12-08 00:05:55 +00:00
|
|
|
int RageFileDriver::GetFileSizeInBytes( const CString &sPath )
|
2003-12-07 22:22:27 +00:00
|
|
|
{
|
|
|
|
|
return FDB->GetFileSize( sPath );
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-10 07:07:42 +00:00
|
|
|
int RageFileDriver::GetFileHash( const CString &sPath )
|
2003-12-07 22:22:27 +00:00
|
|
|
{
|
2003-12-10 07:07:42 +00:00
|
|
|
return FDB->GetFileHash( sPath );
|
2003-12-07 22:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RageFileDriver::FlushDirCache( const CString &sPath )
|
|
|
|
|
{
|
|
|
|
|
FDB->FlushDirCache();
|
|
|
|
|
}
|
|
|
|
|
|
2004-02-10 23:39:45 +00:00
|
|
|
|
|
|
|
|
const struct FileDriverEntry *g_FileDriverList = NULL;
|
|
|
|
|
|
|
|
|
|
FileDriverEntry::FileDriverEntry( CString Type )
|
|
|
|
|
{
|
|
|
|
|
m_Link = g_FileDriverList;
|
|
|
|
|
g_FileDriverList = this;
|
|
|
|
|
m_Type = Type;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileDriverEntry::~FileDriverEntry()
|
|
|
|
|
{
|
|
|
|
|
g_FileDriverList = NULL; /* invalidate */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RageFileDriver *MakeFileDriver( CString Type, CString Root )
|
|
|
|
|
{
|
|
|
|
|
for( const FileDriverEntry *p = g_FileDriverList; p; p = p->m_Link )
|
|
|
|
|
if( !p->m_Type.CompareNoCase(Type) )
|
|
|
|
|
return p->Create( Root );
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-12-04 08:25:59 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2003 by the person(s) listed below. All rights reserved.
|
|
|
|
|
* Glenn Maynard
|
|
|
|
|
*/
|
|
|
|
|
|