summaryrefslogtreecommitdiff
path: root/Source/Core
diff options
context:
space:
mode:
authorLPFaint99 <lpfaint99@gmail.com>2009-02-22 03:23:48 +0000
committerLPFaint99 <lpfaint99@gmail.com>2009-02-22 03:23:48 +0000
commit341ac2640124f0997e9dbfc48e49d910897e0dc4 (patch)
tree2416e08f0aba4efbb66419b971420348eba4d5c8 /Source/Core
parent3d0fcfaaacc271be18e47af2f3d191f68d46832e (diff)
MemcardManager general cleanup, ini settings fixes
disallows multiple formats for icons adds export all saves to right click menu sets exported save name to gamecode+filename.gci git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2353 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source/Core')
-rw-r--r--Source/Core/DolphinWX/Src/MemcardManager.cpp247
-rw-r--r--Source/Core/DolphinWX/Src/MemcardManager.h16
-rw-r--r--Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp331
-rw-r--r--Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h57
4 files changed, 362 insertions, 289 deletions
diff --git a/Source/Core/DolphinWX/Src/MemcardManager.cpp b/Source/Core/DolphinWX/Src/MemcardManager.cpp
index e7acf5c998..cab7f97301 100644
--- a/Source/Core/DolphinWX/Src/MemcardManager.cpp
+++ b/Source/Core/DolphinWX/Src/MemcardManager.cpp
@@ -20,6 +20,9 @@
#include "Common.h"
#include "wx/mstream.h"
//#define DEBUG_MCM true
+#define DEFAULTS wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator
+#define ARROWS slot ? "" : ARROW[slot], slot ? ARROW[slot] : ""
+
const u8 hdr[] = {
0x42,0x4D,
0x38,0x30,0x00,0x00,
@@ -112,6 +115,7 @@ CMemcardManager::CMemcardManager(wxWindow* parent, wxWindowID id, const wxString
MemcardManagerIni.Get("MemcardManager", "Items per page", &itemsPerPage, 16);
MemcardManagerIni.Get("MemcardManager", "DefaultMemcardA", &(DefaultMemcard[SLOT_A]), ".");
MemcardManagerIni.Get("MemcardManager", "DefaultMemcardB", &(DefaultMemcard[SLOT_B]), ".");
+ MemcardManagerIni.Get("MemcardManager", "DefaultIOFolder", &DefaultIOPath, "/Users/GC");
}
else itemsPerPage = 16;
maxPages = (128 / itemsPerPage) - 1;
@@ -153,11 +157,11 @@ CMemcardManager::CMemcardListCtrl::CMemcardListCtrl(wxWindow* parent, const wxWi
MemcardManagerIni.Get("MemcardManager", "cBanner", &column[COLUMN_BANNER], true);
MemcardManagerIni.Get("MemcardManager", "cTitle", &column[COLUMN_TITLE], true);
MemcardManagerIni.Get("MemcardManager", "cComment", &column[COLUMN_COMMENT], true);
+ MemcardManagerIni.Get("MemcardManager", "cIcon", &column[COLUMN_ICON], true);
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);
+ MemcardManagerIni.Get("MemcardManager", "cDebug", &column[NUMBER_OF_COLUMN], false);
#else
column[NUMBER_OF_COLUMN] = false;
#endif
@@ -184,12 +188,13 @@ CMemcardManager::CMemcardListCtrl::CMemcardListCtrl(wxWindow* parent, const wxWi
CMemcardManager::CMemcardListCtrl::~CMemcardListCtrl()
{
MemcardManagerIni.Load(CONFIG_FILE);
+
MemcardManagerIni.Set("MemcardManager", "Use Pages", usePages);
MemcardManagerIni.Set("MemcardManager", "cBanner", column[COLUMN_BANNER]);
MemcardManagerIni.Set("MemcardManager", "cTitle", column[COLUMN_TITLE]);
MemcardManagerIni.Set("MemcardManager", "cComment", column[COLUMN_COMMENT]);
+ MemcardManagerIni.Set("MemcardManager", "cIcon", column[COLUMN_ICON]);
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]);
@@ -200,53 +205,50 @@ CMemcardManager::CMemcardListCtrl::~CMemcardListCtrl()
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("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("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);
- m_MemcardList[SLOT_B] = new CMemcardListCtrl(this, ID_MEMCARDLIST_B, wxDefaultPosition, wxSize(350,400),
- wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT | wxLC_SINGLE_SEL);
-
- m_MemcardList[SLOT_A]->AssignImageList(new wxImageList(96,32),wxIMAGE_LIST_SMALL);
- m_MemcardList[SLOT_B]->AssignImageList(new wxImageList(96,32),wxIMAGE_LIST_SMALL);
-
- t_Status[SLOT_A] = new wxStaticText(this, 0, wxEmptyString, wxDefaultPosition,wxDefaultSize, 0, wxEmptyString);
- t_Status[SLOT_B] = new wxStaticText(this, 0, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString);
+char ARROW[2][3] = {'<','-',0,'-','>',0};
- // buttons
- m_CopyFrom[SLOT_A] = new wxButton(this, ID_COPYFROM_A, wxT("->Copy->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
- m_CopyFrom[SLOT_B] = new wxButton(this, ID_COPYFROM_B, wxT("<-Copy<-"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
+ m_ConvertToGci = new wxButton(this, ID_CONVERTTOGCI, wxT("Convert to GCI"), DEFAULTS);
- m_FixChecksum[SLOT_A] = new wxButton(this, ID_FIXCHECKSUM_A, wxT("<-Fix Checksum"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
- m_FixChecksum[SLOT_B] = new wxButton(this, ID_FIXCHECKSUM_B, wxT("Fix Checksum->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
-
- m_SaveImport[SLOT_A] = new wxButton(this, ID_SAVEIMPORT_A, wxT("<-Import GCI"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
- m_SaveImport[SLOT_B] = new wxButton(this, ID_SAVEIMPORT_B, wxT("Import GCI->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
+ for (int slot = SLOT_A; slot < SLOT_B + 1; slot++)
+ {
+ m_CopyFrom[slot] = new wxButton(this, ID_COPYFROM_A + slot,
+ wxString::Format("%1$sCopy%1$s", ARROW[slot ? 0 : 1]), DEFAULTS);
+ m_FixChecksum[slot] = new wxButton(this, ID_FIXCHECKSUM_A + slot,
+ wxString::Format("%sFix Checksum%s", ARROWS), DEFAULTS);
+ m_SaveImport[slot] = new wxButton(this, ID_SAVEIMPORT_A + slot,
+ wxString::Format("%sImport GCI%s", ARROWS), DEFAULTS);
+ m_SaveExport[slot] = new wxButton(this, ID_SAVEEXPORT_A + slot,
+ wxString::Format("%sExport GCI%s", ARROWS), DEFAULTS);
+ m_Delete[slot] = new wxButton(this, ID_DELETE_A + slot,
+ wxString::Format("%sDelete%s", ARROWS), DEFAULTS);
+
+
+ m_PrevPage[slot] = new wxButton(this, ID_PREVPAGE_A + slot, wxT("Prev Page"), DEFAULTS);
+ m_NextPage[slot] = new wxButton(this, ID_NEXTPAGE_A + slot, wxT("Next Page"), DEFAULTS);
+
+ t_Status[slot] = new wxStaticText(this, 0, wxEmptyString, wxDefaultPosition,wxDefaultSize, 0, wxEmptyString);
+
+ sPages[slot] = new wxBoxSizer(wxHORIZONTAL);
+ sPages[slot]->Add(m_PrevPage[slot], 0, wxEXPAND|wxALL, 1);
+ sPages[slot]->Add(t_Status[slot],0, wxEXPAND|wxALL, 5);
+ sPages[slot]->Add(0, 0, 1, wxEXPAND|wxALL, 0);
+ sPages[slot]->Add(m_NextPage[slot], 0, wxEXPAND|wxALL, 1);
+
+ m_MemcardPath[slot] = new wxFilePickerCtrl(this, ID_MEMCARDPATH_A + slot, wxEmptyString, wxT("Choose a memory card:"),
+ wxT("Gamecube Memory Cards (*.raw,*.gcp)|*.raw;*.gcp"), wxDefaultPosition, wxDefaultSize, wxFLP_USE_TEXTCTRL|wxFLP_OPEN);
- m_SaveExport[SLOT_A] = new wxButton(this, ID_SAVEEXPORT_A, wxT("<-Export GCI"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
- m_SaveExport[SLOT_B] = new wxButton(this, ID_SAVEEXPORT_B, wxT("Export GCI->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
-
- m_ConvertToGci = new wxButton(this, ID_CONVERTTOGCI, wxT("Convert to GCI"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
-
- m_Delete[SLOT_A] = new wxButton(this, ID_DELETE_A, wxT("<-Delete"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
- m_Delete[SLOT_B] = new wxButton(this, ID_DELETE_B, wxT("Delete->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
-
- m_PrevPage[SLOT_A] = new wxButton(this, ID_PREVPAGE_A, wxT("Prev Page"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
- m_PrevPage[SLOT_B] = new wxButton(this, ID_PREVPAGE_B, wxT("Prev Page"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
-
- m_NextPage[SLOT_A] = new wxButton(this, ID_NEXTPAGE_A, wxT("Next Page"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
- m_NextPage[SLOT_B] = new wxButton(this, ID_NEXTPAGE_B, wxT("Next Page"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
+ m_MemcardList[slot] = new CMemcardListCtrl(this, ID_MEMCARDLIST_A + slot, wxDefaultPosition, wxSize(350,400),
+ wxLC_REPORT | wxSUNKEN_BORDER | wxLC_ALIGN_LEFT | wxLC_SINGLE_SEL);
- // Sizers that double as wxStaticBoxes
- sMemcard_A = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Memory Card A"));
- sMemcard_B = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Memory Card B"));
+ m_MemcardList[slot]->AssignImageList(new wxImageList(96,32),wxIMAGE_LIST_SMALL);
+
+ sMemcard[slot] = new wxStaticBoxSizer(wxVERTICAL, this, wxString::Format("Memory Card %c", 'A' + slot));
+ sMemcard[slot]->Add(m_MemcardPath[slot], 0, wxEXPAND|wxALL, 5);
+ sMemcard[slot]->Add(m_MemcardList[slot], 1, wxEXPAND|wxALL, 5);
+ sMemcard[slot]->Add(sPages[slot], 0, wxEXPAND|wxALL, 1);
+ }
- // mmmm sizer goodness
- wxBoxSizer* sButtons;
sButtons = new wxBoxSizer(wxVERTICAL);
sButtons->AddStretchSpacer(2);
sButtons->Add(m_CopyFrom[SLOT_B], 0, wxEXPAND, 5);
@@ -267,34 +269,16 @@ void CMemcardManager::CreateGUIControls()
sButtons->Add(m_Delete[SLOT_B], 0, wxEXPAND, 5);
sButtons->AddStretchSpacer(1);
- sPages_A = new wxBoxSizer(wxHORIZONTAL);
- sPages_B = new wxBoxSizer(wxHORIZONTAL);
-
- sPages_A->Add(m_PrevPage[SLOT_A], 0, wxEXPAND|wxALL, 1);
- sPages_A->Add(t_Status[SLOT_A],0, wxEXPAND|wxALL, 5);
- sPages_A->Add(0, 0, 1, wxEXPAND|wxALL, 0);
- sPages_A->Add(m_NextPage[SLOT_A], 0, wxEXPAND|wxALL, 1);
- sPages_B->Add(m_PrevPage[SLOT_B], 0, wxEXPAND|wxALL, 1);
- sPages_B->Add(t_Status[SLOT_B], 0, wxEXPAND|wxALL, 5);
- sPages_B->Add(0, 0, 1, wxEXPAND|wxALL, 0);
- sPages_B->Add(m_NextPage[SLOT_B], 0, wxEXPAND|wxALL, 1);
-
- sMemcard_A->Add(m_MemcardPath[SLOT_A], 0, wxEXPAND|wxALL, 5);
- sMemcard_A->Add(m_MemcardList[SLOT_A], 1, wxEXPAND|wxALL, 5);
- sMemcard_A->Add(sPages_A, 0, wxEXPAND|wxALL, 1);
- sMemcard_B->Add(m_MemcardPath[SLOT_B], 0, wxEXPAND|wxALL, 5);
- sMemcard_B->Add(m_MemcardList[SLOT_B], 1, wxEXPAND|wxALL, 5);
- sMemcard_B->Add(sPages_B, 0, wxEXPAND|wxALL, 1);
-
sMain = new wxBoxSizer(wxHORIZONTAL);
- sMain->Add(sMemcard_A, 1, wxEXPAND|wxALL, 5);
+ sMain->Add(sMemcard[SLOT_A], 1, wxEXPAND|wxALL, 5);
sMain->Add(sButtons, 0, wxEXPAND, 0);
- sMain->Add(sMemcard_B, 1, wxEXPAND|wxALL, 5);
+ sMain->Add(sMemcard[SLOT_B], 1, wxEXPAND|wxALL, 5);
this->SetSizer(sMain);
sMain->SetSizeHints(this);
Fit();
- for (int i = SLOT_A; i <= SLOT_B; i++)
+
+ for (int i = SLOT_A; i < SLOT_B + 1; i++)
{
m_PrevPage[i]->Disable();
m_NextPage[i]->Disable();
@@ -371,7 +355,7 @@ void CMemcardManager::ChangePath(int id)
}
break;
}
- if (m_Delete[slot]->IsEnabled() && m_Delete[slot2]->IsEnabled())
+ if (m_Delete[SLOT_A]->IsEnabled() && m_Delete[SLOT_B]->IsEnabled())
{
m_CopyFrom[SLOT_A]->Enable();
m_CopyFrom[SLOT_B]->Enable();
@@ -566,7 +550,8 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
case ID_SAVEIMPORT_B:
{
wxString temp = wxFileSelector(_T("Select a save file to import"),
- wxEmptyString, wxEmptyString, wxEmptyString,wxString::Format
+ (strcmp(DefaultIOPath.c_str(), "/Users/GC") == 0) ? wxEmptyString :
+ DefaultIOPath.c_str(), wxEmptyString, wxEmptyString, wxString::Format
(
_T("Gamecube save files(*.gci,*.gcs,*.sav)|*.gci;*.gcs;*.sav|"
"Native GCI files (*.gci)|*.gci|"
@@ -602,22 +587,46 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
case ID_SAVEEXPORT_B:
if (index != wxNOT_FOUND)
{
- wxString temp = wxFileSelector(_T("Save GCI as.."),
- wxEmptyString, wxEmptyString, _T(".gci"), wxString::Format
- (
- _T("GCI File(*.gci)|*.gci"),
- wxFileSelectorDefaultWildcardStr,
- wxFileSelectorDefaultWildcardStr
- ),
- wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
- const char * fileName = temp.ToAscii();
+ char tempC[36], tempC2[32];
+ memoryCard[slot]->DEntry_GameCode(index,tempC);
+ memoryCard[slot]->DEntry_FileName(index,tempC2);
+ sprintf(tempC, "%s_%s.gci", tempC, tempC2);
+ wxString temp = wxFileSelector(_T("Save GCI as.."), _T(DefaultIOPath.c_str()),
+ _T(tempC), _T(".gci"), wxString::Format
+ (
+ _T("GCI File(*.gci)|*.gci"),
+ wxFileSelectorDefaultWildcardStr,
+ wxFileSelectorDefaultWildcardStr
+ ),
+ wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
+
if (temp.length() > 0)
{
- if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName), -1))
+ const char * fileName = temp.ToAscii();
+ if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName, NULL), -1))
+ {
File::Delete(temp.ToAscii());
+ }
}
}
break;
+ case ID_EXPORTALL_A:
+ slot=SLOT_A;
+ case ID_EXPORTALL_B:
+ {
+ std::string path1, path2;
+ SplitPath(m_MemcardPath[slot]->GetPath().mb_str(), &path1, &path2, NULL);
+ path1 += path2;
+ File::CreateDir(path1.c_str());
+ if(PanicYesNo("Warning: This will overwrite any existing saves "
+ "that are in the folder:\n%s\nand have the same name"
+ " as a file on your memcard\nContinue?", path1.c_str()))
+ for (int i = 0; i < DIRLEN; i++)
+ {
+ CopyDeleteSwitch(memoryCard[slot]->ExportGci(i, _("."), &path1), -1);
+ }
+ break;
+ }
case ID_DELETE_A:
slot = SLOT_A;
index = index_A;
@@ -777,8 +786,9 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
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);
+ char iF[17];
+ if (!memoryCard[card]->DEntry_IconFmt(j, iF)) iF[0]=0;
+ m_MemcardList[card]->SetItem(index, COLUMN_ICONFMT, wxString::FromAscii(iF));
tString.Printf(wxT("%02X"), memoryCard[card]->DEntry_AnimSpeed(j));
m_MemcardList[card]->SetItem(index, COLUMN_ANIMSPEED, tString);
@@ -821,7 +831,7 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
m_MemcardList[card]->Show();
wxLabel.Printf(wxT("%d Free Blocks; %d Free Dir Entries"),
- memoryCard[card]->GetFreeBlocks(), 127 - nFiles);
+ memoryCard[card]->GetFreeBlocks(), DIRLEN - nFiles);
t_Status[card]->SetLabel(wxLabel);
return true;
@@ -842,58 +852,47 @@ void CMemcardManager::CMemcardListCtrl::OnRightClick(wxMouseEvent& event)
}
SetItemState(item, wxLIST_STATE_FOCUSED, wxLIST_STATE_FOCUSED);
- if (event.GetId() == ID_MEMCARDLIST_A)
- {
- popupMenu.Append(ID_COPYFROM_A, wxT("Copy to Memcard B"));
- popupMenu.Append(ID_DELETE_A, wxT("Delete Save"));
- popupMenu.Append(ID_SAVEIMPORT_A, wxT("Import Save"));
- popupMenu.Append(ID_SAVEEXPORT_A, wxT("Export Save"));
- if (!twoCardsLoaded)
- popupMenu.FindItem(ID_COPYFROM_A)->Enable(false);
- popupMenu.AppendSeparator();
- popupMenu.Append(ID_FIXCHECKSUM_A, wxT("Fix Checksum"));
- popupMenu.Append(ID_PREVPAGE_A, wxT("Previous Page"));
- popupMenu.Append(ID_NEXTPAGE_A, wxT("Next Page"));
- popupMenu.Append(ID_MEMCARDPATH_A, wxT("Set as default Memcard A"));
- if (!prevPage || !usePages)
- popupMenu.FindItem(ID_PREVPAGE_A)->Enable(false);
- if (!nextPage || !usePages)
- popupMenu.FindItem(ID_NEXTPAGE_A)->Enable(false);
- }
- else if (event.GetId() == ID_MEMCARDLIST_B)
- {
- popupMenu.Append(ID_COPYFROM_B, wxT("Copy to Memcard A"));
- popupMenu.Append(ID_DELETE_B, wxT("Delete Save"));
- popupMenu.Append(ID_SAVEIMPORT_B, wxT("Import Save"));
- popupMenu.Append(ID_SAVEEXPORT_B, wxT("Export Save"));
- if (!twoCardsLoaded)
- popupMenu.FindItem(ID_COPYFROM_B)->Enable(false);
- popupMenu.AppendSeparator();
- popupMenu.Append(ID_FIXCHECKSUM_B, wxT("Fix Checksum"));
- popupMenu.Append(ID_PREVPAGE_B, wxT("Previous Page"));
- popupMenu.Append(ID_NEXTPAGE_B, wxT("Next Page"));
- popupMenu.Append(ID_MEMCARDPATH_B, wxT("Set as default Memcard B"));
- if (!prevPage || !usePages)
- popupMenu.FindItem(ID_PREVPAGE_B)->Enable(false);
- if (!nextPage || !usePages)
- popupMenu.FindItem(ID_NEXTPAGE_B)->Enable(false);
- }
+ int slot = event.GetId() - ID_MEMCARDLIST_A;
+ popupMenu.Append(ID_COPYFROM_A + slot, wxString::Format("Copy to Memcard %c", 'B' - slot));
+ popupMenu.Append(ID_DELETE_A + slot, wxT("Delete Save"));
+ popupMenu.Append(ID_SAVEIMPORT_A + slot, wxT("Import Save"));
+ popupMenu.Append(ID_SAVEEXPORT_A + slot, wxT("Export Save"));
+ popupMenu.Append(ID_EXPORTALL_A + slot, wxT("Export all saves"));
+
+ if (!twoCardsLoaded)
+ popupMenu.FindItem(ID_COPYFROM_A + slot)->Enable(false);
+
+ popupMenu.AppendSeparator();
+
+ popupMenu.Append(ID_FIXCHECKSUM_A + slot, wxT("Fix Checksums"));
+ popupMenu.Append(ID_PREVPAGE_A + slot, wxT("Previous Page"));
+ popupMenu.Append(ID_NEXTPAGE_A + slot, wxT("Next Page"));
+ popupMenu.Append(ID_MEMCARDPATH_A + slot, wxString::Format("Set as default Memcard %c", 'A' + slot));
+ popupMenu.AppendCheckItem(ID_USEPAGES, wxT("Enable pages"));
+
+ if (!prevPage || !usePages)
+ popupMenu.FindItem(ID_PREVPAGE_A + slot)->Enable(false);
+ if (!nextPage || !usePages)
+ popupMenu.FindItem(ID_NEXTPAGE_A + slot)->Enable(false);
+ if(usePages)
+ popupMenu.FindItem(ID_USEPAGES)->Check();
+
+ popupMenu.AppendSeparator();
+
popupMenu.AppendCheckItem(COLUMN_BANNER, wxT("Show save banner"));
- 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();
popupMenu.AppendCheckItem(COLUMN_COMMENT, wxT("Show save comment"));
- 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();
popupMenu.AppendCheckItem(COLUMN_BLOCKS, wxT("Show save blocks"));
- if (column[COLUMN_BLOCKS]) popupMenu.FindItem(COLUMN_BLOCKS)->Check();
+
+ for (int i = COLUMN_BANNER; i <= COLUMN_BLOCKS; i++)
+ {
+ if (column[i]) popupMenu.FindItem(i)->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);
}
diff --git a/Source/Core/DolphinWX/Src/MemcardManager.h b/Source/Core/DolphinWX/Src/MemcardManager.h
index 409dc4b7d0..d5672a21c9 100644
--- a/Source/Core/DolphinWX/Src/MemcardManager.h
+++ b/Source/Core/DolphinWX/Src/MemcardManager.h
@@ -64,12 +64,13 @@ class CMemcardManager
int page[2],
itemsPerPage,
maxPages;
- std::string DefaultMemcard[2];
+ std::string DefaultMemcard[2],
+ DefaultIOPath;
IniFile MemcardManagerIni;
wxBoxSizer *sMain,
- *sPages_A,
- *sPages_B;
+ *sButtons,
+ *sPages[2];
wxButton *m_CopyFrom[2],
*m_FixChecksum[2],
*m_SaveImport[2],
@@ -79,14 +80,13 @@ class CMemcardManager
*m_PrevPage[2],
*m_ConvertToGci;
wxFilePickerCtrl *m_MemcardPath[2];
- wxStaticBoxSizer *sMemcard_A,
- *sMemcard_B;
+ wxStaticBoxSizer *sMemcard[2];
wxStaticText *t_Status[2];
enum
{
- ID_COPYFROM_A = 1000,
- ID_COPYFROM_B,
+ ID_COPYFROM_A = 1000, // Do not rearrange these items,
+ ID_COPYFROM_B, // ID_..._B must be 1 more than ID_..._A
ID_FIXCHECKSUM_A,
ID_FIXCHECKSUM_B,
ID_DELETE_A,
@@ -95,6 +95,8 @@ class CMemcardManager
ID_SAVEEXPORT_B,
ID_SAVEIMPORT_A,
ID_SAVEIMPORT_B,
+ ID_EXPORTALL_A,
+ ID_EXPORTALL_B,
ID_CONVERTTOGCI,
ID_NEXTPAGE_A,
ID_NEXTPAGE_B,
diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp
index 8270c8f06b..d5458ab4e2 100644
--- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp
+++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp
@@ -358,11 +358,11 @@ bool GCMemcard::FixChecksums()
return true;
}
-u32 GCMemcard::GetNumFiles()
+u8 GCMemcard::GetNumFiles()
{
if (!mcdFile) return 0;
- int j = 0;
- for (int i = 0; i < 127; i++)
+ u8 j = 0;
+ for (int i = 0; i < DIRLEN; i++)
{
if (BE32(dir.Dir[i].Gamecode)!= 0xFFFFFFFF)
j++;
@@ -376,54 +376,61 @@ u16 GCMemcard::GetFreeBlocks()
return BE16(bat.FreeBlocks);
}
-bool GCMemcard::TitlePresent(DEntry d)
+u8 GCMemcard::TitlePresent(DEntry d)
{
- if (!mcdFile) return false;
+ if (!mcdFile) return DIRLEN;
- for (int i = 0; i < 127; i++)
+ u8 i = 0;
+ while(i < DIRLEN)
{
if ((BE32(dir.Dir[i].Gamecode) == BE32(d.Gamecode)) &&
(!memcmp(dir.Dir[i].Filename, d.Filename, 32)))
{
- return true;
+ break;
}
+ i++;
}
- return false;
+ return i;
}
-bool GCMemcard::DEntry_GameCode(u8 index, char *fn)
+// DEntry functions, all take u8 index < 127
+// Functions that have ascii output take a char *buffer
+
+bool GCMemcard::DEntry_GameCode(u8 index, char *buffer)
{
if (!mcdFile) return false;
- memcpy(fn, dir.Dir[index].Gamecode, 4);
- fn[4] = 0;
+
+ memcpy(buffer, dir.Dir[index].Gamecode, 4);
+ buffer[4] = 0;
return true;
}
-bool GCMemcard::DEntry_Markercode(u8 index, char *fn)
+
+bool GCMemcard::DEntry_Markercode(u8 index, char *buffer)
{
if (!mcdFile) return false;
- memcpy(fn, dir.Dir[index].Markercode, 2);
- fn[2] = 0;
+ memcpy(buffer, dir.Dir[index].Markercode, 2);
+ buffer[2] = 0;
return true;
}
-bool GCMemcard::DEntry_BIFlags(u8 index, char *fn)
+bool GCMemcard::DEntry_BIFlags(u8 index, char *buffer)
{
if (!mcdFile) return false;
int x = dir.Dir[index].BIFlags;
- for(int n=0; n<8; n++)
+ for (int i = 0; i < 8; i++)
{
- fn[n] = (x & 0x80) ? '1' : '0';
- x = x<<1;
+ buffer[i] = (x & 0x80) ? '1' : '0';
+ x = x << 1;
}
- fn[8]= 0;
+ buffer[8] = 0;
return true;
}
-bool GCMemcard::DEntry_FileName(u8 index, char *fn) //index in the directory array
+bool GCMemcard::DEntry_FileName(u8 index, char *buffer)
{
if (!mcdFile) return false;
- memcpy (fn, (const char*)dir.Dir[index].Filename, 32);
- fn[31] = 0;
+ memcpy (buffer, (const char*)dir.Dir[index].Filename, 32);
+ buffer[31] = 0;
return true;
}
@@ -431,31 +438,48 @@ 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)
+
+bool GCMemcard::DEntry_IconFmt(u8 index, char *buffer)
{
- return BE16(dir.Dir[index].IconFmt);
+ if (!mcdFile) return false;
+
+ int x = dir.Dir[index].IconFmt[0];
+ for(int i = 0; i < 16; i++)
+ {
+ if (i == 8) x = dir.Dir[index].IconFmt[1];
+ buffer[i] = (x & 0x80) ? '1' : '0';
+ x = x << 1;
+ }
+ buffer[16] = 0;
+ return true;
+
}
+
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[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;
@@ -463,6 +487,7 @@ u16 GCMemcard::DEntry_FirstBlock(u8 index)
if (block > (u16) maxBlock) return 0xFFFF;
return block;
}
+
u16 GCMemcard::DEntry_BlockCount(u8 index)
{
if (!mcdFile) return 0xFFFF;
@@ -471,12 +496,13 @@ u16 GCMemcard::DEntry_BlockCount(u8 index)
if (blocks > (u16) maxBlock) return 0xFFFF;
return blocks;
}
+
u32 GCMemcard::DEntry_CommentsAddress(u8 index)
{
return BE32(dir.Dir[index].CommentsAddr);
}
-bool GCMemcard::DEntry_Comment1(u8 index, char* fn)
+bool GCMemcard::DEntry_Comment1(u8 index, char* buffer)
{
if (!mcdFile) return false;
@@ -484,14 +510,15 @@ bool GCMemcard::DEntry_Comment1(u8 index, char* fn)
u32 DataBlock = BE16(dir.Dir[index].FirstBlock) - 5;
if ((DataBlock > maxBlock) || (Comment1 == 0xFFFFFFFF))
{
- fn[0] = 0;
+ buffer[0] = 0;
return false;
}
- memcpy(fn, mc_data + (DataBlock * 0x2000) + Comment1, 32);
- fn[31] = 0;
+ memcpy(buffer, mc_data + (DataBlock * 0x2000) + Comment1, 32);
+ buffer[31] = 0;
return true;
}
-bool GCMemcard::DEntry_Comment2(u8 index, char* fn)
+
+bool GCMemcard::DEntry_Comment2(u8 index, char* buffer)
{
if (!mcdFile) return false;
@@ -500,15 +527,15 @@ bool GCMemcard::DEntry_Comment2(u8 index, char* fn)
u32 DataBlock = BE16(dir.Dir[index].FirstBlock) - 5;
if ((DataBlock > maxBlock) || (Comment1 == 0xFFFFFFFF))
{
- fn[0] = 0;
+ buffer[0] = 0;
return false;
}
- memcpy(fn, mc_data + (DataBlock * 0x2000) + Comment2, 32);
- fn[31] = 0;
+ memcpy(buffer, mc_data + (DataBlock * 0x2000) + Comment2, 32);
+ buffer[31] = 0;
return true;
}
-bool GCMemcard::GetFileInfo(u8 index, GCMemcard::DEntry& info) //index in the directory array
+bool GCMemcard::DEntry_Copy(u8 index, GCMemcard::DEntry& info)
{
if (!mcdFile) return false;
@@ -516,7 +543,7 @@ bool GCMemcard::GetFileInfo(u8 index, GCMemcard::DEntry& info) //index in the di
return true;
}
-u32 GCMemcard::GetFileData(u8 index, u8* dest, bool old) //index in the directory array
+u32 GCMemcard::DEntry_GetSaveData(u8 index, u8* dest, bool old)
{
if (!mcdFile) return NOMEMCARD;
@@ -539,8 +566,8 @@ u32 GCMemcard::GetFileData(u8 index, u8* dest, bool old) //index in the director
if (block == 0) return FAIL;
while (block != 0xffff)
{
- memcpy(dest,mc_data + 0x2000 * (block - 5), 0x2000);
- dest+=0x2000;
+ memcpy(dest, mc_data + 0x2000 * (block - 5), 0x2000);
+ dest += 0x2000;
u16 nextblock = Common::swap16(bat.Map[block - 5]);
if (block + saveLength != memcardSize && nextblock > 0)
@@ -552,12 +579,13 @@ u32 GCMemcard::GetFileData(u8 index, u8* dest, bool old) //index in the director
}
return SUCCESS;
}
+// End DEntry functions
u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove)
{
if (!mcdFile) return NOMEMCARD;
- if (GetNumFiles() >= 127)
+ if (GetNumFiles() >= DIRLEN)
{
return OUTOFDIRENTRIES;
}
@@ -565,11 +593,13 @@ u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove)
{
return OUTOFBLOCKS;
}
- if (!remove && TitlePresent(direntry)) return TITLEPRESENT;
+ if (!remove && (TitlePresent(direntry) != DIRLEN))
+ {
+ return TITLEPRESENT;
+ }
// find first free data block -- assume no freespace fragmentation
int totalspace = (((u32)BE16(hdr.Size) * 16) - 5);
-
int firstFree1 = BE16(bat.LastAllocated) + 1;
int firstFree2 = 0;
for (int i = 0; i < 126; i++)
@@ -606,7 +636,7 @@ u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove)
}
// keep assuming no freespace fragmentation, and copy over all the data
- u8*destination = mc_data + (firstFree1 - 5) * 0x2000;
+ u8 *destination = mc_data + (firstFree1 - 5) * 0x2000;
int fileBlocks = BE16(direntry.BlockCount);
memcpy(destination, contents, 0x2000 * fileBlocks);
@@ -641,11 +671,11 @@ u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove)
if (!remove)
{ // ... and dir update counter
int updateCtr = BE16(dir_backup.UpdateCounter) + 1;
- dir_backup.UpdateCounter[0] = u8(updateCtr>>8);
+ dir_backup.UpdateCounter[0] = u8(updateCtr >> 8);
dir_backup.UpdateCounter[1] = u8(updateCtr);
// ... and bat update counter
updateCtr = BE16(bat_backup.UpdateCounter) + 1;
- bat_backup.UpdateCounter[0] = u8(updateCtr>>8);
+ bat_backup.UpdateCounter[0] = u8(updateCtr >> 8);
bat_backup.UpdateCounter[1] = u8(updateCtr);
}
bat = bat_backup;
@@ -666,46 +696,46 @@ u32 GCMemcard::RemoveFile(u8 index) //index in the directory array
bat.LastAllocated[0] = (u8)(block >> 8);
bat.LastAllocated[1] = (u8)block;
- u8 i = index + 1;
+ u8 nextIndex = index + 1;
memset(&(dir.Dir[index]), 0xFF, 0x40);
- while (i < 127)
+ while (nextIndex < DIRLEN)
{
- DEntry * d = new DEntry;
- GetFileInfo(i, *d);
- u8 *t = NULL;
+ DEntry * tempDEntry = new DEntry;
+ DEntry_Copy(nextIndex, *tempDEntry);
+ u8 * tempSaveData = NULL;
//Only get file data if it is a valid dir entry
- if (BE16(d->FirstBlock) != 0xFFFF)
+ if (BE16(tempDEntry->FirstBlock) != 0xFFFF)
{
- u16 freeBlock= BE16(bat.FreeBlocks) - BE16(d->BlockCount);
+ u16 freeBlock= BE16(bat.FreeBlocks) - BE16(tempDEntry->BlockCount);
bat.FreeBlocks[0] = u8(freeBlock >> 8);
bat.FreeBlocks[1] = u8(freeBlock);
- u16 size = DEntry_BlockCount(i);
+ u16 size = DEntry_BlockCount(nextIndex);
if (size != 0xFFFF)
{
- t = new u8[size * 0x2000];
- switch (GetFileData(i, t, true))
+ tempSaveData = new u8[size * 0x2000];
+ switch (DEntry_GetSaveData(nextIndex, tempSaveData, true))
{
case NOMEMCARD:
- delete[] t;
+ delete[] tempSaveData;
break;
case FAIL:
- delete[] t;
+ delete[] tempSaveData;
return FAIL;
break;
}
}
}
- memset(&(dir.Dir[i]), 0xFF, 0x40);
- //Only call import file if Get File Data returns true
- if (t)
+ memset(&(dir.Dir[nextIndex]), 0xFF, 0x40);
+ //Only call import file if DEntry_GetSaveData returns SUCCESS
+ if (tempSaveData != NULL)
{
- ImportFile(*d, t, blocks_left);
- delete[] t;
+ ImportFile(*tempDEntry, tempSaveData, blocks_left);
+ delete[] tempSaveData;
}
- delete d;
- i++;
+ delete tempDEntry;
+ nextIndex++;
}
//Added to clean up if removing last file
@@ -728,24 +758,24 @@ u32 GCMemcard::CopyFrom(GCMemcard& source, u8 index)
{
if (!mcdFile) return NOMEMCARD;
- DEntry d;
- if (!source.GetFileInfo(index, d)) return NOMEMCARD;
+ DEntry tempDEntry;
+ if (!source.DEntry_Copy(index, tempDEntry)) return NOMEMCARD;
u32 size = source.DEntry_BlockCount(index);
if (size == 0xFFFF) return INVALIDFILESIZE;
- u8 *t = new u8[size * 0x2000];
+ u8 *tempSaveData = new u8[size * 0x2000];
- switch (source.GetFileData(index, t, true))
+ switch (source.DEntry_GetSaveData(index, tempSaveData, true))
{
case FAIL:
- delete[] t;
+ delete[] tempSaveData;
return FAIL;
case NOMEMCARD:
- delete[] t;
+ delete[] tempSaveData;
return NOMEMCARD;
default:
- u32 ret = ImportFile(d,t,0);
- delete[] t;
+ u32 ret = ImportFile(tempDEntry, tempSaveData, 0);
+ delete[] tempSaveData;
return ret;
}
}
@@ -792,10 +822,12 @@ u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
}
}
}
+ delete []tmp;
fseek(gci, offset, SEEK_SET);
- DEntry *d = new DEntry;
- fread(d, 1, 0x40, gci);
+
+ DEntry *tempDEntry = new DEntry;
+ fread(tempDEntry, 1, 0x40, gci);
int fStart = (int) ftell(gci);
fseek(gci, 0, SEEK_END);
int length = (int) ftell(gci) - fStart;
@@ -809,8 +841,8 @@ u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
// If the GCS file is added without using the GameSaves software,
// the value stored is always "1"
int blockCount = length / 0x2000;
- d->BlockCount[0] = u8(blockCount >> 8);
- d->BlockCount[1] = u8(blockCount);
+ tempDEntry->BlockCount[0] = u8(blockCount >> 8);
+ tempDEntry->BlockCount[1] = u8(blockCount);
}
break;
case SAV:
@@ -819,22 +851,22 @@ u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
// 0x34 and 0x35, 0x36 and 0x37, 0x38 and 0x39, 0x3A and 0x3B,
// 0x3C and 0x3D,0x3E and 0x3F.
// It seems that sav files also swap the BIFlags...
- ByteSwap(&d->Unused1, &d->BIFlags);
- ArrayByteSwap((d->ImageOffset));
- ArrayByteSwap(&(d->ImageOffset[2]));
- ArrayByteSwap((d->IconFmt));
- ArrayByteSwap((d->AnimSpeed));
- ByteSwap(&d->Permissions, &d->CopyCounter);
- ArrayByteSwap((d->FirstBlock));
- ArrayByteSwap((d->BlockCount));
- ArrayByteSwap((d->Unused2));
- ArrayByteSwap((d->CommentsAddr));
- ArrayByteSwap(&(d->CommentsAddr[2]));
+ ByteSwap(&tempDEntry->Unused1, &tempDEntry->BIFlags);
+ ArrayByteSwap((tempDEntry->ImageOffset));
+ ArrayByteSwap(&(tempDEntry->ImageOffset[2]));
+ ArrayByteSwap((tempDEntry->IconFmt));
+ ArrayByteSwap((tempDEntry->AnimSpeed));
+ ByteSwap(&tempDEntry->Permissions, &tempDEntry->CopyCounter);
+ ArrayByteSwap((tempDEntry->FirstBlock));
+ ArrayByteSwap((tempDEntry->BlockCount));
+ ArrayByteSwap((tempDEntry->Unused2));
+ ArrayByteSwap((tempDEntry->CommentsAddr));
+ ArrayByteSwap(&(tempDEntry->CommentsAddr[2]));
break;
default:
break;
}
- if (length != BE16(d->BlockCount) * 0x2000)
+ if (length != BE16(tempDEntry->BlockCount) * 0x2000)
{
return LENGTHFAIL;
}
@@ -842,9 +874,9 @@ u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
{
return OPENFAIL;
}
- u32 size = BE16((d->BlockCount)) * 0x2000;
- u8 *t = new u8[size];
- fread(t, 1, size, gci);
+ u32 size = BE16((tempDEntry->BlockCount)) * 0x2000;
+ u8 *tempSaveData = new u8[size];
+ fread(tempSaveData, 1, size, gci);
fclose(gci);
u32 ret;
if(!fileName2.empty())
@@ -854,59 +886,76 @@ u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
if (!gci2) return OPENFAIL;
fseek(gci2, 0, SEEK_SET);
- if (fwrite(d, 1, 0x40, gci2) != 0x40) completeWrite = false;
- int fileBlocks = BE16(d->BlockCount);
+ if (fwrite(tempDEntry, 1, 0x40, gci2) != 0x40) completeWrite = false;
+ int fileBlocks = BE16(tempDEntry->BlockCount);
fseek(gci2, 0x40, SEEK_SET);
- if (fwrite(t, 1, 0x2000 * fileBlocks, gci2) != (unsigned) (0x2000*fileBlocks))
+ if (fwrite(tempSaveData, 1, 0x2000 * fileBlocks, gci2) != (unsigned) (0x2000*fileBlocks))
completeWrite = false;
fclose(gci2);
if (completeWrite) ret = GCS;
else ret = WRITEFAIL;
}
- else ret= ImportFile(*d, t,0);
+ else ret= ImportFile(*tempDEntry, tempSaveData,0);
- delete []t;
- delete []tmp;
- delete d;
+ delete []tempSaveData;
+ delete tempDEntry;
return ret;
}
-u32 GCMemcard::ExportGci(u8 index, const char *fileName)
+u32 GCMemcard::ExportGci(u8 index, const char *fileName, std::string *fileName2)
{
- FILE *gci = fopen(fileName, "wb");
+ FILE *gci;
+ if (!strcasecmp(fileName,"."))
+ {
+ if (BE32(dir.Dir[index].Gamecode) == 0xFFFFFFFF) return SUCCESS;
+
+ int length = fileName2->length() + 42;
+ char *filename = new char[length];
+ char GameCode[5];
+
+ DEntry_GameCode(index, GameCode);
+
+ sprintf(filename,"%s/%s_%s.gci",fileName2->c_str(), GameCode, dir.Dir[index].Filename);
+ gci = fopen((const char *)filename, "wb");
+ }
+ else
+ {
+ gci = fopen(fileName, "wb");
+ }
+
if (!gci) return OPENFAIL;
bool completeWrite = true;
fseek(gci, 0, SEEK_SET);
- DEntry d;
- if (!GetFileInfo(index, d)) return NOMEMCARD;
- if (fwrite(&d, 1, 0x40, gci) != 0x40) completeWrite = false;
+ DEntry tempDEntry;
+ if (!DEntry_Copy(index, tempDEntry)) return NOMEMCARD;
+ if (fwrite(&tempDEntry, 1, 0x40, gci) != 0x40) completeWrite = false;
u32 size = DEntry_BlockCount(index);
if (size == 0xFFFF) return FAIL;
- u8 *t = new u8[size * 0x2000];
+ size *= 0x2000;
+ u8 *tempSaveData = new u8[size];
- switch(GetFileData(index, t, true))
+ switch(DEntry_GetSaveData(index, tempSaveData, true))
{
case FAIL:
fclose(gci);
- delete []t;
+ delete []tempSaveData;
return FAIL;
case NOMEMCARD:
fclose(gci);
- delete []t;
+ delete []tempSaveData;
return NOMEMCARD;
default:
break;
}
-
fseek(gci, 0x40, SEEK_SET);
- if (fwrite(t, 1, 0x2000 * BE16(d.BlockCount), gci) != (unsigned) (0x2000 * BE16(d.BlockCount)))
+ if (fwrite(tempSaveData, 1, size, gci) != size)
completeWrite = false;
fclose(gci);
- delete []t;
+ delete []tempSaveData;
if (completeWrite) return SUCCESS;
else return WRITEFAIL;
@@ -956,6 +1005,10 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays)
{
if (!mcdFile) return 0;
+ // To ensure only one type of icon is used
+ // Sonic Heroes it the only game I have seen that tries to use a CI8 and RGB5A3 icon
+ int fmtCheck = 0;
+
int formats = BE16(dir.Dir[index].IconFmt);
int fdelays = BE16(dir.Dir[index].AnimSpeed);
@@ -997,20 +1050,24 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays)
delays[i] = ((fdelays >> (2*i))&3) << 2;
data[i] = animData;
- switch (fmts[i])
+ if (!fmtCheck) fmtCheck = fmts[i];
+ if (fmtCheck == fmts[i])
{
- case 1: // CI8 with shared palette
- animData += 32*32;
- frames++;
- break;
- case 2: // RGB5A3
- animData += 32*32*2;
- frames++;
- break;
- case 3: // CI8 with own palette
- animData += 32*32 + 2*256;
- frames++;
- break;
+ switch (fmts[i])
+ {
+ case CI8SHARED: // CI8 with shared palette
+ animData += 32*32;
+ frames++;
+ break;
+ case RGB5A3: // RGB5A3
+ animData += 32*32*2;
+ frames++;
+ break;
+ case CI8: // CI8 with own palette
+ animData += 32*32 + 2*256;
+ frames++;
+ break;
+ }
}
}
@@ -1018,20 +1075,24 @@ u32 GCMemcard::ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays)
for (int i = 0; i < 8; i++)
{
- switch (fmts[i])
+
+ if (fmtCheck == fmts[i])
{
- case 1: // CI8 with shared palette
- decodeCI8image(buffer,data[i],sharedPal,32,32);
- buffer += 32*32;
- break;
- case 2: // RGB5A3
- decode5A3image(buffer, (u16*)(data[i]), 32, 32);
- break;
- case 3: // CI8 with own palette
- u16 *paldata = (u16*)(data[i] + 32*32);
- decodeCI8image(buffer, data[i], paldata, 32, 32);
- buffer += 32*32;
- break;
+ switch (fmts[i])
+ {
+ case CI8SHARED: // CI8 with shared palette
+ decodeCI8image(buffer,data[i],sharedPal,32,32);
+ buffer += 32*32;
+ break;
+ case RGB5A3: // RGB5A3
+ decode5A3image(buffer, (u16*)(data[i]), 32, 32);
+ break;
+ case CI8: // CI8 with own palette
+ u16 *paldata = (u16*)(data[i] + 32*32);
+ decodeCI8image(buffer, data[i], paldata, 32, 32);
+ buffer += 32*32;
+ break;
+ }
}
}
diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h
index 4f39e52851..2345822de4 100644
--- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h
+++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h
@@ -34,6 +34,7 @@ enum
LENGTHFAIL,
INVALIDFILESIZE,
TITLEPRESENT,
+ DIRLEN = 0x7F,
SAV = 0x80,
SAVFAIL,
GCS = 0x110,
@@ -42,6 +43,13 @@ enum
WRITEFAIL,
};
+enum
+{
+ CI8SHARED = 1,
+ RGB5A3,
+ CI8
+};
+
class GCMemcard
{
private:
@@ -118,7 +126,7 @@ private:
};
struct Directory {
- DEntry Dir[127]; //0x0000 Directory Entries (max 127)
+ DEntry Dir[DIRLEN]; //0x0000 Directory Entries (max 127)
u8 Padding[0x3a];
u8 UpdateCounter[2];//0x1ffa 2 update Counter
u8 CheckSum1[2]; //0x1ffc 2 Checksum 1
@@ -153,47 +161,50 @@ public:
bool FixChecksums();
// get number of file entries in the directory
- u32 GetNumFiles();
+ u8 GetNumFiles();
// get the free blocks from bat
u16 GetFreeBlocks();
- // 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);
-
+ // If title already on memcard returns index, otherwise returns -1
+ u8 TitlePresent(DEntry d);
+
+ // DEntry functions, all take u8 index < 127
+ // Functions that have ascii output take a char *buffer
+
+ // buffer needs to be a char[5] or bigger
+ bool DEntry_GameCode(u8 index, char *buffer);
+ // buffer needs to be a char[2] or bigger
+ bool DEntry_Markercode(u8 index, char *buffer);
+ // buffer needs to be a char[9] or bigger
+ bool DEntry_BIFlags(u8 index, char *buffer);
+ // buffer needs to be a char[32] or bigger
+ bool DEntry_FileName(u8 index, char *buffer);
u32 DEntry_ModTime(u8 index);
u32 DEntry_ImageOffset(u8 index);
- u16 DEntry_IconFmt(u8 index);
+ // buffer needs to be a char[17] or bigger
+ bool DEntry_IconFmt(u8 index, char *buffer);
u16 DEntry_AnimSpeed(u8 index);
- bool DEntry_Permissions(u8 index, char* fn);
+ // buffer needs to be a char[4] or bigger
+ bool DEntry_Permissions(u8 index, char *buffer);
u8 DEntry_CopyCounter(u8 index);
// get first block for file
u16 DEntry_FirstBlock(u8 index);
// get file length in blocks
u16 DEntry_BlockCount(u8 index);
u32 DEntry_CommentsAddress(u8 index);
-
-
// buffer needs to be a char[32] or bigger
- bool DEntry_Comment1(u8 index, char* buffer);
-
+ bool DEntry_Comment1(u8 index, char *buffer);
// buffer needs to be a char[32] or bigger
- bool DEntry_Comment2(u8 index, char* buffer);
-
- // read directory entry
- bool GetFileInfo(u8 index, DEntry& data);
+ bool DEntry_Comment2(u8 index, char *buffer);
+ // Copies a DEntry from u8 index to DEntry& data
+ bool DEntry_Copy(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(u8 index, u8* buffer, bool old);
+ u32 DEntry_GetSaveData(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
@@ -209,7 +220,7 @@ public:
u32 ImportGci(const char* fileName, std::string fileName2);
// writes a .gci file to disk containing index
- u32 ExportGci(u8 index, const char* fileName);
+ u32 ExportGci(u8 index, const char* fileName, std::string* fileName2);
// reads the banner image
bool ReadBannerRGBA8(u8 index, u32* buffer);