COMMON: Add a function to simplify loading Windows executables

This commit is contained in:
Cameron Cawley 2020-01-04 15:00:40 +00:00 committed by Filippos Karapetis
parent 532f382602
commit a692905eb2
3 changed files with 30 additions and 19 deletions

View file

@ -24,6 +24,8 @@
#include "common/memstream.h"
#include "common/str.h"
#include "common/winexe.h"
#include "common/winexe_ne.h"
#include "common/winexe_pe.h"
namespace Common {
@ -160,4 +162,25 @@ bool WinResources::loadFromCompressedEXE(const String &fileName) {
return loadFromEXE(stream);
}
WinResources *WinResources::createFromEXE(const String &fileName) {
WinResources *exe;
// First try loading via the NE code
exe = new Common::NEResources();
if (exe->loadFromEXE(fileName)) {
return exe;
}
delete exe;
// Then try loading via the PE code
exe = new Common::PEResources();
if (exe->loadFromEXE(fileName)) {
return exe;
}
delete exe;
return nullptr;
}
} // End of namespace Common