summaryrefslogtreecommitdiffstats
path: root/private/nw/convert/nwconv/statbox.c
blob: 70d2b42a8b29a43537573baef9fff5c9f33dac95 (plain) (blame)
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
/*
  +-------------------------------------------------------------------------+
  |           Status Dialog box routines - Used during Conversion           |
  +-------------------------------------------------------------------------+
  |                     (c) Copyright 1993-1994                             |
  |                          Microsoft Corp.                                |
  |                        All rights reserved                              |
  |                                                                         |
  | Program               : [StatBox.c]                                     |
  | Programmer            : Arthur Hanson                                   |
  | Original Program Date : [Feb 08, 1994]                                  |
  | Last Update           : [Feb 08, 1994]                                  |
  |                                                                         |
  | Version:  1.00                                                          |
  |                                                                         |
  | Description:                                                            |
  |                                                                         |
  | History:                                                                |
  |   arth  Feb 08, 1994    1.00    Original Version.                       |
  |                                                                         |
  +-------------------------------------------------------------------------+
*/


#include "globals.h"
#include "convapi.h"

static TCHAR tmpStr[1024];
static TCHAR PanelTitle[80];
static HANDLE hStatus = NULL;
static HANDLE hPanel = NULL;
static BOOL DoCancel = FALSE;

/*+-------------------------------------------------------------------------+
  | Routines for status dialog put up during conversion.                    |
  +-------------------------------------------------------------------------+*/

/*+-------------------------------------------------------------------------+
  | DrainPump()
  +-------------------------------------------------------------------------+*/
void DrainPump() {
   MSG msg;

   while (PeekMessage(&msg, hStatus, 0, 0xfff, PM_REMOVE)) {
       if ((IsDialogMessage(hStatus, &msg) == FALSE) &&
           (IsDialogMessage(hPanel, &msg) == FALSE)) {
           TranslateMessage(&msg);
           DispatchMessage(&msg);
       }
   }

} // DrainPump


/*+-------------------------------------------------------------------------+
  | Status_CurConv()
  +-------------------------------------------------------------------------+*/
// Current server pair being converted
void Status_CurConv(UINT Num) {
   wsprintf(tmpStr, TEXT("%5u"), Num);
   SendDlgItemMessage(hStatus, IDC_S_CUR_CONV, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_CurConv


/*+-------------------------------------------------------------------------+
  | Status_TotConv()
  +-------------------------------------------------------------------------+*/
// Total number of server pairs to convert
void Status_TotConv(UINT Num) {
   wsprintf(tmpStr, TEXT("%5u"), Num);
   SendDlgItemMessage(hStatus, IDC_S_TOT_CONV, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_TotConv


/*+-------------------------------------------------------------------------+
  | Status_SrcServ()
  +-------------------------------------------------------------------------+*/
// Current source server of server pair being converted
void Status_SrcServ(LPTSTR Server) {
   wsprintf(tmpStr, TEXT("%-15s"), Server);
   SendDlgItemMessage(hStatus, IDC_S_SRCSERV, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_SrcServ


/*+-------------------------------------------------------------------------+
  | Status_DestServ()
  +-------------------------------------------------------------------------+*/
// Current destination server of server pair being converted
void Status_DestServ(LPTSTR Server) {
   wsprintf(tmpStr, TEXT("%-15s"), Server);
   SendDlgItemMessage(hStatus, IDC_S_DESTSERV, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_DestServ


/*+-------------------------------------------------------------------------+
  | Status_ConvTxt()
  +-------------------------------------------------------------------------+*/
// Text describing what is being converted (Groups, Users Files)
void Status_ConvTxt(LPTSTR Text) {
   wsprintf(tmpStr, TEXT("%-20s"), Text);
   SendDlgItemMessage(hStatus, IDC_S_CONVTXT, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_ConvTxt


/*+-------------------------------------------------------------------------+
  | Status_CurNum()
  +-------------------------------------------------------------------------+*/
// Current item number being converted (current group # or User # or file #)...
void Status_CurNum(UINT Num) {
   wsprintf(tmpStr, TEXT("%7s"), lToStr(Num));
   SendDlgItemMessage(hStatus, IDC_S_CUR_NUM, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_CurNum


/*+-------------------------------------------------------------------------+
  | Status_CurTot()
  +-------------------------------------------------------------------------+*/
// Total items in set being converted (user, group, files...)
void Status_CurTot(UINT Num) {
   wsprintf(tmpStr, TEXT("%7s"), lToStr(Num));
   SendDlgItemMessage(hStatus, IDC_S_CUR_TOT, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_CurTot


/*+-------------------------------------------------------------------------+
  | Status_ItemLabel()
  +-------------------------------------------------------------------------+*/
// Label for set being converted ("Group:", "User:")
void Status_ItemLabel(LPTSTR Text, ...) {
   va_list marker;

   va_start(marker, Text);

   wvsprintf(tmpStr, Text, marker);
   SendDlgItemMessage(hStatus, IDC_S_ITEMLABEL, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();

   va_end(marker);

} // Status_ItemLabel


/*+-------------------------------------------------------------------------+
  | Status_Item()
  +-------------------------------------------------------------------------+*/
// Name of current thing being converted (actual user or group name)
void Status_Item(LPTSTR Text) {
   wsprintf(tmpStr, TEXT("%-15s"), Text);
   SendDlgItemMessage(hStatus, IDC_S_STATUSITEM, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_Item


/*+-------------------------------------------------------------------------+
  | Status_TotComplete()
  +-------------------------------------------------------------------------+*/
// Total #server pairs converted so far
void Status_TotComplete(UINT Num) {
   wsprintf(tmpStr, TEXT("%7s"), lToStr(Num));
   SendDlgItemMessage(hStatus, IDC_S_TOT_COMP, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_TotComplete


/*+-------------------------------------------------------------------------+
  | Status_TotGroups()
  +-------------------------------------------------------------------------+*/
void Status_TotGroups(UINT Num) {
   wsprintf(tmpStr, TEXT("%7s"), lToStr(Num));
   SendDlgItemMessage(hStatus, IDC_S_TOT_GROUPS, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_TotGroup


/*+-------------------------------------------------------------------------+
  | Status_TotUsers()
  +-------------------------------------------------------------------------+*/
void Status_TotUsers(UINT Num) {
   wsprintf(tmpStr, TEXT("%7s"), lToStr(Num));
   SendDlgItemMessage(hStatus, IDC_S_TOT_USERS, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_TotUsers


/*+-------------------------------------------------------------------------+
  | Status_TotFiles()
  +-------------------------------------------------------------------------+*/
void Status_TotFiles(UINT Num) {
   wsprintf(tmpStr, TEXT("%7s"), lToStr(Num));
   SendDlgItemMessage(hStatus, IDC_S_TOT_FILES, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_TotFiles


/*+-------------------------------------------------------------------------+
  | Status_TotErrors()
  +-------------------------------------------------------------------------+*/
void Status_TotErrors(UINT Num) {
   wsprintf(tmpStr, TEXT("%7s"), lToStr(Num));
   SendDlgItemMessage(hStatus, IDC_S_TOT_ERRORS, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_TotErrors


/*+-------------------------------------------------------------------------+
  | Status_BytesTxt()
  +-------------------------------------------------------------------------+*/
void Status_BytesTxt(LPTSTR Text) {
   wsprintf(tmpStr, TEXT("%-15s"), Text);
   SendDlgItemMessage(hStatus, IDC_PANEL1, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_BytesTxt


/*+-------------------------------------------------------------------------+
  | Status_Bytes()
  +-------------------------------------------------------------------------+*/
void Status_Bytes(LPTSTR Text) {
   wsprintf(tmpStr, TEXT("%s"), Text);
   SendDlgItemMessage(hStatus, IDC_PANEL2, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_Bytes


/*+-------------------------------------------------------------------------+
  | Status_TotBytes()
  +-------------------------------------------------------------------------+*/
void Status_TotBytes(LPTSTR Text) {
   wsprintf(tmpStr, TEXT("%s"), Text);
   SendDlgItemMessage(hStatus, IDC_PANEL3, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_TotBytes


/*+-------------------------------------------------------------------------+
  | Status_BytesSep()
  +-------------------------------------------------------------------------+*/
void Status_BytesSep(LPTSTR Text) {
   wsprintf(tmpStr, TEXT("%s"), Text);
   SendDlgItemMessage(hStatus, IDC_PANEL4, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hStatus, WM_PAINT, 0, 0L);
   DrainPump();
} // Status_BytesSep


/*+-------------------------------------------------------------------------+
  | DlgStatus()
  +-------------------------------------------------------------------------+*/
LRESULT CALLBACK DlgStatus(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
   RECT rc;

   switch (message) {
      case WM_INITDIALOG:
         // Center the dialog over the application window
         CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
         return (TRUE);

      case WM_SETFOCUS:
         GetWindowRect(hDlg, &rc);
         InvalidateRect(hDlg, &rc, FALSE);
         SendMessage(hStatus, WM_PAINT, 0, 0L);
         break;
   }

   return (FALSE); // Didn't process the message

   lParam;
} // DlgStatus



/*+-------------------------------------------------------------------------+
  | DoStatusDlg()
  +-------------------------------------------------------------------------+*/
void DoStatusDlg(HWND hDlg) {
   DLGPROC lpfnDlg;

   lpfnDlg = MakeProcInstance((DLGPROC)DlgStatus, hInst);
   hStatus = CreateDialog(hInst, TEXT("StatusDlg"), hDlg, lpfnDlg) ;
   FreeProcInstance(lpfnDlg);

} // DoStatusDlg


/*+-------------------------------------------------------------------------+
  | StatusDlgKill()
  +-------------------------------------------------------------------------+*/
void StatusDlgKill() {
   DestroyWindow(hStatus);
   hStatus = NULL;

} // StatusDlgKill



/*+-------------------------------------------------------------------------+
  |                 Information (Panel) Dialog Routines                     |
  +-------------------------------------------------------------------------+*/

/*+-------------------------------------------------------------------------+
  | Panel_Line()
  +-------------------------------------------------------------------------+*/
void Panel_Line(int Line, LPTSTR szFormat, ...) {
   va_list marker;

   if (hPanel == NULL)
      return;

   va_start(marker, szFormat);

   wvsprintf(tmpStr, szFormat, marker);
   tmpStr[60] = TEXT('\0');
   SendDlgItemMessage(hPanel, IDC_PANEL1 - 1 + Line, WM_SETTEXT, 0, (LPARAM) tmpStr);
   SendMessage(hPanel, WM_PAINT, 0, 0L);
   DrainPump();

   va_end(marker);

} // Panel_ConvTxt


/*+-------------------------------------------------------------------------+
  | Panel_Cancel()
  +-------------------------------------------------------------------------+*/
BOOL Panel_Cancel() {

   if ((hPanel == NULL) || !DoCancel)
      return FALSE;

   return TRUE;

} // Panel_Cancel


/*+-------------------------------------------------------------------------+
  | DlgPanel()
  +-------------------------------------------------------------------------+*/
LRESULT CALLBACK DlgPanel(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
   int wmId, wmEvent;
   RECT rc;

   switch (message) {
      case WM_INITDIALOG:
         // Center the dialog over the application window
         DoCancel = FALSE;
         CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
         SendMessage(hDlg, WM_SETTEXT, (WPARAM) 0, (LPARAM) PanelTitle);
         return (TRUE);

      case WM_SETFOCUS:
         GetWindowRect(hDlg, &rc);
         InvalidateRect(hDlg, &rc, FALSE);
         SendMessage(hPanel, WM_PAINT, 0, 0L);
         break;

      case WM_COMMAND:
         wmId    = LOWORD(wParam);
         wmEvent = HIWORD(wParam);

         switch (wmId) {
            case IDCANCEL:
               DoCancel = TRUE;
               return (TRUE);

               break;
         }

         break;
   }

   return (FALSE); // Didn't process the message

   lParam;
} // DlgPanel


/*+-------------------------------------------------------------------------+
  | PanelDlg_Do()
  +-------------------------------------------------------------------------+*/
void PanelDlg_Do(HWND hDlg, LPTSTR Title) {
   DLGPROC lpfnDlg;

   lstrcpy(PanelTitle, Title);
   lpfnDlg = MakeProcInstance((DLGPROC)DlgPanel, hInst);
   hPanel = CreateDialog(hInst, TEXT("PanelDLG"), hDlg, lpfnDlg) ;
   FreeProcInstance(lpfnDlg);

} // PanelDlg_Do


/*+-------------------------------------------------------------------------+
  | PanelDlgKill()
  +-------------------------------------------------------------------------+*/
void PanelDlgKill() {

   if (hPanel == NULL)
      return;

   DestroyWindow(hPanel);
   hPanel = NULL;
   DoCancel = FALSE;

} // PanelDlgKill


/*+-------------------------------------------------------------------------+
  |                   Name Error Dialog (User and Group)                    |
  +-------------------------------------------------------------------------+*/

static TCHAR OldName[60];
static TCHAR NewName[60];
static LPTSTR DlgTitle;
static LPTSTR NameErrorProblem;
static ULONG RetType;
static ULONG MaxNameLen;
/*+-------------------------------------------------------------------------+
  | NameErrorDlg()
  |
  +-------------------------------------------------------------------------+*/
LRESULT CALLBACK NameErrorDlg(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
   int wmId, wmEvent;

   switch (message) {
      case WM_INITDIALOG:
         // Center the dialog over the application window
         CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));

         // Init all the display fields
         SendMessage(hDlg, WM_SETTEXT, (WPARAM) 0, (LPARAM) DlgTitle);
         SendMessage(GetDlgItem(hDlg, IDC_OLDNAME), WM_SETTEXT, (WPARAM) 0, (LPARAM) OldName);
         SendMessage(GetDlgItem(hDlg, IDC_NEWNAME), WM_SETTEXT, (WPARAM) 0, (LPARAM) NewName);
         SendMessage(GetDlgItem(hDlg, IDC_PANEL1), WM_SETTEXT, (WPARAM) 0, (LPARAM) NameErrorProblem);

         // limit the name length
         PostMessage(GetDlgItem(hDlg, IDC_NEWNAME), EM_LIMITTEXT, (WPARAM) MaxNameLen, 0);
         return (TRUE);

      case WM_COMMAND:
         wmId    = LOWORD(wParam);
         wmEvent = HIWORD(wParam);

         switch (wmId) {
            case IDABORT:
               // This will cancel the conversion - but need to check with the user
               // if this is what they really want to do
               if (MessageBox(hDlg, Lids(IDS_E_15), Lids(IDS_E_16), MB_YESNO) == IDYES) {
                  RetType = (ULONG) IDABORT;
                  EndDialog(hDlg, 0);
               }

               return (TRUE);
               break;

            case IDRETRY:
               * (WORD *)NewName = (WORD) MaxNameLen + 1;
               SendMessage(GetDlgItem(hDlg, IDC_NEWNAME), EM_GETLINE, 0, (LPARAM) NewName);
               RetType = (ULONG) IDRETRY;
               EndDialog(hDlg, 0);
               return (TRUE);
               break;

            case IDIGNORE:
               RetType = (ULONG) IDCANCEL;
               EndDialog(hDlg, 0);
               return (TRUE);
               break;

         }

         break;
   }

   return (FALSE); // Didn't process the message

   lParam;
} // NameErrorDlg


/*+-------------------------------------------------------------------------+
  | UserNameErrorDlg_Do()
  |
  +-------------------------------------------------------------------------+*/
ULONG UserNameErrorDlg_Do(LPTSTR Title, LPTSTR Problem, USER_BUFFER *User) {
   DLGPROC lpfnDlg;

   lstrcpy(OldName, User->Name);
   lstrcpy(NewName, User->NewName);
   MaxNameLen = MAX_USER_NAME_LEN;

   DlgTitle = Title;
   NameErrorProblem = Problem;
   lpfnDlg = MakeProcInstance((DLGPROC) NameErrorDlg, hInst);
   CursorNormal();
   DialogBox(hInst, TEXT("NameError"), hStatus, lpfnDlg) ;
   CursorHourGlass();
   FreeProcInstance(lpfnDlg);

   if (RetType == IDRETRY) {
      User->err = 0;
      lstrcpy(User->NewName, NewName);

      // if the name is different then flag that it is a new name
      if (lstrcmpi(User->NewName, User->Name))
         User->IsNewName = TRUE;
   }

   return RetType;

} // UserNameErrorDlg_Do


/*+-------------------------------------------------------------------------+
  | GroupNameErrorDlg_Do()
  |
  +-------------------------------------------------------------------------+*/
ULONG GroupNameErrorDlg_Do(LPTSTR Title, LPTSTR Problem, GROUP_BUFFER *Group) {
   DLGPROC lpfnDlg;

   lstrcpy(OldName, Group->Name);
   lstrcpy(NewName, Group->NewName);
   MaxNameLen = MAX_NT_GROUP_NAME_LEN;

   DlgTitle = Title;
   NameErrorProblem = Problem;
   lpfnDlg = MakeProcInstance((DLGPROC) NameErrorDlg, hInst);
   CursorNormal();
   DialogBox(hInst, TEXT("NameError"), hStatus, lpfnDlg) ;
   CursorHourGlass();
   FreeProcInstance(lpfnDlg);

   if (RetType == IDRETRY) {
      Group->err = 0;
      lstrcpy(Group->NewName, NewName);

      // if the name is different then flag that it is a new name
      if (lstrcmpi(Group->NewName, Group->Name))
         Group->IsNewName = TRUE;
   }

   return RetType;

} // GroupNameErrorDlg_Do