From 81b885777cda7817786ec92ab094f501519f61d2 Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 20 Jul 2009 01:41:22 +0000 Subject: [PATCH] fix some rom loading things --- desmume/src/NDSSystem.cpp | 21 +++++---------------- desmume/src/NDSSystem.h | 9 +++++++++ desmume/src/windows/7zip.cpp | 5 +---- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 877fb15c3..1c41b8975 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -739,10 +739,6 @@ static std::vector v; static void loadrom(std::vector* buf, std::string fname) { - memorystream ms(buf); - - std::ostream* os = (std::ostream*)&ms; - std::ifstream fl(fname.c_str()); if (!fl.is_open()) @@ -755,16 +751,10 @@ static void loadrom(std::vector* buf, std::string fname) { fb.open (fname.c_str(), std::ios::in | std::ios::binary); std::istream is(&fb); - char *buffer = new char[size]; - is.read(buffer, size); - ms.write((char*)buffer,size); - - fb.close(); - - ms.trim(); - - gameInfo.romdata = &buffer[0]; + gameInfo.resize(size); + is.read(gameInfo.romdata,size); + fb.close(); } int NDS_LoadROM(const char *filename, const char *logicalFilename) @@ -784,9 +774,8 @@ int NDS_LoadROM(const char *filename, const char *logicalFilename) gameInfo.romsize = buffer.size(); } else if ( !strcasecmp(path.extension().c_str(), "nds")) { - - loadrom(&buffer, path.path); - gameInfo.romsize = buffer.size(); + loadrom(NULL, path.path); //n.b. this does nothing if the file can't be found (i.e. if it was an extracted tempfile)... + //...but since the data was extracted to gameInfo then it is ok type = ROM_NDS; } //ds.gba in archives, it's already been loaded into memory at this point diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index ca0538074..9101b55ed 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -276,6 +276,15 @@ NDS_header * NDS_getROMHeader(void); struct GameInfo { + GameInfo() + : romdata(NULL) + {} + + void resize(int size) { + if(romdata != NULL) delete[] romdata; + romdata = new char[size]; + romsize = size; + } u32 crc; NDS_header header; char ROMserial[20]; diff --git a/desmume/src/windows/7zip.cpp b/desmume/src/windows/7zip.cpp index abf93d932..9c10b5a20 100644 --- a/desmume/src/windows/7zip.cpp +++ b/desmume/src/windows/7zip.cpp @@ -351,10 +351,7 @@ int ArchiveFile::ExtractItem(int index, const char* outFilename) const InFileStream* ifs = new InFileStream(m_filename); if(SUCCEEDED(object->Open(ifs,0,0))) { - if(gameInfo.romdata != NULL) - delete[] gameInfo.romdata; - gameInfo.romdata = new char[rv]; - gameInfo.romsize = rv; + gameInfo.resize(rv); OutStream* os = new OutStream(index, gameInfo.romdata, rv); const UInt32 indices [1] = {index}; hr = object->Extract(indices, 1, 0, os);