-
Notifications
You must be signed in to change notification settings - Fork 42
/
SelectWindowsComponents.h
185 lines (146 loc) · 4.6 KB
/
SelectWindowsComponents.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#pragma once
#include "gui/GUIWindowsComponents.h"
#include "FileSettingsReader.h"
#include <wx/thread.h>
#include <wx/timer.h>
#include <Windows.h>
#include <Vss.h>
#include <VsWriter.h>
#include <VsBackup.h>
#include <vector>
#include <map>
typedef wxLongLong_t int64;
struct SComponent
{
SComponent()
: is_root(false), parent(NULL){ }
bool is_root;
VSS_ID writerId;
std::string name;
std::string logicalPathComponent;
std::string logicalPath;
std::string displayName;
bool selectable;
bool writer;
std::vector<char> icon;
std::vector<SComponent*> children;
std::vector<SComponent*> dependencies;
SComponent* parent;
};
std::string GetErrorHResErrStr(HRESULT res);
class WindowsComponentReader : public wxThread
{
public:
WindowsComponentReader();
~WindowsComponentReader();
SComponent* getRoot();
static bool readComponents(const std::string& restoreXml, const std::vector<std::string>& componentXmls,
const std::vector<SComponent>& filter_except, SComponent& root, std::vector<SComponent*>& components, std::string& errmsg);
static bool wait_for(IVssAsync *vsasync, const std::string& error_prefix, std::string& errmsg);
protected:
virtual ExitCode Entry();
private:
std::string errmsg;
SComponent root;
static SComponent* getComponent(SComponent* node, VSS_ID writerId, std::string logical_path);
std::vector<SComponent*> components;
};
class SelectWindowsComponents : public GUIWindowsComponents, public wxTimer
{
public:
SelectWindowsComponents(wxWindow* parent);
~SelectWindowsComponents();
static void addComponents(wxTreeCtrl* tree, wxImageList* iconList,
wxTreeItemId treeId, SComponent* node, std::map<wxTreeItemId, SComponent*>& tree_components,
std::map<SComponent*, wxTreeItemId>& tree_items, int icon_width, int icon_height);
static void selectTreeItems(wxTreeCtrl* tree, std::map<SComponent*, wxTreeItemId>& tree_items,
SComponent* root, SComponent* node, bool select, bool removeSelect = false);
static bool hasSelectedChild(wxTreeCtrl* tree, std::map<SComponent*, wxTreeItemId>& tree_items,
SComponent* node);
static bool allChildrenSelected(wxTreeCtrl* tree, std::map<SComponent*, wxTreeItemId>& tree_items,
SComponent* node, bool& has_selectable_child);
protected:
virtual void Notify(void);
virtual void evtOnTreeItemGetTooltip(wxTreeEvent& event);
virtual void evtOnTreeStateImageClick(wxTreeEvent& event);
virtual void onOkClick(wxCommandEvent& event);
virtual void onCancel(wxCommandEvent& event);
private:
void selectTreeItems(SComponent* node, bool select, bool removeSelect = false);
void collectComponents(SComponent* node, size_t& idx, std::string& res);
WindowsComponentReader componentReader;
wxImageList* iconList;
wxImageList* selectList;
CFileSettingsReader *settings;
std::map<wxTreeItemId, SComponent*> tree_components;
std::map<SComponent*, wxTreeItemId> tree_items;
int icon_width;
int icon_height;
int use_orig;
int64 use_lm_orig;
};
namespace
{
template<typename T>
class ReleaseIUnknown
{
public:
ReleaseIUnknown(T*& unknown)
: unknown(unknown) {}
~ReleaseIUnknown() {
if (unknown != NULL) {
unknown->Release();
}
}
private:
T*& unknown;
};
#define TOKENPASTE2(x, y) x ## y
#define TOKENPASTE(x, y) TOKENPASTE2(x, y)
#define SCOPED_DECLARE_RELEASE_IUNKNOWN(t, x) t* x = NULL; ReleaseIUnknown<t> TOKENPASTE(ReleaseIUnknown_,__LINE__) (x)
class FreeBStr
{
public:
FreeBStr(BSTR& bstr)
: bstr(bstr)
{}
~FreeBStr() {
if (bstr != NULL) {
SysFreeString(bstr);
}
}
private:
BSTR& bstr;
};
#define SCOPED_DECLARE_FREE_BSTR(x) BSTR x = NULL; FreeBStr TOKENPASTE(FreeBStr_, __LINE__) (x)
class FreeComponentInfo
{
public:
FreeComponentInfo(IVssWMComponent* wmComponent, PVSSCOMPONENTINFO& componentInfo)
: wmComponent(wmComponent), componentInfo(componentInfo)
{}
~FreeComponentInfo() {
if (wmComponent != NULL && componentInfo != NULL) {
wmComponent->FreeComponentInfo(componentInfo);
}
}
private:
IVssWMComponent* wmComponent;
PVSSCOMPONENTINFO componentInfo;
};
#define SCOPED_DECLARE_FREE_COMPONENTINFO(c, i) PVSSCOMPONENTINFO i = NULL; FreeComponentInfo TOKENPASTE(FreeComponentInfo_,__LINE__) (c, i);
std::string convert(VSS_ID id)
{
WCHAR GuidStr[128] = {};
int rc = StringFromGUID2(id, GuidStr, 128);
if (rc > 0)
{
return wxString(std::wstring(GuidStr, rc - 1)).ToStdString();
}
return std::string();
}
std::string ConvertFromWchar(std::wstring str)
{
return ConvertToUTF8(str);
}
}