pass by reference instead of pointer in several places,

return std::strings instead of filling a buffer,
move gci filename generation to a function inside gcmemcard instead of the gui code
 change all functions that do not modify the object to const

Conflicts:

	Source/Core/Core/Src/HW/GCMemcard.cpp
	Source/Core/DolphinWX/Src/MemcardManager.cpp

Signed-off-by: LPFaint99 <lpfaint99@gmail.com>
This commit is contained in:
LPFaint99
2012-02-12 14:39:10 -08:00
parent d5c393fe96
commit dfe890e8f1
3 changed files with 173 additions and 188 deletions
File diff suppressed because it is too large Load Diff
+35 -43
View File
@@ -19,6 +19,7 @@
#define __GCMEMCARD_h__
#include "Common.h"
#include "CommonPaths.h"
#include "Sram.h"
#include "StringUtil.h"
#include "EXI_DeviceIPL.h"
@@ -101,7 +102,7 @@ private:
struct DEntry {
u8 Gamecode[4]; //0x00 0x04 Gamecode
u8 Markercode[2]; //0x04 0x02 Makercode
u8 Makercode[2]; //0x04 0x02 Makercode
u8 Unused1; //0x06 0x01 reserved/unused (always 0xff, has no effect)
u8 BIFlags; //0x07 0x01 banner gfx format and icon animation (Image Key)
// bit(s) description
@@ -168,67 +169,58 @@ private:
};
#pragma pack(pop)
u32 ImportGciInternal(FILE* gcih, const char *inputFile, std::string outputFile);
u32 ImportGciInternal(FILE* gcih, const char *inputFile, const std::string &outputFile);
static void FormatInternal(GCMC_Header &GCP);
public:
GCMemcard(const char* fileName, bool forceCreation=false, bool sjis=false);
bool IsValid() { return m_valid; }
bool IsAsciiEncoding();
bool IsValid() const { return m_valid; }
bool IsAsciiEncoding() const;
bool Save();
bool Format(bool sjis = false, u16 SizeMb = MemCard2043Mb);
static bool Format(u8 * card_data, bool sjis = false, u16 SizeMb = MemCard2043Mb);
static void calc_checksumsBE(u16 *buf, u32 length, u16 *csum, u16 *inv_csum);
u32 TestChecksums();
u32 TestChecksums() const;
bool FixChecksums();
// get number of file entries in the directory
u8 GetNumFiles();
u8 GetFileIndex(u8 fileNumber);
u8 GetNumFiles() const;
u8 GetFileIndex(u8 fileNumber) const;
// get the free blocks from bat
u16 GetFreeBlocks();
u16 GetFreeBlocks() const;
// If title already on memcard returns index, otherwise returns -1
u8 TitlePresent(DEntry d);
// DEntry functions, all take u8 index < DIRLEN (127)
// Functions that have ascii output take a char *buffer
u8 TitlePresent(DEntry d) const;
// buffer needs to be a char[5] or bigger
bool DEntry_GameCode(u8 index, char *buffer);
// buffer needs to be a char[2] or bigger
bool DEntry_Markercode(u8 index, char *buffer);
// buffer needs to be a char[9] or bigger
bool DEntry_BIFlags(u8 index, char *buffer);
// buffer needs to be a char[32] or bigger
bool DEntry_FileName(u8 index, char *buffer);
u32 DEntry_ModTime(u8 index);
u32 DEntry_ImageOffset(u8 index);
// buffer needs to be a char[17] or bigger
bool DEntry_IconFmt(u8 index, char *buffer);
u16 DEntry_AnimSpeed(u8 index);
// buffer needs to be a char[4] or bigger
bool DEntry_Permissions(u8 index, char *buffer);
u8 DEntry_CopyCounter(u8 index);
bool GCI_FileName(u8 index, std::string &filename) const;
// DEntry functions, all take u8 index < DIRLEN (127)
std::string DEntry_GameCode(u8 index) const;
std::string DEntry_Makercode(u8 index) const;
std::string DEntry_BIFlags(u8 index) const;
std::string DEntry_FileName(u8 index) const;
u32 DEntry_ModTime(u8 index) const;
u32 DEntry_ImageOffset(u8 index) const;
std::string DEntry_IconFmt(u8 index) const;
u16 DEntry_AnimSpeed(u8 index) const;
std::string DEntry_Permissions(u8 index) const;
u8 DEntry_CopyCounter(u8 index) const;
// get first block for file
u16 DEntry_FirstBlock(u8 index);
u16 DEntry_FirstBlock(u8 index) const;
// get file length in blocks
u16 DEntry_BlockCount(u8 index);
u32 DEntry_CommentsAddress(u8 index);
// buffer needs to be a char[32] or bigger
bool DEntry_Comment1(u8 index, char *buffer);
// buffer needs to be a char[32] or bigger
bool DEntry_Comment2(u8 index, char *buffer);
u16 DEntry_BlockCount(u8 index) const;
u32 DEntry_CommentsAddress(u8 index) const;
std::string GetSaveComment1(u8 index) const;
std::string GetSaveComment2(u8 index) const;
// Copies a DEntry from u8 index to DEntry& data
bool DEntry_Copy(u8 index, DEntry& data);
bool GetDEntry(u8 index, DEntry &dest) const;
// assumes there's enough space in 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
u32 DEntry_GetSaveData(u8 index, u8* buffer, bool old);
u32 DEntry_GetSaveData(u8 index, u8* buffer, bool old) const;
// adds the file to the directory and copies its contents
// if remove > 0 it will pad bat.map with 0's sizeof remove
@@ -238,23 +230,23 @@ public:
u32 RemoveFile(u8 index);
// reads a save from another memcard, and imports the data into this memcard
u32 CopyFrom(GCMemcard& source, u8 index);
u32 CopyFrom(const GCMemcard& source, u8 index);
// reads a .gci/.gcs/.sav file and calls ImportFile or saves out a gci file
u32 ImportGci(const char* inputFile, std::string outputFile);
u32 ImportGci(const char* inputFile,const std::string &outputFile);
// writes a .gci file to disk containing index
u32 ExportGci(u8 index, const char* fileName, std::string* fileName2);
u32 ExportGci(u8 index, const char* fileName, const std::string &directory) const;
// GCI files are untouched, SAV files are byteswapped
// GCS files have the block count set, default is 1 (For export as GCS)
void Gcs_SavConvert(DEntry* tempDEntry, int saveType, int length = BLOCK_SIZE);
static void Gcs_SavConvert(DEntry &tempDEntry, int saveType, int length = BLOCK_SIZE);
// reads the banner image
bool ReadBannerRGBA8(u8 index, u32* buffer);
bool ReadBannerRGBA8(u8 index, u32* buffer) const;
// reads the animation frames
u32 ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays);
u32 ReadAnimRGBA8(u8 index, u32* buffer, u8 *delays) const;
};
#endif
+14 -16
View File
@@ -546,15 +546,16 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
index = memoryCard[slot]->GetFileIndex(index);
if (index != wxNOT_FOUND)
{
char tempC[10 + DENTRY_STRLEN],
tempC2[DENTRY_STRLEN];
memoryCard[slot]->DEntry_GameCode(index,tempC);
memoryCard[slot]->DEntry_FileName(index,tempC2);
sprintf(tempC, "%s_%s.gci", tempC, tempC2);
std::string gciFilename;
if (!memoryCard[slot]->GCI_FileName(index, gciFilename))
{
PanicAlert("invalid index");
return;
}
wxString fileName = wxFileSelector(
_("Export save as..."),
wxString::From8BitData(DefaultIOPath.c_str()),
wxString::From8BitData(tempC), wxT(".gci"),
wxString::From8BitData(gciFilename.c_str()), wxT(".gci"),
_("Native GCI files(*.gci)") + wxString(wxT("|*.gci|")) +
_("MadCatz Gameshark files(*.gcs)") + wxString(wxT("|*.gcs|")) +
_("Datel MaxDrive/Pro files(*.sav)") + wxString(wxT("|*.sav")),
@@ -562,7 +563,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
if (fileName.length() > 0)
{
if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName.mb_str(), NULL), -1))
if (!CopyDeleteSwitch(memoryCard[slot]->ExportGci(index, fileName.mb_str(), ""), -1))
{
File::Delete(std::string(fileName.mb_str()));
}
@@ -582,7 +583,7 @@ void CMemcardManager::CopyDeleteClick(wxCommandEvent& event)
"%s\nand have the same name as a file on your memcard\nContinue?", path1.c_str()))
for (int i = 0; i < DIRLEN; i++)
{
CopyDeleteSwitch(memoryCard[slot]->ExportGci(i, ".", &path1), -1);
CopyDeleteSwitch(memoryCard[slot]->ExportGci(i, NULL, path1), -1);
}
break;
}
@@ -614,8 +615,7 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
wxComment,
wxBlock,
wxFirstBlock,
wxLabel,
tString;
wxLabel;
m_MemcardList[card]->Hide();
@@ -689,8 +689,6 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
for (j = page[card] * itemsPerPage; (j < nFiles) && (j < pagesMax); j++)
{
char title[DENTRY_STRLEN];
char comment[DENTRY_STRLEN];
u16 blocks;
u16 firstblock;
u8 fileIndex = memoryCard[card]->GetFileIndex(j);
@@ -700,8 +698,8 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
m_MemcardList[card]->SetItem(index, COLUMN_BANNER, wxEmptyString);
if (!memoryCard[card]->DEntry_Comment1(fileIndex, title)) title[0]=0;
if (!memoryCard[card]->DEntry_Comment2(fileIndex, comment)) comment[0]=0;
std::string title = memoryCard[card]->GetSaveComment1(fileIndex);
std::string comment = memoryCard[card]->GetSaveComment2(fileIndex);
bool ascii = memoryCard[card]->IsAsciiEncoding();
@@ -721,8 +719,8 @@ bool CMemcardManager::ReloadMemcard(const char *fileName, int card)
// it returns CP-932, in order to use iconv we need to use CP932
wxCSConv SJISConv(wxT("CP932"));
#endif
wxTitle = wxString(title, ascii ? *wxConvCurrent : SJISConv);
wxComment = wxString(comment, ascii ? *wxConvCurrent : SJISConv);
wxTitle = wxString(title.c_str(), ascii ? *wxConvCurrent : SJISConv);
wxComment = wxString(comment.c_str(), ascii ? *wxConvCurrent : SJISConv);
m_MemcardList[card]->SetItem(index, COLUMN_TITLE, wxTitle);
m_MemcardList[card]->SetItem(index, COLUMN_COMMENT, wxComment);