diff --git a/U3H_appStart.ahk b/U3H_appStart.ahk index 3d15154..5bdbb51 100644 --- a/U3H_appStart.ahk +++ b/U3H_appStart.ahk @@ -30,6 +30,14 @@ IfNotExist %U3_APP_DATA_PATH%\%LSn%\%LADn% } SetWorkingDir %U3_HOST_EXEC_PATH% + +Loop %runsta0% +{ + CurCmd := runsta%A_Index% + CurCmd := EnvParseStr(CurCmd) + RunWait %CurCmd% +} + cmdl := AppExe Loop %0% { diff --git a/U3H_appStop.ahk b/U3H_appStop.ahk index 7a62482..9d0453b 100644 --- a/U3H_appStop.ahk +++ b/U3H_appStop.ahk @@ -1,7 +1,7 @@ ASOnExit: StepsAll = 1 -If (StrLen(RunBeforeStop) > 0) +If runstp0 > 0 StepsAll++ StepsStep := 100/StepsAll StepsPos = 0 @@ -9,13 +9,15 @@ StepsPos = 0 Progress b2 x%PL% y%PT% w%PW% m FM%PFM% FS%PFS%, U3Helper %U3HVer% - (c)2006-2007 Markus Birth , Stopping %AppName% ..., AHKProgress-%AppName% WinSet Transparent, %PTrans%, AHKProgress-%AppName% -If (StrLen(RunBeforeStop) > 0) +Loop %runstp0% { - Progress % StepsPos*StepsStep, Running stop command ... - RunBeforeStop := EnvParseStr(RunBeforeStop) - RunWait %RunBeforeStop% - StepsPos++ + CurCmd := runstp%A_Index% + Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/runstp0, Running stop command ... %CurCmd% + CurCmd := EnvParseStr(CurCmd) + RunWait %CurCmd% } +If runstp0 > 0 + StepsPos++ SplitPath AppExe, AppFile, null, null, null, null diff --git a/U3H_hostCleanUp.ahk b/U3H_hostCleanUp.ahk index 3160ba6..388413c 100644 --- a/U3H_hostCleanUp.ahk +++ b/U3H_hostCleanUp.ahk @@ -5,7 +5,7 @@ ; ########################################################################## StepsAll = 0 -If (StrLen(RunBeforeEject) > 0) +If runeje0 > 0 StepsAll++ If regsvr0 > 0 StepsAll++ @@ -27,13 +27,15 @@ StepsPos = 0 Progress b2 x%PL% y%PT% w%PW% m FM%PFM% FS%PFS%, U3Helper %U3HVer% - (c)2006-2007 Markus Birth , Cleaning up %AppName% ..., AHKProgress-%AppName% WinSet Transparent, %PTrans%, AHKProgress-%AppName% -If (StrLen(RunBeforeEject) > 0) +Loop %runeje0% { - Progress % StepsPos*StepsStep, Running shutdown command ... - RunBeforeEject := EnvParseStr(RunBeforeEject) - RunWait %RunBeforeEject% - StepsPos++ + CurCmd := runeje%A_Index% + Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/runeje0, Running shutdown command ... %CurCmd% + CurCmd := EnvParseStr(CurCmd) + RunWait %CurCmd% } +If runeje0 > 0 + StepsPos++ If (U3_IS_DEVICE_AVAILABLE <> "true") { @@ -100,7 +102,6 @@ Else Skipped = 0 Errors = 0 Dirs = 0 - CopyErrors := "" FileGetAttrib FAttr, %CurMask% IfInString FAttr, D @@ -119,13 +120,13 @@ Else IfInString FAttr, D { ; also create empty directories - Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Creating directory %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / ERR:%Errors%) + Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Creating directory %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / SKP:%Skipped% / ERR:%Errors%) FileCreateDir %TargFile% Dirs++ } Else { - Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Copying data %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / ERR:%Errors%) + Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Copying data %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / SKP:%Skipped% / ERR:%Errors%) FileCopyNewer(CurFile, TargFile) If ErrorLevel = 2 { @@ -217,16 +218,23 @@ Else ;Translate paths in text files SetWorkingDir %U3_APP_DATA_PATH% + TransErrors := "" Loop %dattxt0% { - Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/dattxt0, Translating paths in file %CurFile% ... + OutIndex = %A_Index% CurMask := dattxt%A_Index% - Loop %CurMask% + + FileCount = 0 + Loop %CurMask%, 0, 0 + { + FileCount++ + } + Loop %CurMask%, 0, 0 { CurFile := A_LoopFileFullPath TmpFile := A_LoopFileDir . "\$$$" . A_LoopFileName FileMove %U3_APP_DATA_PATH%\%CurFile%, %U3_APP_DATA_PATH%\%TmpFile%, 1 - Progress % StepsPos*StepsStep+StepsStep*(A_Index-0.5)/dattxt0, Translating paths in file %CurFile% ... + Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/dattxt0, Translating paths in file %CurFile% ... Loop Read, %U3_APP_DATA_PATH%\%TmpFile%, %U3_APP_DATA_PATH%\%CurFile% { IfNotInString A_LoopReadLine, \ @@ -244,12 +252,15 @@ Else Else { FileMove %U3_APP_DATA_PATH%\%TmpFile%, %U3_APP_DATA_PATH%\%CurFile% - MsgBox 4112, Error while translating, The datafile %CurFile% could not be translated. The original state has been restored (hopefully). + TransErrors .= "File: " . CurFile . " (Error while translating)`n" } } } SetWorkingDir %A_ScriptDir% + If (TransErrors <> "") + MsgBox 4112, Error while translating, Following files could not be translated:`n`n%TransErrors%`n`nThe original state has been restored (hopefully). + If dattxt0 > 0 StepsPos++ } @@ -309,6 +320,11 @@ If (KeepSettings = "0" or Unattended = "1") CurBranch := regdel%A_Index% SplitFirst(RegRoot, RegSub, CurBranch, "\") RegDelete %RegRoot%, %RegSub% + If ErrorLevel + { + SplitLast(RegSub, RegKey, RegSub, "\") + RegDelete %RegRoot%, %RegSub%, %RegKey% + } } If regdel0 > 0 diff --git a/U3H_hostConfigure.ahk b/U3H_hostConfigure.ahk index 257b31f..e808beb 100644 --- a/U3H_hostConfigure.ahk +++ b/U3H_hostConfigure.ahk @@ -7,6 +7,8 @@ StepsAll = 0 IfNotExist %U3_HOST_EXEC_PATH%\%A_ScriptName% StepsAll++ +If runcon0 > 0 + StepsAll++ If regsvr0 > 0 StepsAll++ If dattxt0 > 0 @@ -23,16 +25,25 @@ StepsPos = 0 Progress b2 x%PL% y%PT% w%PW% m FM%PFM% FS%PFS%, U3Helper %U3HVer% - (c)2006-2007 Markus Birth , Preparing %AppName% ..., AHKProgress-%AppName% WinSet Transparent, %PTrans%, AHKProgress-%AppName% -; made following step not to display b/c it occurs only once on the first launch of any U3H-app IfNotExist %U3_HOST_EXEC_PATH%\%A_ScriptName% { Progress % StepsPos*StepsStep, Copying U3Helper to disk... - FileCopy %A_ScriptFullPath%, %U3_HOST_EXEC_PATH%\%A_ScriptName%, 0 - StepsPos++ + FileCopy %A_ScriptFullPath%, %U3_HOST_EXEC_PATH%\%A_ScriptName%, 0 + StepsPos++ } ;****************************************************************************** +Loop %runcon0% +{ + CurCmd := runcon%A_Index% + Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/runcon0, Running config command ... %CurCmd% + CurCmd := EnvParseStr(CurCmd) + RunWait %CurCmd% +} +If runcon0 > 0 + StepsPos++ + Progress % StepsPos*StepsStep, Checking registry settings... keycount = 0 ;Registry stuff @@ -112,16 +123,23 @@ If (ForeignSettings = "0") ;Translate paths in text files SetWorkingDir %U3_APP_DATA_PATH% +TransErrors := "" Loop %dattxt0% { - Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/dattxt0, Translating paths in file %CurFile% ... + OutIndex = %A_Index% CurMask := dattxt%A_Index% - Loop %CurMask% + + FileCount = 0 + Loop %CurMask%, 0, 0 + { + FileCount++ + } + Loop %CurMask%, 0, 0 { CurFile := A_LoopFileFullPath TmpFile := A_LoopFileDir . "\$$$" . A_LoopFileName FileMove %U3_APP_DATA_PATH%\%CurFile%, %U3_APP_DATA_PATH%\%TmpFile%, 1 - Progress % StepsPos*StepsStep+StepsStep*(A_Index-0.5)/dattxt0, Translating paths in file %CurFile% ... + Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/dattxt0, Translating paths in file %CurFile% ... Loop Read, %U3_APP_DATA_PATH%\%TmpFile%, %U3_APP_DATA_PATH%\%CurFile% { IfNotInString A_LoopReadLine, `% @@ -140,12 +158,15 @@ Loop %dattxt0% Else { FileMove %U3_APP_DATA_PATH%\%TmpFile%, %U3_APP_DATA_PATH%\%CurFile% - MsgBox 4112, Error while translating, The datafile %CurFile% could not be translated. The original state has been restored (hopefully). + TransErrors .= "File: " . CurFile . " (Error while translating)`n" } } } SetWorkingDir %A_ScriptDir% +If (TransErrors <> "") + MsgBox 4112, Error while translating, Following files could not be translated:`n`n%TransErrors%`n`nThe original state has been restored (hopefully). + If dattxt0 > 0 StepsPos++ diff --git a/U3Helper.ahk b/U3Helper.ahk index 762a736..259902b 100644 --- a/U3Helper.ahk +++ b/U3Helper.ahk @@ -20,15 +20,30 @@ If (StrLen(U3_HOST_EXEC_PATH) > 0) IniRead AppName, %INIFile%, U3Helper, AppName, unknown IniRead AppExe, %INIFile%, U3Helper, AppExe, cmd.exe IniRead Unattended, %INIFile%, U3Helper, Unattended, 0 -IniRead RunBeforeStop, %INIFile%, U3Helper, RunBeforeStop, %A_Space% -IniRead RunBeforeEject, %INIFile%, U3Helper, RunBeforeEject, %A_Space% +IniGetKeys("runcon", INIFile, "RunBeforeConfig") +IniGetKeys("runsta", INIFile, "RunBeforeStart") +IniGetKeys("runstp", INIFile, "RunBeforeStop") +IniGetKeys("runeje", INIFile, "RunBeforeEject") IniGetKeys("regsvr", INIFile, "regsvr32") IniGetKeys("datexe", INIFile, "DataToExecDir") IniGetKeys("dattxt", INIFile, "ParseFiles") -IniGetKeys("dattxt", INIFile, "ParseIniFiles") ; backward compatibility IniGetKeys("regbak", INIFile, "RegBackup") IniGetKeys("regdel", INIFile, "RegDelete") IniGetKeys("fildel", INIFile, "FileDelete") +; backward compatibility: +IniGetKeys("dattxt", INIFile, "ParseIniFiles") ; backward compatibility +IniRead RunBeforeStop, %INIFile%, U3Helper, RunBeforeStop, %A_Space% +IniRead RunBeforeEject, %INIFile%, U3Helper, RunBeforeEject, %A_Space% +If (StrLen(RunBeforeStop) > 0) +{ + runstp0++ + runstp%runstp0% := RunBeforeStop +} +If (StrLen(RunBeforeEject) > 0) +{ + runeje0++ + runeje%runeje0% := RunBeforeEject +} ;****************************************************************************** ;** Get Taskbar position diff --git a/U3Helperex.ini b/U3Helperex.ini index 58d2a63..0eb7f95 100644 --- a/U3Helperex.ini +++ b/U3Helperex.ini @@ -2,16 +2,19 @@ AppName=PC OnPoint AppExe=PConPoint.exe -; enter commandlines to run before stopping the application and before -; ejecting the device. All variables mentioned under [FileDelete] work. -RunBeforeStop= -RunBeforeEject= - ; set Unattended to 1 to suppress settings-related questions ; this way, previously existing settings on the host always get ; replaced by the U3's settings and restored on eject Unattended=0 +; enter commandlines to run before hostConfigure, appStart (if used via +; U3Helper), stopping the application and before ejecting the device. All +; variables mentioned under [FileDelete] work. One command per line. +[RunBeforeConfig] +[RunBeforeStart] +[RunBeforeStop] +[RunBeforeEject] + [RegBackup] ; enter registry branches to be backed up (+deleted) on eject ; and restored on first run diff --git a/mb_EnvTools.ahk b/mb_EnvTools.ahk index 4b6ead7..c9f8ce2 100644 --- a/mb_EnvTools.ahk +++ b/mb_EnvTools.ahk @@ -45,7 +45,7 @@ EnvSort() { CurNam := EnvVarsx%A_Index% CurVal := EnvValsx%A_Index% - If ((StrLen(CurVal) > MaxLen) and (StrLen(CurNam) > 1)) + If ((StrLen(CurVal) > MaxLen) and (StrLen(CurNam) > 0)) { MaxLen := StrLen(CurVal) MaxIndex := A_Index @@ -140,6 +140,8 @@ EnvUnparseStr(instring) { ReplFrom := EnvVals%A_Index% ReplTo := "%" . EnvVars%A_Index% . "%" + If (StrLen(ReplFrom) < 2) + Continue StringReplace instring, instring, %ReplFrom%, %ReplTo%, A } return instring