blob: 37a0bb431f108c7d9f907fbd332539c09e5e1b00 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include "resources.h"
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
#include <wx/image.h>
#include <wx/icon.h>
#include <memory>
#include "../shared/stringConv.h"
#include "../shared/standardPaths.h"
#include "../shared/systemConstants.h"
using namespace FreeFileSync;
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<wxString, wxBitmap*>::iterator i = bitmapResource.begin(); i != bitmapResource.end(); ++i)
delete i->second;
//free other resources
delete programIcon;
}
void GlobalResources::load() const
{
wxFFileInputStream input(FreeFileSync::getInstallationDir() + zToWx(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<wxString, wxBitmap*>::iterator bmp;
while (true)
{
std::auto_ptr<wxZipEntry> 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<wxString, wxBitmap*>::const_iterator bmp = bitmapResource.find(imageName);
if (bmp != bitmapResource.end())
return *bmp->second;
else
return wxNullBitmap;
}
|