diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 8342c0baed..747bbda2af 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -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) diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp index 1de4ad678e..ff90721667 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp @@ -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; }