Archived
1
0

* rewrote mb_EnvTools.ahk to simplify adding custom variables to replace

+ added local names of "Application Data" and "Local Settings" to replacement list
(Issue: 10)
This commit is contained in:
mbirth 2007-05-02 10:08:14 +00:00
parent 2dc2001284
commit a68c2da4b6
4 changed files with 116 additions and 71 deletions

View File

@ -1,28 +1,3 @@
; get names in local language for "Application Data", "Local Settings" and "Application Data" below "Local Settings"
RegRead AD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, AppData
RegRead LS, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Local Settings
RegRead LAD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Local AppData
If LAD
LAD := AD
StringRight ADc, AD, 1
StringRight LSc, LS, 1
StringRight LADc, LAD, 1
If (ADc = "\")
StringTrimRight AD, AD, 1
If (LSc = "\")
StringTrimRight LS, LS, 1
If (LADc = "\")
StringTrimRight LAD, LAD, 1
SplitLast(null, ADn, AD, "\")
SplitLast(null, LSn, LS, "\")
SplitLast(null, LADn, LAD, "\")
EnvSet USERPROFILE, %U3_APP_DATA_PATH% EnvSet USERPROFILE, %U3_APP_DATA_PATH%
; %HOMEPATH% is without drive letter and colon, do it also here ; %HOMEPATH% is without drive letter and colon, do it also here

View File

@ -342,13 +342,14 @@ If (KeepSettings = "0" or Unattended = "1")
IfInString FilAttr, D IfInString FilAttr, D
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/fildel0, Removing directory #%A_Index% from host ... Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/fildel0, Removing directory #%A_Index% from host ...
FileSetAttrib -rhs, %CurFile% FileSetAttrib -RSH, %CurFile%
FileSetAttrib -RSH, %CurFile%\*.*, 1, 1
FileRemoveDir %CurFile%, 1 FileRemoveDir %CurFile%, 1
} }
Else Else
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/fildel0, Removing file #%A_Index% from host ... Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/fildel0, Removing file #%A_Index% from host ...
FileSetAttrib -rhs, %CurFile% FileSetAttrib -RSH, %CurFile%
FileDelete %CurFile% FileDelete %CurFile%
} }
} }

View File

@ -3,7 +3,7 @@
#Include mb_EnvTools.ahk #Include mb_EnvTools.ahk
#Include mb_IniTools.ahk #Include mb_IniTools.ahk
#Include mb_TextTools.ahk #Include mb_TextTools.ahk
U3HVer = 2.1 U3HVer = 2.2
U3HUUID = 0f90f88c-5e05-4cab-8c3a-e1c0112b06fd U3HUUID = 0f90f88c-5e05-4cab-8c3a-e1c0112b06fd
U3_APP_DATA_PATH := EnvValue("U3_APP_DATA_PATH") U3_APP_DATA_PATH := EnvValue("U3_APP_DATA_PATH")
@ -29,6 +29,10 @@ IniGetKeys("regbak", INIFile, "RegBackup")
IniGetKeys("regdel", INIFile, "RegDelete") IniGetKeys("regdel", INIFile, "RegDelete")
IniGetKeys("fildel", INIFile, "FileDelete") IniGetKeys("fildel", INIFile, "FileDelete")
;******************************************************************************
;** Get Taskbar position
;******************************************************************************
WinGetPos,Tx,Ty,Tw,Th,ahk_class Shell_TrayWnd,,, WinGetPos,Tx,Ty,Tw,Th,ahk_class Shell_TrayWnd,,,
; Tw>Th: horizontal taskbar (top or bottom) ; Tw>Th: horizontal taskbar (top or bottom)
; Tw<Th: vertical taskbar (left or right) ; Tw<Th: vertical taskbar (left or right)
@ -61,6 +65,44 @@ if (Tw>Th and Ty<=0) {
PT := A_ScreenHeight - PH PT := A_ScreenHeight - PH
} }
;******************************************************************************
;******************************************************************************
;** Get names in local language for "Application Data", "Local Settings" and
;** "Application Data" below "Local Settings"
;******************************************************************************
RegRead AD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, AppData
RegRead LS, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Local Settings
RegRead LAD, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Local AppData
If LAD
LAD := AD
StringRight ADc, AD, 1
StringRight LSc, LS, 1
StringRight LADc, LAD, 1
If (ADc = "\")
StringTrimRight AD, AD, 1
If (LSc = "\")
StringTrimRight LS, LS, 1
If (LADc = "\")
StringTrimRight LAD, LAD, 1
SplitLast(null, ADn, AD, "\")
SplitLast(null, LSn, LS, "\")
SplitLast(null, LADn, LAD, "\")
EnvAddX("U3H_AppData", ADn)
EnvAddX("U3H_LocalSettings", LSn)
EnvAddX("U3H_LocalAppData", LSn . "\" . LADn)
EnvSort()
;******************************************************************************
FileCopyNewer(srcf, dstf) FileCopyNewer(srcf, dstf)
{ {
IfNotExist %srcf% IfNotExist %srcf%

View File

@ -7,54 +7,64 @@ EnvVals0 = 0
EnvVarsAll := "U3_DEVICE_PATH,U3_DEVICE_DOCUMENT_PATH,U3_DEVICE_VENDOR,U3_DEVICE_PRODUCT,U3_APP_DATA_PATH,U3_HOST_EXEC_PATH" EnvVarsAll := "U3_DEVICE_PATH,U3_DEVICE_DOCUMENT_PATH,U3_DEVICE_VENDOR,U3_DEVICE_PRODUCT,U3_APP_DATA_PATH,U3_HOST_EXEC_PATH"
EnvVarsAll .= ",U3_DEVICE_EXEC_PATH,ALLUSERSPROFILE,APPDATA,CommonProgramFiles,HOMEPATH,ProgramFiles,SystemRoot,USERPROFILE,TEMP,windir" EnvVarsAll .= ",U3_DEVICE_EXEC_PATH,ALLUSERSPROFILE,APPDATA,CommonProgramFiles,HOMEPATH,ProgramFiles,SystemRoot,USERPROFILE,TEMP,windir"
StringSplit EnvVarsx, EnvVarsAll, `,%A_Space% StringSplit EnvVars, EnvVarsAll, `,%A_Space%
; Load EnvVar-Values and store in EnvVals-array ; Load EnvVar-Values and store in EnvVals-array
Loop %EnvVarsx0% Loop %EnvVars0%
{ {
EnvName := EnvVarsx%A_Index% EnvName := EnvVars%A_Index%
EnvGet EnvValsx%A_Index%, %EnvName% EnvGet EnvVals%A_Index%, %EnvName%
} }
EnvValsx0 = %EnvVarsx0% EnvVals0 = %EnvVars0%
EnvSort()
; Sort EnvVar-Values by StrLen() for re-replacement (value to var) ;******************************************************************************
; and clean out empty vars
CurIndex = 1
Loop %EnvVarsx0% EnvSort()
{ {
MaxIndex = -1 global
MaxLen = -1 local CurIndex, CurNam, CurVal, MaxIndex, MaxLen
Loop %EnvValsx0%
Loop %EnvVars0%
{ {
CurNam := EnvVarsx%A_Index% EnvVarsx%A_Index% := EnvVars%A_Index%
CurVal := EnvValsx%A_Index% EnvValsx%A_Index% := EnvVals%A_Index%
If ((StrLen(CurVal) >= MaxLen) and (StrLen(CurNam) > 0)) }
EnvVarsx0 := EnvVars0
EnvValsx0 := EnvVals0
; 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%
{ {
MaxLen := StrLen(CurVal) CurNam := EnvVarsx%A_Index%
MaxIndex := 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% := ""
} }
If (StrLen(EnvValsx%MaxIndex%) > 0)
{ EnvVars0 := CurIndex-1
EnvVars%CurIndex% := EnvVarsx%MaxIndex% EnvVals0 := CurIndex-1
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() EnvList()
{ {
global global
@ -67,7 +77,7 @@ EnvList()
return result return result
} }
EnvValue(envname) EnvValue(envname, add = 1)
{ {
global global
local result local result
@ -81,17 +91,34 @@ EnvValue(envname)
} }
; EnvVar not in list - try to catch it ; EnvVar not in list - try to catch it
EnvGet result, %envname% EnvGet result, %envname%
If (StrLen(result) > 0) If (add && StrLen(result) > 0)
{ {
; seems like a result ~~> add to list ; seems like a result ~~> add to list
MyPointer := ++EnvVars0 EnvAddX(envname, result)
EnvVars%MyPointer% := envname EnvSort()
EnvVals%MyPointer% := result
EnvVals0++
} }
return result return result
} }
EnvAddX(var, val = "%%")
{
global
local MyPointer
If (val = "%%")
{
EnvGet val, %var%
}
If (StrLen(val) > 0)
{
MyPointer := ++EnvVars0
EnvVars%MyPointer% := var
EnvVals%MyPointer% := val
EnvVals0++
return 1
}
return 0
}
EnvParseStr(instring) EnvParseStr(instring)
{ {
global global