diff options
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Common/Src/FileUtil.cpp | 49 | ||||
| -rw-r--r-- | Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.cpp | 22 |
2 files changed, 60 insertions, 11 deletions
diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index 68d333eb7a..8342c0baed 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -32,6 +32,9 @@ #include <stdlib.h>
#endif
+#include <fstream>
+
+
namespace File
{
@@ -221,6 +224,52 @@ bool Copy(const char *srcFilename, const char *destFilename) return CopyFile(srcFilename, destFilename, FALSE);
#else
+#define BSIZE 1024
+
+ int rnum, wnum, err;
+ char buffer[BSIZE];
+ FILE *output, *input;
+
+ if (! (input = fopen(srcFilename, "r"))) {
+ err = errno;
+ PanicAlert("Error copying from %s: %s", srcFilename, strerror(err));
+ return false;
+ }
+
+ if (! (output = fopen(destFilename, "w"))) {
+ err = errno;
+ PanicAlert("Error copying to %s: %s", destFilename, strerror(err));
+ return false;
+ }
+
+ while(! feof(input)) {
+ if((rnum = fread(buffer, sizeof(char), BSIZE, input)) != BSIZE) {
+ if(ferror(input) != 0){
+ PanicAlert("can't read source file\n");
+ return false;
+ }
+ }
+
+ if((wnum = fwrite(buffer, sizeof(char), rnum, output))!= rnum){
+ PanicAlert("can't write output file\n");
+ return false;
+ }
+ }
+
+ fclose(input);
+ fclose(output);
+
+ return true;
+ /*
+ std::ifstream ifs(srcFilename, std::ios::binary);
+ std::ofstream ofs(destFilename, std::ios::binary);
+
+ ofs << ifs.rdbuf();
+
+ ifs.close();
+ ofs.close();
+
+ return true;*/
#endif
}
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 8c6f08cc51..1de4ad678e 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 @@ -104,16 +104,13 @@ CWII_IPC_HLE_Device_FileIO::Open(u32 _CommandAddress, u32 _Mode) if (m_pFileHandle != NULL)
{
- fseek(m_pFileHandle, 0, SEEK_END);
- m_FileLength = (u32)ftell(m_pFileHandle);
- rewind(m_pFileHandle);
-
- ReturnValue = GetDeviceID();
+ m_FileLength = File::GetSize(m_Filename.c_str());
+ ReturnValue = GetDeviceID();
}
else
{
- LOG(WII_IPC_FILEIO, " failed - File doesn't exist");
- ReturnValue = -106;
+ LOG(WII_IPC_FILEIO, " failed - File doesn't exist");
+ ReturnValue = -106;
}
Memory::Write_U32(ReturnValue, _CommandAddress+4);
@@ -133,9 +130,12 @@ CWII_IPC_HLE_Device_FileIO::Seek(u32 _CommandAddress) switch(Mode)
{
case 0:
- fseek(m_pFileHandle, SeekPosition, SEEK_SET);
+ if (fseek(m_pFileHandle, SeekPosition, SEEK_SET) == 0) {
// Seek always return the seek position for success
ReturnValue = SeekPosition;
+ } else {
+ LOG(WII_IPC_FILEIO, "FILEIO: Seek failed");
+ }
break;
case 1: // cur
@@ -212,8 +212,8 @@ CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress) {
case ISFS_IOCTL_GETFILESTATS:
{
- u32 Position = (u32)ftell(m_pFileHandle);
-
+ u32 Position = (u32)ftell(m_pFileHandle);
+
u32 BufferOut = Memory::Read_U32(_CommandAddress + 0x18);
LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS");
LOG(WII_IPC_FILEIO, " Length: %i Seek: %i", m_FileLength, Position);
@@ -245,4 +245,4 @@ CWII_IPC_HLE_Device_FileIO::ReturnFileHandle() return false;
else
return true;
-}
\ No newline at end of file +}
|
