mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-09 03:40:05 +00:00
variables, writeable strings and dangerously shadowed variables. index(), gamma(), exp() and y0() are POSIX functions and using those names can cause namespace confusion. A number of C files were missing the final newline required by ANSI C and some versions of GCC are pedantic enough to complain about this. These changes simply the scons build, allowing us to get rid of filterWarnings which is simply more trouble than it's worth. git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5574 8ced0084-cf51-0410-be5f-012b33b47a6e
149 lines
2.3 KiB
C++
149 lines
2.3 KiB
C++
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "File.h"
|
|
|
|
|
|
namespace W32Util
|
|
{
|
|
|
|
File::File()
|
|
{
|
|
fileHandle = INVALID_HANDLE_VALUE;
|
|
isOpen=false;
|
|
}
|
|
|
|
File::~File()
|
|
{
|
|
|
|
}
|
|
|
|
|
|
bool File::Open(const TCHAR *filename, eFileMode _mode)
|
|
{
|
|
mode = _mode;
|
|
//it's time to open the file
|
|
fileHandle = CreateFile(filename,
|
|
mode==FILE_READ ? GENERIC_READ : GENERIC_WRITE, //open mode
|
|
mode == FILE_READ ? FILE_SHARE_READ : NULL, //sharemode
|
|
NULL, //security
|
|
mode==FILE_READ ? OPEN_EXISTING : CREATE_ALWAYS, //create mode
|
|
FILE_ATTRIBUTE_NORMAL, //atrributes
|
|
NULL); //template
|
|
|
|
if (fileHandle == INVALID_HANDLE_VALUE)
|
|
isOpen=false;
|
|
else
|
|
isOpen=true;
|
|
|
|
return isOpen;
|
|
}
|
|
|
|
|
|
void File::Close()
|
|
{
|
|
if (isOpen)
|
|
{
|
|
//close the file and reset variables
|
|
CloseHandle(fileHandle);
|
|
fileHandle=INVALID_HANDLE_VALUE;
|
|
isOpen=false;
|
|
}
|
|
}
|
|
|
|
int File::GetSize()
|
|
{
|
|
if (!isOpen) //of course
|
|
return 0;
|
|
else
|
|
return GetFileSize(fileHandle,0);
|
|
}
|
|
|
|
int File::Write(void *data, int size) //let's do some writing
|
|
{
|
|
if (isOpen)
|
|
{
|
|
DWORD written;
|
|
WriteFile(fileHandle, data, size, &written,0);
|
|
return written; //we return the number of bytes that actually got written
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
int File::Read(void *data, int size)
|
|
{
|
|
if (isOpen)
|
|
{
|
|
DWORD wasRead;
|
|
ReadFile(fileHandle, data, size, &wasRead,0);
|
|
return wasRead; //we return the number of bytes that actually was read
|
|
}
|
|
else
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
int File::WR(void *data, int size)
|
|
{
|
|
if (mode==FILE_READ)
|
|
return Read(data,size);
|
|
else
|
|
return Write(data,size);
|
|
}
|
|
bool File::MagicCookie(int cookie)
|
|
{
|
|
if (mode==FILE_READ)
|
|
{
|
|
if (ReadInt()!=cookie)
|
|
{
|
|
char mojs[5],temp[256];
|
|
mojs[4]=0;
|
|
*(int*)mojs=cookie;
|
|
sprintf(temp,"W32Util::File: Magic Cookie %s is bad!",mojs);
|
|
MessageBoxA(0,temp,"Error reading file",MB_ICONERROR);
|
|
return false;
|
|
}
|
|
else
|
|
return true;
|
|
}
|
|
else if (mode==FILE_WRITE)
|
|
{
|
|
WriteInt(cookie);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
int File::ReadInt()
|
|
{
|
|
int temp;
|
|
if (Read(&temp, sizeof(int)))
|
|
return temp;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
void File::WriteInt(int i)
|
|
{
|
|
Write(&i,sizeof(int));
|
|
}
|
|
|
|
char File::ReadChar()
|
|
{
|
|
char temp;
|
|
if (Read(&temp, sizeof(char)))
|
|
return temp;
|
|
else
|
|
return 0;
|
|
}
|
|
|
|
void File::WriteChar(char i)
|
|
{
|
|
Write(&i,sizeof(char));
|
|
}
|
|
}
|