aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCameron Cawley2020-01-04 15:00:40 +0000
committerFilippos Karapetis2020-01-11 17:34:12 +0200
commita692905eb273ae8c33ba1351e519b93dbf10f7fd (patch)
tree8f20261edeb46bcb82c39d03f923c0c1637975dc
parent532f3826021178c3affd9dfc042f6d7b33df00ec (diff)
downloadscummvm-rg350-a692905eb273ae8c33ba1351e519b93dbf10f7fd.tar.gz
scummvm-rg350-a692905eb273ae8c33ba1351e519b93dbf10f7fd.tar.bz2
scummvm-rg350-a692905eb273ae8c33ba1351e519b93dbf10f7fd.zip
COMMON: Add a function to simplify loading Windows executables
-rw-r--r--common/winexe.cpp23
-rw-r--r--common/winexe.h2
-rw-r--r--graphics/fonts/winfont.cpp24
3 files changed, 30 insertions, 19 deletions
diff --git a/common/winexe.cpp b/common/winexe.cpp
index fd1d565036..ad6ff96505 100644
--- a/common/winexe.cpp
+++ b/common/winexe.cpp
@@ -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
diff --git a/common/winexe.h b/common/winexe.h
index cdbc0f6d13..2b81a33261 100644
--- a/common/winexe.h
+++ b/common/winexe.h
@@ -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
diff --git a/graphics/fonts/winfont.cpp b/graphics/fonts/winfont.cpp
index 6494f006b3..ad5b36ec23 100644
--- a/graphics/fonts/winfont.cpp
+++ b/graphics/fonts/winfont.cpp
@@ -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;
+ Common::WinResources *exe = Common::WinResources::createFromEXE(fileName);
+ if (!exe)
+ return false;
- // 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;
- }
+ bool ok = loadFromEXE(exe, fileName, dirEntry);
delete exe;
-
- return false;
+ return ok;
}
bool WinFont::loadFromEXE(Common::WinResources *exe, const Common::String &fileName, const WinFontDirEntry &dirEntry) {