Archived
1
0

+ added mb_EnvTools.ahk for everything with environment variables

* implemented ProgressBar on appStop
* use appStop routine in appStart-onExit
+ added RunBeforeStop
+ added RunBeforeEject
* handled all EnvVar-replacements through mb_EnvTools.ahk
This commit is contained in:
mbirth 2007-04-12 18:42:34 +00:00
parent fd4a62a706
commit 7d0cd4700f
9 changed files with 233 additions and 107 deletions

View File

@ -1,6 +1,6 @@
EnvSet USERPROFILE, %U3_APP_DATA_PATH%
EnvSet HOMEPATH, %U3_APP_DATA_PATH%
EnvSet APPDATA, %U3_APP_DATA_PATH%\Application Data
EnvSet USERPROFILE, % EnvValue("U3_APP_DATA_PATH")
EnvSet HOMEPATH, % EnvValue("U3_APP_DATA_PATH")
EnvSet APPDATA, % EnvValue("U3_APP_DATA_PATH") . "\Application Data"
; add custom PATH directories
EnvGet ePATH, PATH
@ -8,24 +8,13 @@ IniGetKeys("envdir", INIFile, "EnvPath")
Loop %envdir0%
{
CurPath := envdir%A_Index%
StringReplace CurPath, CurPath, % "%ALLUSERSPROFILE%", %eALLUSERSPROFILE%, A
StringReplace CurPath, CurPath, % "%APPDATA%", %eAPPDATA%, A
StringReplace CurPath, CurPath, % "%CommonProgramFiles%", %eCommonProgramFiles%, A
StringReplace CurPath, CurPath, % "%HOMEPATH%", %eHOMEPATH%, A
StringReplace CurPath, CurPath, % "%ProgramFiles%", %eProgramFiles%, A
StringReplace CurPath, CurPath, % "%SystemRoot%", %eSystemRoot%, A
StringReplace CurPath, CurPath, % "%USERPROFILE%", %eUSERPROFILE%, A
StringReplace CurPath, CurPath, % "%WINDIR%", %ewindir%, A
StringReplace CurPath, CurPath, % "%TEMP%", %eTEMP%, A
StringReplace CurPath, CurPath, % "%U3_APP_DATA_PATH%", %U3_APP_DATA_PATH%, A
StringReplace CurPath, CurPath, % "%U3_DEVICE_DOCUMENT_PATH%", %U3_DEVICE_DOCUMENT_PATH%, A
StringReplace CurPath, CurPath, % "%U3_DEVICE_EXEC_PATH%", %U3_DEVICE_EXEC_PATH%, A
StringReplace CurPath, CurPath, % "%U3_HOST_EXEC_PATH%", %U3_HOST_EXEC_PATH%, A
CurPath := EnvParseStr(CurPath)
ePATH := CurPath . ";" . ePATH
}
EnvSet PATH, %ePATH%
EnvGet APPDATA, APPDATA
IfNotExist %APPDATA%
{
FileCreateDir %APPDATA%
@ -41,27 +30,3 @@ Loop %0%
}
OnExit ASOnExit
RunWait %cmdl%
Goto ASCloseDone
ASOnExit:
Counter = 0
ToolTip Closing %AppName% ...
SplitPath AppExe, AppFile, null, null, null, null
ASTryClose:
Process Exist, %AppFile%
If ErrorLevel
ProgPID = %ErrorLevel%
Else
ExitApp
WinClose ahk_pid %ProgPID%, , 0.5
If Counter >= 10
Process Close, %ProgPID%
Counter += 1
Sleep 200
Goto ASTryClose
ASCloseDone:
Tooltip

View File

@ -1,10 +1,29 @@
Counter = 0
ASOnExit:
ToolTip Closing %AppName% ...
StepsAll = 1
If (StrLen(RunBeforeStop) > 0)
StepsAll++
StepsStep := 100/StepsAll
StepsPos = 0
Progress b2 x%PL% y%PT% w%PW% m FM%PFM% FS%PFS%, U3Helper %U3HVer% - (c)2006-2007 Markus Birth <mbirth@webwriters.de>, Cleaning up %AppName% ..., AHKProgress-%AppName%
WinSet Transparent, %PTrans%, AHKProgress-%AppName%
If (StrLen(RunBeforeStop) > 0)
{
Progress % StepsPos*StepsStep, Running stop command ...
RunBeforeStop := EnvParseStr(RunBeforeStop)
RunWait %RunBeforeStop%
StepsPos++
}
SplitPath AppExe, AppFile, null, null, null, null
Counter = 0
CounterMax = 10
TryClose:
Progress % StepsPos*StepsStep+StepsStep*Counter/CounterMax, Stopping %AppName% ...
Process Exist, %AppFile%
If ErrorLevel
ProgPID = %ErrorLevel%
@ -12,10 +31,13 @@ Else
Goto CloseDone
WinClose ahk_pid %ProgPID%, , 0.5
If Counter >= 10
If Counter >= %CounterMax%
{
Progress 100, Killing %AppName% ...
Process Close, %ProgPID%
}
Counter += 1
Goto TryClose
CloseDone:
ToolTip
Progress 100, appStop done.

View File

@ -5,6 +5,8 @@
; ##########################################################################
StepsAll = 0
If (StrLen(RunBeforeEject) > 0)
StepsAll++
If regsvr0 > 0
StepsAll++
If datexe0 > 0
@ -23,6 +25,14 @@ StepsPos = 0
Progress b2 x%PL% y%PT% w%PW% m FM%PFM% FS%PFS%, U3Helper %U3HVer% - (c)2006-2007 Markus Birth <mbirth@webwriters.de>, Cleaning up %AppName% ..., AHKProgress-%AppName%
WinSet Transparent, %PTrans%, AHKProgress-%AppName%
If (StrLen(RunBeforeEject) > 0)
{
Progress % StepsPos*StepsStep, Running shutdown command ...
RunBeforeEject := EnvParseStr(RunBeforeEject)
RunWait %RunBeforeEject%
StepsPos++
}
If (U3_IS_DEVICE_AVAILABLE <> "true")
{
; U3 stick not plugged in!!
@ -57,17 +67,7 @@ Else
If (A_LoopRegType = "REG_SZ" or A_LoopRegType = "REG_EXPAND_SZ" or A_LoopRegType = "REG_MULTI_SZ")
{
RegRead RegValue
StringReplace NewRegValue, RegValue, %U3_HOST_EXEC_PATH%, % "%U3_HOST_EXEC_PATH%", A
StringReplace NewRegValue, NewRegValue, %U3_APP_DATA_PATH%, % "%U3_APP_DATA_PATH%", A
StringReplace NewRegValue, NewRegValue, %U3_DEVICE_EXEC_PATH%, % "%U3_DEVICE_EXEC_PATH%", A
StringReplace NewRegValue, NewRegValue, %U3_DEVICE_DOCUMENT_PATH%, % "%U3_DEVICE_DOCUMENT_PATH%", A
StringReplace NewRegValue, NewRegValue, %eTEMP%, % "%TEMP%", A
StringReplace NewRegValue, NewRegValue, %eSystemRoot%, % "%SystemRoot%", A
StringReplace NewRegValue, NewRegValue, %eAPPDATA%, % "%APPDATA%", A
StringReplace NewRegValue, NewRegValue, %eUSERPROFILE%, % "%USERPROFILE%", A
StringReplace NewRegValue, NewRegValue, %eALLUSERSPROFILE%, % "%ALLUSERSPROFILE%", A
StringReplace NewRegValue, NewRegValue, %eCommonProgramFiles%, % "%CommonProgramFiles%", A
StringReplace NewRegValue, NewRegValue, %eProgramFiles%, % "%ProgramFiles%", A
NewRegValue := EnvUnparseStr(RegValue)
If (NewRegValue <> RegValue)
{
RegWrite %NewRegValue%
@ -224,18 +224,7 @@ If (KeepSettings = "0" or Unattended = "1")
Loop %fildel0%
{
CurFile := fildel%A_Index%
StringReplace CurFile, CurFile, % "%ALLUSERSPROFILE%", %eALLUSERSPROFILE%, A
StringReplace CurFile, CurFile, % "%APPDATA%", %eAPPDATA%, A
StringReplace CurFile, CurFile, % "%CommonProgramFiles%", %eCommonProgramFiles%, A
StringReplace CurFile, CurFile, % "%HOMEPATH%", %eHOMEPATH%, A
StringReplace CurFile, CurFile, % "%ProgramFiles%", %eProgramFiles%, A
StringReplace CurFile, CurFile, % "%SystemRoot%", %eSystemRoot%, A
StringReplace CurFile, CurFile, % "%USERPROFILE%", %eUSERPROFILE%, A
StringReplace CurFile, CurFile, % "%WINDIR%", %ewindir%, A
StringReplace CurFile, CurFile, % "%TEMP%", %eTEMP%, A
StringReplace CurFile, CurFile, % "%U3_APP_DATA_PATH%", %U3_APP_DATA_PATH%, A
StringReplace CurFile, CurFile, % "%U3_DEVICE_DOCUMENT_PATH%", %U3_DEVICE_DOCUMENT_PATH%, A
StringReplace CurFile, CurFile, % "%U3_DEVICE_EXEC_PATH%", %U3_DEVICE_EXEC_PATH%, A
CurFile := EnvParseStr(CurFile)
FileGetAttrib FilAttr, %CurFile%
IfInString FilAttr, D
{

View File

@ -82,18 +82,7 @@ If (ForeignSettings = "0")
If (A_LoopRegType = "REG_SZ" or A_LoopRegType = "REG_EXPAND_SZ" or A_LoopRegType = "REG_MULTI_SZ")
{
RegRead RegValue
StringReplace NewRegValue, RegValue, % "%U3_HOST_EXEC_PATH%", %U3_HOST_EXEC_PATH%, A
StringReplace NewRegValue, NewRegValue, % "%U3_APP_DATA_PATH%", %U3_APP_DATA_PATH%, A
StringReplace NewRegValue, NewRegValue, % "%U3_DEVICE_EXEC_PATH%", %U3_DEVICE_EXEC_PATH%, A
StringReplace NewRegValue, NewRegValue, % "%U3_DEVICE_DOCUMENT_PATH%", %U3_DEVICE_DOCUMENT_PATH%, A
StringReplace NewRegValue, NewRegValue, % "%TEMP%", %eTEMP%, A
StringReplace NewRegValue, NewRegValue, % "%SystemRoot%", %eSystemRoot%, A
StringReplace NewRegValue, NewRegValue, % "%WINDIR%", %ewindir%, A
StringReplace NewRegValue, NewRegValue, % "%APPDATA%", %eAPPDATA%, A
StringReplace NewRegValue, NewRegValue, % "%USERPROFILE%", %eUSERPROFILE%, A
StringReplace NewRegValue, NewRegValue, % "%ALLUSERSPROFILE%", %eALLUSERSPROFILE%, A
StringReplace NewRegValue, NewRegValue, % "%CommonProgramFiles%", %eCommonProgramFiles%, A
StringReplace NewRegValue, NewRegValue, % "%ProgramFiles%", %eProgramFiles%, A
NewRegValue := EnvParseStr(RegValue)
If (NewRegValue <> RegValue)
{
RegWrite %NewRegValue%

View File

@ -1,45 +1,27 @@
#NoTrayIcon
#NoEnv
#Include mb_EnvTools.ahk
#Include mb_IniTools.ahk
#Include mb_TextTools.ahk
U3HVer = 1.6
EnvGet U3_DEVICE_SERIAL, U3_DEVICE_SERIAL ; serial number of device (copy protection)
EnvGet U3_DEVICE_PATH, U3_DEVICE_PATH ; drive letter to device (F:)
EnvGet U3_DEVICE_DOCUMENT_PATH, U3_DEVICE_DOCUMENT_PATH ; path to documents (F:\Documents)
EnvGet U3_DEVICE_VENDOR, U3_DEVICE_VENDOR ; vendor
EnvGet U3_DEVICE_PRODUCT, U3_DEVICE_PRODUCT ; product name string
EnvGet U3_DEVICE_VENDOR_ID, U3_DEVICE_VENDOR_ID ; vendor id (decimal!! 2284 = 0x08ec)
EnvGet U3_APP_DATA_PATH, U3_APP_DATA_PATH ; data path for app (on device)
EnvGet U3_HOST_EXEC_PATH, U3_HOST_EXEC_PATH ; path to exe on host
EnvGet U3_DEVICE_EXEC_PATH, U3_DEVICE_EXEC_PATH ; path to needed files on device
EnvGet U3_ENV_VERSION, U3_ENV_VERSION ; should be 1.0
EnvGet U3_ENV_LANGUAGE, U3_ENV_LANGUAGE ; language id of LaunchPad
EnvGet U3_IS_UPGRADE, U3_IS_UPGRADE ; can be "false" or "true"
EnvGet U3_IS_DEVICE_AVAILABLE, U3_IS_DEVICE_AVAILABLE ; "true"/"false"
EnvGet U3_IS_AUTORUN, U3_IS_AUTORUN ; is this an autorun-launch? "true"/"false"
EnvGet U3_DAPI_CONNECT_STRING, U3_DAPI_CONNECT_STRING ; who needs this?
EnvGet eALLUSERSPROFILE, ALLUSERSPROFILE ; C:\Documents and Settings\All Users
EnvGet eAPPDATA, APPDATA ; C:\Doc...\<username>\Application Data
EnvGet eCommonProgramFiles, CommonProgramFiles ; C:\Program Files\Common Files
EnvGet eHOMEPATH, HOMEPATH ; C:\Documents and Settings\<username>
EnvGet eProgramFiles, ProgramFiles ; C:\Program Files
EnvGet eSystemRoot, SystemRoot ; C:\WINDOWS
EnvGet eUSERPROFILE, USERPROFILE ; C:\Documents and Settings\<username>
EnvGet eTEMP, TEMP ; C:\DOCUME~1\<username8.3>\LOCALS~1\Temp
EnvGet ewindir, windir ; C:\WINDOWS
U3HVer = 1.7
SplitPath A_ScriptFullPath, null, ScrDir, null, ScrFile, ScrDrive
INIFile = %ScrDir%\%ScrFile%.ini
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("regsvr", INIFile, "regsvr32")
IniGetKeys("datexe", INIFile, "DataToExecDir")
IniGetKeys("regbak", INIFile, "RegBackup")
IniGetKeys("regdel", INIFile, "RegDelete")
IniGetKeys("fildel", INIFile, "FileDelete")
U3_APP_DATA_PATH := EnvValue("U3_APP_DATA_PATH")
U3_HOST_EXEC_PATH := EnvValue("U3_HOST_EXEC_PATH")
U3_DEVICE_EXEC_PATH := EnvValue("U3_DEVICE_EXEC_PATH")
WinGetPos,Tx,Ty,Tw,Th,ahk_class Shell_TrayWnd,,,
; Tw>Th: horizontal taskbar (top or bottom)
; Tw<Th: vertical taskbar (left or right)
@ -121,5 +103,6 @@ Else If 1 = appstop
}
Else
{
MsgBox No parameter given.
MsgBox 48, U3Helper %U3HVer%, No parameter given.`n`nSee http://www.autohotkey.com/forum/topic11839.html for info.`n`n(c)2006-2007 Markus Birth <mbirth@webwriters.de>
MsgBox 64, U3Helper %U3HVer% - Debug info, % EnvList(), 30
}

View File

@ -1,6 +1,12 @@
[U3Helper]
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

121
mb_EnvTools.ahk Normal file
View File

@ -0,0 +1,121 @@
#NoEnv
EnvVars0 = 0
EnvVals0 = 0
; initial list of EnvVars to load
EnvVarsAll := "U3_DEVICE_SERIAL,U3_DEVICE_PATH,U3_DEVICE_DOCUMENT_PATH,U3_DEVICE_VENDOR,U3_DEVICE_PRODUCT,U3_DEVICE_VENDOR_ID"
EnvVarsAll .= ",U3_APP_DATA_PATH,U3_HOST_EXEC_PATH,U3_DEVICE_EXEC_PATH,U3_ENV_VERSION,U3_ENV_LANGUAGE,U3_IS_UPGRADE"
EnvVarsAll .= ",U3_IS_DEVICE_AVAILABLE,U3_IS_AUTORUN,U3_DAPI_CONNECT_STRING"
EnvVarsAll .= ",ALLUSERSPROFILE,APPDATA,CommonProgramFiles,HOMEPATH,ProgramFiles,SystemRoot,USERPROFILE,TEMP,windir"
StringSplit EnvVarsx, EnvVarsAll, `,%A_Space%
; Load EnvVar-Values and store in EnvVals-array
Loop %EnvVarsx0%
{
EnvName := EnvVarsx%A_Index%
EnvGet EnvValsx%A_Index%, %EnvName%
}
EnvValsx0 = %EnvVarsx0%
; Sort EnvVar-Values by StrLen() for re-replacement (value to var)
; and clean out empty vars
CurIndex = 1
Loop %EnvVarsx0%
{
MaxIndex = -1
MaxLen = -1
Loop %EnvValsx0%
{
CurNam := EnvVarsx%A_Index%
CurVal := EnvValsx%A_Index%
If ((StrLen(CurVal) >= MaxLen) and (StrLen(CurNam) > 0))
{
MaxLen := StrLen(CurVal)
MaxIndex := A_Index
}
}
If (StrLen(EnvValsx%MaxIndex%) > 0)
{
EnvVars%CurIndex% := EnvVarsx%MaxIndex%
EnvVals%CurIndex% := EnvValsx%MaxIndex%
CurIndex++
}
EnvVarsx%MaxIndex% := ""
EnvValsx%MaxIndex% := ""
}
EnvVars0 := CurIndex-1
EnvVals0 := CurIndex-1
; Debugging stuff:
;MsgBox % "comspec:" . EnvValue("comspec")
;MsgBox % EnvList()
;MsgBox % EnvParseStr("This is a %temp% test running %comspec%!")
EnvList()
{
global
local result
result := ""
Loop %EnvVars0%
{
result .= EnvVars%A_Index% . " = " . EnvVals%A_Index% . "`n"
}
return result
}
EnvValue(envname)
{
global
local result
result := ""
Loop %EnvVars0%
{
If (EnvVars%A_Index% = envname)
{
return EnvVals%A_Index%
}
}
; EnvVar not in list - try to catch it
EnvGet result, %envname%
If (StrLen(result) > 0)
{
; seems like a result ~~> add to list
MyPointer := ++EnvVars0
EnvVars%MyPointer% := envname
EnvVals%MyPointer% := result
EnvVals0++
}
return result
}
EnvParseStr(instring)
{
global
local ReplFrom, ReplTo
Loop %EnvVars0%
{
ReplFrom := "%" . EnvVars%A_Index% . "%"
ReplTo := EnvVals%A_Index%
StringReplace instring, instring, %ReplFrom%, %ReplTo%, A
}
return instring
}
EnvUnparseStr(instring)
{
global
local ReplFrom, ReplTo
Loop %EnvVals0%
{
ReplFrom := EnvVals%A_Index%
ReplTo := "%" . EnvVars%A_Index% . "%"
StringReplace instring, instring, %ReplFrom%, %ReplTo%, A
}
return instring
}

24
mb_EnvTools.txt Normal file
View File

@ -0,0 +1,24 @@
EnvAdd("U3_DEVICE_SERIAL") ; serial number of device (copy protection)
EnvAdd("U3_DEVICE_PATH") ; drive letter to device (F:)
EnvAdd("U3_DEVICE_DOCUMENT_PATH") ; path to documents (F:\Documents)
EnvAdd("U3_DEVICE_VENDOR") ; vendor
EnvAdd("U3_DEVICE_PRODUCT") ; product name string
EnvAdd("U3_DEVICE_VENDOR_ID") ; vendor id (decimal!! 2284 = 0x08ec)
EnvAdd("U3_APP_DATA_PATH") ; data path for app (on device)
EnvAdd("U3_HOST_EXEC_PATH") ; path to exe on host
EnvAdd("U3_DEVICE_EXEC_PATH") ; path to needed files on device
EnvAdd("U3_ENV_VERSION") ; should be 1.0
EnvAdd("U3_ENV_LANGUAGE") ; language id of LaunchPad
EnvAdd("U3_IS_UPGRADE") ; can be "false" or "true"
EnvAdd("U3_IS_DEVICE_AVAILABLE") ; "true"/"false"
EnvAdd("U3_IS_AUTORUN") ; is this an autorun-launch? "true"/"false"
EnvAdd("U3_DAPI_CONNECT_STRING") ; who needs this?
EnvAdd("ALLUSERSPROFILE") ; C:\Documents and Settings\All Users
EnvAdd("APPDATA") ; C:\Doc...\<username>\Application Data
EnvAdd("CommonProgramFiles") ; C:\Program Files\Common Files
EnvAdd("HOMEPATH") ; C:\Documents and Settings\<username>
EnvAdd("ProgramFiles") ; C:\Program Files
EnvAdd("SystemRoot") ; C:\WINDOWS
EnvAdd("USERPROFILE") ; C:\Documents and Settings\<username>
EnvAdd("TEMP") ; C:\DOCUME~1\<username8.3>\LOCALS~1\Temp
EnvAdd("windir") ; C:\WINDOWS

27
readme.txt Normal file
View File

@ -0,0 +1,27 @@
U3Helper
(c)2006-2007 by Markus Birth <mbirth@webwriters.de>
Some words for the manifest.u3i:
If your app doesn't store anything inside %USERPROFILE% or such, then just call it directly
inside the <appStart> - such as:
<appStart workingdir="%U3_APP_DATA_PATH%" cmd="%U3_HOST_EXEC_PATH%\WebMon.exe">-prefs "%U3_APP_DATA_PATH%\WebMon.ini" -pages "%U3_APP_DATA_PATH%\pages\WebPages.dat"</appStart>
BUT: If you app DOES store some stuff inside %USERPROFILE% (mostly noticeable if there appears something under
C:\Documents and Settings\<Username>\Application Data\<somewhat>\<something>), call it as follows:
<appStart workingdir="%U3_APP_DATA_PATH%" cmd="%U3_HOST_EXEC_PATH%\U3Helper.exe">appstart</appStart>
This way, the environment variables %USERPROFILE% and a bunch of other related will be set to point to the
data directory on the U3-stick and therefore those app will store its data there instead of on the host system.
Take a look at the U3Helperex.ini as there are all supported settings mentioned. You'll get the idea of the expected
format.
U3Helper Forum: http://vanilla.birth-online.de/3/
U3Helper English info: http://www.autohotkey.com/forum/topic11839.html
U3Helper German info: http://blog.birth-online.de/archives/164-Programme-U3-faehig-machen.html