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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
|
/*
Import plugin for Miranda NG
Copyright (C) 2012-19 Miranda NG team (https://miranda-ng.org)
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "stdafx.h"
time_t dwSinceDate = 0;
wchar_t importFile[MAX_PATH];
//=======================================================================================
// Profile selection dialog
CMirandaPageDlg::CMirandaPageDlg() :
CWizardPageDlg(IDD_MIRANDADB),
m_list(this, IDC_LIST),
btnBack(this, IDC_BACK),
btnOther(this, IDC_OTHER)
{
m_list.OnSelChange = Callback(this, &CMirandaPageDlg::onSelChanged_list);
btnBack.OnClick = Callback(this, &CMirandaPageDlg::onClick_Back);
btnOther.OnClick = Callback(this, &CMirandaPageDlg::onClick_Other);
}
bool CMirandaPageDlg::OnInitDialog()
{
VARSW pfd(L"%miranda_path%\\Profiles");
VARSW pfd1(L"%miranda_path%");
VARSW pfd2(L"%miranda_profilesdir%");
VARSW pfn(L"%miranda_profilename%");
SearchForLists(pfd2, pfn);
SearchForLists(pfd1, nullptr);
if (mir_wstrcmpi(pfd, pfd2))
SearchForLists(pfd, nullptr);
SendDlgItemMessage(m_hwnd, IDC_LIST, LB_SETCURSEL, 0, 0);
SendMessage(m_hwnd, WM_COMMAND, MAKELONG(IDC_LIST, LBN_SELCHANGE), 0);
wchar_t filename[MAX_PATH];
GetDlgItemText(m_hwnd, IDC_FILENAME, filename, _countof(filename));
if (_waccess(filename, 4))
SendMessage(m_hwndParent, WIZM_DISABLEBUTTON, 1, 0);
return true;
}
int CMirandaPageDlg::Resizer(UTILRESIZECONTROL *urc)
{
switch (urc->wId) {
case IDC_STATICTEXT1:
return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP;
case IDC_STATICTEXT2:
return RD_ANCHORX_LEFT | RD_ANCHORY_BOTTOM;
case IDC_FILENAME:
return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM;
case IDC_LIST:
return RD_ANCHORX_WIDTH | RD_ANCHORY_HEIGHT;
}
return RD_ANCHORX_RIGHT | RD_ANCHORY_BOTTOM;
}
void CMirandaPageDlg::OnDestroy()
{
for (int i = SendDlgItemMessage(m_hwnd, IDC_LIST, LB_GETCOUNT, 0, 0) - 1; i >= 0; i--)
mir_free((char*)SendDlgItemMessage(m_hwnd, IDC_LIST, LB_GETITEMDATA, i, 0));
}
void CMirandaPageDlg::OnNext()
{
wchar_t filename[MAX_PATH];
GetDlgItemText(m_hwnd, IDC_FILENAME, filename, _countof(filename));
if (_waccess(filename, 4)) {
MessageBox(m_hwnd, TranslateT("The given file does not exist. Please check that you have entered the name correctly."), TranslateT("Miranda Import"), MB_OK);
return;
}
mir_wstrcpy(importFile, filename);
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaOptionsPageDlg());
}
void CMirandaPageDlg::onClick_Back(CCtrlButton*)
{
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CIntroPageDlg());
}
void CMirandaPageDlg::onClick_Other(CCtrlButton*)
{
ptrW pfd(Utils_ReplaceVarsW(L"%miranda_profilesdir%"));
wchar_t str[MAX_PATH], text[256];
GetDlgItemText(m_hwnd, IDC_FILENAME, str, _countof(str));
mir_snwprintf(text, L"%s (*.dat, *.bak)%c*.dat;*.bak%c%s (*.*)%c*.*%c%c", TranslateT("Miranda NG database"), 0, 0, TranslateT("All Files"), 0, 0, 0);
OPENFILENAME ofn = {};
ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400;
ofn.hwndOwner = m_hwnd;
ofn.lpstrFilter = text;
ofn.lpstrDefExt = L"dat";
ofn.lpstrFile = str;
ofn.Flags = OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_NOCHANGEDIR | OFN_DONTADDTORECENT;
ofn.nMaxFile = _countof(str);
ofn.lpstrInitialDir = pfd;
if (GetOpenFileName(&ofn)) {
if (!mir_wstrcmpi(str, VARSW(L"%miranda_userdata%\\%miranda_profilename%.dat"))) {
MessageBoxW(nullptr, TranslateT("You cannot import your current profile into itself"), L"Miranda NG", MB_OK | MB_ICONERROR);
return;
}
SetDlgItemText(m_hwnd, IDC_FILENAME, str);
m_list.SetCurSel(-1);
SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
}
}
void CMirandaPageDlg::onSelChanged_list(CCtrlListBox*)
{
int sel = m_list.GetCurSel();
if (sel != -1) {
SetDlgItemText(m_hwnd, IDC_FILENAME, (wchar_t*)m_list.GetItemData(sel));
SendMessage(m_hwndParent, WIZM_ENABLEBUTTON, 1, 0);
}
}
void CMirandaPageDlg::SearchForLists(const wchar_t *mirandaPath, const wchar_t *mirandaProf)
{
// find in Miranda profile subfolders
wchar_t searchspec[MAX_PATH];
mir_snwprintf(searchspec, L"%s\\*.*", mirandaPath);
WIN32_FIND_DATA fd;
HANDLE hFind = FindFirstFile(searchspec, &fd);
if (hFind == INVALID_HANDLE_VALUE)
return;
do {
// find all subfolders except "." and ".."
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || !mir_wstrcmp(fd.cFileName, L".") || !mir_wstrcmp(fd.cFileName, L".."))
continue;
// skip the current profile too
if (mirandaProf != nullptr && !mir_wstrcmpi(mirandaProf, fd.cFileName))
continue;
wchar_t buf[MAX_PATH], profile[MAX_PATH];
mir_snwprintf(buf, L"%s\\%s\\%s.dat", mirandaPath, fd.cFileName, fd.cFileName);
if (_waccess(buf, 0) == 0) {
mir_snwprintf(profile, L"%s.dat", fd.cFileName);
m_list.AddString(profile, (LPARAM)mir_wstrdup(buf));
}
} while (FindNextFile(hFind, &fd));
FindClose(hFind);
}
//=======================================================================================
// Import options dialog
CMirandaOptionsPageDlg::CMirandaOptionsPageDlg() :
CWizardPageDlg(IDD_OPTIONS),
btnBack(this, IDC_BACK),
chkDups(this, IDC_CHECK_DUPS)
{
btnBack.OnClick = Callback(this, &CMirandaOptionsPageDlg::onClick_Back);
}
bool CMirandaOptionsPageDlg::OnInitDialog()
{
EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_COMPLETE), TRUE);
EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_ALL), TRUE);
EnableWindow(GetDlgItem(m_hwnd, IDC_STATIC_ALL), TRUE);
EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_CONTACTS), TRUE);
EnableWindow(GetDlgItem(m_hwnd, IDC_STATIC_CONTACTS), TRUE);
EnableWindow(GetDlgItem(m_hwnd, IDC_RADIO_CUSTOM), TRUE);
EnableWindow(GetDlgItem(m_hwnd, IDC_STATIC_CUSTOM), TRUE);
CheckDlgButton(m_hwnd, IDC_RADIO_ALL, BST_CHECKED);
return true;
}
int CMirandaOptionsPageDlg::Resizer(UTILRESIZECONTROL *urc)
{
switch (urc->wId) {
case IDC_STATIC_ALL:
case IDC_STATIC_CONTACTS:
case IDC_STATIC_CUSTOM:
case IDC_STATICTEXT1:
return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP;
}
return RD_ANCHORX_LEFT | RD_ANCHORY_TOP;
}
void CMirandaOptionsPageDlg::onClick_Back(CCtrlButton*)
{
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaPageDlg());
}
void CMirandaOptionsPageDlg::OnNext()
{
int iFlags = chkDups.IsChecked() ? IOPT_CHECKDUPS : 0;
if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_COMPLETE)) {
g_iImportOptions = IOPT_ADDUNKNOWN | IOPT_COMPLETE | iFlags;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
}
else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_ALL)) {
g_iImportOptions = IOPT_HISTORY | IOPT_SYSTEM | IOPT_GROUPS | IOPT_CONTACTS | iFlags;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
}
else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_CONTACTS)) {
g_iImportOptions = IOPT_CONTACTS;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_PROGRESS, (LPARAM)new CProgressPageDlg());
}
else if (IsDlgButtonChecked(m_hwnd, IDC_RADIO_CUSTOM)) {
g_iImportOptions = iFlags;
PostMessage(m_hwndParent, WIZM_GOTOPAGE, IDD_ADVOPTIONS, (LPARAM)new CMirandaAdvOptionsPageDlg());
}
}
//=======================================================================================
// Advanced options dialog
static const UINT InControls[] = { IDC_IN_MSG, IDC_IN_FT, IDC_IN_OTHER };
static const UINT OutControls[] = { IDC_OUT_MSG, IDC_OUT_FT, IDC_OUT_OTHER };
static const UINT SysControls[] = { IDC_CONTACTS, IDC_SYSTEM };
CMirandaAdvOptionsPageDlg::CMirandaAdvOptionsPageDlg() :
CWizardPageDlg(IDD_ADVOPTIONS),
btnBack(this, IDC_BACK),
chkFT(this, IDC_FT),
chkAll(this, IDC_ALL),
chkMsg(this, IDC_MSG),
chkOther(this, IDC_OTHER),
chkSince(this, IDC_SINCE),
chkOutgoing(this, IDC_OUTGOING),
chkIncoming(this, IDC_INCOMING)
{
btnBack.OnClick = Callback(this, &CMirandaAdvOptionsPageDlg::onClick_Back);
chkSince.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_Since);
chkAll.OnChange = chkOutgoing.OnChange = chkIncoming.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_All);
chkMsg.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_Msg);
chkFT.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_FT);
chkOther.OnChange = Callback(this, &CMirandaAdvOptionsPageDlg::onChange_Other);
}
bool CMirandaAdvOptionsPageDlg::OnInitDialog()
{
dwSinceDate = g_plugin.getDword("ImportSinceTS", time(0));
struct tm *TM = localtime(&dwSinceDate);
struct _SYSTEMTIME ST = { 0 };
ST.wYear = TM->tm_year + 1900;
ST.wMonth = TM->tm_mon + 1;
ST.wDay = TM->tm_mday;
DateTime_SetSystemtime(GetDlgItem(m_hwnd, IDC_DATETIMEPICKER), GDT_VALID, &ST);
return true;
}
void CMirandaAdvOptionsPageDlg::onClick_Back(CCtrlButton*)
{
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CMirandaOptionsPageDlg());
}
void CMirandaAdvOptionsPageDlg::OnNext()
{
// clear all another flags but duplicates
g_iImportOptions &= IOPT_CHECKDUPS;
if (IsDlgButtonChecked(m_hwnd, IDC_CONTACTS))
g_iImportOptions |= IOPT_CONTACTS | IOPT_GROUPS;
if (IsDlgButtonChecked(m_hwnd, IDC_SYSTEM))
g_iImportOptions |= IOPT_SYSTEM;
// incoming
if (IsDlgButtonChecked(m_hwnd, IDC_IN_MSG))
g_iImportOptions |= IOPT_MSGRECV;
if (IsDlgButtonChecked(m_hwnd, IDC_IN_FT))
g_iImportOptions |= IOPT_FILERECV;
if (IsDlgButtonChecked(m_hwnd, IDC_IN_OTHER))
g_iImportOptions |= IOPT_OTHERRECV;
// outgoing
if (IsDlgButtonChecked(m_hwnd, IDC_OUT_MSG))
g_iImportOptions |= IOPT_MSGSENT;
if (IsDlgButtonChecked(m_hwnd, IDC_OUT_FT))
g_iImportOptions |= IOPT_FILESENT;
if (IsDlgButtonChecked(m_hwnd, IDC_OUT_OTHER))
g_iImportOptions |= IOPT_OTHERSENT;
// since date
dwSinceDate = 0;
if (chkSince.IsChecked()) {
struct _SYSTEMTIME ST = { 0 };
if (DateTime_GetSystemtime(GetDlgItem(m_hwnd, IDC_DATETIMEPICKER), &ST) == GDT_VALID) {
struct tm TM = { 0 };
TM.tm_mday = ST.wDay;
TM.tm_mon = ST.wMonth - 1;
TM.tm_year = ST.wYear - 1900;
dwSinceDate = mktime(&TM);
g_plugin.setDword("ImportSinceTS", dwSinceDate);
}
}
if (g_iImportOptions)
PostMessage(m_hwndParent, WIZM_GOTOPAGE, 0, (LPARAM)new CProgressPageDlg());
}
void CMirandaAdvOptionsPageDlg::onChange_Since(CCtrlCheck*)
{
EnableWindow(GetDlgItem(m_hwnd, IDC_DATETIMEPICKER), chkSince.IsChecked());
}
void CMirandaAdvOptionsPageDlg::onChange_All(CCtrlCheck *pCheck)
{
if (pCheck->GetCtrlId() == IDC_ALL)
for (auto &it : SysControls)
CheckDlgButton(m_hwnd, it, IsDlgButtonChecked(m_hwnd, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
if (pCheck->GetCtrlId() != IDC_OUTGOING)
for (auto &it : InControls)
CheckDlgButton(m_hwnd, it, IsDlgButtonChecked(m_hwnd, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
if (pCheck->GetCtrlId() != IDC_INCOMING)
for (auto &it : OutControls)
CheckDlgButton(m_hwnd, it, IsDlgButtonChecked(m_hwnd, it) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
}
void CMirandaAdvOptionsPageDlg::onChange_Msg(CCtrlCheck*)
{
CheckDlgButton(m_hwnd, IDC_IN_MSG, IsDlgButtonChecked(m_hwnd, IDC_IN_MSG) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(m_hwnd, IDC_OUT_MSG, IsDlgButtonChecked(m_hwnd, IDC_OUT_MSG) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
}
void CMirandaAdvOptionsPageDlg::onChange_FT(CCtrlCheck*)
{
CheckDlgButton(m_hwnd, IDC_IN_FT, IsDlgButtonChecked(m_hwnd, IDC_IN_FT) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(m_hwnd, IDC_OUT_FT, IsDlgButtonChecked(m_hwnd, IDC_OUT_FT) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
}
void CMirandaAdvOptionsPageDlg::onChange_Other(CCtrlCheck*)
{
CheckDlgButton(m_hwnd, IDC_IN_OTHER, IsDlgButtonChecked(m_hwnd, IDC_IN_OTHER) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(m_hwnd, IDC_OUT_OTHER, IsDlgButtonChecked(m_hwnd, IDC_OUT_OTHER) == BST_UNCHECKED ? BST_CHECKED : BST_UNCHECKED);
}
|