mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-26 12:35:27 +00:00
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:
parent
064d45024c
commit
116509985a
@ -28,44 +28,47 @@
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -65,7 +65,7 @@ private:
|
||||
};
|
||||
|
||||
FILE* m_pFileHandle;
|
||||
u32 m_FileLength;
|
||||
u64 m_FileLength;
|
||||
|
||||
std::string m_Filename;
|
||||
};
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user