2008-01-15 20:27:44 +00:00
|
|
|
#include "DirectoryDevice.h"
|
|
|
|
#include "StdStream.h"
|
|
|
|
#include "../Config.h"
|
|
|
|
|
|
|
|
using namespace Framework;
|
|
|
|
using namespace std;
|
2008-01-19 03:36:27 +00:00
|
|
|
using namespace Iop::Ioman;
|
2008-01-15 20:27:44 +00:00
|
|
|
|
|
|
|
CDirectoryDevice::CDirectoryDevice(const char* basePathPreferenceName) :
|
|
|
|
m_basePathPreferenceName(basePathPreferenceName)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CDirectoryDevice::~CDirectoryDevice()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CStream* CDirectoryDevice::GetFile(uint32 accessType, const char* devicePath)
|
|
|
|
{
|
|
|
|
const char* mode(NULL);
|
|
|
|
string path;
|
|
|
|
|
2008-03-19 23:26:24 +00:00
|
|
|
const char* basePath = CConfig::GetInstance().GetPreferenceString(m_basePathPreferenceName.c_str());
|
2008-01-15 20:27:44 +00:00
|
|
|
|
|
|
|
path = basePath;
|
|
|
|
if(devicePath[0] != '/')
|
|
|
|
{
|
|
|
|
path += "/";
|
|
|
|
}
|
|
|
|
path += devicePath;
|
|
|
|
|
|
|
|
switch(accessType)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case O_RDONLY:
|
|
|
|
mode = "rb";
|
|
|
|
break;
|
|
|
|
case (O_RDWR | O_CREAT):
|
|
|
|
mode = "w+";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FILE* stream = fopen(path.c_str(), mode);
|
|
|
|
if(stream == NULL) return NULL;
|
|
|
|
|
|
|
|
return new CStdStream(stream);
|
|
|
|
}
|