diff --git a/Source/Core/DolphinWX/Src/MemcardManager.cpp b/Source/Core/DolphinWX/Src/MemcardManager.cpp index 92f0296b07..754047f6f3 100644 --- a/Source/Core/DolphinWX/Src/MemcardManager.cpp +++ b/Source/Core/DolphinWX/Src/MemcardManager.cpp @@ -207,7 +207,8 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) int slot = 1; int index2 = index1; std::string fileName2(""); - int freeblocks = 0; + int freeBlocks = 0; + wxString blocksOpen; switch (event.GetId()) { @@ -296,12 +297,9 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) wxT("Success"),wxOK); break; case OUTOFBLOCKS: - freeblocks = BE16(memoryCard[slot]->bat.FreeBlocks); - { - wxString Foobar; - Foobar.Printf(wxT("Only %d blocks available"), freeblocks); - wxMessageBox(Foobar,wxT("Failure"),wxOK); - } + freeBlocks = BE16(memoryCard[slot]->bat.FreeBlocks); + blocksOpen.Printf(wxT("Only %d blocks available"), freeBlocks); + wxMessageBox(blocksOpen,wxT("Failure"),wxOK); break; case OUTOFDIRENTRIES: wxMessageBox(wxT("No free dir index entries"), @@ -311,6 +309,10 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event) wxMessageBox(wxT("File is not recognized as a memcard"), wxT("Failure"),wxOK); break; + case TITLEPRESENT: + wxMessageBox(wxT("Memcard already has a save for this title"), + wxT("Failure"),wxOK); + break; default: memoryCard[slot]->Save(); slot == 1 ? ReloadMemcard(m_Memcard2Path->GetPath().mb_str(), 1) diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp index 645fe81fb1..930b09f59a 100644 --- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp +++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.cpp @@ -83,6 +83,18 @@ u32 GCMemcard::GetNumFiles() return j; } +bool GCMemcard::titlePresent(u32 gameCode) +{ + if (!mcdFile) return 0; + + for (int i = 0; i < 127; i++) + { + if (BE32(dir.Dir[i].Gamecode) == gameCode) + return true; + } + return false; +} + bool GCMemcard::RemoveFile(u32 index) //index in the directory array { if (!mcdFile) return false; @@ -93,11 +105,13 @@ bool GCMemcard::RemoveFile(u32 index) //index in the directory array //free the blocks int blocks_left = BE16(dir.Dir[index].BlockCount); - int block = BE16(dir.Dir[index].FirstBlock); - bat.LastAllocated[0] = (u8)((block - 1) >> 8); - bat.LastAllocated[1] = (u8)(block - 1); + int block = BE16(dir.Dir[index].FirstBlock) - 1; + bat.LastAllocated[0] = (u8)(block >> 8); + bat.LastAllocated[1] = (u8)block; + int i = index + 1; memset(&(dir.Dir[index]), 0xFF, 0x40); + while (i < 127) { DEntry * d = new DEntry; @@ -126,7 +140,14 @@ bool GCMemcard::RemoveFile(u32 index) //index in the directory array i++; } - + //Added to clean up if removing last file + if (BE16(bat.LastAllocated) == (u16)4) + { + for (int j = 0; j < blocks_left; j++) + { + bat.Map[j] = 0x0000; + } + } // increment update counter int updateCtr = BE16(dir.UpdateCounter) + 1; dir.UpdateCounter[0] = u8(updateCtr >> 8); @@ -141,9 +162,6 @@ bool GCMemcard::RemoveFile(u32 index) //index in the directory array u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove) { - // TODO: add a check for existing game id - // so that only one save per title is allowed - // until then any particular title will always use the first save if (!mcdFile) return NOMEMCARD; if (GetNumFiles() >= 127) @@ -154,6 +172,7 @@ u32 GCMemcard::ImportFile(DEntry& direntry, u8* contents, int remove) { return OUTOFBLOCKS; } + if (!remove && titlePresent(BE32(direntry.Gamecode))) return TITLEPRESENT; // find first free data block -- assume no freespace fragmentation int totalspace = (((u32)BE16(hdr.Size) * 16) - 5); diff --git a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h index 878fea369a..ecde3a233d 100644 --- a/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h +++ b/Source/Core/DolphinWX/Src/MemoryCards/GCMemcard.h @@ -31,7 +31,8 @@ enum GCS = 0x110, OUTOFBLOCKS, OUTOFDIRENTRIES, - NOMEMCARD + NOMEMCARD, + TITLEPRESENT }; class GCMemcard @@ -141,6 +142,9 @@ public: // get number of file entries in the directory u32 GetNumFiles(); + + // Returns true if title already on memcard + bool titlePresent(u32 gameCode); // read directory entry bool GetFileInfo(u32 index, DEntry& data);