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 2e2abe08b1..da4574aed0 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 @@ -90,37 +90,47 @@ CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode) { "Read and Write" } }; - INFO_LOG(WII_IPC_FILEIO, "FileIO: Open %s (%s)", GetDeviceName().c_str(), Modes[_Mode]); - m_Filename = std::string(HLE_IPC_BuildFilename(GetDeviceName().c_str(), 64)); // Reading requires the file to exist, but writing doesn't (what a smart thought) - if(_Mode != 0x02 && !File::Exists(m_Filename.c_str())) { - ERROR_LOG(WII_IPC_FILEIO, " FileIO failed open for reading: %s - File doesn't exist", m_Filename.c_str()); - ReturnValue = FS_FILE_NOT_EXIST; - } else { + if(File::Exists(m_Filename.c_str())) + { + INFO_LOG(WII_IPC_FILEIO, "FileIO: Open %s (%s), File exists", GetDeviceName().c_str(), Modes[_Mode]); switch(_Mode) { case 0x01: m_pFileHandle = fopen(m_Filename.c_str(), "rb"); break; - case 0x02: m_pFileHandle = fopen(m_Filename.c_str(), "wb"); break; + case 0x02: // m_pFileHandle = fopen(m_Filename.c_str(), "wb"); break; + // MK Wii gets here corrupting its saves, however using rb+ mode works fine + // TODO : figure it properly... case 0x03: m_pFileHandle = fopen(m_Filename.c_str(), "r+b"); break; - default: PanicAlert("CWII_IPC_HLE_Device_FileIO: unknown open mode"); break; + default: PanicAlert("CWII_IPC_HLE_Device_FileIO: unknown open mode : 0x%02x", _Mode); break; + } + } + else + { + if (_Mode == 0x02) { + INFO_LOG(WII_IPC_FILEIO, "FileIO: Open %s (%s), File doesn't exist", GetDeviceName().c_str(), Modes[_Mode]); + m_pFileHandle = fopen(m_Filename.c_str(), "wb"); + } + else { + ERROR_LOG(WII_IPC_FILEIO, " FileIO failed open for reading: %s - File doesn't exist", m_Filename.c_str()); + ReturnValue = FS_FILE_NOT_EXIST; } } - - if (m_pFileHandle != NULL) - { - m_FileLength = File::GetSize(m_Filename.c_str()); - ReturnValue = GetDeviceID(); - } - else if(ReturnValue == 0) - { - ERROR_LOG(WII_IPC_FILEIO, " FileIO failed open: %s(%s) - I/O Error", m_Filename.c_str(), Modes[_Mode]); - ReturnValue = FS_INVALID_ARGUMENT; - } - Memory::Write_U32(ReturnValue, _CommandAddress+4); - return true; + if (m_pFileHandle != NULL) + { + m_FileLength = File::GetSize(m_Filename.c_str()); + ReturnValue = GetDeviceID(); + } + else if(ReturnValue == 0) + { + ERROR_LOG(WII_IPC_FILEIO, " FileIO failed open: %s(%s) - I/O Error", m_Filename.c_str(), Modes[_Mode]); + ReturnValue = FS_INVALID_ARGUMENT; + } + + Memory::Write_U32(ReturnValue, _CommandAddress+4); + return true; } bool @@ -132,6 +142,7 @@ CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress) INFO_LOG(WII_IPC_FILEIO, "FileIO: Old Seek Pos: %s, Mode: %i (Device=%s, FileSize=%s)", ThS(SeekPosition).c_str(), Mode, GetDeviceName().c_str(), ThS((int)m_FileLength).c_str()); + // TODO : The following hack smells bad /* Zelda - TP Fix: It doesn't make much sense but it works in Zelda - TP and it's probably better than trying to read outside the file (it seeks to 0x6000 instead of the correct 0x2000 for the second half of the file). Could this be right diff --git a/Source/Core/DolphinWX/Src/FrameTools.cpp b/Source/Core/DolphinWX/Src/FrameTools.cpp index bbfab3867b..372cf92dec 100644 --- a/Source/Core/DolphinWX/Src/FrameTools.cpp +++ b/Source/Core/DolphinWX/Src/FrameTools.cpp @@ -49,6 +49,7 @@ Core::GetWindowHandle(). #include "GameListCtrl.h" #include "BootManager.h" #include "LogWindow.h" +#include "WxUtils.h" #include "Common.h" // Common #include "FileUtil.h" @@ -65,8 +66,6 @@ Core::GetWindowHandle(). #include // wxWidgets -// ugly that this lib included code from the main -#include "../../DolphinWX/Src/WxUtils.h" // ---------------------------------------------------------------------------- // Resources diff --git a/Source/Core/DolphinWX/Src/GameListCtrl.cpp b/Source/Core/DolphinWX/Src/GameListCtrl.cpp index b48b8e15b0..5404d00462 100644 --- a/Source/Core/DolphinWX/Src/GameListCtrl.cpp +++ b/Source/Core/DolphinWX/Src/GameListCtrl.cpp @@ -32,6 +32,7 @@ #include "IniFile.h" #include "FileUtil.h" #include "CDUtils.h" +#include "WxUtils.h" #if USE_XPM_BITMAPS #include "../resources/Flag_Europe.xpm" @@ -44,9 +45,6 @@ #include "../resources/Platform_Gamecube.xpm" #endif // USE_XPM_BITMAPS -// ugly that this lib included code from the main -#include "../../DolphinWX/Src/WxUtils.h" - size_t CGameListCtrl::m_currentItem = 0; size_t CGameListCtrl::m_numberItem = 0; std::string CGameListCtrl::m_currentFilename;