diff --git a/Source/Core/Common/Src/FileUtil.cpp b/Source/Core/Common/Src/FileUtil.cpp index f018c7dae4..7fd81d3ae0 100644 --- a/Source/Core/Common/Src/FileUtil.cpp +++ b/Source/Core/Common/Src/FileUtil.cpp @@ -28,44 +28,47 @@ #else #include #include -#include #include #include #endif #include +#include +#ifndef S_ISDIR +#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) +#endif namespace File { +inline void stripTailDirSlashes(std::string& fname) { + while(fname.at(fname.length() - 1) == DIR_SEP_CHR) + fname.resize(fname.length() - 1); +} + bool Exists(const char *filename) { -#ifdef _WIN32 - return GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES; -#else struct stat file_info; - int result = stat(filename, &file_info); - return result == 0; -#endif + + std::string copy = filename; + stripTailDirSlashes(copy); + + int result = stat(copy.c_str(), &file_info); + return (result == 0); } bool IsDirectory(const char *filename) { -#ifdef _WIN32 - DWORD Attribs = GetFileAttributes(filename); - if (Attribs == INVALID_FILE_ATTRIBUTES) - return false; - - return (GetFileAttributes(filename) & FILE_ATTRIBUTE_DIRECTORY) != 0; -#else struct stat file_info; - int result = stat(filename, &file_info); + std::string copy = filename; + stripTailDirSlashes(copy); + + int result = stat(copy.c_str(), &file_info); if (result == 0) return S_ISDIR(file_info.st_mode); else return false; -#endif } bool Delete(const char *filename) @@ -296,24 +299,17 @@ std::string GetUserDirectory() u64 GetSize(const char *filename) { -#ifdef _WIN32 - FILE *pFile = fopen(filename, "rb"); - if (pFile) - { - fseek(pFile, 0, SEEK_END); - u64 pos = ftell(pFile); - fclose(pFile); - return pos; - } -#else + if(!Exists(filename)) + return 0; + struct stat buf; if (stat(filename, &buf) == 0) { return buf.st_size; } int err = errno; - PanicAlert("Error stating %s: %s", filename, strerror(err)); -#endif + PanicAlert("Error accessing %s: %s", filename, strerror(err)); + return 0; } diff --git a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp index bd4c857945..8a6a8170cc 100644 --- a/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp +++ b/Source/Core/Core/Src/HW/EXI_DeviceMemoryCard.cpp @@ -72,7 +72,7 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF if (pFile) { fseek( pFile, 0L, SEEK_END ); - long MemFileSize = ftell( pFile ); + u64 MemFileSize = ftell( pFile ); switch ((MemFileSize / (8 * 1024))-5) // Convert the filesize in bytes to the "nintendo-size" { @@ -137,7 +137,8 @@ void CEXIMemoryCard::Flush(bool exiting) { std::string dir; SplitPath(m_strFilename, &dir, 0, 0); - File::CreateDir(dir.c_str()); + if(!File::IsDirectory(dir.c_str())) + File::CreateDir(dir.c_str()); pFile = fopen(m_strFilename.c_str(), "wb"); } if (!pFile) //Note - pFile changed inside above if 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 49c9f8ba48..33f0e405ea 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 @@ -216,7 +216,7 @@ CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress) LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS"); LOG(WII_IPC_FILEIO, " Length: %i Seek: %i", m_FileLength, Position); - Memory::Write_U32(m_FileLength, BufferOut); + Memory::Write_U32((u32)m_FileLength, BufferOut); Memory::Write_U32(Position, BufferOut+4); } break; diff --git a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.h b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.h index 1b12f9f2ce..cf2808af05 100644 --- a/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.h +++ b/Source/Core/Core/Src/IPC_HLE/WII_IPC_HLE_Device_FileIO.h @@ -65,7 +65,7 @@ private: }; FILE* m_pFileHandle; - u32 m_FileLength; + u64 m_FileLength; std::string m_Filename; }; diff --git a/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_LoadStore.cpp b/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_LoadStore.cpp index 1aa639dd9c..9a4fc71026 100644 --- a/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_LoadStore.cpp +++ b/Source/Core/Core/Src/PowerPC/Interpreter/Interpreter_LoadStore.cpp @@ -432,6 +432,7 @@ void stfdx(UGeckoInstruction _inst) // __________________________________________________________________________________________________ // stfiwx // TODO - examine what this really does +// Stores Floating points into Integers indeXed void stfiwx(UGeckoInstruction _inst) { u32 uAddress = Helper_Get_EA_X(_inst);