aboutsummaryrefslogtreecommitdiff
path: root/devtools/create_titanic
diff options
context:
space:
mode:
Diffstat (limited to 'devtools/create_titanic')
-rw-r--r--devtools/create_titanic/winexe.cpp14
-rw-r--r--devtools/create_titanic/winexe.h35
-rw-r--r--devtools/create_titanic/winexe_pe.cpp46
-rw-r--r--devtools/create_titanic/winexe_pe.h22
4 files changed, 76 insertions, 41 deletions
diff --git a/devtools/create_titanic/winexe.cpp b/devtools/create_titanic/winexe.cpp
index c23bd84a89..49be23dbd4 100644
--- a/devtools/create_titanic/winexe.cpp
+++ b/devtools/create_titanic/winexe.cpp
@@ -80,4 +80,18 @@ String WinResourceID::toString() const {
return "";
}
+bool WinResources::loadFromEXE(const String &fileName) {
+ if (fileName.empty())
+ return false;
+
+ File *file = new File();
+
+ if (!file->open(fileName.c_str())) {
+ delete file;
+ return false;
+ }
+
+ return loadFromEXE(file);
+}
+
} // End of namespace Common
diff --git a/devtools/create_titanic/winexe.h b/devtools/create_titanic/winexe.h
index 102f1494fd..6bfe2a25a0 100644
--- a/devtools/create_titanic/winexe.h
+++ b/devtools/create_titanic/winexe.h
@@ -23,6 +23,7 @@
#ifndef COMMON_WINEXE_H
#define COMMON_WINEXE_H
+#include "file.h"
#include "hash-str.h"
#include "str.h"
@@ -90,6 +91,40 @@ struct WinResourceID_EqualTo {
bool operator()(const WinResourceID &id1, const WinResourceID &id2) const { return id1 == id2; }
};
+/**
+ * A class able to load resources from a Windows Executable, such
+ * as cursors, bitmaps, and sounds.
+ */
+class WinResources {
+public:
+ virtual ~WinResources() {}
+
+ /** Clear all information. */
+ virtual void clear() = 0;
+
+ /** Load from an EXE file. */
+ virtual bool loadFromEXE(const String &fileName);
+
+ virtual bool loadFromEXE(File *stream) = 0;
+
+ /** Return a list of IDs for a given type. */
+ virtual const Array<WinResourceID> getIDList(const WinResourceID &type) const = 0;
+
+ /** Return a list of languages for a given type and ID. */
+ virtual const Array<WinResourceID> getLangList(const WinResourceID &type, const WinResourceID &id) const {
+ Array<WinResourceID> array;
+ return array;
+ };
+
+ /** Return a stream to the specified resource, taking the first language found (or 0 if non-existent). */
+ virtual File *getResource(const WinResourceID &type, const WinResourceID &id) = 0;
+
+ /** Return a stream to the specified resource (or 0 if non-existent). */
+ virtual File *getResource(const WinResourceID &type, const WinResourceID &id, const WinResourceID &lang) {
+ return getResource(type, id);
+ }
+};
+
} // End of namespace Common
#endif
diff --git a/devtools/create_titanic/winexe_pe.cpp b/devtools/create_titanic/winexe_pe.cpp
index 16ad16ab63..f55740f692 100644
--- a/devtools/create_titanic/winexe_pe.cpp
+++ b/devtools/create_titanic/winexe_pe.cpp
@@ -44,20 +44,6 @@ void PEResources::clear() {
delete _exe; _exe = 0;
}
-bool PEResources::loadFromEXE(const String &fileName) {
- if (fileName.empty())
- return false;
-
- File *file = new File();
-
- if (!file->open(fileName.c_str())) {
- delete file;
- return false;
- }
-
- return loadFromEXE(file);
-}
-
bool PEResources::loadFromEXE(File *stream) {
clear();
@@ -151,7 +137,7 @@ void PEResources::parseResourceLevel(Section &section, uint32 offset, int level)
if (level == 0)
_curType = id;
else if (level == 1)
- _curName = id;
+ _curID = id;
else if (level == 2)
_curLang = id;
@@ -165,7 +151,7 @@ void PEResources::parseResourceLevel(Section &section, uint32 offset, int level)
resource.offset = _exe->readUint32LE() + section.offset - section.virtualAddress;
resource.size = _exe->readUint32LE();
- _resources[_curType][_curName][_curLang] = resource;
+ _resources[_curType][_curID][_curLang] = resource;
}
_exe->seek(lastOffset);
@@ -184,32 +170,32 @@ const Array<WinResourceID> PEResources::getTypeList() const {
return array;
}
-const Array<WinResourceID> PEResources::getNameList(const WinResourceID &type) const {
+const Array<WinResourceID> PEResources::getIDList(const WinResourceID &type) const {
Array<WinResourceID> array;
if (!_exe || !_resources.contains(type))
return array;
- const NameMap &nameMap = _resources[type];
+ const IDMap &idMap = _resources[type];
- for (NameMap::const_iterator it = nameMap.begin(); it != nameMap.end(); it++)
+ for (IDMap::const_iterator it = idMap.begin(); it != idMap.end(); it++)
array.push_back(it->_key);
return array;
}
-const Array<WinResourceID> PEResources::getLangList(const WinResourceID &type, const WinResourceID &name) const {
+const Array<WinResourceID> PEResources::getLangList(const WinResourceID &type, const WinResourceID &id) const {
Array<WinResourceID> array;
if (!_exe || !_resources.contains(type))
return array;
- const NameMap &nameMap = _resources[type];
+ const IDMap &idMap = _resources[type];
- if (!nameMap.contains(name))
+ if (!idMap.contains(id))
return array;
- const LangMap &langMap = nameMap[name];
+ const LangMap &langMap = idMap[id];
for (LangMap::const_iterator it = langMap.begin(); it != langMap.end(); it++)
array.push_back(it->_key);
@@ -217,13 +203,13 @@ const Array<WinResourceID> PEResources::getLangList(const WinResourceID &type, c
return array;
}
-File *PEResources::getResource(const WinResourceID &type, const WinResourceID &name) {
- Array<WinResourceID> langList = getLangList(type, name);
+File *PEResources::getResource(const WinResourceID &type, const WinResourceID &id) {
+ Array<WinResourceID> langList = getLangList(type, id);
if (langList.empty())
return 0;
- const Resource &resource = _resources[type][name][langList[0]];
+ const Resource &resource = _resources[type][id][langList[0]];
byte *data = (byte *)malloc(resource.size);
_exe->seek(resource.offset);
_exe->read(data, resource.size);
@@ -233,16 +219,16 @@ File *PEResources::getResource(const WinResourceID &type, const WinResourceID &n
return file;
}
-File *PEResources::getResource(const WinResourceID &type, const WinResourceID &name, const WinResourceID &lang) {
+File *PEResources::getResource(const WinResourceID &type, const WinResourceID &id, const WinResourceID &lang) {
if (!_exe || !_resources.contains(type))
return 0;
- const NameMap &nameMap = _resources[type];
+ const IDMap &idMap = _resources[type];
- if (!nameMap.contains(name))
+ if (!idMap.contains(id))
return 0;
- const LangMap &langMap = nameMap[name];
+ const LangMap &langMap = idMap[id];
if (!langMap.contains(lang))
return 0;
diff --git a/devtools/create_titanic/winexe_pe.h b/devtools/create_titanic/winexe_pe.h
index 3c960053b2..6ab7ae847a 100644
--- a/devtools/create_titanic/winexe_pe.h
+++ b/devtools/create_titanic/winexe_pe.h
@@ -38,7 +38,7 @@ class SeekableReadStream;
* A class able to load resources from a Windows Portable Executable, such
* as cursors, bitmaps, and sounds.
*/
-class PEResources {
+class PEResources : WinResources {
public:
PEResources();
~PEResources();
@@ -47,24 +47,24 @@ public:
void clear();
/** Load from an EXE file. */
- bool loadFromEXE(const String &fileName);
+ using WinResources::loadFromEXE;
bool loadFromEXE(File *stream);
/** Return a list of resource types. */
const Array<WinResourceID> getTypeList() const;
- /** Return a list of names for a given type. */
- const Array<WinResourceID> getNameList(const WinResourceID &type) const;
+ /** Return a list of IDs for a given type. */
+ const Array<WinResourceID> getIDList(const WinResourceID &type) const;
- /** Return a list of languages for a given type and name. */
- const Array<WinResourceID> getLangList(const WinResourceID &type, const WinResourceID &name) const;
+ /** Return a list of languages for a given type and ID. */
+ const Array<WinResourceID> getLangList(const WinResourceID &type, const WinResourceID &id) const;
/** Return a stream to the specified resource, taking the first language found (or 0 if non-existent). */
- File *getResource(const WinResourceID &type, const WinResourceID &name);
+ File *getResource(const WinResourceID &type, const WinResourceID &id);
/** Return a stream to the specified resource (or 0 if non-existent). */
- File *getResource(const WinResourceID &type, const WinResourceID &name, const WinResourceID &lang);
+ File *getResource(const WinResourceID &type, const WinResourceID &id, const WinResourceID &lang);
/** Returns true if the resources is empty */
bool empty() const { return _sections.empty(); }
@@ -80,7 +80,7 @@ private:
File *_exe;
void parseResourceLevel(Section &section, uint32 offset, int level);
- WinResourceID _curType, _curName, _curLang;
+ WinResourceID _curType, _curID, _curLang;
struct Resource {
uint32 offset;
@@ -88,8 +88,8 @@ private:
};
typedef HashMap<WinResourceID, Resource, WinResourceID_Hash, WinResourceID_EqualTo> LangMap;
- typedef HashMap<WinResourceID, LangMap, WinResourceID_Hash, WinResourceID_EqualTo> NameMap;
- typedef HashMap<WinResourceID, NameMap, WinResourceID_Hash, WinResourceID_EqualTo> TypeMap;
+ typedef HashMap<WinResourceID, LangMap, WinResourceID_Hash, WinResourceID_EqualTo> IDMap;
+ typedef HashMap<WinResourceID, IDMap, WinResourceID_Hash, WinResourceID_EqualTo> TypeMap;
TypeMap _resources;
};