blob: f81af50a99122771386962d929845681018314db (
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
|
// **************************************************************************
// * This file is part of the FreeFileSync project. It is distributed under *
// * GNU General Public License: http://www.gnu.org/licenses/gpl.html *
// * Copyright (C) ZenJu (zhnmju123 AT gmx DOT de) - All Rights Reserved *
// **************************************************************************
#include "resources.h"
#include <memory>
#include <wx/wfstream.h>
#include <wx/zipstrm.h>
#include <wx/image.h>
#include "../lib/ffs_paths.h"
using namespace zen;
const GlobalResources& GlobalResources::instance()
{
static GlobalResources inst;
return inst;
}
GlobalResources::GlobalResources()
{
wxFFileInputStream input(toWx(zen::getResourceDir()) + wxT("Resources.zip"));
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, wxConvUTF8);
//do NOT rely on wxConvLocal! May result in "Cannot convert from the charset 'Unknown encoding (-1)'!"
while (true)
{
std::unique_ptr<wxZipEntry> entry(resourceFile.GetNextEntry());
if (entry.get() == nullptr)
break;
const wxString name = entry->GetName();
//generic image loading
if (name.EndsWith(wxT(".png")))
bitmaps.insert(std::make_pair(name, wxImage(resourceFile, wxBITMAP_TYPE_PNG)));
}
}
#ifdef FFS_WIN
//for compatibility it seems we need to stick with a "real" icon
programIcon = wxIcon(wxT("A_PROGRAM_ICON"));
#else
//use big logo bitmap for better quality
programIcon.CopyFromBitmap(getImageInt(wxT("RealtimeSync.png")));
#endif
}
const wxBitmap& GlobalResources::getImageInt(const wxString& name) const
{
auto iter = bitmaps.find(name.Find(L'.') == wxNOT_FOUND ? //assume .png ending if nothing else specified
name + wxT(".png") :
name);
if (iter != bitmaps.end())
return iter->second;
else
{
assert(false);
return wxNullBitmap;
}
}
|