few more small fixes

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1337 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
nakeee 2008-11-30 13:39:11 +00:00
parent 1c34151182
commit b46152cdbd
2 changed files with 53 additions and 39 deletions

View File

@ -83,11 +83,16 @@ bool Delete(const char *filename)
std::string SanitizePath(const char *filename)
{
std::string copy = filename;
for (size_t i = 0; i < copy.size(); i++)
if (copy[i] == '/')
copy[i] = '\\';
return copy;
std::string copy = filename;
#ifdef _WIN32
for (size_t i = 0; i < copy.size(); i++)
if (copy[i] == '/')
copy[i] = '\\';
#else
// Should we do the otherway around?
#endif
return copy;
}
void Launch(const char *filename)

View File

@ -74,47 +74,56 @@ CWII_IPC_HLE_Device_FileIO::Close(u32 _CommandAddress)
bool
CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode)
{
//LOG(WII_IPC_FILEIO, "===================================================================");
u32 ReturnValue = 0;
const char Modes[][128] =
//LOG(WII_IPC_FILEIO, "===================================================================");
u32 ReturnValue = 0;
const char Modes[][128] =
{
{ "Unk Mode" },
{ "Read only" },
{ "Write only" },
{ "Read and Write" }
{ "Unk Mode" },
{ "Read only" },
{ "Write only" },
{ "Read and Write" }
};
LOG(WII_IPC_FILEIO, "FileIO: Open %s (%s)", GetDeviceName().c_str(), Modes[_Mode]);
m_Filename = std::string(HLE_IPC_BuildFilename(GetDeviceName().c_str(), 64));
m_Filename = std::string(HLE_IPC_BuildFilename(GetDeviceName().c_str(), 64));
if (File::Exists(m_Filename.c_str()))
{
switch(_Mode)
{
// Do "r+b" for all writing to avoid truncating the file
case 0x01: m_pFileHandle = fopen(m_Filename.c_str(), "rb"); break;
case 0x02: //m_pFileHandle = fopen(m_Filename.c_str(), "wb"); break;
case 0x03: m_pFileHandle = fopen(m_Filename.c_str(), "r+b"); break;
default: PanicAlert("CWII_IPC_HLE_Device_FileIO: unknown open mode"); break;
}
}
if (m_pFileHandle != NULL)
{
m_FileLength = File::GetSize(m_Filename.c_str());
ReturnValue = GetDeviceID();
}
else
{
LOG(WII_IPC_FILEIO, " failed - File doesn't exist");
LOG(WII_IPC_FILEIO, "FileIO: Open %s (%s)", GetDeviceName().c_str(), Modes[_Mode]);
if (File::Exists(m_Filename.c_str())) {
switch(_Mode)
{
// Do "r+b" for all writing to avoid truncating the file
case 0x01:
m_pFileHandle = fopen(m_Filename.c_str(), "rb");
break;
case 0x02:
//m_pFileHandle = fopen(m_Filename.c_str(), "wb"); break;
case 0x03:
m_pFileHandle = fopen(m_Filename.c_str(), "r+b");
break;
default:
PanicAlert("CWII_IPC_HLE_Device_FileIO: unknown open mode");
break;
}
if (m_pFileHandle != NULL) {
m_FileLength = File::GetSize(m_Filename.c_str());
ReturnValue = GetDeviceID();
}
else {
LOG(WII_IPC_FILEIO, "Error opening file %s", m_Filename.c_str());
ReturnValue = -106;
}
} else {
LOG(WII_IPC_FILEIO, "File %s doesn't exist", m_Filename.c_str() );
ReturnValue = -106;
}
Memory::Write_U32(ReturnValue, _CommandAddress+4);
//LOG(WII_IPC_FILEIO, "===================================================================");
//LOG(WII_IPC_FILEIO, "===================================================================");
return true;
}