On windows, this can be solved since you can embed resources in the executable. On linux though, you still have lots of files. Here's how to embed arbitrary resources in an executable (cross platform compatible too).
Starting from http://www.wxwidgets.org/wiki/index.php ... PNG_Images, I had the idea that something like this is possible, but this still doesn't allow just anything to be embedded.
So, here's the process:
1. Take all your resources and make a zip file out of them (it can be more than one, but one is more convenient). For example, I'll call my zip file Example.zip
2. Using the c version of the program listed on that page, (http://www.wxwidgets.org/wiki/index.php ... der_guards) convert your zip file into c code. For example mine might be called Example.zip.h
3. #include the zip file in one of the first classes that executes. For example, as part of the class that inherits from wxApp, I use the code
Code: Select all
#include "Example.zip.h"
Code: Select all
wxFileSystem::AddHandler( new wxArchiveFSHandler );
wxFileSystem::AddHandler( new wxMemoryFSHandler );
5. After those lines of code add something like the following
Code: Select all
wxMemoryFSHandler::AddFileWithMimeType( _T("Example.zip"), Example_zip, sizeof(Example_zip), _T("application/zip") );
Note that according to the documentation, this call only works in wx 2.8
6. Now you can use wxFileSystem to access the contents of the zip. The path is memory:Example.zip#zip:someDirectoryInZip/someFile
A few examples:
Using the wx help system, to add a help file named HelpFile.hhp located in the Documentation directory of the zip file, do something like
Code: Select all
wxHtmlHelpController* helpSystem = new wxHtmlHelpController( wxHF_DEFAULT_STYLE, this );
helpSystem->AddBook( _T("memory:Example.zip#zip:Documentation/HelpFile.hhp") );
Getting an image out is a little trickier but here's how
Assuming the image is called image.png and is located in the icons directory,
Code: Select all
wxImage theImage;
wxFileSystem fs;
wxFsFile* imageFile;
imageFile = fs.OpenFile( _T("memory:Example.zip#zip:icons/image.png") );
if( imageFile != NULL )
{
theImage.LoadFile( *imageFile->GetStream(), imageFile->GetMimeType() );
//do something with the image
}
else
//the image does not exist, error handling
One limitation of this method is that you cannot change any of these files - they are compiled into the executable, so changing them in the executable is a somewhat difficult task.