Wrapped fopen/close/read/write functions inside a simple "IOFile" class. Reading, writing, and error checking became simpler in most cases. It should be near impossible to forget to close a file now that the destructor takes care of it. (I hope this fixes Issue 3635) I have tested the functionality of most things, but it is possible I broke something. :p

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@7328 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2011-03-11 10:21:46 +00:00
parent 4f69672b2b
commit 59fd1008ca
68 changed files with 1112 additions and 1154 deletions

View File

@ -280,34 +280,33 @@ void CCodeWindow::OnSymbolsMenu(wxCommandEvent& event)
case IDM_RENAME_SYMBOLS:
{
wxString path = wxFileSelector(
const wxString path = wxFileSelector(
_("Apply signature file"), wxEmptyString,
wxEmptyString, wxEmptyString,
_T("Dolphin Symbol Rename File (*.sym)|*.sym"),
wxFD_OPEN | wxFD_FILE_MUST_EXIST, this);
if (! path.IsEmpty())
{
FILE *f = fopen(path.mb_str(), "r");
if (!f)
return;
while (!feof(f))
if (!path.IsEmpty())
{
std::ifstream f(path.mb_str());
std::string line;
while (std::getline(f, line))
{
char line[512];
fgets(line, 511, f);
if (strlen(line) < 4)
if (line.length() < 12)
continue;
u32 address, type;
char name[512];
sscanf(line, "%08x %02i %s", &address, &type, name);
std::string name;
std::istringstream ss(line);
ss >> std::hex >> address >> std::dec >> type >> name;
Symbol *symbol = g_symbolDB.GetSymbolFromAddr(address);
if (symbol) {
symbol->name = line+12;
}
if (symbol)
symbol->name = line.substr(12);
}
fclose(f);
Host_NotifyMapLoaded();
}
}

View File

@ -228,40 +228,31 @@ void CMemoryWindow::OnHostMessage(wxCommandEvent& event)
}
}
void DumpArray(const std::string& filename, const u8* data, size_t length)
{
if (data)
{
File::IOFile f(filename, "wb");
f.WriteBytes(data, length);
}
}
// Write mram to file
void CMemoryWindow::OnDumpMemory( wxCommandEvent& event )
{
FILE* f = fopen(File::GetUserPath(F_RAMDUMP_IDX).c_str(), "wb");
if (f && Memory::m_pRAM)
{
fwrite(Memory::m_pRAM, Memory::REALRAM_SIZE, 1, f);
fclose(f);
}
DumpArray(File::GetUserPath(F_RAMDUMP_IDX), Memory::m_pRAM, Memory::REALRAM_SIZE);
}
// Write exram (aram or mem2) to file
void CMemoryWindow::OnDumpMem2( wxCommandEvent& event )
{
FILE* f = NULL;
{
if (SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
{
f = fopen(File::GetUserPath(F_ARAMDUMP_IDX).c_str(), "wb");
if (f && Memory::m_pEXRAM)
{
fwrite(Memory::m_pEXRAM, Memory::EXRAM_SIZE, 1, f);
fclose(f);
}
DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), Memory::m_pEXRAM, Memory::EXRAM_SIZE);
}
else
{
u8* aram = DSP::GetARAMPtr();
f = fopen(File::GetUserPath(F_ARAMDUMP_IDX).c_str(), "wb");
if (f && aram)
{
fwrite(aram, DSP::ARAM_SIZE, 1, f);
fclose(f);
}
DumpArray(File::GetUserPath(F_ARAMDUMP_IDX), DSP::GetARAMPtr(), DSP::ARAM_SIZE);
}
}