More portable file management. Verify on linux and check Wii's un-save-able games.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1405 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
XTra.KrazzY 2008-12-05 17:04:15 +00:00
parent 064d45024c
commit 116509985a
5 changed files with 30 additions and 32 deletions

View File

@ -28,44 +28,47 @@
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <dirent.h> #include <dirent.h>
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#endif #endif
#include <fstream> #include <fstream>
#include <sys/stat.h>
#ifndef S_ISDIR
#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
#endif
namespace File 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) bool Exists(const char *filename)
{ {
#ifdef _WIN32
return GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES;
#else
struct stat file_info; struct stat file_info;
int result = stat(filename, &file_info);
return result == 0; std::string copy = filename;
#endif stripTailDirSlashes(copy);
int result = stat(copy.c_str(), &file_info);
return (result == 0);
} }
bool IsDirectory(const char *filename) 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; 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) if (result == 0)
return S_ISDIR(file_info.st_mode); return S_ISDIR(file_info.st_mode);
else else
return false; return false;
#endif
} }
bool Delete(const char *filename) bool Delete(const char *filename)
@ -296,24 +299,17 @@ std::string GetUserDirectory()
u64 GetSize(const char *filename) u64 GetSize(const char *filename)
{ {
#ifdef _WIN32 if(!Exists(filename))
FILE *pFile = fopen(filename, "rb"); return 0;
if (pFile)
{
fseek(pFile, 0, SEEK_END);
u64 pos = ftell(pFile);
fclose(pFile);
return pos;
}
#else
struct stat buf; struct stat buf;
if (stat(filename, &buf) == 0) { if (stat(filename, &buf) == 0) {
return buf.st_size; return buf.st_size;
} }
int err = errno; int err = errno;
PanicAlert("Error stating %s: %s", filename, strerror(err));
#endif PanicAlert("Error accessing %s: %s", filename, strerror(err));
return 0; return 0;
} }

View File

@ -72,7 +72,7 @@ CEXIMemoryCard::CEXIMemoryCard(const std::string& _rName, const std::string& _rF
if (pFile) if (pFile)
{ {
fseek( pFile, 0L, SEEK_END ); 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" 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; std::string dir;
SplitPath(m_strFilename, &dir, 0, 0); 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"); pFile = fopen(m_strFilename.c_str(), "wb");
} }
if (!pFile) //Note - pFile changed inside above if if (!pFile) //Note - pFile changed inside above if

View File

@ -216,7 +216,7 @@ CWII_IPC_HLE_Device_FileIO::IOCtl(u32 _CommandAddress)
LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS"); LOG(WII_IPC_FILEIO, "FileIO: ISFS_IOCTL_GETFILESTATS");
LOG(WII_IPC_FILEIO, " Length: %i Seek: %i", m_FileLength, Position); 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); Memory::Write_U32(Position, BufferOut+4);
} }
break; break;

View File

@ -65,7 +65,7 @@ private:
}; };
FILE* m_pFileHandle; FILE* m_pFileHandle;
u32 m_FileLength; u64 m_FileLength;
std::string m_Filename; std::string m_Filename;
}; };

View File

@ -432,6 +432,7 @@ void stfdx(UGeckoInstruction _inst)
// __________________________________________________________________________________________________ // __________________________________________________________________________________________________
// stfiwx // stfiwx
// TODO - examine what this really does // TODO - examine what this really does
// Stores Floating points into Integers indeXed
void stfiwx(UGeckoInstruction _inst) void stfiwx(UGeckoInstruction _inst)
{ {
u32 uAddress = Helper_Get_EA_X(_inst); u32 uAddress = Helper_Get_EA_X(_inst);