Files
itgmania212121/src/RageFileDriver.cpp
T

118 lines
3.3 KiB
C++
Raw Normal View History

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
2005-12-13 03:27:44 +00:00
int RageFileDriver::GetPathValue( const RString &sPath )
2003-12-05 02:25:32 +00:00
{
2005-12-13 03:27:44 +00:00
vector<RString> asParts;
split( sPath, "/", asParts, true );
2003-12-05 02:25:32 +00:00
2005-12-13 03:27:44 +00:00
RString sPartialPath;
2003-12-05 02:25:32 +00:00
2005-12-13 03:27:44 +00:00
for( unsigned i = 0; i < asParts.size(); ++i )
2003-12-05 02:25:32 +00:00
{
2005-12-13 03:27:44 +00:00
sPartialPath += asParts[i];
if( i+1 < asParts.size() )
sPartialPath += "/";
2003-12-05 02:25:32 +00:00
2005-12-13 03:27:44 +00:00
const RageFileManager::FileType Type = GetFileType( sPartialPath );
2003-12-05 02:25:32 +00:00
switch( Type )
{
case RageFileManager::TYPE_NONE:
2005-12-13 03:27:44 +00:00
return asParts.size()-i;
2003-12-05 02:25:32 +00:00
/* If this is the last part (the whole path), it needs to be a file; otherwise a directory. */
case RageFileManager::TYPE_FILE:
2005-12-13 03:27:44 +00:00
if( i != asParts.size()-1 )
2003-12-05 02:25:32 +00:00
return -1;
break;
case RageFileManager::TYPE_DIR:
2005-12-13 03:27:44 +00:00
if( i == asParts.size()-1 )
2003-12-05 02:25:32 +00:00
return -1;
break;
}
}
return 0;
}
2005-12-13 03:27:44 +00:00
void RageFileDriver::GetDirListing( const RString &sPath, vector<RString> &asAddTo, bool bOnlyDirs, bool bReturnPathToo )
2003-12-07 22:22:27 +00:00
{
2005-12-13 03:27:44 +00:00
FDB->GetDirListing( sPath, asAddTo, bOnlyDirs, bReturnPathToo );
2003-12-07 22:22:27 +00:00
}
RageFileManager::FileType RageFileDriver::GetFileType( const RString &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
}
int RageFileDriver::GetFileSizeInBytes( const RString &sPath )
2003-12-07 22:22:27 +00:00
{
return FDB->GetFileSize( sPath );
}
int RageFileDriver::GetFileHash( const RString &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 RString &sPath )
2003-12-07 22:22:27 +00:00
{
FDB->FlushDirCache( sPath );
2003-12-07 22:22:27 +00:00
}
2004-02-10 23:39:45 +00:00
2005-12-13 03:27:44 +00:00
const struct FileDriverEntry *g_pFileDriverList = NULL;
2004-02-10 23:39:45 +00:00
2005-12-28 03:59:52 +00:00
FileDriverEntry::FileDriverEntry( const RString &sType )
2004-02-10 23:39:45 +00:00
{
2005-12-13 03:27:44 +00:00
m_pLink = g_pFileDriverList;
g_pFileDriverList = this;
m_sType = sType;
2004-02-10 23:39:45 +00:00
}
FileDriverEntry::~FileDriverEntry()
{
2005-12-13 03:27:44 +00:00
g_pFileDriverList = NULL; /* invalidate */
2004-02-10 23:39:45 +00:00
}
2005-12-28 03:59:52 +00:00
RageFileDriver *MakeFileDriver( const RString &sType, const RString &sRoot )
2004-02-10 23:39:45 +00:00
{
2005-12-13 03:27:44 +00:00
for( const FileDriverEntry *p = g_pFileDriverList; p; p = p->m_pLink )
if( !p->m_sType.CompareNoCase(sType) )
return p->Create( sRoot );
2004-02-10 23:39:45 +00:00
return NULL;
}
2003-12-04 08:25:59 +00:00
/*
2004-05-06 00:42:06 +00:00
* Copyright (c) 2003-2004 Glenn Maynard
* All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, and/or sell copies of the Software, and to permit persons to
* whom the Software is furnished to do so, provided that the above
* copyright notice(s) and this permission notice appear in all copies of
* the Software and that both the above copyright notice(s) and this
* permission notice appear in supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
2003-12-04 08:25:59 +00:00
*/