mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 16:19:28 +01:00
MemcardManager and GCMemcard fixes/code cleanup
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1518 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
984a3ad699
commit
d1712f15ca
@ -73,8 +73,8 @@ wxBitmap wxBitmapFromMemoryRGBA(const unsigned char* data, int width, int height
|
||||
BEGIN_EVENT_TABLE(CMemcardManager, wxDialog)
|
||||
EVT_CLOSE(CMemcardManager::OnClose)
|
||||
|
||||
EVT_BUTTON(ID_COPYTO_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_BUTTON(ID_COPYTO_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_BUTTON(ID_COPYFROM_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_BUTTON(ID_COPYFROM_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_BUTTON(ID_FIXCHECKSUM_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_BUTTON(ID_FIXCHECKSUM_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_BUTTON(ID_DELETE_A,CMemcardManager::CopyDeleteClick)
|
||||
@ -93,7 +93,7 @@ BEGIN_EVENT_TABLE(CMemcardManager, wxDialog)
|
||||
EVT_FILEPICKER_CHANGED(ID_MEMCARDPATH_B,CMemcardManager::OnPathChange)
|
||||
|
||||
EVT_MENU(ID_USEPAGES, CMemcardManager::OnMenuChange)
|
||||
EVT_MENU_RANGE(ID_COPYTO_A, ID_CONVERTTOGCI, CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU_RANGE(ID_COPYFROM_A, ID_CONVERTTOGCI, CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU_RANGE(ID_NEXTPAGE_A, ID_PREVPAGE_B, CMemcardManager::OnPageChange)
|
||||
EVT_MENU_RANGE(COLUMN_BANNER, NUMBER_OF_COLUMN, CMemcardManager::OnMenuChange)
|
||||
END_EVENT_TABLE()
|
||||
@ -191,8 +191,8 @@ void CMemcardManager::CreateGUIControls()
|
||||
t_Status_B = new wxStaticText(this, 0, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, wxEmptyString);
|
||||
|
||||
// buttons
|
||||
m_CopyTo_A = new wxButton(this, ID_COPYTO_A, wxT("<-Copy<-"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_CopyTo_B = new wxButton(this, ID_COPYTO_B, wxT("->Copy->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_CopyFrom_A = new wxButton(this, ID_COPYFROM_A, wxT("->Copy->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_CopyFrom_B = new wxButton(this, ID_COPYFROM_B, wxT("<-Copy<-"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
|
||||
m_FixChecksum_A = new wxButton(this, ID_FIXCHECKSUM_A, wxT("<-Fix Checksum"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
m_FixChecksum_B = new wxButton(this, ID_FIXCHECKSUM_B, wxT("Fix Checksum->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
|
||||
@ -222,8 +222,8 @@ void CMemcardManager::CreateGUIControls()
|
||||
wxBoxSizer* sButtons;
|
||||
sButtons = new wxBoxSizer(wxVERTICAL);
|
||||
sButtons->AddStretchSpacer(2);
|
||||
sButtons->Add(m_CopyTo_A, 0, wxEXPAND, 5);
|
||||
sButtons->Add(m_CopyTo_B, 0, wxEXPAND, 5);
|
||||
sButtons->Add(m_CopyFrom_B, 0, wxEXPAND, 5);
|
||||
sButtons->Add(m_CopyFrom_A, 0, wxEXPAND, 5);
|
||||
sButtons->AddStretchSpacer(1);
|
||||
sButtons->Add(m_FixChecksum_A, 0, wxEXPAND, 5);
|
||||
sButtons->Add(m_FixChecksum_B, 0, wxEXPAND, 5);
|
||||
@ -272,8 +272,8 @@ void CMemcardManager::CreateGUIControls()
|
||||
m_NextPage_A->Disable();
|
||||
m_PrevPage_B->Disable();
|
||||
m_NextPage_B->Disable();
|
||||
m_CopyTo_A->Disable();
|
||||
m_CopyTo_B->Disable();
|
||||
m_CopyFrom_A->Disable();
|
||||
m_CopyFrom_B->Disable();
|
||||
m_FixChecksum_A->Disable();
|
||||
m_FixChecksum_B->Disable();
|
||||
m_SaveImport_A->Disable();
|
||||
@ -313,6 +313,11 @@ void CMemcardManager::OnPathChange(wxFileDirPickerEvent& event)
|
||||
m_Delete_A->Enable();
|
||||
break;
|
||||
}
|
||||
if (memoryCard[SLOT_A])
|
||||
{
|
||||
delete memoryCard[SLOT_A];
|
||||
memoryCard[SLOT_A] = NULL;
|
||||
}
|
||||
m_MemcardList[SLOT_B]->twoCardsLoaded = false;
|
||||
m_MemcardPath_A->SetPath(wxEmptyString);
|
||||
m_MemcardList[SLOT_A]->ClearAll();
|
||||
@ -347,6 +352,11 @@ void CMemcardManager::OnPathChange(wxFileDirPickerEvent& event)
|
||||
m_Delete_B->Enable();
|
||||
break;
|
||||
}
|
||||
if (memoryCard[SLOT_B])
|
||||
{
|
||||
delete memoryCard[SLOT_B];
|
||||
memoryCard[SLOT_B] = NULL;
|
||||
}
|
||||
m_MemcardList[SLOT_A]->twoCardsLoaded = false;
|
||||
m_MemcardPath_B->SetPath(wxEmptyString);
|
||||
m_MemcardList[SLOT_B]->ClearAll();
|
||||
@ -364,13 +374,13 @@ void CMemcardManager::OnPathChange(wxFileDirPickerEvent& event)
|
||||
}
|
||||
if (m_Delete_B->IsEnabled() && m_Delete_A->IsEnabled())
|
||||
{
|
||||
m_CopyTo_A->Enable();
|
||||
m_CopyTo_B->Enable();
|
||||
m_CopyFrom_A->Enable();
|
||||
m_CopyFrom_B->Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_CopyTo_A->Disable();
|
||||
m_CopyTo_B->Disable();
|
||||
m_CopyFrom_A->Disable();
|
||||
m_CopyFrom_B->Disable();
|
||||
}
|
||||
}
|
||||
|
||||
@ -461,6 +471,69 @@ void CMemcardManager::OnMenuChange(wxCommandEvent& event)
|
||||
if (memoryCard[SLOT_B]) ReloadMemcard(m_MemcardPath_B->GetPath().mb_str(), SLOT_B, pageB);
|
||||
|
||||
}
|
||||
bool CMemcardManager::CopyDeleteSwitch(u32 error, int slot)
|
||||
{
|
||||
wxString blocksOpen;
|
||||
switch (error)
|
||||
{
|
||||
case GCS:
|
||||
SuccessAlert("File converted to .gci");
|
||||
break;
|
||||
case SUCCESS:
|
||||
if (slot != -1)
|
||||
{
|
||||
memoryCard[slot]->FixChecksums();
|
||||
if (!memoryCard[slot]->Save()) PanicAlert(E_SAVEFAILED);
|
||||
slot == SLOT_B ? ReloadMemcard(m_MemcardPath_B->GetPath().mb_str(), slot, FIRSTPAGE)
|
||||
: ReloadMemcard(m_MemcardPath_A->GetPath().mb_str(), slot, FIRSTPAGE);
|
||||
}
|
||||
break;
|
||||
case NOMEMCARD:
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case OPENFAIL:
|
||||
PanicAlert(E_OPENFAIL);
|
||||
break;
|
||||
case OUTOFBLOCKS:
|
||||
if (slot == -1)
|
||||
{
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
blocksOpen.Printf(wxT(E_OUTOFBLOCKS), memoryCard[slot]->GetFreeBlocks());
|
||||
PanicAlert(blocksOpen.ToAscii());
|
||||
break;
|
||||
case OUTOFDIRENTRIES:
|
||||
PanicAlert(E_OUTOFDIRENTRIES);
|
||||
break;
|
||||
case LENGTHFAIL:
|
||||
PanicAlert(E_LENGTHFAIL);
|
||||
break;
|
||||
case INVALIDFILESIZE:
|
||||
PanicAlert(E_INVALIDFILESIZE);
|
||||
break;
|
||||
case TITLEPRESENT:
|
||||
PanicAlert(E_TITLEPRESENT);
|
||||
break;
|
||||
case SAVFAIL:
|
||||
PanicAlert(E_SAVFAIL);
|
||||
break;
|
||||
case GCSFAIL:
|
||||
PanicAlert(E_GCSFAIL);
|
||||
break;
|
||||
case FAIL:
|
||||
if (slot == -1) return false;
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case WRITEFAIL:
|
||||
PanicAlert(E_SAVEFAILED);
|
||||
break;
|
||||
default:
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
||||
{
|
||||
@ -468,184 +541,71 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
||||
int index_A = m_MemcardList[SLOT_A]->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
int index_B = m_MemcardList[SLOT_B]->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
|
||||
int slot = SLOT_B;
|
||||
int slot2 = SLOT_A;
|
||||
int index = index_B;
|
||||
std::string fileName2("");
|
||||
wxString blocksOpen;
|
||||
|
||||
if (index_A != wxNOT_FOUND && pageA) index_A += itemsPerPage * pageA;
|
||||
if (index_B != wxNOT_FOUND && pageB) index_B += itemsPerPage * pageB;
|
||||
|
||||
switch (event.GetId())
|
||||
{
|
||||
case ID_COPYTO_A:
|
||||
if ((index_B != wxNOT_FOUND) && (memoryCard[SLOT_A] != NULL))
|
||||
case ID_COPYFROM_B:
|
||||
slot = SLOT_A;
|
||||
slot2 = SLOT_B;
|
||||
case ID_COPYFROM_A:
|
||||
index = slot2 ? index_B : index_A;
|
||||
if ((index != wxNOT_FOUND))
|
||||
{
|
||||
switch (memoryCard[SLOT_A]->CopyFrom(*memoryCard[SLOT_B], index_B))
|
||||
{
|
||||
case FAIL:
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case NOMEMCARD:
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case TITLEPRESENT:
|
||||
PanicAlert(E_TITLEPRESENT);
|
||||
break;
|
||||
case INVALIDFILESIZE:
|
||||
PanicAlert(E_INVALIDFILESIZE);
|
||||
break;
|
||||
case OUTOFBLOCKS:
|
||||
blocksOpen.Printf(wxT(E_OUTOFBLOCKS), memoryCard[slot]->GetFreeBlocks());
|
||||
PanicAlert(blocksOpen.ToAscii());
|
||||
break;
|
||||
case OUTOFDIRENTRIES:
|
||||
PanicAlert(E_OUTOFDIRENTRIES);
|
||||
break;
|
||||
case SUCCESS:
|
||||
memoryCard[SLOT_A]->FixChecksums();
|
||||
if (!memoryCard[SLOT_A]->Save()) PanicAlert(E_SAVEFAILED);
|
||||
ReloadMemcard(m_MemcardPath_A->GetPath().mb_str(), SLOT_A, FIRSTPAGE);
|
||||
break;
|
||||
default:
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case ID_COPYTO_B:
|
||||
if ((index_A != wxNOT_FOUND) && (memoryCard[SLOT_B] != NULL))
|
||||
{
|
||||
switch (memoryCard[SLOT_B]->CopyFrom(*memoryCard[SLOT_A], index_A))
|
||||
{
|
||||
case FAIL:
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case NOMEMCARD:
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case TITLEPRESENT:
|
||||
PanicAlert(E_TITLEPRESENT);
|
||||
break;
|
||||
case INVALIDFILESIZE:
|
||||
PanicAlert(E_INVALIDFILESIZE);
|
||||
break;
|
||||
case OUTOFBLOCKS:
|
||||
blocksOpen.Printf(wxT(E_OUTOFBLOCKS), memoryCard[slot]->GetFreeBlocks());
|
||||
PanicAlert(blocksOpen.ToAscii());
|
||||
break;
|
||||
case OUTOFDIRENTRIES:
|
||||
PanicAlert(E_OUTOFDIRENTRIES);
|
||||
break;
|
||||
case SUCCESS:
|
||||
memoryCard[SLOT_B]->FixChecksums();
|
||||
if (!memoryCard[SLOT_B]->Save()) PanicAlert(E_SAVEFAILED);
|
||||
ReloadMemcard(m_MemcardPath_B->GetPath().mb_str(), SLOT_B, FIRSTPAGE);
|
||||
break;
|
||||
default:
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
CopyDeleteSwitch(memoryCard[slot]->CopyFrom(*memoryCard[slot2], index), slot);
|
||||
}
|
||||
break;
|
||||
case ID_FIXCHECKSUM_A:
|
||||
slot = SLOT_A;
|
||||
case ID_FIXCHECKSUM_B:
|
||||
if (memoryCard[slot] != NULL)
|
||||
if (memoryCard[slot]->FixChecksums() && memoryCard[slot]->Save())
|
||||
{
|
||||
// Fix checksums and save the changes
|
||||
if (memoryCard[slot]->FixChecksums())
|
||||
{
|
||||
SuccessAlert("The checksum was successfully fixed");
|
||||
if (!memoryCard[slot]->Save()) PanicAlert(E_SAVEFAILED);
|
||||
}
|
||||
else PanicAlert(E_NOMEMCARD);
|
||||
|
||||
SuccessAlert("The checksum was successfully fixed");
|
||||
}
|
||||
else PanicAlert(E_SAVEFAILED);
|
||||
break;
|
||||
case ID_CONVERTTOGCI:
|
||||
fileName2 = "convert";
|
||||
case ID_SAVEIMPORT_A:
|
||||
slot = SLOT_A;
|
||||
case ID_SAVEIMPORT_B:
|
||||
if (memoryCard[slot] != NULL || !fileName2.empty())
|
||||
{
|
||||
wxString temp = wxFileSelector(_T("Select a save file to import"),
|
||||
wxEmptyString, wxEmptyString, wxEmptyString,wxString::Format
|
||||
(
|
||||
_T("Gamecube save files(*.gci,*.gcs,*.sav)|*.gci;*.gcs;*.sav|"
|
||||
"Native GCI files (*.gci)|*.gci|"
|
||||
"MadCatz Gameshark files(*.gcs)|*.gcs|"
|
||||
"Datel MaxDrive/Pro files(*.sav)|*.sav"),
|
||||
wxFileSelectorDefaultWildcardStr,
|
||||
wxFileSelectorDefaultWildcardStr
|
||||
),
|
||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
const char * fileName = temp.ToAscii();
|
||||
if (!temp.empty() && !fileName2.empty())
|
||||
{
|
||||
wxString temp = wxFileSelector(_T("Select a save file to import"),
|
||||
wxEmptyString, wxEmptyString, wxEmptyString,wxString::Format
|
||||
wxString temp2 = wxFileSelector(_T("Save GCI as.."),
|
||||
wxEmptyString, wxEmptyString, _T(".gci"), wxString::Format
|
||||
(
|
||||
_T("Gamecube save files(*.gci,*.gcs,*.sav)|*.gci;*.gcs;*.sav|"
|
||||
"Native GCI files (*.gci)|*.gci|"
|
||||
"MadCatz Gameshark files(*.gcs)|*.gcs|"
|
||||
"Datel MaxDrive/Pro files(*.sav)|*.sav"),
|
||||
_T("GCI File(*.gci)|*.gci"),
|
||||
wxFileSelectorDefaultWildcardStr,
|
||||
wxFileSelectorDefaultWildcardStr
|
||||
),
|
||||
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
const char * fileName = temp.ToAscii();
|
||||
if (!temp.empty() && !fileName2.empty())
|
||||
{
|
||||
wxString temp2 = wxFileSelector(_T("Save GCI as.."),
|
||||
wxEmptyString, wxEmptyString, _T(".gci"), wxString::Format
|
||||
(
|
||||
_T("GCI File(*.gci)|*.gci"),
|
||||
wxFileSelectorDefaultWildcardStr,
|
||||
wxFileSelectorDefaultWildcardStr
|
||||
),
|
||||
wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
|
||||
if (temp2.empty()) break;
|
||||
fileName2 = temp2.mb_str();
|
||||
}
|
||||
if (temp.length() > 0)
|
||||
{
|
||||
switch(memoryCard[slot]->ImportGci(fileName, fileName2))
|
||||
{
|
||||
case LENGTHFAIL:
|
||||
PanicAlert(E_LENGTHFAIL);
|
||||
break;
|
||||
case GCSFAIL:
|
||||
PanicAlert(E_GCSFAIL);
|
||||
break;
|
||||
case SAVFAIL:
|
||||
PanicAlert(E_SAVFAIL);
|
||||
break;
|
||||
case OPENFAIL:
|
||||
PanicAlert(E_OPENFAIL);
|
||||
break;
|
||||
case OUTOFBLOCKS:
|
||||
blocksOpen.Printf(wxT(E_OUTOFBLOCKS), memoryCard[slot]->GetFreeBlocks());
|
||||
PanicAlert(blocksOpen.ToAscii());
|
||||
break;
|
||||
case OUTOFDIRENTRIES:
|
||||
PanicAlert(E_OUTOFDIRENTRIES);
|
||||
break;
|
||||
case NOMEMCARD:
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case TITLEPRESENT:
|
||||
PanicAlert(E_TITLEPRESENT);
|
||||
break;
|
||||
case FAIL:
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case WRITEFAIL:
|
||||
PanicAlert(E_SAVEFAILED);
|
||||
break;
|
||||
case GCS:
|
||||
SuccessAlert("File converted to .gci");
|
||||
break;
|
||||
case SUCCESS:
|
||||
memoryCard[slot]->FixChecksums();
|
||||
if (!memoryCard[slot]->Save()) PanicAlert(E_SAVEFAILED);
|
||||
slot == SLOT_B ? ReloadMemcard(m_MemcardPath_B->GetPath().mb_str(), SLOT_B, FIRSTPAGE)
|
||||
: ReloadMemcard(m_MemcardPath_A->GetPath().mb_str(), SLOT_A, FIRSTPAGE);
|
||||
break;
|
||||
default:
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
|
||||
if (temp2.empty()) break;
|
||||
fileName2 = temp2.mb_str();
|
||||
}
|
||||
break;
|
||||
if (temp.length() > 0)
|
||||
{
|
||||
CopyDeleteSwitch(memoryCard[slot]->ImportGci(fileName, fileName2), slot);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ID_SAVEEXPORT_A:
|
||||
slot=SLOT_A;
|
||||
index = index_A;
|
||||
@ -661,30 +621,10 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
||||
),
|
||||
wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
|
||||
const char * fileName = temp.ToAscii();
|
||||
|
||||
if (temp.length() > 0)
|
||||
{
|
||||
switch (memoryCard[slot]->ExportGci(index, fileName))
|
||||
{
|
||||
case NOMEMCARD:
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case NOFILE:
|
||||
PanicAlert(E_NOFILE);
|
||||
break;
|
||||
case FAIL:
|
||||
//TODO: delete file if fails
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case WRITEFAIL:
|
||||
PanicAlert(E_SAVEFAILED);
|
||||
break;
|
||||
case SUCCESS:
|
||||
break;
|
||||
default:
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName), -1))
|
||||
File::Delete(temp.c_str());
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -694,21 +634,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
||||
case ID_DELETE_B:
|
||||
if (index != wxNOT_FOUND)
|
||||
{
|
||||
switch (memoryCard[slot]->RemoveFile(index))
|
||||
{
|
||||
case NOMEMCARD:
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case FAIL:
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case SUCCESS:
|
||||
memoryCard[slot]->FixChecksums();
|
||||
if (!memoryCard[slot]->Save()) PanicAlert(E_SAVEFAILED);
|
||||
slot == SLOT_B ? ReloadMemcard(m_MemcardPath_B->GetPath().mb_str(), SLOT_B, FIRSTPAGE)
|
||||
: ReloadMemcard(m_MemcardPath_A->GetPath().mb_str(), SLOT_A, FIRSTPAGE);
|
||||
break;
|
||||
}
|
||||
CopyDeleteSwitch(memoryCard[slot]->RemoveFile(index), slot);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -908,12 +834,12 @@ void CMemcardManager::CMemcardListCtrl::OnRightClick(wxMouseEvent& event)
|
||||
wxMenu popupMenu;
|
||||
if (event.GetId() == ID_MEMCARDLIST_A)
|
||||
{
|
||||
popupMenu.Append(ID_COPYTO_B, wxT("Copy to Memcard B"));
|
||||
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_COPYTO_B)->Enable(false);
|
||||
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"));
|
||||
@ -925,12 +851,12 @@ void CMemcardManager::CMemcardListCtrl::OnRightClick(wxMouseEvent& event)
|
||||
}
|
||||
else if (event.GetId() == ID_MEMCARDLIST_B)
|
||||
{
|
||||
popupMenu.Append(ID_COPYTO_A, wxT("Copy to Memcard A"));
|
||||
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_COPYTO_A)->Enable(false);
|
||||
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"));
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <wx/imaglist.h>
|
||||
|
||||
#include "IniFile.h"
|
||||
#include "FileUtil.h"
|
||||
#include "MemoryCards/GCMemcard.h"
|
||||
|
||||
#undef MEMCARD_MANAGER_STYLE
|
||||
@ -41,8 +42,7 @@
|
||||
#define E_LENGTHFAIL "Imported file has invalid length"
|
||||
#define E_GCSFAIL "Imported file has gsc extension\nbut does not have a correct header"
|
||||
#define E_SAVFAIL "Imported file has sav extension\nbut does not have a correct header"
|
||||
#define E_OPENFAIL "Imported file could not be opened\nor does not have a valid extension"
|
||||
#define E_NOFILE "Could not open gci for writing"
|
||||
#define E_OPENFAIL "File could not be opened\nor does not have a valid extension"
|
||||
#define E_SAVEFAILED "File write failed"
|
||||
#define E_UNK "Unknown error"
|
||||
#define FIRSTPAGE 0
|
||||
@ -71,8 +71,8 @@ class CMemcardManager
|
||||
wxBoxSizer *sPages_B;
|
||||
wxStaticText *t_Status_A;
|
||||
wxStaticText *t_Status_B;
|
||||
wxButton *m_CopyTo_A;
|
||||
wxButton *m_CopyTo_B;
|
||||
wxButton *m_CopyFrom_A;
|
||||
wxButton *m_CopyFrom_B;
|
||||
wxButton *m_FixChecksum_A;
|
||||
wxButton *m_FixChecksum_B;
|
||||
wxButton *m_SaveImport_A;
|
||||
@ -94,8 +94,8 @@ class CMemcardManager
|
||||
|
||||
enum
|
||||
{
|
||||
ID_COPYTO_A = 1000,
|
||||
ID_COPYTO_B,
|
||||
ID_COPYFROM_A = 1000,
|
||||
ID_COPYFROM_B,
|
||||
ID_FIXCHECKSUM_A,
|
||||
ID_FIXCHECKSUM_B,
|
||||
ID_DELETE_A,
|
||||
@ -138,6 +138,7 @@ class CMemcardManager
|
||||
void OnPageChange(wxCommandEvent& event);
|
||||
void OnPathChange(wxFileDirPickerEvent& event);
|
||||
bool ReadError(GCMemcard *memcard);
|
||||
bool CopyDeleteSwitch(u32 error, int slot);
|
||||
|
||||
class CMemcardListCtrl : public wxListCtrl
|
||||
{
|
||||
|
@ -220,6 +220,7 @@ GCMemcard::GCMemcard(const char *filename)
|
||||
(size == 0x0020) || (size == 0x0010) ||
|
||||
(size == 0x0008) || (size == 0x0004))
|
||||
{
|
||||
maxBlock = size * 0x10;
|
||||
mc_data_size = (((u32)size * 16) - 5) * 0x2000;
|
||||
mc_data = new u8[mc_data_size];
|
||||
|
||||
@ -406,7 +407,7 @@ u16 GCMemcard::GetFirstBlock(u32 index)
|
||||
{
|
||||
if (!mcdFile) return 0xFFFF;
|
||||
u16 block = BE16(dir.Dir[index].FirstBlock);
|
||||
if (block > MAXBLOCK) return 0xFFFF;
|
||||
if (block > (u16) maxBlock) return 0xFFFF;
|
||||
return block;
|
||||
}
|
||||
|
||||
@ -415,7 +416,7 @@ u16 GCMemcard::GetFileSize(u32 index) //index in the directory array
|
||||
if (!mcdFile) return 0xFFFF;
|
||||
|
||||
u16 blocks = BE16(dir.Dir[index].BlockCount);
|
||||
if (blocks > (u16) MAXBLOCK) return 0xFFFF;
|
||||
if (blocks > (u16) maxBlock) return 0xFFFF;
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@ -434,7 +435,7 @@ bool GCMemcard::GetComment1(u32 index, char *fn) //index in the directory array
|
||||
|
||||
u32 Comment1 = BE32(dir.Dir[index].CommentsAddr);
|
||||
u32 DataBlock = BE16(dir.Dir[index].FirstBlock) - 5;
|
||||
if ((DataBlock > MAXBLOCK) || (Comment1 == 0xFFFFFFFF))
|
||||
if ((DataBlock > maxBlock) || (Comment1 == 0xFFFFFFFF))
|
||||
{
|
||||
fn[0] = 0;
|
||||
return false;
|
||||
@ -451,7 +452,7 @@ bool GCMemcard::GetComment2(u32 index, char *fn) //index in the directory array
|
||||
u32 Comment1 = BE32(dir.Dir[index].CommentsAddr);
|
||||
u32 Comment2 = Comment1 + 32;
|
||||
u32 DataBlock = BE16(dir.Dir[index].FirstBlock) - 5;
|
||||
if ((DataBlock > MAXBLOCK) || (Comment1 == 0xFFFFFFFF))
|
||||
if ((DataBlock > maxBlock) || (Comment1 == 0xFFFFFFFF))
|
||||
{
|
||||
fn[0] = 0;
|
||||
return false;
|
||||
@ -703,7 +704,7 @@ u32 GCMemcard::CopyFrom(GCMemcard& source, u32 index)
|
||||
}
|
||||
}
|
||||
|
||||
s32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
|
||||
u32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
|
||||
{
|
||||
if (fileName2.empty() && !mcdFile) return OPENFAIL;
|
||||
|
||||
@ -826,7 +827,7 @@ s32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
|
||||
u32 GCMemcard::ExportGci(u32 index, const char *fileName)
|
||||
{
|
||||
FILE *gci = fopen(fileName, "wb");
|
||||
if (!gci) return NOFILE;
|
||||
if (!gci) return OPENFAIL;
|
||||
bool completeWrite = true;
|
||||
|
||||
fseek(gci, 0, SEEK_SET);
|
||||
@ -877,7 +878,7 @@ bool GCMemcard::ReadBannerRGBA8(u32 index, u32* buffer)
|
||||
u32 DataOffset = BE32(dir.Dir[index].ImageOffset);
|
||||
u32 DataBlock = BE16(dir.Dir[index].FirstBlock) - 5;
|
||||
|
||||
if ((DataBlock > MAXBLOCK) || (DataOffset == 0xFFFFFFFF))
|
||||
if ((DataBlock > maxBlock) || (DataOffset == 0xFFFFFFFF))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -914,7 +915,7 @@ u32 GCMemcard::ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays)
|
||||
u32 DataOffset = BE32(dir.Dir[index].ImageOffset);
|
||||
u32 DataBlock = BE16(dir.Dir[index].FirstBlock) - 5;
|
||||
|
||||
if ((DataBlock > MAXBLOCK) || (DataOffset == 0xFFFFFFFF))
|
||||
if ((DataBlock > maxBlock) || (DataOffset == 0xFFFFFFFF))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -983,3 +984,4 @@ u32 GCMemcard::ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays)
|
||||
|
||||
return frames;
|
||||
}
|
||||
|
||||
|
@ -22,11 +22,9 @@
|
||||
|
||||
enum
|
||||
{
|
||||
LENGTHFAIL = -4,
|
||||
GCSFAIL,
|
||||
SAVFAIL,
|
||||
OPENFAIL,
|
||||
GCI,
|
||||
GCI = 0,
|
||||
SUCCESS,
|
||||
NOMEMCARD,
|
||||
HDR_READ_ERROR,
|
||||
DIR_READ_ERROR,
|
||||
DIR_BAK_READ_ERROR,
|
||||
@ -38,18 +36,18 @@ enum
|
||||
DATA_READ_FAIL,
|
||||
HDR_SIZE_FFFF,
|
||||
NOTRAWORGCP,
|
||||
SAV = 0x80,
|
||||
GCS = 0x110,
|
||||
OPENFAIL,
|
||||
OUTOFBLOCKS,
|
||||
OUTOFDIRENTRIES,
|
||||
NOMEMCARD,
|
||||
NOFILE,
|
||||
LENGTHFAIL,
|
||||
INVALIDFILESIZE,
|
||||
TITLEPRESENT,
|
||||
SUCCESS = 0x2000,
|
||||
SAV = 0x80,
|
||||
SAVFAIL,
|
||||
GCS = 0x110,
|
||||
GCSFAIL,
|
||||
FAIL,
|
||||
WRITEFAIL,
|
||||
MAXBLOCK = 0x2049
|
||||
};
|
||||
|
||||
class GCMemcard
|
||||
@ -57,6 +55,7 @@ class GCMemcard
|
||||
private:
|
||||
void* mcdFile;
|
||||
|
||||
u32 maxBlock;
|
||||
u32 mc_data_size;
|
||||
u8* mc_data;
|
||||
|
||||
@ -157,11 +156,11 @@ public:
|
||||
bool Save();
|
||||
|
||||
void calc_checksumsBE(u16 *buf, u32 num, u16 *c1, u16 *c2);
|
||||
u32 TestChecksums();
|
||||
u32 TestChecksums();
|
||||
bool FixChecksums();
|
||||
|
||||
// get number of file entries in the directory
|
||||
u32 GetNumFiles();
|
||||
u32 GetNumFiles();
|
||||
|
||||
// get the free blocks from bat
|
||||
u16 GetFreeBlocks(void);
|
||||
@ -169,12 +168,11 @@ public:
|
||||
// Returns true if title already on memcard
|
||||
bool TitlePresent(DEntry d);
|
||||
|
||||
|
||||
// get first block for file
|
||||
u16 GetFirstBlock(u32 index);
|
||||
|
||||
// get file length in blocks
|
||||
u16 GetFileSize(u32 index);
|
||||
u16 GetFileSize(u32 index);
|
||||
|
||||
// buffer needs to be a char[32] or bigger
|
||||
bool GetFileName(u32 index, char* buffer);
|
||||
@ -196,16 +194,16 @@ public:
|
||||
|
||||
// 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);
|
||||
u32 ImportFile(DEntry& direntry, u8* contents, int remove);
|
||||
|
||||
// delete a file from the directory
|
||||
u32 RemoveFile(u32 index);
|
||||
|
||||
// reads a save from another memcard, and imports the data into this memcard
|
||||
u32 CopyFrom(GCMemcard& source, u32 index);
|
||||
u32 CopyFrom(GCMemcard& source, u32 index);
|
||||
|
||||
// reads a .gci/.gcs/.sav file and calls ImportFile or saves out a gci file
|
||||
s32 ImportGci(const char* fileName, std::string fileName2);
|
||||
u32 ImportGci(const char* fileName, std::string fileName2);
|
||||
|
||||
// writes a .gci file to disk containing index
|
||||
u32 ExportGci(u32 index, const char* fileName);
|
||||
@ -214,8 +212,5 @@ public:
|
||||
bool ReadBannerRGBA8(u32 index, u32* buffer);
|
||||
|
||||
// reads the animation frames
|
||||
u32 ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays);
|
||||
|
||||
|
||||
|
||||
u32 ReadAnimRGBA8(u32 index, u32* buffer, u8 *delays);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user