From aa9a41545ad331acb37dde0790adfa8298b1f8b5 Mon Sep 17 00:00:00 2001 From: Cameron Cawley Date: Thu, 2 Jan 2020 21:23:35 +0000 Subject: COMMON: Add a common base class for the Windows resource classes --- devtools/create_titanic/winexe.cpp | 14 ++++++++++++++ devtools/create_titanic/winexe.h | 35 +++++++++++++++++++++++++++++++++++ devtools/create_titanic/winexe_pe.cpp | 14 -------------- devtools/create_titanic/winexe_pe.h | 4 ++-- 4 files changed, 51 insertions(+), 16 deletions(-) (limited to 'devtools') 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 getIDList(const WinResourceID &type) const = 0; + + /** Return a list of languages for a given type and ID. */ + virtual const Array getLangList(const WinResourceID &type, const WinResourceID &id) const { + Array 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 9d35f592fc..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(); diff --git a/devtools/create_titanic/winexe_pe.h b/devtools/create_titanic/winexe_pe.h index f72b6fbb04..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,7 +47,7 @@ public: void clear(); /** Load from an EXE file. */ - bool loadFromEXE(const String &fileName); + using WinResources::loadFromEXE; bool loadFromEXE(File *stream); -- cgit v1.2.3