diff --git a/Source/Core/DolphinWX/Src/MemcardManager.cpp b/Source/Core/DolphinWX/Src/MemcardManager.cpp index 8cbc33dfe6..574096e178 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.cpp +++ b/Source/Core/DolphinWX/Src/MemcardManager.cpp @@ -75,6 +75,7 @@ BEGIN_EVENT_TABLE(CMemcardManager, wxDialog) EVT_CLOSE(CMemcardManager::OnClose) EVT_BUTTON(ID_COPYRIGHT,CMemcardManager::CopyDeleteClick) EVT_BUTTON(ID_COPYLEFT,CMemcardManager::CopyDeleteClick) + EVT_BUTTON(ID_FIXCHECKSUM,CMemcardManager::CopyDeleteClick) EVT_BUTTON(ID_DELETERIGHT,CMemcardManager::CopyDeleteClick) EVT_BUTTON(ID_DELETELEFT,CMemcardManager::CopyDeleteClick) EVT_FILEPICKER_CHANGED(ID_MEMCARD1PATH,CMemcardManager::OnPathChange) @@ -107,6 +108,8 @@ void CMemcardManager::CreateGUIControls() m_CopyRight = new wxButton(this, ID_COPYRIGHT, wxT("->Copy->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); m_CopyLeft = new wxButton(this, ID_COPYLEFT, wxT("<-Copy<-"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); + m_FixChecksum = new wxButton(this, ID_FIXCHECKSUM, wxT("Fix\nchecksum"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); + m_DeleteRight = new wxButton(this, ID_DELETERIGHT, wxT("Delete->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); m_DeleteLeft = new wxButton(this, ID_DELETELEFT, wxT("<-Delete"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator); @@ -136,6 +139,8 @@ void CMemcardManager::CreateGUIControls() sButtons->Add(m_CopyRight, 0, 0, 5); sButtons->Add(m_CopyLeft, 0, 0, 5); sButtons->AddStretchSpacer(2); + sButtons->Add(m_FixChecksum, 0, 0, 5); + sButtons->AddStretchSpacer(2); sButtons->Add(m_DeleteRight, 0, 0, 5); sButtons->Add(m_DeleteLeft, 0, 0, 5); sButtons->AddStretchSpacer(1); @@ -195,6 +200,17 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0); } break; + case ID_FIXCHECKSUM: + if(m_MemcardList[0]->GetItemCount() > 0) + { + // --------------------------------------------------------------------------------------- + // Fix checksums and save the changes + memoryCard[0]->FixChecksums(); + memoryCard[0]->Save(); + MessageBox(0, "The checksum was successfully fixed", "Message", 0); + // --------------------------------------------------------------------------------------- + } + break; case ID_DELETERIGHT: if(index1 != -1) { @@ -221,8 +237,6 @@ void CMemcardManager::ReloadMemcard(const char *fileName, int card) // TODO: add error checking and animate icons memoryCard[card] = new GCMemcard(fileName); - memoryCard[0]->Save(); // save the changes we made in TestChecksums - m_MemcardList[card]->Hide(); m_MemcardList[card]->ClearAll(); m_MemcardList[card]->InsertColumn(COLUMN_BANNER, _T("Banner")); diff --git a/Source/Core/DolphinWX/Src/MemcardManager.h b/Source/Core/DolphinWX/Src/MemcardManager.h index f848027769..12df1504a5 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.h +++ b/Source/Core/DolphinWX/Src/MemcardManager.h @@ -45,6 +45,7 @@ class CMemcardManager wxBoxSizer* sMain; wxButton* m_CopyRight; wxButton* m_CopyLeft; + wxButton* m_FixChecksum; wxButton* m_DeleteRight; wxButton* m_DeleteLeft; wxStaticBoxSizer* sMemcard1; @@ -60,6 +61,7 @@ class CMemcardManager { ID_COPYRIGHT = 1000, ID_COPYLEFT, + ID_FIXCHECKSUM, ID_DELETERIGHT, ID_DELETELEFT, ID_MEMCARD1PATH, diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp index 7d6c8eaffd..0bee47ca44 100644 --- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp +++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp @@ -525,26 +525,10 @@ u32 GCMemcard::TestChecksums() if(BE16(dir.CheckSum1)!=csum1) results |= 2; if(BE16(dir.CheckSum2)!=csum2) results |= 2; - // ------------------------------------------------------------------------------------------ - // Save the checksums we just calculated - dir.CheckSum1[0]=u8(csum1>>8); - dir.CheckSum1[1]=u8(csum1); - dir.CheckSum2[0]=u8(csum2>>8); - dir.CheckSum2[1]=u8(csum2); - // ------------------------------------------------------------------------------------------ - calc_checksumsBE((u16*)&dir_backup,0xFFE,&csum1,&csum2); if(BE16(dir_backup.CheckSum1)!=csum1) results |= 4; if(BE16(dir_backup.CheckSum2)!=csum2) results |= 4; - // ------------------------------------------------------------------------------------------ - // Save the checksums we just calculated - dir_backup.CheckSum1[0]=u8(csum1>>8); - dir_backup.CheckSum1[1]=u8(csum1); - dir_backup.CheckSum2[0]=u8(csum2>>8); - dir_backup.CheckSum2[1]=u8(csum2); - // ------------------------------------------------------------------------------------------ - calc_checksumsBE((u16*)(((u8*)&bat)+4),0xFFE,&csum1,&csum2); if(BE16(bat.CheckSum1)!=csum1) results |= 8; if(BE16(bat.CheckSum2)!=csum2) results |= 8; @@ -556,6 +540,47 @@ u32 GCMemcard::TestChecksums() return 0; } + +// ========================================================================================== +// Fix checksums - I'll begin with fixing Directory and Directory backup. Feel free to add the +// other blocks. +// ------------------------------------------------------------------------------------------ +u32 GCMemcard::FixChecksums() +{ + if(!mcdFile) return 0xFFFFFFFF; + + u16 csum1=0,csum2=0; + + u32 results = 0; + + calc_checksumsBE((u16*)&dir,0xFFE,&csum1,&csum2); + if(BE16(dir.CheckSum1) != csum1) results |= 2; + if(BE16(dir.CheckSum2) != csum2) results |= 2; + + // ------------------------------------------------------------------------------------------ + // Save the values we just read + dir.CheckSum1[0]=u8(csum1>>8); + dir.CheckSum1[1]=u8(csum1); + dir.CheckSum2[0]=u8(csum2>>8); + dir.CheckSum2[1]=u8(csum2); + // ------------------------------------------------------------------------------------------ + + calc_checksumsBE((u16*)&dir_backup,0xFFE,&csum1,&csum2); + if(BE16(dir_backup.CheckSum1) != csum1) results |= 4; + if(BE16(dir_backup.CheckSum2) != csum2) results |= 4; + + // ------------------------------------------------------------------------------------------ + // Save the values we just read + dir_backup.CheckSum1[0]=u8(csum1>>8); + dir_backup.CheckSum1[1]=u8(csum1); + dir_backup.CheckSum2[0]=u8(csum2>>8); + dir_backup.CheckSum2[1]=u8(csum2); + // ------------------------------------------------------------------------------------------ + return 0; +} +// ========================================================================================== + + u32 GCMemcard::CopyFrom(GCMemcard& source, u32 index) { if(!mcdFile) return 0; diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h index e8527f9921..2a5626fdf5 100644 --- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h +++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h @@ -128,6 +128,7 @@ public: bool IsOpen(); u32 TestChecksums(); + u32 FixChecksums(); // get number of file entries in the directory u32 GetNumFiles();