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
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
|
/*++
Module Name:
config.c
Abstract:
This module contains the functions that save the configuration files
into the repair directory, and copy these files to the Emergency
Repair disk.
Author:
Jaime Sasson
Environment:
Windows
--*/
#include "precomp.h"
#pragma hdrstop
#define SYSTEM_HIVE (LPWSTR)L"system"
#define SOFTWARE_HIVE (LPWSTR)L"software"
#define SECURITY_HIVE (LPWSTR)L"security"
#define SAM_HIVE (LPWSTR)L"sam"
#define DEFAULT_USER_HIVE (LPWSTR)L".default"
#define DEFAULT_USER_HIVE_FILE (LPWSTR)L"default"
#define NTUSER_HIVE_FILE (LPWSTR)L"ntuser.dat"
#define REPAIR_DIRECTORY (LPWSTR)L"\\repair"
#define PROFILES_DIRECTORY (LPWSTR)L"\\profiles"
#define SETUP_LOG_FILE (LPWSTR)L"setup.log"
#define SYSTEM_COMPRESSED_FILE_NAME ( LPWSTR )L"system._"
#define SOFTWARE_COMPRESSED_FILE_NAME ( LPWSTR )L"software._"
#define SOFTWARE_COMPRESSED_FILE_NAME ( LPWSTR )L"software._"
#define SECURITY_COMPRESSED_FILE_NAME ( LPWSTR )L"security._"
#define SAM_COMPRESSED_FILE_NAME ( LPWSTR )L"sam._"
#define DEFAULT_COMPRESSED_FILE_NAME ( LPWSTR )L"default._"
#define NTUSER_COMPRESSED_FILE_NAME ( LPWSTR )L"ntuser.da_"
#define AUTOEXEC_NT_FILE_NAME ( LPWSTR )L"autoexec.nt"
#define CONFIG_NT_FILE_NAME ( LPWSTR )L"config.nt"
//
// Relative costs to perform various actions,
// to help make the gas gauge mean something.
//
#define COST_SAVE_HIVE 3
#define COST_COMPRESS_HIVE 20
#define COST_SAVE_VDM_FILE 1
typedef enum _OPERATION_TYPE {
SaveConfiguration,
CopyConfigurationFiles,
} OPERATION_TYPE;
typedef struct _PROGRESS_PARAMETERS {
OPERATION_TYPE OperationType;
WCHAR DriveLetter;
} PROGRESS_PARAMETERS, *PPROGRESS_PARAMETERS;
typedef struct _THREAD_ARGUMENTS {
HWND hWnd;
WCHAR DriveLetter;
} THREAD_ARGUMENTS, *PTHREAD_ARGUMENTS;
//
// Structure used in the array of hives to be saved.
// This structure contains the predefined key that contains the hive
// to be saved, and the name of the hive root, and the name of the file
// where the hive should be saved.
//
typedef struct _HIVE_INFO {
HKEY PredefinedKey;
PWSTR HiveName;
PWSTR FileName;
} HIVE_INFO, *PHIVE_INFO;
FCenterDialogOnDesktop(HWND);
BOOL
NotifyCB(
IN PSTR src,
IN PSTR dst,
IN WORD code
)
{
UNREFERENCED_PARAMETER(src);
UNREFERENCED_PARAMETER(dst);
UNREFERENCED_PARAMETER(code);
return(TRUE);
}
DWORD
SaveOneHive(
IN LPWSTR DirectoryName,
IN LPWSTR HiveName,
IN HKEY hkey,
IN HWND hWnd,
IN OUT PDWORD GaugePosition,
IN DWORD GaugeDeltaUnit
)
/*++
Routine Description:
Save one registry hive. The way we will do this is to do a RegSaveKey
of the hive into a temporary localtion, and then call the LZ apis to
compress the file from that temporary location to the floppy.
LZ must have already been initialized via InitGloablBuffersEx()
BEFORE calling this routine.
Arguments:
DirectoryName - Full path of the directory where the hive will be saved.
HiveName - base name of the hive file to save. The file will end up
compressed on disk with the name <HiveName>._.
hkey - supplies handle to open key of root of hive to save.
GaugePosition - in input, supplies current position of the gas gauge.
On output, supplies new position of gas gauge.
GaugeDeltaUnit - supplies cost of one unit of activity.
Return Value:
DWORD - Return ERROR_SUCCESS if the hive was saved. Otherwise, it returns
an error code.
--*/
{
DWORD Status;
WCHAR SaveFilename[ MAX_PATH + 1 ];
WCHAR CompressPath[ MAX_PATH + 1 ];
CHAR SaveFilenameAnsi[ MAX_PATH + 1 ];
CHAR CompressPathAnsi[ MAX_PATH + 1 ];
LPWSTR TempName = ( LPWSTR )L"\\$$hive$$.tmp";
//
// Create the name of the file into which we will save the
// uncompressed hive.
//
wsprintf(SaveFilename,L"%ls\\$$hive$$.tmp",DirectoryName);
wsprintfA(SaveFilenameAnsi,"%ls\\$$hive$$.tmp",DirectoryName);
//
// Delete the file just in case, because RegSaveKey will fail if the file
// already exists.
//
SetFileAttributes(SaveFilename,FILE_ATTRIBUTE_NORMAL);
DeleteFile(SaveFilename);
//
// Save the registry hive into the temporary file.
//
Status = RegSaveKey(hkey,SaveFilename,NULL);
//
// Update the gas gauge.
//
*GaugePosition += GaugeDeltaUnit * COST_SAVE_HIVE;
SendDlgItemMessage( hWnd,
ID_BAR,
PBM_SETPOS,
*GaugePosition,
0L
);
//
// If the hive was saved successfully, then compress it and update
// the gas gauge. Otherwise, update the gas gauge and return.
//
if(Status == ERROR_SUCCESS) {
//
// Form the name of the file into which the saved hive file is
// to be compressed.
//
wsprintf(CompressPath,L"%ls\\%ls._",DirectoryName,HiveName);
wsprintfA(CompressPathAnsi,"%ls\\%ls._",DirectoryName,HiveName );
//
// Delete the destination file just in case.
//
SetFileAttributes(CompressPath,FILE_ATTRIBUTE_NORMAL);
DeleteFile(CompressPath);
//
// Compress the hive into the destination file.
//
Status = DiamondCompressFile(
SaveFilenameAnsi,
CompressPathAnsi,
*GaugePosition,
GaugeDeltaUnit * COST_COMPRESS_HIVE,
hWnd
);
//
// Delete the temporary saved hive.
//
SetFileAttributes(SaveFilename,FILE_ATTRIBUTE_NORMAL);
DeleteFile(SaveFilename);
}
*GaugePosition += GaugeDeltaUnit * COST_COMPRESS_HIVE;
SendDlgItemMessage( hWnd,
ID_BAR,
PBM_SETPOS,
*GaugePosition,
0L
);
return(Status);
}
VOID
SaveConfigurationWorker(
IN PTHREAD_ARGUMENTS Arguments
)
/*++
Routine Description:
This routine implements the thread that saves all system configuration
files into the repair directory. It first saves and compresses the
registry hives, and then it save the VDM configuration files (autoexec.nt
and config.nt).
If the application is running in the SilentMode (invoked by setup),
then system, software, default, security and sam hives will be saved
and compressed.
If the application was invoked by the user, then only system, software
and default will be saved.
This thread will send messages to the gas gauge dialog prcedure, so that
the gas gauge gets updated after each configuration file is saved.
This thread will also inform the user about errors that might have
occurred during the process of saving the configuration files.
Arguments:
Arguments - Pointer to a structure that contains the parameters to be passed to
thread.
Return Value:
None.
However, the this routine will send a message to the dialog procedure
that created the thread, informing the outcome the operation.
--*/
{
DWORD i;
HKEY hkey;
BOOL ErrorOccurred;
CHAR SourceUserHivePathAnsi[ MAX_PATH + 1 ];
CHAR CompressedUserHivePathAnsi[ MAX_PATH + 1 ];
WCHAR ProfilesDirectory[ MAX_PATH + 1 ];
WCHAR RepairDirectory[ MAX_PATH + 1 ];
WCHAR SystemDirectory[ MAX_PATH + 1 ];
WCHAR Source[ MAX_PATH + 1 ];
WCHAR Target[ MAX_PATH + 1 ];
DWORD GaugeDeltaUnit;
DWORD GaugePosition;
DWORD NumberOfHivesToSave;
DWORD NumberOfUserHivesToSave;
DWORD NumberOfVdmFiles;
HWND hWnd;
DWORD Error;
DWORD Status;
HANDLE Token;
BOOL b;
TOKEN_PRIVILEGES NewPrivileges;
LUID Luid;
//
// The array below contains the location and name of all hives that
// we need to save. When the utility is operating on the silent mode,
// (invoked from setup), then all hives will be saved. Otherwise, only
// system and software will be saved.
// For this reason, do not change the order of the hives in the array
// below. System and software must be the first elements of
// the array.
//
HIVE_INFO HiveList[] = { { HKEY_LOCAL_MACHINE, SYSTEM_HIVE, SYSTEM_HIVE },
{ HKEY_LOCAL_MACHINE, SOFTWARE_HIVE, SOFTWARE_HIVE },
{ HKEY_USERS, DEFAULT_USER_HIVE, DEFAULT_USER_HIVE_FILE },
{ HKEY_LOCAL_MACHINE, SECURITY_HIVE, SECURITY_HIVE },
{ HKEY_LOCAL_MACHINE, SAM_HIVE, SAM_HIVE }
};
PWSTR VdmFiles[] = {
AUTOEXEC_NT_FILE_NAME,
CONFIG_NT_FILE_NAME
};
Error = ERROR_SUCCESS;
hWnd = Arguments->hWnd;
ErrorOccurred = FALSE;
//
// Compute the cost of saving the hives and vdm files.
// For every hive we save, we have to save a key into a file and then
// compress the file. After each of these tasks is completed, we upgrade
// the gas gauge by the amount dicated by the COST_xxx values.
// The cost of saving the hives depends on the mode that the utility is
// running.
// In the silent mode we save system, software, security, sam and default.
// In the non-silent mode, we save system and software only.
//
NumberOfHivesToSave = ( _SilentMode )?
sizeof( HiveList ) / sizeof( HIVE_INFO ) :
(sizeof( HiveList ) / sizeof( HIVE_INFO ))-3;
NumberOfUserHivesToSave = 1;
NumberOfVdmFiles = sizeof( VdmFiles ) / sizeof( PWSTR );
GaugeDeltaUnit = GAUGE_BAR_RANGE / ( (COST_SAVE_HIVE * NumberOfHivesToSave)
+ (COST_COMPRESS_HIVE * NumberOfHivesToSave)
+ (COST_COMPRESS_HIVE * NumberOfUserHivesToSave)
+ (COST_SAVE_VDM_FILE * NumberOfVdmFiles));
GaugePosition = 0;
//
// Enable BACKUP privilege
//
if(OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&Token)) {
if(LookupPrivilegeValue(NULL,SE_BACKUP_NAME,&Luid)) {
NewPrivileges.PrivilegeCount = 1;
NewPrivileges.Privileges[0].Luid = Luid;
NewPrivileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(Token,FALSE,&NewPrivileges,0,NULL,NULL);
}
}
GetWindowsDirectory( RepairDirectory, sizeof( RepairDirectory ) / sizeof( WCHAR ) );
lstrcpy( ProfilesDirectory, RepairDirectory );
lstrcat( RepairDirectory, REPAIR_DIRECTORY );
lstrcat( ProfilesDirectory, PROFILES_DIRECTORY );
GetSystemDirectory( SystemDirectory, sizeof( SystemDirectory ) / sizeof( WCHAR ) );
//
// Make sure that the repair directory already exists.
// If it doesn't exist, then create one.
//
if( CreateDirectory( RepairDirectory, NULL ) ||
( ( Error = GetLastError() ) == ERROR_ALREADY_EXISTS ) ||
( Error == ERROR_ACCESS_DENIED )
) {
//
// If the repair directory didn't exist and we were able to create it,
// or if the repair directory already exists, then save and compress
// the hives.
//
Error = ERROR_SUCCESS;
for( i=0; i < NumberOfHivesToSave; i++ ) {
//
// First open the root of the hive to be saved
//
Status = RegOpenKeyEx( HiveList[i].PredefinedKey,
HiveList[i].HiveName,
REG_OPTION_RESERVED,
READ_CONTROL,
&hkey );
//
// If unable to open the key, update the gas gauge to reflect
// that the operation on this hive was completed.
// Otherwise, save the hive. Note that Save hive will update
// the gas gauge, as it saves and compresses the hive.
//
if(Status != ERROR_SUCCESS) {
//
// If this is the first error while saving the hives,
// then save the error code, so that we can display the
// correct error message to the user.
//
if( Error == ERROR_SUCCESS ) {
Error = Status;
}
//
// Update the gas gauge
//
GaugePosition += GaugeDeltaUnit * (COST_SAVE_HIVE + COST_COMPRESS_HIVE);
SendMessage( hWnd,
AP_UPDATE_GAUGE,
GaugePosition,
0L );
} else {
//
// Save and compress the hive.
// Note that the gas gauge will up be updated by SaveOneHive
// Note also that when we save the default user hive, we skip
// the first character of the
//
Status = SaveOneHive(RepairDirectory,
HiveList[i].FileName,
hkey,
hWnd,
&GaugePosition,
GaugeDeltaUnit );
//
// If this is the first error while saving the hives,
// then save the error code, so that we can display the
// correct error message to the user.
//
if( Error == ERROR_SUCCESS ) {
Error = Status;
}
RegCloseKey(hkey);
}
}
//
// Save the hive for the Default User
//
wsprintfA(SourceUserHivePathAnsi,"%ls\\%ls\\%ls",ProfilesDirectory,L"Default User",NTUSER_HIVE_FILE);
wsprintfA(CompressedUserHivePathAnsi,"%ls\\%ls",RepairDirectory,NTUSER_COMPRESSED_FILE_NAME);
//
// Delete the destination file just in case.
//
SetFileAttributesA(CompressedUserHivePathAnsi,FILE_ATTRIBUTE_NORMAL);
DeleteFileA(CompressedUserHivePathAnsi);
//
// Compress the hive into the destination file.
//
Status = DiamondCompressFile(
SourceUserHivePathAnsi,
CompressedUserHivePathAnsi,
GaugePosition,
GaugeDeltaUnit * COST_COMPRESS_HIVE,
hWnd
);
if( Status != ERROR_SUCCESS ) {
if( Error == ERROR_SUCCESS ) {
Error = Status;
}
}
GaugePosition += GaugeDeltaUnit * COST_COMPRESS_HIVE;
SendDlgItemMessage( hWnd,
ID_BAR,
PBM_SETPOS,
GaugePosition,
0L
);
//
// Now that the hives are saved, save the vdm files
//
for( i = 0; i < NumberOfVdmFiles; i++ ) {
wsprintf(Source,L"%ls\\%ls",SystemDirectory,VdmFiles[i]);
wsprintf(Target,L"%ls\\%ls",RepairDirectory,VdmFiles[i]);
if( !CopyFile( Source, Target, FALSE ) ) {
Status = GetLastError();
if( Error != ERROR_SUCCESS ) {
Error = Status;
}
}
GaugePosition += GaugeDeltaUnit * COST_SAVE_VDM_FILE;
SendMessage( ( HWND )hWnd,
AP_UPDATE_GAUGE,
GaugePosition,
0L );
}
}
//
// At this point, the operation was completed (successfully, or not).
// So update the gas gauge to 100%
//
SendMessage(hWnd,AP_UPDATE_GAUGE,GAUGE_BAR_RANGE,0L);
if( Error != ERROR_SUCCESS && !_SilentMode ) {
DisplayMsgBox(hWnd,
IDS_CANT_SAVE_CONFIGURATION,
MB_OK | MB_ICONEXCLAMATION,
_szApplicationName);
} else {
Sleep( 200 );
}
SendMessage( ( HWND )hWnd,
AP_TASK_COMPLETED,
(WPARAM)(Error == ERROR_SUCCESS),
0L );
ExitThread( 0 );
}
VOID
CopyFilesWorker(
IN PTHREAD_ARGUMENTS Arguments
)
/*++
Routine Description:
This routine implements the thread that copiess all configuration information
from the repair directory to the repair disk.
This thread will send messages to the gas gauge dialog prcedure, so that
the gas gauge gets updated after each configuration file is copied.
This thread will also inform the user about errors that might have
occurred during the process of saving the configuration files.
Arguments:
Arguments - Pointer to a structure that contains the parameters to be passed to
thread.
Return Value:
None.
However, the this routine will send a message to the dialog procedure
that created the thread, informing the outcome the operation.
--*/
{
HWND hWnd;
WCHAR Drive;
WCHAR Buffer[ MAX_PATH + 1 ];
WCHAR Source[ MAX_PATH + 1 ];
WCHAR Target[ MAX_PATH + 1 ];
DWORD i;
DWORD GaugePosition = 0;
BOOLEAN AllFilesCopied = TRUE;
DWORD Error;
LPWSTR FileNames[] = { SETUP_LOG_FILE,
SYSTEM_COMPRESSED_FILE_NAME,
SOFTWARE_COMPRESSED_FILE_NAME,
SECURITY_COMPRESSED_FILE_NAME,
SAM_COMPRESSED_FILE_NAME,
DEFAULT_COMPRESSED_FILE_NAME,
NTUSER_COMPRESSED_FILE_NAME,
AUTOEXEC_NT_FILE_NAME,
CONFIG_NT_FILE_NAME
};
DWORD DeltaCompleted = GAUGE_BAR_RANGE / ( sizeof( FileNames )/sizeof( PWSTR ) );
hWnd = Arguments->hWnd;
Drive = Arguments->DriveLetter;
GetWindowsDirectory( Buffer, sizeof( Buffer ) / sizeof( WCHAR ) );
for( i=0;
i < ( sizeof( FileNames )/sizeof( PWCHAR ) );
i++) {
wsprintf(Source,L"%ls\\repair\\%ls",Buffer,FileNames[i] );
wsprintf(Target,L"%wc:\\%ls",Drive,FileNames[i]);
if( !CopyFile( Source, Target, FALSE ) ) {
AllFilesCopied = FALSE;
Error = GetLastError();
}
GaugePosition += DeltaCompleted;
SendMessage( ( HWND )hWnd,
AP_UPDATE_GAUGE,
GaugePosition,
0L
);
}
SendMessage( ( HWND )hWnd,
AP_UPDATE_GAUGE,
GAUGE_BAR_RANGE,
0L
);
if( !AllFilesCopied && !_SilentMode ) {
DWORD MsgId;
if( Error == ERROR_FILE_NOT_FOUND ) {
MsgId = IDS_FILE_NOT_FOUND;
} else if( Error == ERROR_DISK_FULL ) {
MsgId = IDS_DISK_FULL;
} else {
MsgId = IDS_UNABLE_TO_COPY_ALL_FILES;
}
DisplayMsgBox(hWnd,MsgId,MB_OK | MB_ICONEXCLAMATION,_szApplicationName);
} else {
Sleep( 200 );
}
SendMessage( ( HWND )hWnd,
AP_TASK_COMPLETED,
(WPARAM)AllFilesCopied,
0L
);
ExitThread(0);
}
BOOL
Progress2DlgProc(
IN HWND hdlg,
IN UINT Msg,
IN WPARAM wParam,
IN LONG lParam
)
/*++
Routine Description:
Dialog procedure for the dialog that contains the gas gauge that is
displayed while the utility is saving the system configuration, and
while it is copying the configuration information to the repair disk.
Arguments:
Standard Windows' Proc parameters.
Return Value:
long - Returns 0 if the message was handled.
--*/
{
static THREAD_ARGUMENTS ThreadArguments;
switch(Msg) {
case WM_INITDIALOG:
{
WCHAR Buffer[MAX_PATH];
LPTHREAD_START_ROUTINE StartAddress;
DWORD ThreadId;
PPROGRESS_PARAMETERS Parameters;
Parameters = ( PPROGRESS_PARAMETERS )lParam;
//
// set up range for percentage (0-100) display
//
SendDlgItemMessage(hdlg,ID_BAR,PBM_SETRANGE,0,MAKELPARAM(0,GAUGE_BAR_RANGE));
//
// Set the caption
//
switch( Parameters->OperationType ) {
case SaveConfiguration:
LoadString( _hModule,
IDS_SAVING_CONFIGURATION,Buffer,
sizeof(Buffer)/sizeof(WCHAR) );
StartAddress = ( LPTHREAD_START_ROUTINE )SaveConfigurationWorker;
break;
case CopyConfigurationFiles:
LoadString( _hModule,
IDS_COPYING_FILES,
Buffer,sizeof(Buffer)/sizeof(WCHAR) );
StartAddress = ( LPTHREAD_START_ROUTINE )CopyFilesWorker;
break;
default:
//
// Error condition!!
// Do something here
//
break;
}
SetWindowText( hdlg, Buffer);
//
// center the dialog relative to the desk top
//
FCenterDialogOnDesktop(hdlg);
ThreadArguments.hWnd = hdlg;
ThreadArguments.DriveLetter = Parameters->DriveLetter;
CreateThread( NULL,
1024,
StartAddress,
&ThreadArguments,
0,
&ThreadId );
break;
}
case AP_UPDATE_GAUGE:
SendDlgItemMessage( hdlg,
ID_BAR,
PBM_SETPOS,
wParam,
0L );
break;
case AP_TASK_COMPLETED:
{
BOOLEAN MessagePosted;
SendDlgItemMessage( hdlg,
ID_BAR,
PBM_SETPOS,
GAUGE_BAR_RANGE,
0L );
MessagePosted = FALSE;
while( !MessagePosted ) {
MessagePosted = PostMessage( hdlg,
AP_TERMINATE_DIALOG,
wParam,
0 );
}
break;
}
case AP_TERMINATE_DIALOG:
EndDialog(hdlg, wParam);
break;
default:
return(FALSE);
}
return(TRUE);
}
BOOLEAN
CopyFilesToRepairDisk(
IN WCHAR Drive
)
/*++
Routine Description:
Copy the files in the repair directory, to the emergency repair disk.
Arguments:
Drive - Drive where the repair disk is.
Return Value:
BOOLEAN - Returns TRUE if the operation succeeded, or FALSE otherwise.
--*/
{
PROGRESS_PARAMETERS Parameters;
BOOLEAN Result;
Parameters.OperationType = CopyConfigurationFiles;
Parameters.DriveLetter = Drive;
Result = (BOOLEAN)DialogBoxParam( _hModule,
MAKEINTRESOURCE( IDD_PROGRESS2 ),
_hWndMain,
( DLGPROC )Progress2DlgProc,
( LPARAM )&Parameters
);
return( Result );
}
BOOLEAN
DetectConfigFilesInRepairDirectory(
)
/*++
Routine Description:
Determine whether or not the the repair directory contains at
least one configuration file.
Arguments:
None.
Return Value:
BOOLEAN - Returns TRUE if at least one configuration file is present.
Returns FALSE if no configuration files are present.
--*/
{
HANDLE Handle;
WIN32_FIND_DATA FindData;
WCHAR RepairDirectory[ MAX_PATH + 1];
WCHAR FileName[ MAX_PATH + 1];
DWORD i;
BOOLEAN AtLeastOneFilePresent = FALSE;
LPWSTR ConfigurationFiles[] = { AUTOEXEC_NT_FILE_NAME,
CONFIG_NT_FILE_NAME,
SYSTEM_COMPRESSED_FILE_NAME,
SOFTWARE_COMPRESSED_FILE_NAME,
SECURITY_COMPRESSED_FILE_NAME,
SAM_COMPRESSED_FILE_NAME,
DEFAULT_COMPRESSED_FILE_NAME,
NTUSER_COMPRESSED_FILE_NAME
};
GetWindowsDirectory( RepairDirectory, sizeof( RepairDirectory ) / sizeof( WCHAR ) );
wcscat( RepairDirectory, REPAIR_DIRECTORY );
for( i = 0;
i < sizeof( ConfigurationFiles ) / sizeof( PWSTR );
i++ ) {
wsprintf(FileName,L"%ls\\%ls",RepairDirectory,ConfigurationFiles[i]);
if( ( Handle = FindFirstFile(FileName, &FindData) ) != INVALID_HANDLE_VALUE ) {
AtLeastOneFilePresent = TRUE;
FindClose( Handle );
break;
}
}
return( AtLeastOneFilePresent );
}
BOOLEAN
SaveCurrentConfiguration(
)
/*++
Routine Description:
Save all files that contain the current system configuration, into
the repair directory.
Arguments:
None.
Return Value:
BOOLEAN - Returns TRUE if the operation succeeded, or FALSE otherwise.
--*/
{
PROGRESS_PARAMETERS Parameters;
BOOLEAN Result;
Result = FALSE;
if( _SilentMode ||
!DetectConfigFilesInRepairDirectory() ||
( DisplayMsgBox( _hWndMain,
IDS_CONFIRM_SAVE_CONFIGURATION,
MB_ICONQUESTION | MB_YESNO | MB_DEFBUTTON2 ) == IDYES ) ) {
Parameters.OperationType = SaveConfiguration;
Parameters.DriveLetter = ( WCHAR )'\0';
Result = (BOOLEAN)DialogBoxParam( _hModule,
MAKEINTRESOURCE( IDD_PROGRESS2 ),
_hWndMain,
( DLGPROC )Progress2DlgProc,
( LPARAM )&Parameters
);
}
return( Result );
}
|