From 297834017a56140d1a33a4ce642bc9f39f54cf28 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Fri, 22 Apr 2011 00:29:18 +0200 Subject: WIN32: Embed engine data files and theme files into executable. This embeds all the engine data files from dists/engine-data into the executable in case the engines using them are included statically. Furthermore it includes the theme dist files in the executable. --- backends/platform/sdl/win32/win32.cpp | 86 +++++++++++++++++++++++++++++++++++ backends/platform/sdl/win32/win32.h | 1 + 2 files changed, 87 insertions(+) (limited to 'backends/platform/sdl/win32') diff --git a/backends/platform/sdl/win32/win32.cpp b/backends/platform/sdl/win32/win32.cpp index fffc3a2a75..d6a39ff48f 100644 --- a/backends/platform/sdl/win32/win32.cpp +++ b/backends/platform/sdl/win32/win32.cpp @@ -39,6 +39,8 @@ #include "backends/platform/sdl/win32/win32.h" #include "backends/fs/windows/windows-fs-factory.h" +#include "common/memstream.h" + #define DEFAULT_CONFIG_FILE "scummvm.ini" //#define HIDE_CONSOLE @@ -170,4 +172,88 @@ Common::WriteStream *OSystem_Win32::createLogFile() { } } +namespace { + +class Win32ResourceArchive : public Common::Archive { + friend BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam); +public: + Win32ResourceArchive(); + + virtual bool hasFile(const Common::String &name); + virtual int listMembers(Common::ArchiveMemberList &list); + virtual Common::ArchiveMemberPtr getMember(const Common::String &name); + virtual Common::SeekableReadStream *createReadStreamForMember(const Common::String &name) const; +private: + typedef Common::List FilenameList; + + FilenameList _files; +}; + +BOOL CALLBACK EnumResNameProc(HMODULE hModule, LPCTSTR lpszType, LPTSTR lpszName, LONG_PTR lParam) { + if (IS_INTRESOURCE(lpszName)) + return TRUE; + + Win32ResourceArchive *arch = (Win32ResourceArchive *)lParam; + arch->_files.push_back(lpszName); + return TRUE; +} + +Win32ResourceArchive::Win32ResourceArchive() { + EnumResourceNames(NULL, MAKEINTRESOURCE(256), &EnumResNameProc, (LONG_PTR)this); +} + +bool Win32ResourceArchive::hasFile(const Common::String &name) { + for (FilenameList::const_iterator i = _files.begin(); i != _files.end(); ++i) { + if (i->equalsIgnoreCase(name)) + return true; + } + + return false; +} + +int Win32ResourceArchive::listMembers(Common::ArchiveMemberList &list) { + int count = 0; + + for (FilenameList::const_iterator i = _files.begin(); i != _files.end(); ++i, ++count) + list.push_back(Common::ArchiveMemberPtr(new Common::GenericArchiveMember(*i, this))); + + return count; +} + +Common::ArchiveMemberPtr Win32ResourceArchive::getMember(const Common::String &name) { + return Common::ArchiveMemberPtr(new Common::GenericArchiveMember(name, this)); +} + +Common::SeekableReadStream *Win32ResourceArchive::createReadStreamForMember(const Common::String &name) const { + HRSRC resource = FindResource(NULL, name.c_str(), MAKEINTRESOURCE(256)); + + if (resource == NULL) + return 0; + + HGLOBAL handle = LoadResource(NULL, resource); + + if (handle == NULL) + return 0; + + const byte *data = (const byte *)LockResource(handle); + + if (data == NULL) + return 0; + + uint32 size = SizeofResource(NULL, resource); + + if (size == 0) + return 0; + + return new Common::MemoryReadStream(data, size); +} + +} // End of anonymous namespace + +void OSystem_Win32::addSysArchivesToSearchSet(Common::SearchSet &s, int priority) { + s.add("Win32Res", new Win32ResourceArchive()); + + OSystem_SDL::addSysArchivesToSearchSet(s, priority); +} + #endif diff --git a/backends/platform/sdl/win32/win32.h b/backends/platform/sdl/win32/win32.h index 8379c49437..25cb6bfbba 100644 --- a/backends/platform/sdl/win32/win32.h +++ b/backends/platform/sdl/win32/win32.h @@ -32,6 +32,7 @@ class OSystem_Win32 : public OSystem_SDL { public: virtual void init(); + virtual void addSysArchivesToSearchSet(Common::SearchSet &s, int priority = 0); protected: virtual Common::String getDefaultConfigFileName(); virtual Common::WriteStream *createLogFile(); -- cgit v1.2.3