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
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
|
#include "commonheaders.h"
INT_PTR CALLBACK DlgProcContactInfo(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_INITDIALOG:
{
HANDLE hContact = (HANDLE)((PROPSHEETPAGE*)lParam)->lParam;
char name[2048];
TranslateDialogDefault(hwnd);
SetWindowLong(hwnd, GWLP_USERDATA, (LPARAM)(HANDLE)hContact);
if (!db_get_static(hContact, MODNAME, "Name", name)) break;
SetDlgItemTextA(hwnd, IDC_DISPLAY_NAME, name);
if (!db_get_static(hContact, MODNAME, "ToolTip", name)) break;
SetDlgItemTextA(hwnd, IDC_TOOLTIP, name);
}
return TRUE;
case WM_COMMAND:
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
return TRUE;
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->idFrom) {
case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
HANDLE hContact = (HANDLE)GetWindowLong(hwnd, GWLP_USERDATA);
if (GetWindowTextLength(GetDlgItem(hwnd,IDC_DISPLAY_NAME))) {
char text[512];
GetDlgItemTextA(hwnd,IDC_DISPLAY_NAME,text,sizeof(text));
db_set_s(hContact, MODNAME, "Name", text);
WriteSetting(hContact, MODNAME, "Name", MODNAME, "Nick");
}
else {
db_unset(hContact, MODNAME, "Name");
db_unset(hContact, MODNAME, "Nick");
}
if (GetWindowTextLength(GetDlgItem(hwnd,IDC_TOOLTIP))) {
char text[2048];
GetDlgItemTextA(hwnd,IDC_TOOLTIP,text,sizeof(text));
db_set_s(hContact, MODNAME, "ToolTip", text);
WriteSetting(hContact, MODNAME, "ToolTip", "UserInfo", "MyNotes");
}
else {
db_unset(hContact, MODNAME, "ToolTip");
db_unset(hContact, "UserInfo", "MyNotes");
}
}
return TRUE;
}
break;
}
return FALSE;
}
static WNDPROC g_PrevBtnWndProc = 0;
LRESULT CALLBACK ButtWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT res = CallWindowProc(g_PrevBtnWndProc, hWnd, message, wParam, lParam);
if (WM_PAINT == message) {
RECT rc;
HDC dc = GetDC(hWnd);
BOOL isPressed = BST_CHECKED == SendMessage(hWnd, BM_GETCHECK, 0, 0);
GetClientRect(hWnd, &rc);
rc.left += (rc.right - rc.left - 16) / 2;
rc.top += (rc.bottom - rc.top - 16) / 2;
if (isPressed)
OffsetRect(&rc, 1, 1);
DrawIconEx(dc, rc.left, rc.top, (HICON)GetWindowLong(hWnd, GWLP_USERDATA),
16, 16, 0, 0, DI_NORMAL);
ReleaseDC(hWnd, dc);
}
return res;
}
void checkGroups(char* group)
{
int i;
char str[50], name[256];
DBVARIANT dbv;
if (lstrlenA(group) < 1)
return;
for (i = 0;; i++) {
_itoa(i, str, 10);
if (DBGetContactSetting(NULL, "CListGroups", str, &dbv))
break;
if (dbv.type == DBVT_ASCIIZ) {
if (dbv.pszVal[0] != '\0' && !lstrcmpiA(dbv.pszVal + 1, group)) {
db_free(&dbv);
return;
}
db_free(&dbv);
}
}
name[0] = 1 | GROUPF_EXPANDED;
strncpy(name + 1, group, sizeof(name) - 1);
name[strlen(group) + 1] = '\0';
db_set_s(NULL, "CListGroups", str, name);
CallService(MS_CLUI_GROUPADDED, i + 1, 0);
}
int BrowseForFolder(HWND hwnd,char *szPath)
{
int result=0;
if (SUCCEEDED(OleInitialize(NULL))) {
LPMALLOC pMalloc;
if (SUCCEEDED(CoGetMalloc(1,&pMalloc))) {
mir_ptr<TCHAR> tszPath( mir_a2t(szPath));
BROWSEINFO bi={0};
bi.hwndOwner = hwnd;
bi.pszDisplayName = tszPath;
bi.lpszTitle = TranslateT("Select Folder");
bi.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS; // Use this combo instead of BIF_USENEWUI
bi.lParam = (LPARAM)szPath;
ITEMIDLIST *pidlResult = SHBrowseForFolder(&bi);
if (pidlResult) {
SHGetPathFromIDListA(pidlResult, szPath);
lstrcatA(szPath,"\\");
result = 1;
}
pMalloc->Free(pidlResult);
pMalloc->Release();
}
OleUninitialize();
}
return result;
}
INT_PTR CALLBACK DlgProcOtherStuff(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_INITDIALOG:
{
int i = 0;
DBVARIANT dbv;
char string[512];
HANDLE hContact = (HANDLE)((PROPSHEETPAGE*)lParam)->lParam;
TranslateDialogDefault(hwnd);
SetWindowLong(hwnd, GWLP_USERDATA, (LPARAM)(HANDLE)hContact);
if (!hContact)
break;
/* link*/
if (db_get_static(hContact, MODNAME, "ProgramString", string))
SetDlgItemTextA(hwnd, IDC_LINK, string);
if (db_get_static(hContact, MODNAME, "ProgramParamsString", string))
SetDlgItemTextA(hwnd, IDC_PARAMS, string);
/* group*/
while (i != -1)
{
char str[3], name[256];
wsprintfA(str, "%d", i);
if (!DBGetContactSetting(NULL, "CListGroups", str, &dbv))
{
lstrcpynA(name,dbv.pszVal+1,sizeof(name));
SendMessage(GetDlgItem(hwnd, IDC_GROUP), CB_INSERTSTRING,0, (LPARAM)name);
i++;
}
else i = -1;
}
if (!DBGetContactSetting(hContact, "CList", "Group", &dbv))
SetDlgItemTextA(hwnd, IDC_GROUP, dbv.pszVal);
/* icons */
CheckRadioButton(hwnd, 40072, 40080, db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
SetWindowLong(GetDlgItem(hwnd, CHK_ONLINE), GWLP_USERDATA, (LONG)LoadSkinnedProtoIcon(MODNAME, ID_STATUS_ONLINE));
g_PrevBtnWndProc = (WNDPROC)SetWindowLong(GetDlgItem(hwnd, CHK_ONLINE), GWLP_WNDPROC, (LONG)ButtWndProc);
for (i = ID_STATUS_ONLINE; i<=ID_STATUS_OUTTOLUNCH; i++) {
SetWindowLong(GetDlgItem(hwnd, i), GWLP_USERDATA, (LONG)LoadSkinnedProtoIcon(MODNAME, i));
SetWindowLong(GetDlgItem(hwnd, i), GWLP_WNDPROC, (LONG)ButtWndProc);
}
db_free(&dbv);
/* timer */
CheckDlgButton(hwnd, CHK_USE_TIMER, db_get_b(hContact, MODNAME ,"UseTimer", 0));
if (db_get_w(hContact, MODNAME ,"Timer", 15)) {
CheckDlgButton(hwnd, CHK_USE_TIMER,1);
EnableWindow(GetDlgItem(hwnd, IDC_TIMER), 1);
SetDlgItemTextA(hwnd, IDC_TIMER, _itoa(db_get_w(hContact, MODNAME ,"Timer", 15), string, 10));
if (!db_get_w(NULL, MODNAME ,"Timer", 1))
SetDlgItemTextA(hwnd,IDC_TIMER_INTERVAL_MSG, "Non-IM Contact protocol timer is Disabled");
else {
_snprintf(string, sizeof(string), "Timer intervals... Non-IM Contact Protocol timer is %d seconds",db_get_w(NULL, MODNAME ,"Timer", 1));
SetDlgItemTextA(hwnd,IDC_TIMER_INTERVAL_MSG, string);
}
}
/* always visible */
if (db_get_b(hContact, MODNAME ,"AlwaysVisible", 0)) {
CheckDlgButton(hwnd, IDC_ALWAYS_VISIBLE, 1);
EnableWindow(GetDlgItem(hwnd, IDC_VISIBLE_UNLESS_OFFLINE),1);
CheckDlgButton(hwnd, IDC_VISIBLE_UNLESS_OFFLINE, db_get_b(hContact, MODNAME ,"VisibleUnlessOffline", 1));
}
}
return TRUE;
case WM_COMMAND:
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
switch(LOWORD(wParam)) {
case IDC_ALWAYS_VISIBLE:
if (IsDlgButtonChecked(hwnd, IDC_ALWAYS_VISIBLE)) {
HANDLE hContact = (HANDLE)GetWindowLong(hwnd, GWLP_USERDATA);
EnableWindow(GetDlgItem(hwnd, IDC_VISIBLE_UNLESS_OFFLINE),1);
CheckDlgButton(hwnd, IDC_VISIBLE_UNLESS_OFFLINE, db_get_b(hContact, MODNAME ,"VisibleUnlessOffline", 1));
}
else EnableWindow(GetDlgItem(hwnd, IDC_VISIBLE_UNLESS_OFFLINE),0);
break;
case CHK_USE_TIMER:
if (IsDlgButtonChecked(hwnd, CHK_USE_TIMER)) {
HANDLE hContact = (HANDLE)GetWindowLong(hwnd, GWLP_USERDATA);
char string[4];
EnableWindow(GetDlgItem(hwnd, IDC_TIMER), 1);
SetDlgItemTextA(hwnd, IDC_TIMER, _itoa(db_get_w(hContact, MODNAME ,"Timer", 15), string, 10));
}
else EnableWindow(GetDlgItem(hwnd, IDC_TIMER), 0);
break;
case IDC_OPEN_FILE:
{
char szFileName[512];
if ( Openfile(szFileName,1))
SetDlgItemTextA(hwnd, IDC_LINK, szFileName);
}
break;
case IDC_OPEN_FOLDER:
{
char szFileName[512];
if (BrowseForFolder(hwnd, szFileName)) {
wsprintfA(szFileName, "%s ,/e", szFileName);
SetDlgItemTextA(hwnd, IDC_LINK, "explorer.exe");
SetDlgItemTextA(hwnd, IDC_PARAMS, szFileName);
}
}
}
break;
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->idFrom) {
case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
int status = GetLCStatus(0,0);
HANDLE hContact = (HANDLE)GetWindowLong(hwnd, GWLP_USERDATA);
int i;
if (GetWindowTextLength(GetDlgItem(hwnd,IDC_LINK)))
{
char text[512];
GetDlgItemTextA(hwnd,IDC_LINK,text,sizeof(text));
db_set_s(hContact, MODNAME, "ProgramString", text);
WriteSetting(hContact, MODNAME, "ProgramString", MODNAME, "Program");
}
else db_unset(hContact, MODNAME, "ProgramString");
if (GetWindowTextLength(GetDlgItem(hwnd,IDC_PARAMS)))
{
char text[512];
GetDlgItemTextA(hwnd,IDC_PARAMS,text,sizeof(text));
db_set_s(hContact, MODNAME, "ProgramParamsString", text);
WriteSetting(hContact, MODNAME, "ProgramParamsString", MODNAME, "ProgramParams");
}
else db_unset(hContact, MODNAME, "ProgramParamsString");
if (GetWindowTextLength(GetDlgItem(hwnd,IDC_GROUP)))
{
char text[512];
GetDlgItemTextA(hwnd,IDC_GROUP,text,sizeof(text));
checkGroups(text);
db_set_s(hContact, "CList", "Group", text);
}
else db_unset(hContact, "CList", "Group");
for (i = ID_STATUS_ONLINE; i<=ID_STATUS_OUTTOLUNCH; i++)
{
if (IsDlgButtonChecked(hwnd, i))
db_set_w(hContact, MODNAME, "Icon", (WORD)i);
}
/* set correct status */
if ( (status == ID_STATUS_ONLINE) || (status == ID_STATUS_AWAY) ||
(status == db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE) )
)
db_set_w(hContact, MODNAME, "Status", (WORD)db_get_w(hContact, MODNAME, "Icon", ID_STATUS_ONLINE));
else
db_set_w(hContact, MODNAME, "Status", ID_STATUS_OFFLINE);
if (IsDlgButtonChecked(hwnd, CHK_USE_TIMER))
{
if (GetWindowTextLength(GetDlgItem(hwnd,IDC_TIMER)))
{
char text[512];
GetDlgItemTextA(hwnd,IDC_TIMER,text,sizeof(text));
db_set_w(hContact, MODNAME, "Timer", (WORD)atoi(text));
}
else db_set_w(hContact, MODNAME, "Timer", 15);
}
else db_set_w(hContact, MODNAME, "Timer", 0);
// always visible
db_set_b(hContact, MODNAME, "AlwaysVisible", (BYTE)IsDlgButtonChecked(hwnd, IDC_ALWAYS_VISIBLE));
db_set_b(hContact, MODNAME, "VisibleUnlessOffline", (BYTE)IsDlgButtonChecked(hwnd, IDC_VISIBLE_UNLESS_OFFLINE));
}
return TRUE;
}
break;
}
return FALSE;
}
char* copyReplaceString(char* oldStr, char* newStr, char* findStr, char* replaceWithStr)
{
int i=0;
while (oldStr[i] != '\0') {
// msg(&oldStr[i],"");
if (!strncmp(&oldStr[i],findStr, strlen(findStr))) {
strcat(newStr,replaceWithStr);
i += (int)strlen(findStr);
}
else {
strncat(newStr,&oldStr[i],1);
i++;
}
}
return newStr;
}
#define MAX_REPLACES 15
INT_PTR CALLBACK DlgProcCopy(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg) {
case WM_INITDIALOG:
{
HANDLE hContact = (HANDLE)((PROPSHEETPAGE*)lParam)->lParam;
TranslateDialogDefault(hwnd);
SetWindowLong(hwnd, GWLP_USERDATA, (LPARAM)(HANDLE)hContact);
}
return TRUE;
case WM_COMMAND:
SendMessage(GetParent(hwnd), PSM_CHANGED, 0, 0);
switch(LOWORD(wParam)) {
case IDC_EXPORT:
ExportContact((HANDLE)GetWindowLong(hwnd, GWLP_USERDATA));
break;
case IDC_DOIT:
if (GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE))) {
char *replace = (char*)malloc(GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) +1);
char newString[MAX_REPLACES][512], oldString[MAX_REPLACES][512];
char dbVar1[2000], dbVar2[2000];
int i=0,j=0, k=0;
char *string = oldString[k];
HANDLE hContact1 = (HANDLE)GetWindowLong(hwnd, GWLP_USERDATA), hContact2;
GetDlgItemTextA(hwnd, IDC_STRING_REPLACE, replace, GetWindowTextLength(GetDlgItem(hwnd, IDC_STRING_REPLACE)) +1);
if (db_get_static(hContact1, MODNAME, "Name", dbVar1)) {
// get the list of replace strings
while (replace[i] != '\0') {
if (replace[i] == ',') {
string = newString[k];
j=0;
}
else if (!strncmp(&replace[i], "\r\n",2)) {
if (string == newString[k])
k--;
if (k = MAX_REPLACES) break;
string = oldString[++k];
i+=2;
continue;
}
else {
string[j] = replace[i];
string[++j] = '\0';
}
i++;
}
hContact2 =(HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0);
CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)hContact2,(LPARAM)MODNAME);
CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE);
db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact"));
// blank dbVar2 so the replaceing doesnt crash..
strcpy(dbVar2, "");
// copy the name (dbVar1 is the name)
for (i=0;i<=k;i++)
copyReplaceString(dbVar1, dbVar2, oldString[i],newString[i] );
db_set_s(hContact2, MODNAME, "Name", dbVar2);
// copy the ProgramString
if (db_get_static(hContact1, MODNAME, "ProgramString",dbVar1)) {
strcpy(dbVar2, "");
for (i=0;i<=k;i++)
copyReplaceString(dbVar1, dbVar2, oldString[i],newString[i] );
db_set_s(hContact2, MODNAME, "ProgramString", dbVar2);
}
// copy the ProgramParamString
if (db_get_static(hContact1, MODNAME, "ProgramParamString",dbVar1)) {
strcpy(dbVar2, "");
for (i=0;i<=k;i++)
copyReplaceString(dbVar1, dbVar2, oldString[i],newString[i] );
db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar2);
}
// copy the group
if (db_get_static(hContact1, "CList", "Group",dbVar1)) {
strcpy(dbVar2, "");
for (i=0;i<=k;i++)
copyReplaceString(dbVar1, dbVar2, oldString[i],newString[i] );
db_set_s(hContact2, "CList", "Group", dbVar2);
}
// copy the ToolTip
if (db_get_static(hContact1, MODNAME, "ToolTip",dbVar1)) {
strcpy(dbVar2, "");
for (i=0;i<=k;i++)
copyReplaceString(dbVar1, dbVar2, oldString[i],newString[i] );
db_set_s(hContact2, MODNAME, "ToolTip", dbVar2);
}
// timer
db_set_b(hContact2, MODNAME, "UseTimer", (BYTE)db_get_b(hContact1, MODNAME, "UseTimer", 0));
db_set_b(hContact2, MODNAME, "Minutes", (BYTE)db_get_b(hContact1, MODNAME, "Minutes", 0));
db_set_w(hContact2, MODNAME, "Timer", (WORD)db_get_w(hContact1, MODNAME, "Timer", 0));
//icon
db_set_w(hContact2, MODNAME, "Icon", (WORD)db_get_w(hContact1, MODNAME, "Icon", 40072));
replaceAllStrings(hContact2);
}
}
else {
char dbVar1[2000];
HANDLE hContact1 = (HANDLE)GetWindowLong(hwnd, GWLP_USERDATA), hContact2;
if (db_get_static(hContact1, MODNAME, "Name", dbVar1)) {
if (!(hContact2 =(HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0))) {
msg("contact did not get created","");
return 0;
}
CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)hContact2,(LPARAM)MODNAME);
CallService(MS_IGNORE_IGNORE, (WPARAM)hContact2, IGNOREEVENT_USERONLINE);
db_set_s(hContact2, MODNAME, "Nick", Translate("New Non-IM Contact"));
db_set_s(hContact2, MODNAME, "Name", dbVar1);
if (db_get_static(hContact1, MODNAME, "ProgramString",dbVar1))
db_set_s(hContact2, MODNAME, "ProgramString", dbVar1);
// copy the ProgramParamString
if (db_get_static(hContact1, MODNAME, "ProgramParamString",dbVar1))
db_set_s(hContact2, MODNAME, "ProgramParamString", dbVar1);
// copy the group
if (db_get_static(hContact1, "CList", "Group",dbVar1))
db_set_s(hContact2, "CList", "Group", dbVar1);
// copy the ToolTip
if (db_get_static(hContact1, MODNAME, "ToolTip",dbVar1))
db_set_s(hContact2, MODNAME, "ToolTip", dbVar1);
// timer
db_set_b(hContact2, MODNAME, "UseTimer", (BYTE)db_get_b(hContact1, MODNAME, "UseTimer", 0));
db_set_b(hContact2, MODNAME, "Minutes", (BYTE)db_get_b(hContact1, MODNAME, "Minutes", 0));
db_set_w(hContact2, MODNAME, "Timer", (WORD)db_get_w(hContact1, MODNAME, "Timer", 0));
//icon
db_set_w(hContact2, MODNAME, "Icon", (WORD)db_get_w(hContact1, MODNAME, "Icon", 40072));
replaceAllStrings(hContact2);
}
}
}
break;
case WM_NOTIFY:
switch(((LPNMHDR)lParam)->idFrom) {
case 0:
switch (((LPNMHDR)lParam)->code) {
case PSN_APPLY:
return TRUE;
}
}
break;
}
return FALSE;
}
void ExportContact(HANDLE hContact)
{
FILE* file;
char szFileName[MAX_PATH];
char DBVar[1024];
int tmp;
if (Openfile(szFileName, 0))
{
// if (tmp = MessageBox(0, "Do you want to overwrite the contents of the file?\r\n\r\nPressing No will append this contact to the end of the file.",modFullname, MB_YESNO) == IDYES)
// file = fopen(szFileName, "w");
// else
file = fopen(szFileName, "a");
if (file)
{
if (db_get_static(hContact, MODNAME, "Name", DBVar))
{
fprintf(file, "\r\n[Non-IM Contact]\r\nName=%s\r\n", DBVar);
if (db_get_static(hContact, MODNAME, "ProgramString", DBVar))
fprintf(file, "ProgramString=%s\r\n", DBVar);
if (db_get_static(hContact, MODNAME, "ProgramParamString", DBVar))
fprintf(file, "ProgramParamString=%s\r\n", DBVar);
if (db_get_static(hContact, MODNAME, "ToolTip", DBVar))
fprintf(file, "ToolTip=%s</tooltip>\r\n", DBVar);
if (db_get_static(hContact, "CList", "Group", DBVar))
fprintf(file, "Group=%s\r\n", DBVar);
if (tmp = db_get_w(hContact, MODNAME, "Icon", 40072))
fprintf(file, "Icon=%d\r\n", tmp);
if (tmp = db_get_b(hContact, MODNAME, "UseTimer", 0))
fprintf(file, "UseTimer=%d\r\n", tmp);
if (tmp = db_get_b(hContact, MODNAME, "Minutes", 1))
fprintf(file, "Minutes=%d\r\n", tmp);
if (tmp = db_get_w(hContact, MODNAME, "Timer", 0))
fprintf(file, "Timer=%d\r\n", tmp);
fprintf(file, "[/Non-IM Contact]\r\n");
}
else ("Contact is invalid",modFullname);
fclose(file);
}
}
}
INT_PTR ImportContacts(WPARAM wParam, LPARAM lParam)
{
HANDLE hContact;
char name[256] = "", program[256] = "", programparam[256] = "", group[256] = "", tooltip[3000] = "", line[2001] = "";
int icon = 40072, usetimer = 0, minutes = 1, timer = 0;
char fn[MAX_PATH];
int i,j, contactDone = 0;
if ( !Openfile(fn, 1))
return 1;
FILE *file = fopen(fn, "r");
if (!file)
return 1;
while (fgets(line,2000,file)) {
if (!strcmp(line, "\r\n\0"))
continue;
if (!strcmp(line,"[Non-IM Contact]\r\n"))
contactDone = 0;
else if (!strncmp(line, "Name=" ,strlen("Name="))) {
i = (int)strlen("Name=");j=0;
while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') {
name[j] = line[i++];
name[++j] = '\0';
}
contactDone =1;
}
else if (!strncmp(line, "ProgramString=" ,strlen("ProgramString="))) {
i = (int)strlen("ProgramString=");j=0;
while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') {
program[j] = line[i++];
program[++j] = '\0';
}
}
else if (!strncmp(line, "ProgramParamString=" ,strlen("ProgramParamString="))) {
i = (int)strlen("ProgramParamString=");j=0;
while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') {
programparam[j] = line[i++];
programparam[++j] = '\0';
}
}
else if (!strncmp(line, "Group=" ,strlen("Group="))) {
i = (int)strlen("Group=");j=0;
while (line[i] != '\r' && line[i] != '\n' && line[i] != '\0') {
group[j] = line[i++];
group[++j] = '\0';
}
}
else if (!strncmp(line, "ToolTip=" ,strlen("ToolTip="))) {
i = (int)strlen("ToolTip=");
strcpy(tooltip, &line[i]);
fgets(line,2000,file);
while (!strstr(line,"</tooltip>\r\n")) {
strcat(tooltip,line);
fgets(line,2000,file);
}
// the line that has the </tooltip>
strncat(tooltip,line, strlen(line) - strlen("</tooltip>\r\n"));
}
else if (!strncmp(line, "Icon=", strlen("Icon="))) {
i = (int)strlen("Icon=");
sscanf(&line[i], "%d", &icon);
}
else if (!strncmp(line, "UseTimer=", strlen("UseTimer="))) {
i = (int)strlen("UseTimer=");
sscanf(&line[i], "%d", &usetimer);
}
else if (!strncmp(line, "Timer=" ,strlen("Timer="))) {
i = (int)strlen("Timer=");
sscanf(&line[i], "%d", &timer);
}
else if (!strncmp(line, "Minutes=", strlen("Minutes="))) {
i = (int)strlen("Minutes=");
sscanf(&line[i], "%d", &minutes);
}
else if (contactDone && !strcmp(line,"[/Non-IM Contact]\r\n")) {
if (!name) continue;
char *msg = (char*)malloc(strlen(name) + strlen("Do you want to import this Non-IM Contact?\r\n\r\nName: \r\n") + 1);
wsprintfA(msg, "Do you want to import this Non-IM Contact?\r\n\r\nName: %s\r\n", name);
if (program) {
msg = (char*)realloc(msg, strlen(msg) + strlen(program) +strlen("Program: \r\n") +1);
strcat(msg, "Program: ");
strcat(msg,program);
strcat(msg,"\r\n");
}
if (programparam) {
msg = (char*)realloc(msg, strlen(msg) + strlen(programparam) +strlen("Program Parameters: \r\n") +1);
strcat(msg, "Program Parameters: ");
strcat(msg,programparam);
strcat(msg,"\r\n");
}
if (tooltip) {
msg = (char*)realloc(msg, strlen(msg) + strlen(tooltip) +strlen("ToolTip: \r\n") +1);
strcat(msg, "ToolTip: ");
strcat(msg,tooltip);
strcat(msg,"\r\n");
}
if (group) {
msg = (char*)realloc(msg, strlen(msg) + strlen(group) +strlen("Group: \r\n") +1);
strcat(msg, "Group: ");
strcat(msg,group);
strcat(msg,"\r\n");
}
if (icon) {
char tmp[64];
if (icon == ID_STATUS_ONLINE)
wsprintfA(tmp, "Icon: Online\r\n");
else if (icon == ID_STATUS_AWAY)
wsprintfA(tmp, "Icon: Away\r\n");
else if (icon == ID_STATUS_NA)
wsprintfA(tmp, "Icon: NA\r\n");
else if (icon == ID_STATUS_DND)
wsprintfA(tmp, "Icon: DND\r\n");
else if (icon == ID_STATUS_OCCUPIED)
wsprintfA(tmp, "Icon: Occupied\r\n");
else if (icon == ID_STATUS_FREECHAT)
wsprintfA(tmp, "Icon: Free For Chat\r\n");
else if (icon == ID_STATUS_INVISIBLE)
wsprintfA(tmp, "Icon: Invisible\r\n");
else if (icon == ID_STATUS_ONTHEPHONE)
wsprintfA(tmp, "Icon: On The Phone\r\n");
else if (icon == ID_STATUS_OUTTOLUNCH)
wsprintfA(tmp, "Icon: Out To Lunch\r\n");
msg = (char*)realloc(msg, strlen(msg) + strlen(tmp) +1);
strcat(msg,tmp);
}
if (usetimer && timer) {
char tmp[64],tmp2[8];
if (minutes)
strcpy(tmp2,"Minutes");
else strcpy(tmp2,"Seconds");
wsprintfA(tmp, "UseTimer: Yes\r\nTimer: %d %s",timer, tmp2);
msg = (char*)realloc(msg, strlen(msg) + strlen(tmp) +1);
strcat(msg,tmp);
}
if (MessageBoxA(0,msg,modFullname,MB_YESNO) == IDYES) {
if (!(hContact =(HANDLE) CallService(MS_DB_CONTACT_ADD, 0, 0))) {
msg("contact did get created","");
continue;
}
CallService(MS_PROTO_ADDTOCONTACT,(WPARAM)hContact,(LPARAM)MODNAME);
CallService(MS_IGNORE_IGNORE, (WPARAM)hContact, IGNOREEVENT_USERONLINE);
db_set_s(hContact, MODNAME, "Nick", Translate("New Non-IM Contact"));
db_set_s(hContact, MODNAME, "Name", name);
db_set_s(hContact, MODNAME, "ProgramString", program);
// copy the ProgramParamString
db_set_s(hContact, MODNAME, "ProgramParamString", programparam);
// copy the group
db_set_s(hContact, "CList", "Group", group);
// copy the ToolTip
db_set_s(hContact, MODNAME, "ToolTip", tooltip);
// timer
db_set_b(hContact, MODNAME, "UseTimer", (BYTE)usetimer);
db_set_b(hContact, MODNAME, "Minutes", (BYTE)minutes);
db_set_w(hContact, MODNAME, "Timer", (WORD)timer);
//icon
db_set_w(hContact, MODNAME, "Icon", (WORD)icon);
replaceAllStrings(hContact);
}
free(msg);
contactDone = 0;
name[0] = '\0';
program[0] = '\0';
programparam[0] = '\0';
group[0] = '\0';
tooltip[0] = '\0';
line[0] = '\0';
icon = 40072;
usetimer = 0;
minutes = 1;
timer = 0;
}
}
fclose(file);
return 1;
}
|