An attempt to fix my coding style to match wiki page

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@858 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
LPFaint99 2008-10-14 05:19:31 +00:00
parent d84fa6195c
commit 6b4169e5b1
3 changed files with 74 additions and 70 deletions

View File

@ -234,7 +234,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
} }
break; break;
case ID_CONVERTTOGCI: case ID_CONVERTTOGCI:
{//Wont compile without brackets?? VC++ Express { // Wont compile without brackets?? VC++ Express
wxString temp = wxFileSelector(_T("Select the save file to convert"), wxString temp = wxFileSelector(_T("Select the save file to convert"),
wxEmptyString, wxEmptyString, wxEmptyString,wxString::Format wxEmptyString, wxEmptyString, wxEmptyString,wxString::Format
( (
@ -257,9 +257,9 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
const char * fileName2 = temp2.ToAscii(); const char * fileName2 = temp2.ToAscii();
int len = temp.length(); int len = temp.length();
if(len>0) if (len > 0)
{ {
memoryCard[0]->ImportGci(fileName,len,fileName2); memoryCard[0]->ImportGci(fileName, len, fileName2);
} }
} }
break; break;
@ -280,9 +280,9 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
const char * fileName = temp.ToAscii(); const char * fileName = temp.ToAscii();
int len = temp.length(); int len = temp.length();
if(len>0) if(len > 0)
{ {
memoryCard[0]->ImportGci(fileName,len,0); memoryCard[0]->ImportGci(fileName, len, 0);
memoryCard[0]->Save(); memoryCard[0]->Save();
ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0); ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
} }
@ -304,9 +304,9 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
wxFD_OPEN | wxFD_FILE_MUST_EXIST); wxFD_OPEN | wxFD_FILE_MUST_EXIST);
const char * fileName = temp.ToAscii(); const char * fileName = temp.ToAscii();
int len = temp.length(); int len = temp.length();
if(len>0) if(len > 0)
{ {
memoryCard[1]->ImportGci(fileName,len,0); memoryCard[1]->ImportGci(fileName, len, 0);
memoryCard[1]->Save(); memoryCard[1]->Save();
ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0); ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
} }
@ -325,7 +325,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
wxFD_OVERWRITE_PROMPT|wxFD_SAVE); wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
const char * fileName = temp.ToAscii(); const char * fileName = temp.ToAscii();
if (temp.length()>0) if (temp.length() > 0)
memoryCard[0]->ExportGci(index0, fileName); memoryCard[0]->ExportGci(index0, fileName);
} }
break; break;
@ -342,7 +342,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
wxFD_OVERWRITE_PROMPT|wxFD_SAVE); wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
const char * fileName = temp.ToAscii(); const char * fileName = temp.ToAscii();
if (temp.length()>0) if (temp.length() > 0)
memoryCard[1]->ExportGci(index1, fileName); memoryCard[1]->ExportGci(index1, fileName);
} }
break; break;

View File

@ -611,10 +611,10 @@ u32 GCMemcard::CopyFrom(GCMemcard& source, u32 index)
u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileName2) u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileName2)
{ {
if(!mcdFile && !fileName2) return 0; if (!mcdFile && !fileName2) return 0;
wxFFile gci(wxString::FromAscii(fileName), _T("rb")); wxFFile gci(wxString::FromAscii(fileName), _T("rb"));
if(!gci.IsOpened())return 0; if (!gci.IsOpened()) return 0;
enum enum
{ {
@ -626,87 +626,91 @@ u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileNam
char * tmp = new char[0xD]; char * tmp = new char[0xD];
u16 tmpU16; u16 tmpU16;
const char * fileType= (char*)fileName+ endFile-3; const char * fileType = (char*) fileName + endFile - 3;
if(!strcasecmp(fileType,"gci") && !fileName2)//Extension can be either case if( !strcasecmp(fileType, "gci") && !fileName2) // Extension can be either case
offset = GCI; offset = GCI;
else else
{ {
gci.Read(tmp,0xD); gci.Read(tmp, 0xD);
if(!strcasecmp(fileType,"gcs"))//Extension can be either case if (!strcasecmp(fileType, "gcs")) // Extension can be either case
{ {
if(!memcmp(tmp,"GCSAVE",6)) //Header must be uppercase if (!memcmp(tmp, "GCSAVE", 6)) // Header must be uppercase
offset = GCS; offset = GCS;
else else
{ {
//TODO error message, file has gsc extension but does not have a correct header // TODO: Add error message
// file has gsc extension but does not have a correct header
return 0; return 0;
} }
} }
else{ else{
if(!strcasecmp(fileType,"sav"))//Extension can be either case if (!strcasecmp(fileType, "sav")) // Extension can be either case
{ {
if(!memcmp(tmp,"DATELGC_SAVE",0xC))//Header must be uppercase if (!memcmp(tmp, "DATELGC_SAVE", 0xC)) // Header must be uppercase
offset = SAV; offset = SAV;
else else
{ {
//TODO error message, file has sav extension but does not have a correct header // TODO: Add error message
//file has sav extension but does not have a correct header
return 0; return 0;
} }
} }
else else
{ {
//TODO error message, file has invalid extension // TODO: Add error message, file has invalid extension
return 0; return 0;
} }
} }
} }
gci.Seek(offset,wxFromStart); gci.Seek(offset, wxFromStart);
DEntry *d = new DEntry; DEntry *d = new DEntry;
gci.Read(d,0x40); gci.Read(d, 0x40);
switch(offset){ switch(offset){
case GCS: case GCS:
//field containing the Block count as displayed within the GameSaves software // field containing the Block count as displayed within
//is not stored in the GCS file. // the GameSaves software is not stored in the GCS file.
//It is stored only within the corresponding GSV file. // It is stored only within the corresponding GSV file.
//If the GCS file is added without using the GameSaves software, // If the GCS file is added without using the GameSaves software,
//the value stored is always "1" // the value stored is always "1"
tmpU16 =(((int)gci.Length()-offset-0x40)/0x2000); tmpU16 = (((int)gci.Length() - offset - 0x40) / 0x2000);
if(tmpU16<0x100){ if (tmpU16<0x100)
{
d->BlockCount[1] = (u8)tmpU16; d->BlockCount[1] = (u8)tmpU16;
} }
else{ else{
d->BlockCount[0] = (u8)(tmpU16-0xFF); d->BlockCount[0] = (u8)(tmpU16 - 0xFF);
d->BlockCount[1] = 0xFF; d->BlockCount[1] = 0xFF;
} }
break; break;
case SAV: case SAV:
//swap byte pairs // swap byte pairs
//0x2C and 0x2D,0x2E and 0x2F,0x30 and 0x31,0x32 and 0x33,0x34 and 0x35, // 0x2C and 0x2D, 0x2E and 0x2F, 0x30 and 0x31, 0x32 and 0x33,
//0x36 and 0x37,0x38 and 0x39,0x3A and 0x3B,0x3C and 0x3D,0x3E and 0x3F. // 0x34 and 0x35, 0x36 and 0x37, 0x38 and 0x39, 0x3A and 0x3B,
SWAP((d->ImageOffset)); // 0x3C and 0x3D,0x3E and 0x3F.
SWAP(&(d->ImageOffset[2])); ArrayByteSwap((d->ImageOffset));
SWAP((d->IconFmt)); ArrayByteSwap(&(d->ImageOffset[2]));
SWAP((d->AnimSpeed)); ArrayByteSwap((d->IconFmt));
varSwap(&d->Permissions,&d->CopyCounter); ArrayByteSwap((d->AnimSpeed));
SWAP((d->FirstBlock)); ByteSwap(&d->Permissions, &d->CopyCounter);
SWAP((d->BlockCount)); ArrayByteSwap((d->FirstBlock));
SWAP((d->Unused2)); ArrayByteSwap((d->BlockCount));
SWAP((d->CommentsAddr)); ArrayByteSwap((d->Unused2));
SWAP(&(d->CommentsAddr[2])); ArrayByteSwap((d->CommentsAddr));
ArrayByteSwap(&(d->CommentsAddr[2]));
break; break;
default: default:
break; break;
} }
//TODO verify file length // TODO: verify file length
assert(((int)gci.Length()-offset)== ((BE16(d->BlockCount)* 0x2000) + 0x40)); assert(((int)gci.Length() - offset) == ((BE16(d->BlockCount) * 0x2000) + 0x40));
u32 size=BE16((d->BlockCount))*0x2000; u32 size = BE16((d->BlockCount)) * 0x2000;
u8 *t = new u8[size]; u8 *t = new u8[size];
gci.Read(t,size); gci.Read(t, size);
gci.Close(); gci.Close();
@ -714,19 +718,19 @@ u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileNam
if(!fileName2) if(!fileName2)
{ {
wxFFile gci2(wxString::FromAscii(fileName2), _T("wb")); wxFFile gci2(wxString::FromAscii(fileName2), _T("wb"));
if(!gci2.IsOpened())return 0; if (!gci2.IsOpened()) return 0;
gci2.Seek(0,wxFromStart); gci2.Seek(0, wxFromStart);
gci2.Write(d,0x40); gci2.Write(d, 0x40);
int fileBlocks=BE16(d->BlockCount); int fileBlocks = BE16(d->BlockCount);
gci2.Seek(0x40,wxFromStart); gci2.Seek(0x40, wxFromStart);
gci2.Write(t,0x2000*fileBlocks); gci2.Write(t, 0x2000 * fileBlocks);
gci2.Close(); gci2.Close();
} }
else ret = ImportFile(*d,t); else ret = ImportFile(*d, t);
delete[] t; delete []t;
delete[] tmp; delete []tmp;
delete d; delete d;
return ret; return ret;
} }
@ -735,25 +739,25 @@ bool GCMemcard::ExportGci(u32 index, const char *fileName)
{ {
wxFFile gci(wxString::FromAscii(fileName), _T("wb")); wxFFile gci(wxString::FromAscii(fileName), _T("wb"));
if(!gci.IsOpened())return false; if (!gci.IsOpened()) return false;
gci.Seek(0,wxFromStart); gci.Seek(0, wxFromStart);
DEntry d; DEntry d;
if(!this->GetFileInfo(index,d)) return false; if(!this->GetFileInfo(index, d)) return false;
gci.Write(&d,0x40); gci.Write(&d, 0x40);
u8 *t = new u8[this->GetFileSize(index)*0x2000]; u8 *t = new u8[this->GetFileSize(index) * 0x2000];
if(!this->GetFileData(index,t)) return false; if (!this->GetFileData(index, t)) return false;
int fileBlocks=BE16(d.BlockCount); int fileBlocks = BE16(d.BlockCount);
gci.Seek(0x40,wxFromStart); gci.Seek(0x40, wxFromStart);
gci.Write(t,0x2000*fileBlocks); gci.Write(t, 0x2000 * fileBlocks);
gci.Close(); gci.Close();
delete[] t; delete []t;
return true; return true;
} }

View File

@ -23,9 +23,9 @@ typedef unsigned short u16;
typedef unsigned int u32; typedef unsigned int u32;
#define SWAP(a) (varSwap(a,a+sizeof(u8))); #define ArrayByteSwap(a) (ByteSwap(a, a+sizeof(u8)));
void varSwap(u8 *valueA,u8 *valueB); void ByteSwap(u8 *valueA, u8 *valueB);
u16 __inline bswap16(u16 s) u16 __inline bswap16(u16 s)
{ {
@ -187,7 +187,7 @@ public:
bool ExportGci(u32 index, const char* fileName); bool ExportGci(u32 index, const char* fileName);
// reads a .gci/.gcs/.sav file and calls ImportFile or saves out a gci file // reads a .gci/.gcs/.sav file and calls ImportFile or saves out a gci file
u32 ImportGci(const char* fileName, int endFile,const char* fileName2); u32 ImportGci(const char* fileName, int endFile, const char* fileName2);
// reads the banner image // reads the banner image
bool ReadBannerRGBA8(u32 index, u32* buffer); bool ReadBannerRGBA8(u32 index, u32* buffer);