memcardmanager: lots of code cleanup a few minor fixes
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1504 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
b743aad2a5
commit
3e33e06844
|
@ -17,7 +17,7 @@
|
|||
|
||||
#include "Globals.h"
|
||||
#include "MemcardManager.h"
|
||||
|
||||
#include "Common.h"
|
||||
#include "wx/mstream.h"
|
||||
|
||||
const u8 hdr[] = {
|
||||
|
@ -89,31 +89,13 @@ BEGIN_EVENT_TABLE(CMemcardManager, wxDialog)
|
|||
EVT_BUTTON(ID_PREVPAGE_B, CMemcardManager::OnPageChange)
|
||||
EVT_BUTTON(ID_NEXTPAGE_B, CMemcardManager::OnPageChange)
|
||||
|
||||
EVT_MENU(ID_COPYTO_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_COPYTO_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_FIXCHECKSUM_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_FIXCHECKSUM_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_DELETE_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_DELETE_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_SAVEIMPORT_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_SAVEEXPORT_B,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_SAVEIMPORT_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_SAVEEXPORT_A,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_CONVERTTOGCI,CMemcardManager::CopyDeleteClick)
|
||||
EVT_MENU(ID_PREVPAGE_A, CMemcardManager::OnPageChange)
|
||||
EVT_MENU(ID_NEXTPAGE_A, CMemcardManager::OnPageChange)
|
||||
EVT_MENU(ID_PREVPAGE_B, CMemcardManager::OnPageChange)
|
||||
EVT_MENU(ID_NEXTPAGE_B, CMemcardManager::OnPageChange)
|
||||
EVT_MENU(COLUMN_BANNER, CMemcardManager::OnMenuChange)
|
||||
EVT_MENU(COLUMN_TITLE, CMemcardManager::OnMenuChange)
|
||||
EVT_MENU(COLUMN_COMMENT, CMemcardManager::OnMenuChange)
|
||||
EVT_MENU(COLUMN_ICON, CMemcardManager::OnMenuChange)
|
||||
EVT_MENU(COLUMN_BLOCKS, CMemcardManager::OnMenuChange)
|
||||
EVT_MENU(COLUMN_FIRSTBLOCK, CMemcardManager::OnMenuChange)
|
||||
EVT_MENU(ID_USEPAGES, CMemcardManager::OnMenuChange)
|
||||
|
||||
EVT_FILEPICKER_CHANGED(ID_MEMCARDPATH_A,CMemcardManager::OnPathChange)
|
||||
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_NEXTPAGE_A, ID_PREVPAGE_B, CMemcardManager::OnPageChange)
|
||||
EVT_MENU_RANGE(COLUMN_BANNER, NUMBER_OF_COLUMN, CMemcardManager::OnMenuChange)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
BEGIN_EVENT_TABLE(CMemcardManager::CMemcardListCtrl, wxListCtrl)
|
||||
|
@ -320,7 +302,7 @@ void CMemcardManager::OnPathChange(wxFileDirPickerEvent& event)
|
|||
}
|
||||
if (!strcasecmp(m_MemcardPath_A->GetPath().mb_str(), m_MemcardPath_B->GetPath().mb_str()))
|
||||
{
|
||||
wxMessageBox(wxT("Memcard already opened"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_ALREADYOPENED);
|
||||
}
|
||||
else if (ReloadMemcard(event.GetPath().mb_str(), SLOT_A, pageA))
|
||||
{
|
||||
|
@ -354,7 +336,7 @@ void CMemcardManager::OnPathChange(wxFileDirPickerEvent& event)
|
|||
}
|
||||
if (!strcasecmp(m_MemcardPath_A->GetPath().mb_str(), m_MemcardPath_B->GetPath().mb_str()))
|
||||
{
|
||||
wxMessageBox(wxT("Memcard already opened"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_ALREADYOPENED);
|
||||
}
|
||||
else if (ReloadMemcard(event.GetPath().mb_str(), SLOT_B, pageB))
|
||||
{
|
||||
|
@ -496,43 +478,40 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
|||
switch (event.GetId())
|
||||
{
|
||||
case ID_COPYTO_A:
|
||||
if ((index_B != wxNOT_FOUND) && (memoryCard[0] != NULL))
|
||||
if ((index_B != wxNOT_FOUND) && (memoryCard[SLOT_A] != NULL))
|
||||
{
|
||||
switch (memoryCard[SLOT_A]->CopyFrom(*memoryCard[SLOT_B], index_B))
|
||||
{
|
||||
case FAIL:
|
||||
wxMessageBox(wxT("Invalid bat.map or dir entry"), wxT("Failure"), wxOK);
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case NOMEMCARD:
|
||||
wxMessageBox(wxT("File is not recognized as a memcard"), wxT("Failure"), wxOK);
|
||||
break;
|
||||
case SUCCESS:
|
||||
memoryCard[SLOT_A]->Save();
|
||||
ReloadMemcard(m_MemcardPath_A->GetPath().mb_str(), SLOT_A, FIRSTPAGE);
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case TITLEPRESENT:
|
||||
wxMessageBox(wxT("Memcard already has a save for this title"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_TITLEPRESENT);
|
||||
break;
|
||||
case INVALIDFILESIZE:
|
||||
wxMessageBox(wxT("The save you are trying to copy has an invalid file size"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_INVALIDFILESIZE);
|
||||
break;
|
||||
case OUTOFBLOCKS:
|
||||
blocksOpen.Printf(wxT("Only %d blocks available"), memoryCard[slot]->GetFreeBlocks());
|
||||
blocksOpen.Printf(wxT(E_OUTOFBLOCKS), memoryCard[slot]->GetFreeBlocks());
|
||||
wxMessageBox(blocksOpen, wxT("Error"), wxOK|wxICON_ERROR);
|
||||
break;
|
||||
case OUTOFDIRENTRIES:
|
||||
wxMessageBox(wxT("No free dir index entries"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
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:
|
||||
wxMessageBox(wxEmptyString, wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox(wxT("You have not selected a save to copy"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
}
|
||||
break;
|
||||
case ID_COPYTO_B:
|
||||
if ((index_A != wxNOT_FOUND) && (memoryCard[SLOT_B] != NULL))
|
||||
|
@ -540,41 +519,34 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
|||
switch (memoryCard[SLOT_B]->CopyFrom(*memoryCard[SLOT_A], index_A))
|
||||
{
|
||||
case FAIL:
|
||||
wxMessageBox(wxT("Invalid bat.map or dir entry"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case NOMEMCARD:
|
||||
wxMessageBox(wxT("File is not recognized as a memcard"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
break;
|
||||
case SUCCESS:
|
||||
memoryCard[SLOT_B]->Save();
|
||||
ReloadMemcard(m_MemcardPath_B->GetPath().mb_str(), SLOT_B, FIRSTPAGE);
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case TITLEPRESENT:
|
||||
wxMessageBox(wxT("Memcard already has a save for this title"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_TITLEPRESENT);
|
||||
break;
|
||||
case INVALIDFILESIZE:
|
||||
wxMessageBox(wxT("The save you are trying to copy has an invalid file size"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_INVALIDFILESIZE);
|
||||
break;
|
||||
case OUTOFBLOCKS:
|
||||
blocksOpen.Printf(wxT("Only %d blocks available"), memoryCard[slot]->GetFreeBlocks());
|
||||
wxMessageBox(blocksOpen, wxT("Error"), wxOK|wxICON_ERROR);
|
||||
blocksOpen.Printf(wxT(E_OUTOFBLOCKS), memoryCard[slot]->GetFreeBlocks());
|
||||
PanicAlert(blocksOpen);
|
||||
break;
|
||||
case OUTOFDIRENTRIES:
|
||||
wxMessageBox(wxT("No free dir index entries"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
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:
|
||||
wxMessageBox(wxEmptyString, wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox(wxT("You have not selected a save to copy"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
}
|
||||
break;
|
||||
case ID_FIXCHECKSUM_A:
|
||||
slot = SLOT_A;
|
||||
|
@ -582,18 +554,17 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
|||
if (memoryCard[slot] != NULL)
|
||||
{
|
||||
// Fix checksums and save the changes
|
||||
memoryCard[slot]->FixChecksums() ? wxMessageBox(wxT("The checksum was successfully fixed"), wxT("Success"), wxOK)
|
||||
: wxMessageBox(wxT("The checksum could not be successfully fixed"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
memoryCard[slot]->Save();
|
||||
}
|
||||
else
|
||||
if (memoryCard[slot]->FixChecksums())
|
||||
{
|
||||
wxMessageBox(wxT("memorycard is not loaded"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
wxMessageBox(wxT("The checksum was successfully fixed"), wxT("Success"), wxOK);
|
||||
if (!memoryCard[slot]->Save()) PanicAlert(E_SAVEFAILED);
|
||||
}
|
||||
else PanicAlert(E_NOMEMCARD);
|
||||
|
||||
}
|
||||
break;
|
||||
case ID_CONVERTTOGCI:
|
||||
fileName2 = "convert";
|
||||
|
||||
case ID_SAVEIMPORT_A:
|
||||
slot = SLOT_A;
|
||||
case ID_SAVEIMPORT_B:
|
||||
|
@ -629,60 +600,51 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
|||
switch(memoryCard[slot]->ImportGci(fileName, fileName2))
|
||||
{
|
||||
case LENGTHFAIL:
|
||||
wxMessageBox(wxT("Imported file has invalid length"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_LENGTHFAIL);
|
||||
break;
|
||||
case GCSFAIL:
|
||||
wxMessageBox(wxT("Imported file has gsc extension\nbut"
|
||||
" does not have a correct header"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_GCSFAIL);
|
||||
break;
|
||||
case SAVFAIL:
|
||||
wxMessageBox(wxT("Imported file has sav extension\nbut"
|
||||
" does not have a correct header"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_SAVFAIL);
|
||||
break;
|
||||
case OPENFAIL:
|
||||
wxMessageBox(wxT("Imported file could not be opened\nor"
|
||||
" does not have a valid extension"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
break;
|
||||
case GCS:
|
||||
wxMessageBox(wxT("File converted to .gci"),
|
||||
wxT("Success"), wxOK);
|
||||
PanicAlert(E_OPENFAIL);
|
||||
break;
|
||||
case OUTOFBLOCKS:
|
||||
blocksOpen.Printf(wxT("Only %d blocks available"), memoryCard[slot]->GetFreeBlocks());
|
||||
wxMessageBox(blocksOpen, wxT("Error"), wxOK|wxICON_ERROR);
|
||||
blocksOpen.Printf(wxT(E_OUTOFBLOCKS), memoryCard[slot]->GetFreeBlocks());
|
||||
PanicAlert(blocksOpen);
|
||||
break;
|
||||
case OUTOFDIRENTRIES:
|
||||
wxMessageBox(wxT("No free dir index entries"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_OUTOFDIRENTRIES);
|
||||
break;
|
||||
case NOMEMCARD:
|
||||
wxMessageBox(wxT("File is not recognized as a memcard"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case TITLEPRESENT:
|
||||
wxMessageBox(wxT("Memcard already has a save for this title"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_TITLEPRESENT);
|
||||
break;
|
||||
case FAIL:
|
||||
wxMessageBox(wxT("Invalid bat.map or dir entry"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
default:
|
||||
memoryCard[slot]->Save();
|
||||
case WRITEFAIL:
|
||||
PanicAlert(E_SAVEFAILED);
|
||||
break;
|
||||
case GCS:
|
||||
wxMessageBox(wxT("File converted to .gci"), wxT("Success"), wxOK);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox(wxT("Memory card is not loaded"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
}
|
||||
break;
|
||||
case ID_SAVEEXPORT_A:
|
||||
slot=SLOT_A;
|
||||
|
@ -705,27 +667,26 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
|||
switch (memoryCard[slot]->ExportGci(index, fileName))
|
||||
{
|
||||
case NOMEMCARD:
|
||||
wxMessageBox(wxT("File is not recognized as a memcard"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case NOFILE:
|
||||
wxMessageBox(wxT("Could not open gci for writing"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_NOFILE);
|
||||
break;
|
||||
case FAIL:
|
||||
//TODO: delete file if fails
|
||||
wxMessageBox(wxT("Invalid bat.map or dir entry"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case WRITEFAIL:
|
||||
PanicAlert(E_SAVEFAILED);
|
||||
break;
|
||||
case SUCCESS:
|
||||
break;
|
||||
default:
|
||||
PanicAlert(E_UNK);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox(wxT("You have not selected a save to export"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
}
|
||||
break;
|
||||
case ID_DELETE_A:
|
||||
slot=SLOT_A;
|
||||
|
@ -736,24 +697,19 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
|
|||
switch (memoryCard[slot]->RemoveFile(index))
|
||||
{
|
||||
case NOMEMCARD:
|
||||
wxMessageBox(wxT("File is not recognized as a memcard"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_NOMEMCARD);
|
||||
break;
|
||||
case FAIL:
|
||||
wxMessageBox(wxT("Invalid bat.map or dir entry"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
PanicAlert(E_INVALID);
|
||||
break;
|
||||
case SUCCESS:
|
||||
memoryCard[slot]->Save();
|
||||
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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
wxMessageBox(wxT("You have not selected a save to delete"), wxT("Error"), wxOK|wxICON_ERROR);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -921,33 +877,17 @@ bool CMemcardManager::ReadError(GCMemcard *memcard)
|
|||
{
|
||||
if (!memcard->fail[0]) return false;
|
||||
wxString wxBlock;
|
||||
if (memcard->fail[HDR_READ_ERROR]) wxMessageBox(wxT("Failed to read header correctly\n(0x0000-0x1FFF)"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[DIR_READ_ERROR]) wxMessageBox(wxT("Failed to read directory correctly\n(0x2000-0x3FFF)"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[DIR_BAK_READ_ERROR]) wxMessageBox(wxT("Failed to read directory backup correctly\n(0x4000-0x5FFF)"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[BAT_READ_ERROR]) wxMessageBox(wxT("Failed to read block allocation table correctly\n(0x6000-0x7FFF)"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[BAT_BAK_READ_ERROR]) wxMessageBox(wxT("Failed to read block allocation table backup correctly\n(0x8000-0x9FFF)"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[HDR_CSUM_FAIL]) wxMessageBox(wxT("Header checksum failed"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[DIR_CSUM_FAIL])
|
||||
{
|
||||
wxMessageBox(wxT("Directory checksum failed"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
wxMessageBox(wxT("Directory backup checksum failed"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
}
|
||||
if (memcard->fail[BAT_CSUM_FAIL]) wxMessageBox(wxT("Block Allocation Table checksum failed"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[DATA_READ_FAIL]) wxMessageBox(wxT("Failed to read save data\n(0xA000-)\nMemcard may be truncated"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[HDR_SIZE_FFFF]) wxMessageBox(wxT("Memcard failed to load\n Card size is invalid"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[NOTRAWORGCP]) wxMessageBox(wxT("File does not have a valid extension (.raw/.gcp)"),
|
||||
wxT("Error"), wxOK|wxICON_ERROR);
|
||||
if (memcard->fail[HDR_READ_ERROR]) PanicAlert("Failed to read header correctly\n(0x0000-0x1FFF)");
|
||||
if (memcard->fail[DIR_READ_ERROR]) PanicAlert("Failed to read directory correctly\n(0x2000-0x3FFF)");
|
||||
if (memcard->fail[DIR_BAK_READ_ERROR]) PanicAlert("Failed to read directory backup correctly\n(0x4000-0x5FFF)");
|
||||
if (memcard->fail[BAT_READ_ERROR]) PanicAlert("Failed to read block allocation table correctly\n(0x6000-0x7FFF)");
|
||||
if (memcard->fail[BAT_BAK_READ_ERROR]) PanicAlert("Failed to read block allocation table backup correctly\n(0x8000-0x9FFF)");
|
||||
if (memcard->fail[HDR_CSUM_FAIL]) PanicAlert("Header checksum failed");
|
||||
if (memcard->fail[DIR_CSUM_FAIL]) PanicAlert("Directory checksum failed\n and Directory backup checksum failed");
|
||||
if (memcard->fail[BAT_CSUM_FAIL]) PanicAlert("Block Allocation Table checksum failed");
|
||||
if (memcard->fail[DATA_READ_FAIL]) PanicAlert("Failed to read save data\n(0xA000-)\nMemcard may be truncated");
|
||||
if (memcard->fail[HDR_SIZE_FFFF]) PanicAlert("Memcard failed to load\n Card size is invalid");
|
||||
if (memcard->fail[NOTRAWORGCP]) PanicAlert("File does not have a valid extension (.raw/.gcp)");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,20 @@
|
|||
#undef MEMCARD_MANAGER_STYLE
|
||||
#define MEMCARD_MANAGER_STYLE wxCAPTION | wxSYSTEM_MENU | wxDIALOG_NO_PARENT | wxCLOSE_BOX | wxRESIZE_BORDER | wxMAXIMIZE_BOX
|
||||
#define MEMCARDMAN_TITLE "Memory Card Manager WARNING-Make backups before using, should be fixed but could mangle stuff!"
|
||||
#define E_ALREADYOPENED "Memcard already opened"
|
||||
#define E_INVALID "Invalid bat.map or dir entry"
|
||||
#define E_NOMEMCARD "File is not recognized as a memcard"
|
||||
#define E_TITLEPRESENT "Memcard already has a save for this title"
|
||||
#define E_INVALIDFILESIZE "The save you are trying to copy has an invalid file size"
|
||||
#define E_OUTOFBLOCKS "Only %d blocks available"
|
||||
#define E_OUTOFDIRENTRIES "No free dir index entries"
|
||||
#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_SAVEFAILED "File write failed"
|
||||
#define E_UNK "Unknown error"
|
||||
#define FIRSTPAGE 0
|
||||
#define SLOT_A 0
|
||||
#define SLOT_B 1
|
||||
|
@ -68,10 +82,10 @@ class CMemcardManager
|
|||
wxButton *m_ConvertToGci;
|
||||
wxButton *m_Delete_A;
|
||||
wxButton *m_Delete_B;
|
||||
wxButton *m_PrevPage_A;
|
||||
wxButton *m_NextPage_A;
|
||||
wxButton *m_PrevPage_B;
|
||||
wxButton *m_NextPage_B;
|
||||
wxButton *m_PrevPage_A;
|
||||
wxButton *m_PrevPage_B;
|
||||
wxStaticBoxSizer *sMemcard_A;
|
||||
wxStaticBoxSizer *sMemcard_B;
|
||||
wxFilePickerCtrl *m_MemcardPath_A;
|
||||
|
@ -80,25 +94,25 @@ class CMemcardManager
|
|||
|
||||
enum
|
||||
{
|
||||
ID_COPYTO_B = 1000,
|
||||
ID_COPYTO_A,
|
||||
ID_COPYTO_A = 1000,
|
||||
ID_COPYTO_B,
|
||||
ID_FIXCHECKSUM_A,
|
||||
ID_FIXCHECKSUM_B,
|
||||
ID_DELETE_B,
|
||||
ID_DELETE_A,
|
||||
ID_MEMCARDPATH_A,
|
||||
ID_MEMCARDPATH_B,
|
||||
ID_NEXTPAGE_A,
|
||||
ID_PREVPAGE_A,
|
||||
ID_NEXTPAGE_B,
|
||||
ID_PREVPAGE_B,
|
||||
ID_DELETE_B,
|
||||
ID_SAVEEXPORT_A,
|
||||
ID_SAVEEXPORT_B,
|
||||
ID_SAVEIMPORT_A,
|
||||
ID_SAVEIMPORT_B,
|
||||
ID_CONVERTTOGCI,
|
||||
ID_NEXTPAGE_A,
|
||||
ID_NEXTPAGE_B,
|
||||
ID_PREVPAGE_A,
|
||||
ID_PREVPAGE_B,
|
||||
ID_MEMCARDLIST_A,
|
||||
ID_MEMCARDLIST_B,
|
||||
ID_MEMCARDPATH_A,
|
||||
ID_MEMCARDPATH_B,
|
||||
ID_USEPAGES,
|
||||
ID_DUMMY_VALUE_ //don't remove this value unless you have other enum values
|
||||
};
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#ifdef _WIN32
|
||||
#include "stdafx.h"
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "GCMemcard.h"
|
||||
|
@ -196,10 +195,6 @@ u32 GCMemcard::RemoveFile(u32 index) //index in the directory array
|
|||
dir.UpdateCounter[0] = u8(updateCtr >> 8);
|
||||
dir.UpdateCounter[1] = u8(updateCtr);
|
||||
|
||||
|
||||
FixChecksums();
|
||||
Save();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -299,12 +294,6 @@ u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove)
|
|||
bat_backup.UpdateCounter[1] = u8(updateCtr);
|
||||
}
|
||||
bat = bat_backup;
|
||||
|
||||
if (!remove)
|
||||
{
|
||||
FixChecksums();
|
||||
Save();
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -312,8 +301,8 @@ u32 GCMemcard::GetFileData(u32 index, u8* dest, bool old) //index in the directo
|
|||
{
|
||||
if (!mcdFile) return NOMEMCARD;
|
||||
|
||||
u16 block = BE16(dir.Dir[index].FirstBlock);
|
||||
u16 saveLength = BE16(dir.Dir[index].BlockCount);
|
||||
u16 block = GetFirstBlock(index);
|
||||
u16 saveLength = GetFileSize(index);
|
||||
u16 memcardSize = BE16(hdr.Size) * 0x0010;
|
||||
|
||||
if ((block == 0xFFFF) || (saveLength == 0xFFFF)
|
||||
|
@ -328,7 +317,7 @@ u32 GCMemcard::GetFileData(u32 index, u8* dest, bool old) //index in the directo
|
|||
}
|
||||
else
|
||||
{
|
||||
assert(block > 0);
|
||||
if (block == 0) return FAIL;
|
||||
while (block != 0xffff)
|
||||
{
|
||||
memcpy(dest,mc_data + 0x2000 * (block - 5), 0x2000);
|
||||
|
@ -660,6 +649,7 @@ bool GCMemcard::FixChecksums()
|
|||
|
||||
return true;
|
||||
}
|
||||
|
||||
u32 GCMemcard::CopyFrom(GCMemcard& source, u32 index)
|
||||
{
|
||||
if (!mcdFile) return NOMEMCARD;
|
||||
|
@ -784,15 +774,19 @@ s32 GCMemcard::ImportGci(const char *fileName, std::string fileName2)
|
|||
if(!fileName2.empty())
|
||||
{
|
||||
FILE * gci2 = fopen(fileName2.c_str(), "wb");
|
||||
bool completeWrite = true;
|
||||
if (!gci2) return OPENFAIL;
|
||||
fseek(gci2, 0, SEEK_SET);
|
||||
assert(fwrite(d, 1, 0x40, gci2)==0x40);
|
||||
|
||||
if (fwrite(d, 1, 0x40, gci2) != 0x40) completeWrite = false;
|
||||
int fileBlocks = BE16(d->BlockCount);
|
||||
fseek(gci2, 0x40, SEEK_SET);
|
||||
|
||||
assert(fwrite(t, 1, 0x2000 * fileBlocks, gci2)==(unsigned) (0x2000*fileBlocks));
|
||||
if (fwrite(t, 1, 0x2000 * fileBlocks, gci2) != (unsigned) (0x2000*fileBlocks))
|
||||
completeWrite = false;
|
||||
fclose(gci2);
|
||||
ret = GCS;
|
||||
if (completeWrite) ret = GCS;
|
||||
else ret = WRITEFAIL;
|
||||
}
|
||||
else ret= ImportFile(*d, t,0);
|
||||
|
||||
|
@ -806,11 +800,13 @@ u32 GCMemcard::ExportGci(u32 index, const char *fileName)
|
|||
{
|
||||
FILE *gci = fopen(fileName, "wb");
|
||||
if (!gci) return NOFILE;
|
||||
bool completeWrite = true;
|
||||
|
||||
fseek(gci, 0, SEEK_SET);
|
||||
|
||||
DEntry d;
|
||||
if (!GetFileInfo(index, d)) return NOMEMCARD;
|
||||
assert(fwrite(&d, 1, 0x40, gci) == 0x40);
|
||||
if (fwrite(&d, 1, 0x40, gci) != 0x40) completeWrite = false;
|
||||
|
||||
u32 size = GetFileSize(index);
|
||||
if (size == 0xFFFF) return FAIL;
|
||||
|
@ -831,25 +827,27 @@ u32 GCMemcard::ExportGci(u32 index, const char *fileName)
|
|||
}
|
||||
|
||||
fseek(gci, 0x40, SEEK_SET);
|
||||
assert(fwrite(t, 1, 0x2000 * BE16(d.BlockCount), gci)== (unsigned) (0x2000 * BE16(d.BlockCount)));
|
||||
if (fwrite(t, 1, 0x2000 * BE16(d.BlockCount), gci) != (unsigned) (0x2000 * BE16(d.BlockCount)))
|
||||
completeWrite = false;
|
||||
fclose(gci);
|
||||
delete []t;
|
||||
return SUCCESS;
|
||||
if (completeWrite) return SUCCESS;
|
||||
else return WRITEFAIL;
|
||||
|
||||
}
|
||||
|
||||
bool GCMemcard::Save()
|
||||
{
|
||||
if (!mcdFile) return false;
|
||||
|
||||
bool completeWrite = true;
|
||||
FILE *mcd=(FILE*)mcdFile;
|
||||
fseek(mcd, 0, SEEK_SET);
|
||||
assert(fwrite(&hdr, 1, 0x2000, mcd) == 0x2000);
|
||||
assert(fwrite(&dir, 1, 0x2000, mcd) == 0x2000);
|
||||
assert(fwrite(&dir_backup, 1, 0x2000, mcd) == 0x2000);
|
||||
assert(fwrite(&bat, 1, 0x2000 ,mcd) == 0x2000);
|
||||
assert(fwrite(&bat_backup, 1, 0x2000, mcd) == 0x2000);
|
||||
assert(fwrite(mc_data, 1, mc_data_size, mcd) == mc_data_size);
|
||||
return true;
|
||||
if (fwrite(&hdr, 1, 0x2000, mcd) != 0x2000) completeWrite = false;
|
||||
if (fwrite(&dir, 1, 0x2000, mcd) != 0x2000) completeWrite = false;
|
||||
if (fwrite(&dir_backup, 1, 0x2000, mcd) != 0x2000) completeWrite = false;
|
||||
if (fwrite(&bat, 1, 0x2000 ,mcd) != 0x2000) completeWrite = false;
|
||||
if (fwrite(&bat_backup, 1, 0x2000, mcd) != 0x2000) completeWrite = false;
|
||||
if (fwrite(mc_data, 1, mc_data_size, mcd) != mc_data_size) completeWrite = false;
|
||||
return completeWrite;
|
||||
}
|
||||
|
||||
bool GCMemcard::IsOpen()
|
||||
|
|
|
@ -48,6 +48,7 @@ enum
|
|||
TITLEPRESENT,
|
||||
SUCCESS = 0x2000,
|
||||
FAIL,
|
||||
WRITEFAIL,
|
||||
MAXBLOCK = 0x2049
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue