Some WIP work on MemcardManager, nothing for enduser.

Mostly to avoid using a hexeditor to look at dir entries

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1874 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
LPFaint99 2009-01-15 06:06:30 +00:00
parent 4a325d466d
commit aced3c00fd
4 changed files with 246 additions and 100 deletions

View File

@ -19,7 +19,7 @@
#include "MemcardManager.h"
#include "Common.h"
#include "wx/mstream.h"
//#define DEBUG_MCM true
const u8 hdr[] = {
0x42,0x4D,
0x38,0x30,0x00,0x00,
@ -132,8 +132,15 @@ CMemcardManager::~CMemcardManager()
}
MemcardManagerIni.Load(CONFIG_FILE);
MemcardManagerIni.Set("MemcardManager", "Items per page", itemsPerPage);
if (!DefaultMemcard[SLOT_A].empty() && (strcmp(DefaultMemcard[SLOT_A].c_str(), ".")))
MemcardManagerIni.Set("MemcardManager", "DefaultMemcardA", DefaultMemcard[SLOT_A]);
else
MemcardManagerIni.DeleteKey("MemcardManager", "DefaultMemcardA");
if (!DefaultMemcard[SLOT_B].empty() && (strcmp(DefaultMemcard[SLOT_B].c_str(), ".")))
MemcardManagerIni.Set("MemcardManager", "DefaultMemcardB", DefaultMemcard[SLOT_B]);
else
MemcardManagerIni.DeleteKey("MemcardManager", "DefaultMemcardB");
MemcardManagerIni.Save(CONFIG_FILE);
}
@ -149,11 +156,24 @@ CMemcardManager::CMemcardListCtrl::CMemcardListCtrl(wxWindow* parent, const wxWi
MemcardManagerIni.Get("MemcardManager", "cBlocks", &column[COLUMN_BLOCKS], true);
MemcardManagerIni.Get("MemcardManager", "cBanner", &column[COLUMN_BANNER], true);
MemcardManagerIni.Get("MemcardManager", "cFirst Block", &column[COLUMN_FIRSTBLOCK], true);
#ifdef DEBUG_MCM
MemcardManagerIni.Get("MemcardManager", "cDebug", &column[NUMBER_OF_COLUMN], false);
#else
column[NUMBER_OF_COLUMN] = false;
#endif
for(int i = COLUMN_GAMECODE; i < NUMBER_OF_COLUMN; i++)
{
column[i] = column[NUMBER_OF_COLUMN];
}
}
else
{
usePages = true;
for (int i = 0; i < NUMBER_OF_COLUMN; i++) column[i] = true;
for (int i = 0; i < NUMBER_OF_COLUMN; i++)
{
if ( i > COLUMN_FIRSTBLOCK) column[i] = false;
else column[i] = true;
}
}
twoCardsLoaded = false;
prevPage = false;
@ -171,6 +191,9 @@ CMemcardManager::CMemcardListCtrl::~CMemcardListCtrl()
MemcardManagerIni.Set("MemcardManager", "cBlocks", column[COLUMN_BLOCKS]);
MemcardManagerIni.Set("MemcardManager", "cBanner", column[COLUMN_BANNER]);
MemcardManagerIni.Set("MemcardManager", "cFirst Block", column[COLUMN_FIRSTBLOCK]);
#ifdef DEBUG_MCM
MemcardManagerIni.Set("MemcardManager", "cDebug", column[NUMBER_OF_COLUMN]);
#endif
MemcardManagerIni.Save(CONFIG_FILE);
}
@ -179,9 +202,9 @@ void CMemcardManager::CreateGUIControls()
// Create the controls for both memcards
// Loading invalid .raw files should no longer crash the app
m_MemcardPath[SLOT_A] = new wxFilePickerCtrl(this, ID_MEMCARDPATH_A, wxEmptyString, wxT("Choose a memory card:"),
wxT("Raw memcards (*.raw)|*.raw"), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL|wxFLP_OPEN);
wxT("Gamecube Memory Cards (*.raw,*.gcp)|*.raw;*.gcp"), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL|wxFLP_OPEN);
m_MemcardPath[SLOT_B] = new wxFilePickerCtrl(this, ID_MEMCARDPATH_B, wxEmptyString, wxT("Choose a memory card:"),
wxT("Raw memcards (*.raw)|*.raw"), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL|wxFLP_OPEN);
wxT("Gamecube Memory Cards (*.raw,*.gcp)|*.raw;*.gcp"), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL|wxFLP_OPEN);
m_MemcardList[SLOT_A] = new CMemcardListCtrl(this, ID_MEMCARDLIST_A, wxDefaultPosition, wxSize(350,400),
wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT | wxLC_SINGLE_SEL);
@ -271,7 +294,7 @@ void CMemcardManager::CreateGUIControls()
this->SetSizer(sMain);
sMain->SetSizeHints(this);
Fit();
for (int i = 0; i < 2; i++)
for (int i = SLOT_A; i <= SLOT_B; i++)
{
m_PrevPage[i]->Disable();
m_NextPage[i]->Disable();
@ -280,7 +303,7 @@ void CMemcardManager::CreateGUIControls()
m_SaveImport[i]->Disable();
m_SaveExport[i]->Disable();
m_Delete[i]->Disable();
if (strcasecmp(DefaultMemcard[i].c_str(), "."))
if (strcmp(DefaultMemcard[i].c_str(), "."))
{
m_MemcardPath[i]->SetPath(wxString::FromAscii(DefaultMemcard[i].c_str()));
ChangePath(ID_MEMCARDPATH_A + i);
@ -316,6 +339,7 @@ void CMemcardManager::ChangePath(int id)
}
if (!strcasecmp(m_MemcardPath[slot2]->GetPath().mb_str(), m_MemcardPath[slot]->GetPath().mb_str()))
{
if(!m_MemcardPath[slot]->GetPath().IsEmpty())
PanicAlert(E_ALREADYOPENED);
}
else if (ReloadMemcard(m_MemcardPath[slot]->GetPath().mb_str(), slot))
@ -421,6 +445,12 @@ void CMemcardManager::OnMenuChange(wxCommandEvent& event)
case ID_MEMCARDPATH_B:
DefaultMemcard[SLOT_B] = m_MemcardPath[SLOT_B]->GetPath().mb_str();
break;
case NUMBER_OF_COLUMN:
for( int i = COLUMN_GAMECODE; i < NUMBER_OF_COLUMN; i++)
{
m_MemcardList[SLOT_A]->column[i] = !m_MemcardList[SLOT_A]->column[i];
m_MemcardList[SLOT_B]->column[i] = !m_MemcardList[SLOT_B]->column[i];
}
default:
m_MemcardList[SLOT_A]->column[event.GetId()] = !m_MemcardList[SLOT_A]->column[event.GetId()];
m_MemcardList[SLOT_B]->column[event.GetId()] = !m_MemcardList[SLOT_B]->column[event.GetId()];
@ -478,7 +508,11 @@ bool CMemcardManager::CopyDeleteSwitch(u32 error, int slot)
PanicAlert(E_GCSFAIL);
break;
case FAIL:
if (slot == -1) return false;
if (slot == -1)
{
PanicAlert("Export Failed");
return false;
}
PanicAlert(E_INVALID);
break;
case WRITEFAIL:
@ -601,6 +635,8 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
wxString wxBlock;
wxString wxFirstBlock;
wxString wxLabel;
wxString tString;
int j;
if (memoryCard[card]) delete memoryCard[card];
@ -619,6 +655,19 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
m_MemcardList[card]->InsertColumn(COLUMN_ICON, _T("Icon"));
m_MemcardList[card]->InsertColumn(COLUMN_BLOCKS, _T("Blocks"));
m_MemcardList[card]->InsertColumn(COLUMN_FIRSTBLOCK, _T("First Block"));
#ifdef DEBUG_MCM
m_MemcardList[card]->InsertColumn(COLUMN_GAMECODE, _T("GameCode"));
m_MemcardList[card]->InsertColumn(COLUMN_MAKERCODE, _T("MakerCode"));
m_MemcardList[card]->InsertColumn(COLUMN_BIFLAGS, _T("BIFLAGS"));
m_MemcardList[card]->InsertColumn(COLUMN_FILENAME, _T("FILENAME"));
m_MemcardList[card]->InsertColumn(COLUMN_MODTIME, _T("MODTIME"));
m_MemcardList[card]->InsertColumn(COLUMN_IMAGEADD, _T("IMAGEADD"));
m_MemcardList[card]->InsertColumn(COLUMN_ICONFMT, _T("ICONFMT"));
m_MemcardList[card]->InsertColumn(COLUMN_ANIMSPEED, _T("ANIMSPEED"));
m_MemcardList[card]->InsertColumn(COLUMN_PERMISSIONS, _T("PERMISSIONS"));
m_MemcardList[card]->InsertColumn(COLUMN_COPYCOUNTER, _T("COPYCOUNTER"));
m_MemcardList[card]->InsertColumn(COLUMN_COMMENTSADDRESS, _T("COMMENTSADDRESS"));
#endif
wxImageList *list = m_MemcardList[card]->GetImageList(wxIMAGE_LIST_SMALL);
list->RemoveAll();
@ -686,15 +735,15 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
int index = m_MemcardList[card]->InsertItem(j, wxEmptyString);
m_MemcardList[card]->SetItem(index, COLUMN_BANNER, wxEmptyString);
if (!memoryCard[card]->GetComment1(j, title)) title[0]=0;
if (!memoryCard[card]->DEntry_Comment1(j, title)) title[0]=0;
m_MemcardList[card]->SetItem(index, COLUMN_TITLE, wxString::FromAscii(title));
if (!memoryCard[card]->GetComment2(j, comment)) comment[0]=0;
if (!memoryCard[card]->DEntry_Comment2(j, comment)) comment[0]=0;
m_MemcardList[card]->SetItem(index, COLUMN_COMMENT, wxString::FromAscii(comment));
blocks = memoryCard[card]->GetFileSize(j);
blocks = memoryCard[card]->DEntry_BlockCount(j);
if (blocks == 0xFFFF) blocks = 0;
wxBlock.Printf(wxT("%10d"), blocks);
m_MemcardList[card]->SetItem(index,COLUMN_BLOCKS, wxBlock);
firstblock = memoryCard[card]->GetFirstBlock(j);
firstblock = memoryCard[card]->DEntry_FirstBlock(j);
if (firstblock == 0xFFFF) firstblock = 3; // to make firstblock -1
wxFirstBlock.Printf(wxT("%15d"), firstblock-4);
m_MemcardList[card]->SetItem(index,COLUMN_FIRSTBLOCK, wxFirstBlock);
@ -705,6 +754,45 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
m_MemcardList[card]->SetItemImage(index, images[j*2]);
m_MemcardList[card]->SetItemColumnImage(index, COLUMN_ICON, images[j*2+1]);
}
#ifdef DEBUG_MCM
char gC[5];
if (!memoryCard[card]->DEntry_GameCode(j, gC)) gC[0]=0;
m_MemcardList[card]->SetItem(index, COLUMN_GAMECODE, wxString::FromAscii(gC));
char mC[3];
if (!memoryCard[card]->DEntry_Markercode(j, mC)) mC[0]=0;
m_MemcardList[card]->SetItem(index, COLUMN_MAKERCODE, wxString::FromAscii(mC));
char bI[9];
if (!memoryCard[card]->DEntry_BIFlags(j, bI)) bI[0]=0;
m_MemcardList[card]->SetItem(index, COLUMN_BIFLAGS, wxString::FromAscii(bI));
char fN[32];
if (!memoryCard[card]->DEntry_FileName(j, fN)) fN[0]=0;
m_MemcardList[card]->SetItem(index, COLUMN_FILENAME, wxString::FromAscii(fN));
tString.Printf(wxT("%04X"), memoryCard[card]->DEntry_ModTime(j));
m_MemcardList[card]->SetItem(index, COLUMN_MODTIME, tString);
tString.Printf(wxT("%04X"), memoryCard[card]->DEntry_ImageOffset(j));
m_MemcardList[card]->SetItem(index, COLUMN_IMAGEADD, tString);
tString.Printf(wxT("%02X"), memoryCard[card]->DEntry_IconFmt(j));
m_MemcardList[card]->SetItem(index, COLUMN_ICONFMT, tString);
tString.Printf(wxT("%02X"), memoryCard[card]->DEntry_AnimSpeed(j));
m_MemcardList[card]->SetItem(index, COLUMN_ANIMSPEED, tString);
char per[40];
if (!memoryCard[card]->DEntry_Permissions(j, per)) per[0]=0;
m_MemcardList[card]->SetItem(index, COLUMN_PERMISSIONS, wxString::FromAscii(per));
tString.Printf(wxT("%0X"), memoryCard[card]->DEntry_CopyCounter(j));
m_MemcardList[card]->SetItem(index, COLUMN_COPYCOUNTER, tString);
tString.Printf(wxT("%04X"), memoryCard[card]->DEntry_CommentsAddress(j));
m_MemcardList[card]->SetItem(index, COLUMN_COMMENTSADDRESS, tString);
#endif
}
if (m_MemcardList[card]->usePages)
@ -744,6 +832,7 @@ void CMemcardManager::CMemcardListCtrl::OnRightClick(wxMouseEvent& event)
int flags;
long item = HitTest(event.GetPosition(), flags);
wxMenu popupMenu;
if (item != wxNOT_FOUND)
{
@ -753,7 +842,6 @@ void CMemcardManager::CMemcardListCtrl::OnRightClick(wxMouseEvent& event)
}
SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
wxMenu popupMenu;
if (event.GetId() == ID_MEMCARDLIST_A)
{
popupMenu.Append(ID_COPYFROM_A, wxT("Copy to Memcard B"));
@ -791,26 +879,21 @@ void CMemcardManager::CMemcardListCtrl::OnRightClick(wxMouseEvent& event)
popupMenu.FindItem(ID_NEXTPAGE_B)->Enable(false);
}
popupMenu.AppendCheckItem(COLUMN_BANNER, wxT("Show save banner"));
if(column[COLUMN_BANNER]) popupMenu.FindItem(COLUMN_BANNER)->Check();
if (column[COLUMN_BANNER]) popupMenu.FindItem(COLUMN_BANNER)->Check();
popupMenu.AppendCheckItem(COLUMN_TITLE, wxT("Show save title"));
if(column[COLUMN_TITLE]) popupMenu.FindItem(COLUMN_TITLE)->Check();
if (column[COLUMN_TITLE]) popupMenu.FindItem(COLUMN_TITLE)->Check();
popupMenu.AppendCheckItem(COLUMN_COMMENT, wxT("Show save comment"));
if(column[COLUMN_COMMENT]) popupMenu.FindItem(COLUMN_COMMENT)->Check();
if (column[COLUMN_COMMENT]) popupMenu.FindItem(COLUMN_COMMENT)->Check();
popupMenu.AppendCheckItem(COLUMN_ICON, wxT("Show save icon"));
if(column[COLUMN_ICON]) popupMenu.FindItem(COLUMN_ICON)->Check();
if (column[COLUMN_ICON]) popupMenu.FindItem(COLUMN_ICON)->Check();
popupMenu.AppendCheckItem(COLUMN_BLOCKS, wxT("Show save blocks"));
if(column[COLUMN_BLOCKS]) popupMenu.FindItem(COLUMN_BLOCKS)->Check();
popupMenu.AppendCheckItem(COLUMN_FIRSTBLOCK, wxT("Show save first block"));
if(column[COLUMN_FIRSTBLOCK]) popupMenu.FindItem(COLUMN_FIRSTBLOCK)->Check();
if (column[COLUMN_BLOCKS]) popupMenu.FindItem(COLUMN_BLOCKS)->Check();
#ifdef DEBUG_MCM
popupMenu.AppendCheckItem(NUMBER_OF_COLUMN, wxT("Debug Memcard"));
if (column[NUMBER_OF_COLUMN]) popupMenu.FindItem(NUMBER_OF_COLUMN)->Check();
#endif
popupMenu.AppendCheckItem(ID_USEPAGES, wxT("Enable pages"));
if(usePages) popupMenu.FindItem(ID_USEPAGES)->Check();
PopupMenu(&popupMenu);
}
PopupMenu(&popupMenu);
}

View File

@ -116,6 +116,17 @@ class CMemcardManager
COLUMN_ICON,
COLUMN_BLOCKS,
COLUMN_FIRSTBLOCK,
COLUMN_GAMECODE,
COLUMN_MAKERCODE,
COLUMN_FILENAME,
COLUMN_BIFLAGS,
COLUMN_MODTIME,
COLUMN_IMAGEADD,
COLUMN_ICONFMT,
COLUMN_ANIMSPEED,
COLUMN_PERMISSIONS,
COLUMN_COPYCOUNTER,
COLUMN_COMMENTSADDRESS,
NUMBER_OF_COLUMN
};
@ -142,7 +153,7 @@ class CMemcardManager
usePages,
prevPage,
nextPage,
column[NUMBER_OF_COLUMN];
column[NUMBER_OF_COLUMN+1];
private:
DECLARE_EVENT_TABLE()
void OnRightClick(wxMouseEvent& event);

View File

@ -17,9 +17,6 @@
#include "GCMemcard.h"
// i think there is support for this stuff in the common lib... if not there should be support
#define BE16(x) ((u16((x)[0])<<8) | u16((x)[1]))
#define BE32(x) ((u32((x)[0])<<24) | (u32((x)[1])<<16) | (u32((x)[2])<<8) | u32((x)[3]))
#define ArrayByteSwap(a) (ByteSwap(a, a+sizeof(u8)));
// undefined functions... prolly it means something like that
void ByteSwap(u8 *valueA, u8 *valueB)
@ -381,44 +378,92 @@ u16 GCMemcard::GetFreeBlocks()
bool GCMemcard::TitlePresent(DEntry d)
{
//TODO: Clean up this function
bool equal = false;
if (!mcdFile) return false;
for (int i = 0; i < 127; i++)
{
if (BE32(dir.Dir[i].Gamecode) == BE32(d.Gamecode))
{
for ( int j = 0; j < 32; j++)
{
if (dir.Dir[i].Filename[j] != d.Filename[j])
{
equal = false;
break;
}
else
{
equal = true;
}
}
if (equal)
if ((BE32(dir.Dir[i].Gamecode) == BE32(d.Gamecode)) &&
(!memcmp(dir.Dir[i].Filename, d.Filename, 32)))
{
return true;
}
}
}
return false;
}
u16 GCMemcard::GetFirstBlock(u32 index)
bool GCMemcard::DEntry_GameCode(u8 index, char *fn)
{
if (!mcdFile) return false;
memcpy(fn, dir.Dir[index].Gamecode, 4);
fn[4] = 0;
return true;
}
bool GCMemcard::DEntry_Markercode(u8 index, char *fn)
{
if (!mcdFile) return false;
memcpy(fn, dir.Dir[index].Markercode, 2);
fn[2] = 0;
return true;
}
bool GCMemcard::DEntry_BIFlags(u8 index, char *fn)
{
if (!mcdFile) return false;
int x = dir.Dir[index].BIFlags;
for(int n=0; n<8; n++)
{
fn[n] = (x & 0x80) ? '1' : '0';
x = x<<1;
}
fn[8]= 0;
return true;
}
bool GCMemcard::DEntry_FileName(u8 index, char *fn) //index in the directory array
{
if (!mcdFile) return false;
memcpy (fn, (const char*)dir.Dir[index].Filename, 32);
fn[31] = 0;
return true;
}
u32 GCMemcard::DEntry_ModTime(u8 index)
{
return BE32(dir.Dir[index].ModTime);
}
u32 GCMemcard::DEntry_ImageOffset(u8 index)
{
return BE32(dir.Dir[index].ImageOffset);
}
u16 GCMemcard::DEntry_IconFmt(u8 index)
{
return BE16(dir.Dir[index].IconFmt);
}
u16 GCMemcard::DEntry_AnimSpeed(u8 index)
{
return BE16(dir.Dir[index].AnimSpeed);
}
bool GCMemcard::DEntry_Permissions(u8 index, char *fn)
{
if (!mcdFile) return false;
fn[0] = (dir.Dir[index].Permissions & 16) ? 'x' : 'M';
fn[1] = (dir.Dir[index].Permissions & 8) ? 'x' : 'C';
fn[2] = (dir.Dir[index].Permissions & 4) ? 'P' : 'x';
fn[3] = 0;
return true;
}
u8 GCMemcard::DEntry_CopyCounter(u8 index)
{
return dir.Dir[index].CopyCounter;
}
u16 GCMemcard::DEntry_FirstBlock(u8 index)
{
if (!mcdFile) return 0xFFFF;
u16 block = BE16(dir.Dir[index].FirstBlock);
if (block > (u16) maxBlock) return 0xFFFF;
return block;
}
u16 GCMemcard::GetFileSize(u32 index) //index in the directory array
u16 GCMemcard::DEntry_BlockCount(u8 index)
{
if (!mcdFile) return 0xFFFF;
@ -426,17 +471,12 @@ u16 GCMemcard::GetFileSize(u32 index) //index in the directory array
if (blocks > (u16) maxBlock) return 0xFFFF;
return blocks;
}
bool GCMemcard::GetFileName(u32 index, char *fn) //index in the directory array
u32 GCMemcard::DEntry_CommentsAddress(u8 index)
{
if (!mcdFile) return false;
memcpy (fn, (const char*)dir.Dir[index].Filename, 32);
fn[31] = 0;
return true;
return BE32(dir.Dir[index].CommentsAddr);
}
bool GCMemcard::GetComment1(u32 index, char *fn) //index in the directory array
bool GCMemcard::DEntry_Comment1(u8 index, char* fn)
{
if (!mcdFile) return false;
@ -451,8 +491,7 @@ bool GCMemcard::GetComment1(u32 index, char *fn) //index in the directory array
fn[31] = 0;
return true;
}
bool GCMemcard::GetComment2(u32 index, char *fn) //index in the directory array
bool GCMemcard::DEntry_Comment2(u8 index, char* fn)
{
if (!mcdFile) return false;
@ -469,7 +508,7 @@ bool GCMemcard::GetComment2(u32 index, char *fn) //index in the directory array
return true;
}
bool GCMemcard::GetFileInfo(u32 index, GCMemcard::DEntry& info) //index in the directory array
bool GCMemcard::GetFileInfo(u8 index, GCMemcard::DEntry& info) //index in the directory array
{
if (!mcdFile) return false;
@ -477,12 +516,12 @@ bool GCMemcard::GetFileInfo(u32 index, GCMemcard::DEntry& info) //index in the d
return true;
}
u32 GCMemcard::GetFileData(u32 index, u8* dest, bool old) //index in the directory array
u32 GCMemcard::GetFileData(u8 index, u8* dest, bool old) //index in the directory array
{
if (!mcdFile) return NOMEMCARD;
u16 block = GetFirstBlock(index);
u16 saveLength = GetFileSize(index);
u16 block = DEntry_FirstBlock(index);
u16 saveLength = DEntry_BlockCount(index);
u16 memcardSize = BE16(hdr.Size) * 0x0010;
if ((block == 0xFFFF) || (saveLength == 0xFFFF)
@ -613,7 +652,7 @@ u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove)
return SUCCESS;
}
u32 GCMemcard::RemoveFile(u32 index) //index in the directory array
u32 GCMemcard::RemoveFile(u8 index) //index in the directory array
{
if (!mcdFile) return NOMEMCARD;
@ -627,7 +666,7 @@ u32 GCMemcard::RemoveFile(u32 index) //index in the directory array
bat.LastAllocated[0] = (u8)(block >> 8);
bat.LastAllocated[1] = (u8)block;
int i = index + 1;
u8 i = index + 1;
memset(&(dir.Dir[index]), 0xFF, 0x40);
while (i < 127)
@ -642,7 +681,7 @@ u32 GCMemcard::RemoveFile(u32 index) //index in the directory array
bat.FreeBlocks[0] = u8(freeBlock >> 8);
bat.FreeBlocks[1] = u8(freeBlock);
u16 size = GetFileSize(i);
u16 size = DEntry_BlockCount(i);
if (size != 0xFFFF)
{
t = new u8[size * 0x2000];
@ -685,14 +724,14 @@ u32 GCMemcard::RemoveFile(u32 index) //index in the directory array
return SUCCESS;
}
u32 GCMemcard::CopyFrom(GCMemcard& source, u32 index)
u32 GCMemcard::CopyFrom(GCMemcard& source, u8 index)
{
if (!mcdFile) return NOMEMCARD;
DEntry d;
if (!source.GetFileInfo(index, d)) return NOMEMCARD;
u32 size = source.GetFileSize(index);
u32 size = source.DEntry_BlockCount(index);
if (size == 0xFFFF) return INVALIDFILESIZE;
u8 *t = new u8[size * 0x2000];
@ -831,7 +870,7 @@ u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
return ret;
}
u32 GCMemcard::ExportGci(u32 index, const char *fileName)
u32 GCMemcard::ExportGci(u8 index, const char *fileName)
{
FILE *gci = fopen(fileName, "wb");
if (!gci) return OPENFAIL;
@ -843,7 +882,7 @@ u32 GCMemcard::ExportGci(u32 index, const char *fileName)
if (!GetFileInfo(index, d)) return NOMEMCARD;
if (fwrite(&d, 1, 0x40, gci) != 0x40) completeWrite = false;
u32 size = GetFileSize(index);
u32 size = DEntry_BlockCount(index);
if (size == 0xFFFF) return FAIL;
u8 *t = new u8[size * 0x2000];
@ -871,7 +910,7 @@ u32 GCMemcard::ExportGci(u32 index, const char *fileName)
}
bool GCMemcard::ReadBannerRGBA8(u32 index, u32* buffer)
bool GCMemcard::ReadBannerRGBA8(u8 index, u32* buffer)
{
if (!mcdFile) return false;
@ -908,7 +947,7 @@ bool GCMemcard::ReadBannerRGBA8(u32 index, u32* buffer)
return true;
}
u32 GCMemcard::ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays)
u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays)
{
if (!mcdFile) return 0;

View File

@ -19,6 +19,9 @@
#include "Common.h"
#include "StringUtil.h"
#define BE32(x) ((u32((x)[0])<<24) | (u32((x)[1])<<16) | (u32((x)[2])<<8) | u32((x)[3]))
#define BE16(x) ((u16((x)[0])<<8) | u16((x)[1]))
#define ArrayByteSwap(a) (ByteSwap(a, a+sizeof(u8)));
enum
{
@ -158,49 +161,59 @@ public:
// Returns true if title already on memcard
bool TitlePresent(DEntry d);
bool DEntry_GameCode(u8 index, char* fn);
bool DEntry_Markercode(u8 index, char* fn);
bool DEntry_BIFlags(u8 index, char* fn);
// fn needs to be a char[32] or bigger
bool DEntry_FileName(u8 index, char* fn);
u32 DEntry_ModTime(u8 index);
u32 DEntry_ImageOffset(u8 index);
u16 DEntry_IconFmt(u8 index);
u16 DEntry_AnimSpeed(u8 index);
bool DEntry_Permissions(u8 index, char* fn);
u8 DEntry_CopyCounter(u8 index);
// get first block for file
u16 GetFirstBlock(u32 index);
u16 DEntry_FirstBlock(u8 index);
// get file length in blocks
u16 GetFileSize(u32 index);
u16 DEntry_BlockCount(u8 index);
u32 DEntry_CommentsAddress(u8 index);
// buffer needs to be a char[32] or bigger
bool GetFileName(u32 index, char* buffer);
bool DEntry_Comment1(u8 index, char* buffer);
// buffer needs to be a char[32] or bigger
bool GetComment1(u32 index, char* buffer);
// buffer needs to be a char[32] or bigger
bool GetComment2(u32 index, char* buffer);
bool DEntry_Comment2(u8 index, char* buffer);
// read directory entry
bool GetFileInfo(u32 index, DEntry& data);
bool GetFileInfo(u8 index, DEntry& data);
// assumes there's enough space in buffer
// old determines if function uses old or new method of copying data
// some functions only work with old way, some only work with new way
// TODO: find a function that works for all calls or split into 2 functions
u32 GetFileData(u32 index, u8* buffer, bool old);
u32 GetFileData(u8 index, u8* buffer, bool old);
// adds the file to the directory and copies its contents
// if remove > 0 it will pad bat.map with 0's sifeof remove
u32 ImportFile(DEntry& direntry, u8* contents, int remove);
// delete a file from the directory
u32 RemoveFile(u32 index);
u32 RemoveFile(u8 index);
// reads a save from another memcard, and imports the data into this memcard
u32 CopyFrom(GCMemcard& source, u32 index);
u32 CopyFrom(GCMemcard& source, u8 index);
// reads a .gci/.gcs/.sav file and calls ImportFile or saves out a gci file
u32 ImportGci(const char* fileName, std::string fileName2);
// writes a .gci file to disk containing index
u32 ExportGci(u32 index, const char* fileName);
u32 ExportGci(u8 index, const char* fileName);
// reads the banner image
bool ReadBannerRGBA8(u32 index, u32* buffer);
bool ReadBannerRGBA8(u8 index, u32* buffer);
// reads the animation frames
u32 ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays);
u32 ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays);
};