ImportFile and RemoveFile "fixed", should not cause corruption anymore, but still needs more work

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@1098 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
LPFaint99
2008-11-08 20:34:43 +00:00
parent 8684b734e8
commit d2bbd6bda2
4 changed files with 350 additions and 356 deletions
+49 -26
View File
@@ -72,8 +72,8 @@ wxBitmap wxBitmapFromMemoryRGBA(const unsigned char* data, int width, int height
BEGIN_EVENT_TABLE(CMemcardManager, wxDialog)
EVT_CLOSE(CMemcardManager::OnClose)
EVT_BUTTON(ID_COPYLEFT,CMemcardManager::CopyDeleteClick)
EVT_BUTTON(ID_COPYRIGHT,CMemcardManager::CopyDeleteClick)
EVT_BUTTON(ID_COPYTOLEFT,CMemcardManager::CopyDeleteClick)
EVT_BUTTON(ID_COPYTORIGHT,CMemcardManager::CopyDeleteClick)
EVT_BUTTON(ID_FIXCHECKSUM,CMemcardManager::CopyDeleteClick)
EVT_BUTTON(ID_DELETELEFT,CMemcardManager::CopyDeleteClick)
EVT_BUTTON(ID_DELETERIGHT,CMemcardManager::CopyDeleteClick)
@@ -111,8 +111,8 @@ CMemcardManager::~CMemcardManager()
void CMemcardManager::CreateGUIControls()
{
// buttons
m_CopyLeft = new wxButton(this, ID_COPYLEFT, wxT("<-Copy<-"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_CopyRight = new wxButton(this, ID_COPYRIGHT, wxT("->Copy->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_CopyToLeft = new wxButton(this, ID_COPYTOLEFT, wxT("<-Copy<-"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_CopyToRight = new wxButton(this, ID_COPYTORIGHT, wxT("->Copy->"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
m_FixChecksum = new wxButton(this, ID_FIXCHECKSUM, wxT("<-Fix\nChecksum"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator);
@@ -150,8 +150,8 @@ void CMemcardManager::CreateGUIControls()
wxBoxSizer* sButtons;
sButtons = new wxBoxSizer(wxVERTICAL);
sButtons->AddStretchSpacer(2);
sButtons->Add(m_CopyLeft, 0, wxEXPAND, 5);
sButtons->Add(m_CopyRight, 0, wxEXPAND, 5);
sButtons->Add(m_CopyToLeft, 0, wxEXPAND, 5);
sButtons->Add(m_CopyToRight, 0, wxEXPAND, 5);
sButtons->AddStretchSpacer(1);
sButtons->Add(m_FixChecksum, 0, wxEXPAND, 5);
sButtons->AddStretchSpacer(1);
@@ -206,22 +206,25 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
int index1 = m_MemcardList[1]->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
int slot = 1;
int index2 = index1;
char * fileName2 = NULL;
std::string fileName2("");
int freeblocks = 0;
switch(event.GetId())
switch (event.GetId())
{
case ID_COPYLEFT:
slot=0;
index2 = index0;
case ID_COPYRIGHT:
if ((index2 != -1) && (memoryCard[slot] != NULL))
case ID_COPYTOLEFT:
if ((index1 != -1) && (memoryCard[0] != NULL))
{
int slot2;
slot == 0 ? slot2=1:slot2=0;
memoryCard[slot]->CopyFrom(*memoryCard[slot2], index2);
memoryCard[slot]->Save();
slot == 1 ? ReloadMemcard(m_Memcard2Path->GetPath().mb_str(), 1)
: ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
memoryCard[0]->CopyFrom(*memoryCard[1], index1);
memoryCard[0]->Save();
ReloadMemcard(m_Memcard1Path->GetPath().mb_str(), 0);
}
break;
case ID_COPYTORIGHT:
if ((index0 != -1) && (memoryCard[1] != NULL))
{
memoryCard[1]->CopyFrom(*memoryCard[0], index0);
memoryCard[1]->Save();
ReloadMemcard(m_Memcard2Path->GetPath().mb_str(), 1);
}
break;
case ID_FIXCHECKSUM:
@@ -234,11 +237,12 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
}
break;
case ID_CONVERTTOGCI:
fileName2 = new char;
fileName2 = "convert";
case ID_SAVEIMPORTLEFT:
slot = 0;
case ID_SAVEIMPORTRIGHT:
if (memoryCard[slot] != NULL || fileName2 != NULL)
if (memoryCard[slot] != NULL || !fileName2.empty())
{
wxString temp = wxFileSelector(_T("Select the GCI file to import"),
wxEmptyString, wxEmptyString, wxEmptyString,wxString::Format
@@ -249,10 +253,10 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
"Datel MaxDrive/Pro files(*.sav)|*.sav"),
wxFileSelectorDefaultWildcardStr,
wxFileSelectorDefaultWildcardStr
),
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
),
wxFD_OPEN | wxFD_FILE_MUST_EXIST);
const char * fileName = temp.ToAscii();
if (*fileName2 != NULL && !temp.empty())
if (!temp.empty() && !fileName2.empty())
{
wxString temp2 = wxFileSelector(_T("Save GCI as.."),
wxEmptyString, wxEmptyString, _T(".gci"), wxString::Format
@@ -262,8 +266,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
wxFileSelectorDefaultWildcardStr
),
wxFD_OVERWRITE_PROMPT|wxFD_SAVE);
delete fileName2;
fileName2 = (char*)temp2.ToAscii();
fileName2 = temp2.mb_str();
}
if (temp.length() > 0)
{
@@ -288,6 +291,26 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
" does not have a valid extension"), wxT("Error"),
wxOK|wxICON_ERROR);
break;
case GCS:
wxMessageBox(wxT("File converted to .gci"),
wxT("Success"),wxOK);
break;
case OUTOFBLOCKS:
freeblocks = BE16(memoryCard[slot]->bat.FreeBlocks);
{
wxString Foobar;
Foobar.Printf("Only %d blocks available", freeblocks);
wxMessageBox(Foobar,wxT("Failure"),wxOK);
}
break;
case OUTOFDIRENTRIES:
wxMessageBox(wxT("No free dir index entries"),
wxT("Failure"),wxOK);
break;
case NOMEMCARD:
wxMessageBox(wxT("File is not recognized as a memcard"),
wxT("Failure"),wxOK);
break;
default:
memoryCard[slot]->Save();
slot == 1 ? ReloadMemcard(m_Memcard2Path->GetPath().mb_str(), 1)
+6 -6
View File
@@ -26,7 +26,7 @@
#include <wx/imaglist.h>
#include "MemoryCards/GCMemcard.h"
#define BE16(x) ((u16((x)[0])<<8) | u16((x)[1]))
#undef MEMCARD_MANAGER_STYLE
#define MEMCARD_MANAGER_STYLE wxCAPTION | wxSYSTEM_MENU | wxDIALOG_NO_PARENT | wxCLOSE_BOX | wxRESIZE_BORDER | wxMAXIMIZE_BOX
@@ -35,7 +35,7 @@ class CMemcardManager
{
public:
CMemcardManager(wxWindow *parent, wxWindowID id = 1, const wxString& title = wxT("Memory Card Manager WARNING-Make backups before using, will probably mangle stuff!"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = MEMCARD_MANAGER_STYLE);
CMemcardManager(wxWindow *parent, wxWindowID id = 1, const wxString& title = wxT("Memory Card Manager WARNING-Make backups before using, should be fixed but could mangle stuff!"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = MEMCARD_MANAGER_STYLE);
virtual ~CMemcardManager();
private:
@@ -43,8 +43,8 @@ class CMemcardManager
DECLARE_EVENT_TABLE();
wxBoxSizer *sMain;
wxButton *m_CopyLeft;
wxButton *m_CopyRight;
wxButton *m_CopyToLeft;
wxButton *m_CopyToRight;
wxButton *m_FixChecksum;
wxButton *m_SaveImportLeft;
wxButton *m_SaveExportLeft;
@@ -62,8 +62,8 @@ class CMemcardManager
enum
{
ID_COPYRIGHT = 1000,
ID_COPYLEFT,
ID_COPYTORIGHT = 1000,
ID_COPYTOLEFT,
ID_FIXCHECKSUM,
ID_DELETERIGHT,
ID_DELETELEFT,
File diff suppressed because it is too large Load Diff
@@ -28,7 +28,10 @@ enum
OPENFAIL,
GCI,
SAV = 0x80,
GCS = 0x110
GCS = 0x110,
OUTOFBLOCKS,
OUTOFDIRENTRIES,
NOMEMCARD
};
class GCMemcard
@@ -155,13 +158,17 @@ public:
u32 GetFileSize(u32 index);
// assumes there's enough space in buffer
bool GetFileData(u32 index, u8* buffer);
// old determines if function uses old or new method of copying data
// some functions only work with old way, some only work with new way
// TODO: find a function that works for all calls or split into 2 functions
bool GetFileData(u32 index, u8* buffer, bool old);
// delete a file from the directory
bool RemoveFile(u32 index);
// adds the file to the directory and copies its contents
u32 ImportFile(DEntry& direntry, u8* contents);
// if remove > 0 it will pad bat.map with 0's sifeof remove
u32 ImportFile(DEntry& direntry, u8* contents, int remove);
// reads a save from another memcard, and imports the data into this memcard
u32 CopyFrom(GCMemcard& source, u32 index);
@@ -170,7 +177,7 @@ public:
bool ExportGci(u32 index, const char* fileName);
// reads a .gci/.gcs/.sav file and calls ImportFile or saves out a gci file
int ImportGci(const char* fileName, const char* fileName2);
s32 ImportGci(const char* fileName, std::string fileName2);
// reads the banner image
bool ReadBannerRGBA8(u32 index, u32* buffer);