-
Notifications
You must be signed in to change notification settings - Fork 0
/
USMTGUI.au3
415 lines (378 loc) · 15.3 KB
/
USMTGUI.au3
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
#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Version=Beta
#AutoIt3Wrapper_Icon=mig.ico
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Date.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <WinAPIFiles.au3>
Opt("ExpandEnvStrings", 1)
$LastState = 1
Global $StartTime
Global $WaitMessageDots
Global $WaitIncrease = True
Global $FoundSize = False
Global $ProgFile, $ListFiles, $CurrentFile
$Main = GUICreate("User State Migration Toolkit GUI", 500, 430, -1, -1, Default, $WS_EX_ACCEPTFILES)
GUISetBkColor(0xb2ccff, $Main)
GUISetFont(8.5, 400)
GUICtrlCreateLabel("Specify the location to save the backup ( type, browse, or drag path )", 10, 10, 480, 15)
$SavePath = GUICtrlCreateInput("", 10, 30, 445, 20)
GUICtrlSetState($SavePath, $GUI_DROPACCEPTED)
$BrowseSavePath = GUICtrlCreateButton("...", 460, 30, 30, 20)
GUICtrlCreateLabel("Customer Last Name or Business Name", 10, 80, 200, 15)
$Name = GUICtrlCreateInput("", 10, 100, 200, 20)
GUICtrlCreateLabel("Repair Number", 220, 80, 130, 15)
$Number = GUICtrlCreateInput("", 220, 100, 130, 20)
GUICtrlCreateLabel("Tech's Initials", 360, 80, 130, 15)
$Tech = GUICtrlCreateInput("", 360, 100, 130, 20)
$OfflineCheckbox = GUICtrlCreateCheckbox("Specify a path for offline recovery if not backing up this computer", 10, 200, 480, 15)
$Message1 = GUICtrlCreateLabel("( IE X:\Windows, X:\Winnt, etc )", 25, 215, 300, 15)
$OfflinePath = GUICtrlCreateInput("", 10, 235, 445, 20)
$Message2 = GUICtrlCreateLabel("( type, browse, or drag path )", 25, 260, 300, 15)
GUICtrlSetState($OfflinePath, $GUI_HIDE)
GUICtrlSetState($Message1, $GUI_HIDE)
GUICtrlSetState($Message2, $GUI_HIDE)
GUICtrlSetState($OfflinePath, $GUI_DROPACCEPTED)
$BrowseOfflinePath = GUICtrlCreateButton("...", 460, 235, 30, 20)
$Go = GUICtrlCreateButton("GO", 200, 310, 100, 50)
GUICtrlSetFont($Go, 20, 400)
$Cancel = GUICtrlCreateCheckbox("Cancel", 175, 310, 140, 50)
GUICtrlSetState($Cancel, $GUI_HIDE)
GUICtrlSetFont($Cancel, 20, 400)
$ShowTime = GUICtrlCreateLabel("", 390, 310, 100, 15, $SS_RIGHT)
$ShowSize = GUICtrlCreateLabel("", 390, 330, 100, 15, $SS_RIGHT)
$ProgressBar = GUICtrlCreateProgress(10, 380, 370, 20)
GUICtrlSetState($ProgressBar, $GUI_HIDE)
$ProgressText = GUICtrlCreateLabel("", 390, 383, 100, 15, $SS_RIGHT)
$ShowWaitMessage = GUICtrlCreateLabel("Please wait, setting up", 174, 380, 110, 15)
GUICtrlSetState($ShowWaitMessage, $GUI_HIDE)
$ShowWaitMessageDots = GUICtrlCreateLabel($WaitMessageDots, 284, 380, 200, 15)
GUICtrlSetState($ShowWaitMessageDots, $GUI_HIDE)
$ShowCurrentFile = GUICtrlCreateLabel("", 10, 405, 480, 15, $DT_END_ELLIPSIS)
GUISetState(@SW_SHOW, $Main)
Local $AccelKeys[1][2] = [["{ENTER}", $Go]]
GUISetAccelerators($AccelKeys)
Do
$MSG = GUIGetMsg()
If $MSG == $GUI_EVENT_CLOSE Then Exit
If $MSG == $BrowseSavePath Then
$Where = FileSelectFolder("Choose the location to save the data", "", 1 + 4)
GUICtrlSetData($SavePath, $Where)
EndIf
If $MSG == $BrowseOfflinePath Then
$Where = FileSelectFolder("Choose the WINDOWS location of the drive to save data", "")
GUICtrlSetData($OfflinePath, $Where)
EndIf
If $MSG == $Go Then
$GetName = StringUpper(StringReplace(GUICtrlRead($Name), "-", "_"))
$GetNumber = StringUpper(StringReplace(GUICtrlRead($Number), "-", "_"))
$GetTech = StringUpper(StringReplace(GUICtrlRead($Tech), "-", "_"))
$GetSavePath = GUICtrlRead($SavePath)
$GetOfflinePath = GUICtrlRead($OfflinePath)
$GetWorkOffline = GUICtrlRead($OfflineCheckbox)
If $GetWorkOffline == 1 Then
$WorkingOffline = True
Else
$WorkingOffline = False
EndIf
If $GetName == "" Then
MsgBox(16, "ERROR", "You have not specified a customer/business name, please do so now.")
Else
If $GetNumber == "" Then
MsgBox(16, "ERROR", "You have not specified a repair number, please do so now.")
Else
If $GetTech == "" Then
MsgBox(16, "ERROR", "You have not specified the technician, please do so now.")
Else
If $GetSavePath == "" Then
MsgBox(16, "ERROR", "You have not specified a path to save the data, please do so now.")
Else
If $WorkingOffline == True And $GetOfflinePath == "" Then
MsgBox(16, "ERROR", "You have specified that you are backing up an offline drive but have not specified an offline path, please do so now.")
Else
If $WorkingOffline == True And $GetOfflinePath <> "" And Not FileExists($GetOfflinePath & "\system32\config\software") Then
MsgBox(16, "ERROR", "The offline path you have specified does not appear to be a valid Windows installation folder. Please check the path.")
Else
$Date = _NowCalcDate()
$DateBreak = StringSplit($Date, "/")
$FullSavePath = StringUpper(StringReplace($GetSavePath & "\" & $GetName & "-" & $GetNumber & "-" & $GetTech & "-" & $DateBreak[2] & $DateBreak[3] & StringRight($DateBreak[1], 2), "\\", "\"))
If StringLeft($FullSavePath, 1) == "\" Then $FullSavePath = "\" & $FullSavePath
$Exist = FileExists($FullSavePath)
Local $YesOrNo
If $Exist Then $YesOrNo = MsgBox(4, "Overwrite?", "The save path specified already exists:" & @CR & $FullSavePath & @CR & @CR & "Overwrite?")
If $YesOrNo == 6 Or Not $Exist Then
$TempFile = _TempFile($FullSavePath)
$TestTempFile = FileOpen($TempFile, 1 + 8)
FileClose($TestTempFile)
FileDelete($TempFile)
If $TestTempFile == -1 Then
MsgBox(16, "ERROR", "The path you have specified does not exist or is not writable. Please check the path.")
Else
$StartTime = TimerInit()
GUICtrlDelete($Go)
GUICtrlSetState($Cancel, $GUI_SHOW)
GUICtrlSetState($SavePath, $GUI_DISABLE)
GUICtrlSetState($BrowseSavePath, $GUI_DISABLE)
GUICtrlSetState($Name, $GUI_DISABLE)
GUICtrlSetState($Number, $GUI_DISABLE)
GUICtrlSetState($Tech, $GUI_DISABLE)
GUICtrlSetState($OfflineCheckbox, $GUI_DISABLE)
GUICtrlSetState($OfflinePath, $GUI_DISABLE)
GUICtrlSetState($BrowseOfflinePath, $GUI_DISABLE)
AdlibRegister("_PlayWithWaitMessage", 100)
_RunStreams($FullSavePath, $WorkingOffline, $GetOfflinePath)
_BuildUSMTCommand($FullSavePath, $WorkingOffline, $GetOfflinePath)
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
EndIf
If $LastState == 4 And GUICtrlRead($OfflineCheckbox) == 1 Then
GUICtrlSetState($OfflinePath, $GUI_SHOW)
GUICtrlSetState($Message1, $GUI_SHOW)
GUICtrlSetState($Message2, $GUI_SHOW)
GUICtrlSetState($BrowseOfflinePath, $GUI_SHOW)
EndIf
If $LastState == 1 And GUICtrlRead($OfflineCheckbox) == 4 Then
GUICtrlSetState($OfflinePath, $GUI_HIDE)
GUICtrlSetState($Message1, $GUI_HIDE)
GUICtrlSetState($Message2, $GUI_HIDE)
GUICtrlSetState($BrowseOfflinePath, $GUI_HIDE)
EndIf
$LastState = GUICtrlRead($OfflineCheckbox)
Until True == False
Func _BuildUSMTCommand($sFullSavePath, $sWorkingOffline, $sOfflinePath)
GUICtrlSetData($ShowCurrentFile, "Extracting USMT archives")
GUICtrlSetState($ShowWaitMessage, $GUI_SHOW)
GUICtrlSetState($ShowWaitMessageDots, $GUI_SHOW)
$ListFiles = @ScriptDir & "\listfiles.txt"
$ProgFile = @ScriptDir & "\prog.txt"
$LogFile = '"' & $sFullSavePath & '\log.txt"'
FileDelete($ListFiles)
FileDelete($ProgFile)
FileDelete($LogFile)
If @OSArch == "X86" Then
$path = @ScriptDir & "\x86"
Else
$path = @ScriptDir & "\amd64"
EndIf
$Arguments = '"' & $sFullSavePath & '"' & ' /o /localonly /nocompress /auto /c /vsc /l:' & $LogFile & ' /progress:"' & $ProgFile & '" /listfiles:"' & $ListFiles & '"'
If $sWorkingOffline == True Then $Arguments &= ' /offlinewindir:' & $sOfflinePath
GUICtrlSetData($ShowCurrentFile, "Looking for data")
ShellExecuteWait($path & "\scanstate.exe", $Arguments, $sFullSavePath, "open", @SW_HIDE)
ShellExecute("notepad.exe", $LogFile, @ScriptDir, "open", @SW_MAXIMIZE)
Sleep(5000)
Send("^{END}")
MsgBox(64, "Done", "USMT has finished. Please review the end of the log and confirm that the backup finished with no errors.")
Exit
EndFunc ;==>_BuildUSMTCommand
Func _PlayWithWaitMessage()
If GUICtrlRead($Cancel) == 1 Then
$YesOrNo = MsgBox(4, "Quit?", "Do you really want to quit?")
If $YesOrNo == 6 Then
Do
Sleep(10)
ProcessClose("scanstate.exe")
Until Not ProcessExists("scanstate.exe")
Exit
EndIf
GUICtrlSetState($Cancel, $GUI_UNCHECKED)
EndIf
GUICtrlSetData($ShowTime, _NiceTime(TimerDiff($StartTime) / 1000))
If $WaitIncrease == True Then
$WaitMessageDots &= "."
Else
$WaitMessageDots = StringTrimRight($WaitMessageDots, 1)
EndIf
GUICtrlSetData($ShowWaitMessageDots, $WaitMessageDots)
If StringLen($WaitMessageDots) < 1 Then $WaitIncrease = True
If StringLen($WaitMessageDots) > 30 Then $WaitIncrease = False
If $FoundSize == False Then
$OpenProg = FileOpen($ProgFile, 0)
Do
$Line = FileReadLine($OpenProg)
If @error Then ExitLoop
If StringInStr($Line, "totalPercentageCompleted") Then
FileClose($OpenProg)
AdlibUnRegister("_PlayWithWaitMessage")
AdlibRegister("_Progress", 500)
FileClose($OpenProg)
$OpenProg = FileOpen($ProgFile, 0)
Do
$Line = FileReadLine($OpenProg)
If @error Then ExitLoop
If StringInStr($Line, "totalSizeInMBToTransfer") Then
$Break = StringSplit($Line, ",")
GUICtrlSetData($ShowSize, _ByteSuffix($Break[5]))
GUICtrlDelete($ShowWaitMessage)
GUICtrlDelete($ShowWaitMessageDots)
GUICtrlSetState($ProgressBar, $GUI_SHOW)
$FoundSize = True
$StartTime = TimerInit()
FileClose($OpenProg)
EndIf
Until True == False
EndIf
Until True == False
FileClose($OpenProg)
EndIf
EndFunc ;==>_PlayWithWaitMessage
Func _Progress()
If GUICtrlRead($Cancel) == 1 Then
$YesOrNo = MsgBox(4, "Quit?", "Do you really want to quit?")
If $YesOrNo == 6 Then
Do
Sleep(10)
ProcessClose("scanstate.exe")
Until Not ProcessExists("scanstate.exe")
Do
Sleep(10)
If @OSArch == "X86" Then
ProcessClose("streams.exe")
Else
ProcessClose("streams64.exe")
EndIf
Until Not ProcessExists("streams.exe") And Not ProcessExists("streams64.exe")
Exit
EndIf
GUICtrlSetState($Cancel, $GUI_UNCHECKED)
EndIf
GUICtrlSetData($ShowTime, _NiceTime(TimerDiff($StartTime) / 1000))
$OpenProg = FileOpen($ProgFile, 0)
$Line = FileReadLine($OpenProg, -1)
FileClose($OpenProg)
$BreakProg = StringSplit($Line, ", ", 1)
If $BreakProg[1] > 4 Then
If $BreakProg[5] == "Saving" Then
GUICtrlSetData($ProgressBar, 100)
GUICtrlSetData($ProgressText, "100%")
GUICtrlDelete($Cancel)
AdlibUnRegister()
Else
GUICtrlSetData($ProgressBar, $BreakProg[5])
GUICtrlSetData($ProgressText, $BreakProg[5] & "%")
EndIf
EndIf
$LastFile = $CurrentFile
$Count = _FileCountLines($ListFiles)
$OpenList = FileOpen($ListFiles, 0)
$CurrentFile = FileReadLine($OpenList, $Count)
FileClose($OpenList)
If $LastFile <> $CurrentFile Then GUICtrlSetData($ShowCurrentFile, StringTrimLeft($CurrentFile, 3))
EndFunc ;==>_Progress
Func _NiceTime($iSecs)
Return StringFormat('%02i:%02i:%02i', Floor($iSecs / 3600), Floor(Mod($iSecs, 3600) / 60), Mod($iSecs, 60))
EndFunc ;==>_NiceTime
Func _ByteSuffix($Bytes)
Local $BytesSuffix[4] = [" MB", " GB", " TB", " PB"]
$x = 0
While $Bytes > 1023
$x += 1
$Bytes /= 1024
WEnd
Return StringFormat('%.2f', $Bytes) & $BytesSuffix[$x]
EndFunc ;==>_ByteSuffix
Func _RunStreams($rsFullSavePath, $rsWorkingOffline, $rsGetOfflinePath)
If $rsWorkingOffline == True Then
$rsDrive = StringLeft($rsGetOfflinePath, 1)
Else
$rsDrive = StringLeft(@WindowsDir, 1)
EndIf
$rsExclusions = StringSplit("application data|local settings|userdata|appdata", "|")
$rsDocsFolder = $rsDrive & ":\documents and settings"
For $a = 1 To 2
$GetUserDirs = FileFindFirstFile($rsDocsFolder & "\*.*")
Do
$User = FileFindNextFile($GetUserDirs)
If @error Then ExitLoop
If StringInStr(FileGetAttrib($rsDocsFolder & "\" & $User), "D") Then
GUICtrlSetData($ShowCurrentFile, 'Setting files in ' & $rsDocsFolder & '\' & $User & ' to "unblocked"')
If @OSArch == "X86" Then
ShellExecuteWait(@ScriptDir & "\streams.exe", "-d " & $rsDocsFolder & "\" & $User, @ScriptDir, "open", @SW_HIDE)
Else
ShellExecuteWait(@ScriptDir & "\streams64.exe", "-d " & $rsDocsFolder & "\" & $User, @ScriptDir, "open", @SW_HIDE)
EndIf
$GetDocDirs = FileFindFirstFile($rsDocsFolder & "\" & $User & "\*.*")
Do
$FoundFolders = FileFindNextFile($GetDocDirs)
If @error Then ExitLoop
If StringInStr(FileGetAttrib($rsDocsFolder & "\" & $User & "\" & $FoundFolders), "D") Then
$CanRunStream = True
For $b = 1 To $rsExclusions[0]
If StringLower($FoundFolders) == $rsExclusions[$b] Then $CanRunStream = False
Next
If $CanRunStream == True Then
GUICtrlSetData($ShowCurrentFile, 'Setting files in ' & $rsDocsFolder & '\' & $User & '\' & $FoundFolders & ' to "unblocked"')
If @OSArch == "X86" Then
ShellExecuteWait(@ScriptDir & "\streams.exe", "-s -d " & $rsDocsFolder & "\" & $User & "\" & $FoundFolders, @ScriptDir, "open", @SW_HIDE)
Else
ShellExecuteWait(@ScriptDir & "\streams64.exe", "-s -d " & $rsDocsFolder & "\" & $User & "\" & $FoundFolders, @ScriptDir, "open", @SW_HIDE)
EndIf
EndIf
EndIf
Until True == False
EndIf
Until True == False
$rsDocsFolder = $rsDrive & ":\users"
Next
EndFunc ;==>_RunStreams
#cs
Func _DeleteStreams($rsFullSavePath, $rsWorkingOffline, $rsGetOfflinePath)
If $rsWorkingOffline == True Then
$rsDrive = StringLeft($rsGetOfflinePath, 1)
Else
$rsDrive = StringLeft(@WindowsDir, 1)
EndIf
$rsExclusions = StringSplit("application data|local settings|userdata|appdata", "|")
$rsDocsFolder = $rsDrive & ":\documents and settings"
For $a = 1 To 2
$GetUserDirs = FileFindFirstFile($rsDocsFolder & "\*.*")
Do
$User = FileFindNextFile($GetUserDirs)
If @error Then ExitLoop
If StringInStr(FileGetAttrib($rsDocsFolder & "\" & $User), "D") Then
GUICtrlSetData($ShowCurrentFile, 'Setting files in ' & $rsDocsFolder & '\' & $User & ' to "unblocked"')
_DelStream($rsDocsFolder & "\" & $User)
$GetDocDirs = FileFindFirstFile($rsDocsFolder & "\" & $User & "\*.*")
Do
$FoundFolders = FileFindNextFile($GetDocDirs)
If @error Then ExitLoop
If StringInStr(FileGetAttrib($rsDocsFolder & "\" & $User & "\" & $FoundFolders), "D") Then
$CanRunStream = True
For $b = 1 To $rsExclusions[0]
If StringLower($FoundFolders) == $rsExclusions[$b] Then $CanRunStream = False
Next
If $CanRunStream == True Then
GUICtrlSetData($ShowCurrentFile, 'Setting files in ' & $rsDocsFolder & '\' & $User & '\' & $FoundFolders & ' to "unblocked"')
_DelStream($rsDocsFolder & "\" & $User & "\" & $FoundFolders)
EndIf
EndIf
Until True == False
EndIf
Until True == False
$rsDocsFolder = $rsDrive & ":\users"
Next
EndFunc ;==>_DeleteStreams
Func _DelStream($folpath)
$files = _FileListToArrayRec($folpath, "*", $FLTAR_FILES, $FLTAR_RECUR)
For $b = 1 To $files[0] Step 1
If FileExists($folpath & "\" & $files[$b] & ":Zone.Identifier") Then
_WinAPI_DeleteFile($folpath & "\" & $files[$b] & ":Zone.Identifier:$DATA")
Else
ContinueLoop
EndIf
Next
EndFunc ;==>_DelStream
#ce