small update, adds check to importFile so only one save per game allowed, adds check to remove file so removing last file on memcard will not corrupt it
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1120 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
parent
70837bb034
commit
8373b94fd2
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -31,7 +31,8 @@ enum
|
|||
GCS = 0x110,
|
||||
OUTOFBLOCKS,
|
||||
OUTOFDIRENTRIES,
|
||||
NOMEMCARD
|
||||
NOMEMCARD,
|
||||
TITLEPRESENT
|
||||
};
|
||||
|
||||
class GCMemcard
|
||||
|
@ -142,6 +143,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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue