#include "resources.h" #include #include #include #include #include "../shared/globalFunctions.h" #include "../shared/standardPaths.h" const GlobalResources& GlobalResources::getInstance() { static GlobalResources instance; return instance; } GlobalResources::GlobalResources() { //map, allocate and initialize pictures bitmapResource[wxT("start red.png")] = (bitmapStart = new wxBitmap(wxNullBitmap)); bitmapResource[wxT("add pair.png")] = (bitmapAddFolderPair = new wxBitmap(wxNullBitmap)); bitmapResource[wxT("remove pair.png")] = (bitmapRemoveFolderPair = new wxBitmap(wxNullBitmap)); programIcon = new wxIcon(wxNullIcon); } GlobalResources::~GlobalResources() { //free bitmap resources for (std::map::iterator i = bitmapResource.begin(); i != bitmapResource.end(); ++i) delete i->second; //free other resources delete programIcon; } void GlobalResources::load() const { wxFFileInputStream input(FreeFileSync::getInstallationDir() + globalFunctions::FILE_NAME_SEPARATOR + wxT("Resources.dat")); if (input.IsOk()) //if not... we don't want to react too harsh here { //activate support for .png files wxImage::AddHandler(new wxPNGHandler); //ownership passed wxZipInputStream resourceFile(input); std::map::iterator bmp; while (true) { std::auto_ptr entry(resourceFile.GetNextEntry()); if (entry.get() == NULL) break; const wxString name = entry->GetName(); //search if entry is available in map if ((bmp = bitmapResource.find(name)) != bitmapResource.end()) *(bmp->second) = wxBitmap(wxImage(resourceFile, wxBITMAP_TYPE_PNG)); } } #ifdef FFS_WIN *programIcon = wxIcon(wxT("A_PROGRAM_ICON")); #else #include "RealtimeSync.xpm" *programIcon = wxIcon(RealtimeSync_xpm); #endif } const wxBitmap& GlobalResources::getImageByName(const wxString& imageName) const { std::map::const_iterator bmp = bitmapResource.find(imageName); if (bmp != bitmapResource.end()) return *bmp->second; else return wxNullBitmap; }