COMMON: Add a function to simplify loading Windows executables
This commit is contained in:
parent
532f382602
commit
a692905eb2
3 changed files with 30 additions and 19 deletions
|
@ -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
|
||||
|
|
|
@ -128,6 +128,8 @@ public:
|
|||
virtual SeekableReadStream *getResource(const WinResourceID &type, const WinResourceID &id, const WinResourceID &lang) {
|
||||
return getResource(type, id);
|
||||
}
|
||||
|
||||
static WinResources *createFromEXE(const String &fileName);
|
||||
};
|
||||
|
||||
} // End of namespace Common
|
||||
|
|
|
@ -77,27 +77,13 @@ static WinFontDirEntry readDirEntry(Common::SeekableReadStream &stream) {
|
|||
}
|
||||
|
||||
bool WinFont::loadFromFON(const Common::String &fileName, const WinFontDirEntry &dirEntry) {
|
||||
Common::WinResources *exe;
|
||||
|
||||
// First try loading via the NE code
|
||||
exe = new Common::NEResources();
|
||||
if (exe->loadFromEXE(fileName)) {
|
||||
bool ok = loadFromEXE(exe, fileName, dirEntry);
|
||||
delete exe;
|
||||
return ok;
|
||||
}
|
||||
delete exe;
|
||||
|
||||
// Then try loading via the PE code
|
||||
exe = new Common::PEResources();
|
||||
if (exe->loadFromEXE(fileName)) {
|
||||
bool ok = loadFromEXE(exe, fileName, dirEntry);
|
||||
delete exe;
|
||||
return ok;
|
||||
}
|
||||
delete exe;
|
||||
|
||||
Common::WinResources *exe = Common::WinResources::createFromEXE(fileName);
|
||||
if (!exe)
|
||||
return false;
|
||||
|
||||
bool ok = loadFromEXE(exe, fileName, dirEntry);
|
||||
delete exe;
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool WinFont::loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue