* 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:
parent
2dc2001284
commit
a68c2da4b6
@ -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%
|
||||
|
||||
; %HOMEPATH% is without drive letter and colon, do it also here
|
||||
|
@ -342,13 +342,14 @@ If (KeepSettings = "0" or Unattended = "1")
|
||||
IfInString FilAttr, D
|
||||
{
|
||||
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
|
||||
}
|
||||
Else
|
||||
{
|
||||
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/fildel0, Removing file #%A_Index% from host ...
|
||||
FileSetAttrib -rhs, %CurFile%
|
||||
FileSetAttrib -RSH, %CurFile%
|
||||
FileDelete %CurFile%
|
||||
}
|
||||
}
|
||||
|
44
U3Helper.ahk
44
U3Helper.ahk
@ -3,7 +3,7 @@
|
||||
#Include mb_EnvTools.ahk
|
||||
#Include mb_IniTools.ahk
|
||||
#Include mb_TextTools.ahk
|
||||
U3HVer = 2.1
|
||||
U3HVer = 2.2
|
||||
U3HUUID = 0f90f88c-5e05-4cab-8c3a-e1c0112b06fd
|
||||
|
||||
U3_APP_DATA_PATH := EnvValue("U3_APP_DATA_PATH")
|
||||
@ -29,6 +29,10 @@ IniGetKeys("regbak", INIFile, "RegBackup")
|
||||
IniGetKeys("regdel", INIFile, "RegDelete")
|
||||
IniGetKeys("fildel", INIFile, "FileDelete")
|
||||
|
||||
;******************************************************************************
|
||||
;** Get Taskbar position
|
||||
;******************************************************************************
|
||||
|
||||
WinGetPos,Tx,Ty,Tw,Th,ahk_class Shell_TrayWnd,,,
|
||||
; Tw>Th: horizontal taskbar (top or bottom)
|
||||
; Tw<Th: vertical taskbar (left or right)
|
||||
@ -61,6 +65,44 @@ if (Tw>Th and Ty<=0) {
|
||||
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)
|
||||
{
|
||||
IfNotExist %srcf%
|
||||
|
113
mb_EnvTools.ahk
113
mb_EnvTools.ahk
@ -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_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
|
||||
Loop %EnvVarsx0%
|
||||
Loop %EnvVars0%
|
||||
{
|
||||
EnvName := EnvVarsx%A_Index%
|
||||
EnvGet EnvValsx%A_Index%, %EnvName%
|
||||
EnvName := EnvVars%A_Index%
|
||||
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
|
||||
MaxLen = -1
|
||||
Loop %EnvValsx0%
|
||||
global
|
||||
local CurIndex, CurNam, CurVal, MaxIndex, MaxLen
|
||||
|
||||
Loop %EnvVars0%
|
||||
{
|
||||
CurNam := EnvVarsx%A_Index%
|
||||
CurVal := EnvValsx%A_Index%
|
||||
If ((StrLen(CurVal) >= MaxLen) and (StrLen(CurNam) > 0))
|
||||
EnvVarsx%A_Index% := EnvVars%A_Index%
|
||||
EnvValsx%A_Index% := EnvVals%A_Index%
|
||||
}
|
||||
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)
|
||||
MaxIndex := A_Index
|
||||
}
|
||||
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% := ""
|
||||
}
|
||||
If (StrLen(EnvValsx%MaxIndex%) > 0)
|
||||
{
|
||||
EnvVars%CurIndex% := EnvVarsx%MaxIndex%
|
||||
EnvVals%CurIndex% := EnvValsx%MaxIndex%
|
||||
CurIndex++
|
||||
}
|
||||
EnvVarsx%MaxIndex% := ""
|
||||
EnvValsx%MaxIndex% := ""
|
||||
|
||||
EnvVars0 := CurIndex-1
|
||||
EnvVals0 := CurIndex-1
|
||||
}
|
||||
|
||||
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
|
||||
@ -67,7 +77,7 @@ EnvList()
|
||||
return result
|
||||
}
|
||||
|
||||
EnvValue(envname)
|
||||
EnvValue(envname, add = 1)
|
||||
{
|
||||
global
|
||||
local result
|
||||
@ -81,17 +91,34 @@ EnvValue(envname)
|
||||
}
|
||||
; EnvVar not in list - try to catch it
|
||||
EnvGet result, %envname%
|
||||
If (StrLen(result) > 0)
|
||||
If (add && StrLen(result) > 0)
|
||||
{
|
||||
; seems like a result ~~> add to list
|
||||
MyPointer := ++EnvVars0
|
||||
EnvVars%MyPointer% := envname
|
||||
EnvVals%MyPointer% := result
|
||||
EnvVals0++
|
||||
EnvAddX(envname, result)
|
||||
EnvSort()
|
||||
}
|
||||
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)
|
||||
{
|
||||
global
|
||||
|
Reference in New Issue
Block a user