mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-02-11 00:40:16 +00:00
Removes wx from gcmemcard, misc code cleanup
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@869 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
2195e645fd
commit
f417aac20b
@ -255,11 +255,9 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
|||||||
),
|
),
|
||||||
wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
|
wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
|
||||||
const char * fileName2 = temp2.ToAscii();
|
const char * fileName2 = temp2.ToAscii();
|
||||||
|
if (temp.length() > 0)
|
||||||
int len = temp.length();
|
|
||||||
if (len > 0)
|
|
||||||
{
|
{
|
||||||
memoryCard[0]->ImportGci(fileName, len, fileName2);
|
memoryCard[0]->ImportGci(fileName, fileName2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -278,11 +276,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();
|
||||||
|
if (temp.length() > 0)
|
||||||
int len = temp.length();
|
|
||||||
if(len > 0)
|
|
||||||
{
|
{
|
||||||
memoryCard[0]->ImportGci(fileName, len, 0);
|
memoryCard[0]->ImportGci(fileName, 0);
|
||||||
memoryCard[0]->Save();
|
memoryCard[0]->Save();
|
||||||
ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
|
ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
|
||||||
}
|
}
|
||||||
@ -303,10 +299,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();
|
if (temp.length() > 0)
|
||||||
if(len > 0)
|
|
||||||
{
|
{
|
||||||
memoryCard[1]->ImportGci(fileName, len, 0);
|
memoryCard[1]->ImportGci(fileName, 0);
|
||||||
memoryCard[1]->Save();
|
memoryCard[1]->Save();
|
||||||
ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
|
ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
|
||||||
}
|
}
|
||||||
|
@ -230,10 +230,7 @@ u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents)
|
|||||||
firstFree3 = max<int>(firstFree3,(int)(BE16(dir.Dir[i].FirstBlock) + BE16(dir.Dir[i].BlockCount)));
|
firstFree3 = max<int>(firstFree3,(int)(BE16(dir.Dir[i].FirstBlock) + BE16(dir.Dir[i].BlockCount)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
firstFree1 = max<int>(firstFree1, max<int>(firstFree3, firstFree2));
|
||||||
if(firstFree2 > firstFree1) firstFree1 = firstFree2;
|
|
||||||
if(firstFree3 > firstFree1) firstFree1 = firstFree3;
|
|
||||||
|
|
||||||
if(firstFree1>=126)
|
if(firstFree1>=126)
|
||||||
{
|
{
|
||||||
// TODO: show messagebox about the error
|
// TODO: show messagebox about the error
|
||||||
@ -301,12 +298,12 @@ bool GCMemcard::GetFileData(u32 index, u8*dest) //index in the directory array
|
|||||||
memcpy(dest,mc_data + 0x2000*(block-5),0x2000);
|
memcpy(dest,mc_data + 0x2000*(block-5),0x2000);
|
||||||
dest+=0x2000;
|
dest+=0x2000;
|
||||||
|
|
||||||
if(block + saveLength != memcardSize)
|
int nextblock = bswap16(bat.Map[block-5]);
|
||||||
{
|
if(block + saveLength != memcardSize && nextblock > 0)
|
||||||
int nextblock=bswap16(bat.Map[block-5]);
|
{ //Fixes for older memcards that were not initialized with FF
|
||||||
assert(nextblock>0);
|
block = nextblock;
|
||||||
block=nextblock;
|
}
|
||||||
}else block=0xffff;
|
else block = 0xffff;
|
||||||
}
|
}
|
||||||
while(block!=0xffff);
|
while(block!=0xffff);
|
||||||
|
|
||||||
@ -638,12 +635,12 @@ u32 GCMemcard::CopyFrom(GCMemcard& source, u32 index)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileName2)
|
u32 GCMemcard::ImportGci(const char *fileName, const char *fileName2)
|
||||||
{
|
{
|
||||||
if (!mcdFile && !fileName2) return 0;
|
if (!mcdFile && !fileName2) return 0;
|
||||||
|
|
||||||
wxFFile gci(wxString::FromAscii(fileName), _T("rb"));
|
FILE *gci = fopen(_T(fileName), _T("rb"));
|
||||||
if (!gci.IsOpened()) return 0;
|
if (!gci) return 0;
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -653,16 +650,15 @@ u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileNam
|
|||||||
};
|
};
|
||||||
int offset;
|
int offset;
|
||||||
char * tmp = new char[0xD];
|
char * tmp = new char[0xD];
|
||||||
u16 tmpU16;
|
std::string fileType;
|
||||||
|
SplitPath(fileName, NULL, NULL, &fileType);
|
||||||
|
|
||||||
const char * fileType = (char*) fileName + endFile - 3;
|
if( !strcasecmp(fileType.c_str(), ".gci") && !fileName2)
|
||||||
|
|
||||||
if( !strcasecmp(fileType, "gci") && !fileName2) // Extension can be either case
|
|
||||||
offset = GCI;
|
offset = GCI;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
gci.Read(tmp, 0xD);
|
fread(tmp, 1, 0xD, gci);
|
||||||
if (!strcasecmp(fileType, "gcs")) // Extension can be either case
|
if (!strcasecmp(fileType.c_str(), ".gcs"))
|
||||||
{
|
{
|
||||||
if (!memcmp(tmp, "GCSAVE", 6)) // Header must be uppercase
|
if (!memcmp(tmp, "GCSAVE", 6)) // Header must be uppercase
|
||||||
offset = GCS;
|
offset = GCS;
|
||||||
@ -674,7 +670,7 @@ u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileNam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
if (!strcasecmp(fileType, "sav")) // Extension can be either case
|
if (!strcasecmp(fileType.c_str(), ".sav"))
|
||||||
{
|
{
|
||||||
if (!memcmp(tmp, "DATELGC_SAVE", 0xC)) // Header must be uppercase
|
if (!memcmp(tmp, "DATELGC_SAVE", 0xC)) // Header must be uppercase
|
||||||
offset = SAV;
|
offset = SAV;
|
||||||
@ -692,27 +688,26 @@ u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileNam
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gci.Seek(offset, wxFromStart);
|
fseek(gci, offset, SEEK_SET);
|
||||||
|
|
||||||
DEntry *d = new DEntry;
|
DEntry *d = new DEntry;
|
||||||
gci.Read(d, 0x40);
|
fread(d, 1, 0x40, gci);
|
||||||
|
int fStart = ftell(gci);
|
||||||
|
fseek(gci, 0, SEEK_END);
|
||||||
|
int length = ftell(gci) - fStart;
|
||||||
|
fseek(gci, offset + 0x40, SEEK_SET);
|
||||||
|
|
||||||
switch(offset){
|
switch(offset){
|
||||||
case GCS:
|
case GCS:
|
||||||
// field containing the Block count as displayed within
|
{ // field containing the Block count as displayed within
|
||||||
// the GameSaves software 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);
|
int blockCount = length / 0x2000;
|
||||||
if (tmpU16<0x100)
|
d->BlockCount[0] = u8(blockCount >> 8);
|
||||||
{
|
d->BlockCount[1] = u8(blockCount);
|
||||||
d->BlockCount[1] = (u8)tmpU16;
|
}
|
||||||
}
|
|
||||||
else{
|
|
||||||
d->BlockCount[0] = (u8)(tmpU16 - 0xFF);
|
|
||||||
d->BlockCount[1] = 0xFF;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case SAV:
|
case SAV:
|
||||||
// swap byte pairs
|
// swap byte pairs
|
||||||
@ -734,28 +729,26 @@ u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileNam
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// TODO: verify file length
|
// TODO: verify file length
|
||||||
assert(((int)gci.Length() - offset) == ((BE16(d->BlockCount) * 0x2000) + 0x40));
|
assert(length == BE16(d->BlockCount) * 0x2000);
|
||||||
|
assert(ftell(gci) == offset + 0x40); // Verify correct file position
|
||||||
|
|
||||||
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);
|
fread(t, 1, size, gci);
|
||||||
|
fclose(gci);
|
||||||
gci.Close();
|
|
||||||
|
|
||||||
u32 ret = 0;
|
u32 ret = 0;
|
||||||
if(!fileName2)
|
if(fileName2)
|
||||||
{
|
{
|
||||||
wxFFile gci2(wxString::FromAscii(fileName2), _T("wb"));
|
FILE * gci2 = fopen(_T(fileName2), _T("wb"));
|
||||||
if (!gci2.IsOpened()) return 0;
|
if (!gci2) return 0;
|
||||||
gci2.Seek(0, wxFromStart);
|
fseek(gci2, 0, SEEK_SET);
|
||||||
gci2.Write(d, 0x40);
|
fwrite(d, 1, 0x40, gci2);
|
||||||
int fileBlocks = BE16(d->BlockCount);
|
int fileBlocks = BE16(d->BlockCount);
|
||||||
gci2.Seek(0x40, wxFromStart);
|
fseek(gci2, 0x40, SEEK_SET);
|
||||||
gci2.Write(t, 0x2000 * fileBlocks);
|
fwrite(t, 0, 0x2000 * fileBlocks, gci2);
|
||||||
gci2.Close();
|
fclose(gci2);
|
||||||
}
|
}
|
||||||
else ret = ImportFile(*d, t);
|
else ret = ImportFile(*d, t);
|
||||||
|
|
||||||
|
|
||||||
delete []t;
|
delete []t;
|
||||||
@ -766,28 +759,21 @@ u32 GCMemcard::ImportGci(const char *fileName, int endFile, const char *fileNam
|
|||||||
|
|
||||||
bool GCMemcard::ExportGci(u32 index, const char *fileName)
|
bool GCMemcard::ExportGci(u32 index, const char *fileName)
|
||||||
{
|
{
|
||||||
wxFFile gci(wxString::FromAscii(fileName), _T("wb"));
|
FILE *gci = fopen(_T(fileName), _T("wb"));
|
||||||
|
if(!gci) return false;
|
||||||
if (!gci.IsOpened()) return false;
|
fseek(gci, 0, SEEK_SET);
|
||||||
|
|
||||||
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);
|
fwrite(&d, 1, 0x40, gci);
|
||||||
|
|
||||||
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);
|
fseek(gci, 0x40, SEEK_SET);
|
||||||
|
fwrite(t, 1, 0x2000 * BE16(d.BlockCount), gci);
|
||||||
gci.Seek(0x40, wxFromStart);
|
fclose(gci);
|
||||||
gci.Write(t, 0x2000 * fileBlocks);
|
|
||||||
|
|
||||||
gci.Close();
|
|
||||||
delete []t;
|
delete []t;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Common.h"
|
#include "Common.h"
|
||||||
|
#include "StringUtil.h"
|
||||||
|
|
||||||
class GCMemcard
|
class GCMemcard
|
||||||
{
|
{
|
||||||
@ -158,7 +159,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, const char* fileName2);
|
||||||
|
|
||||||
// reads the banner image
|
// reads the banner image
|
||||||
bool ReadBannerRGBA8(u32 index, u32* buffer);
|
bool ReadBannerRGBA8(u32 index, u32* buffer);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user