Archived
1
0

* [FileDelete] and [DataToExecDir] now work with wildcards

! Problem noticed with [ParseFiles]: Unicode files don't work!
(Issue: 14)
This commit is contained in:
mbirth 2007-05-08 09:29:01 +00:00
parent 4267762598
commit 80851ff25a
4 changed files with 211 additions and 174 deletions

View File

@ -56,6 +56,9 @@ Else
IniDelete %INIFile%, U3Helper, ForeignSettings IniDelete %INIFile%, U3Helper, ForeignSettings
} }
} }
;******************************************************************************
IniRead ForeignSettings, %INIFile%, U3Helper, ForeignSettings, 0 IniRead ForeignSettings, %INIFile%, U3Helper, ForeignSettings, 0
If (ForeignSettings = "0") If (ForeignSettings = "0")
{ {
@ -84,89 +87,64 @@ Else
If regbak0 > 0 If regbak0 > 0
StepsPos++ StepsPos++
;******************************************************************************
;Copy data files ;Copy data files
SetWorkingDir %U3_HOST_EXEC_PATH%
CopyErrors := "" CopyErrors := ""
Loop %datexe0% Loop %datexe0%
{ {
CurFile := datexe%A_Index% OutIndex = %A_Index%
FileGetAttrib FilAttr, %U3_HOST_EXEC_PATH%\%CurFile% CurMask := datexe%A_Index%
IfInString FilAttr, D Copied = 0
Skipped = 0
Errors = 0
Dirs = 0
CopyErrors := ""
FileGetAttrib FAttr, %CurMask%
IfInString FAttr, D
CurMask .= "\*.*"
FileCount = 0
Loop %CurMask%, 1, 1
{ {
; CurFile is a directory FileCount++
IfExist %U3_HOST_EXEC_PATH%\%CurFile%
{
Copied = 0
Skipped = 0
Errors = 0
OutIndex = %A_Index%
FileCount = 0
SetWorkingDir %U3_HOST_EXEC_PATH%\%CurFile%
Loop *.*, 1, 1
{
FileCount++
}
Loop *.*, 1, 1
{
Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Saving data directory %CurFile% ... (CPY:%Copied% / SKP:%Skipped% / ERR:%Errors%)
FileGetAttrib FAttr, %A_LoopFileLongPath%
IfInString FAttr, D
{
IfNotExist %U3_APP_DATA_PATH%\%CurFile%\%A_LoopFileFullPath%
FileCreateDir %U3_APP_DATA_PATH%\%CurFile%\%A_LoopFileFullPath%
If ErrorLevel
Errors++
Else
Copied++
}
Else
{
FileCopyNewer(A_LoopFileLongPath, U3_APP_DATA_PATH . "\" CurFile . "\" . A_LoopFileFullPath)
If ErrorLevel = 2
{
CopyErrors .= "Dir-entry: " . CurFile . "\" . A_LoopFileFullPath . " (Error while copying)`n"
Errors++
}
else if ErrorLevel = 1
{
CopyErrors .= "Dir-entry: " . CurFile . "\" . A_LoopFileFullPath . " (File does not exist)`n"
Errors++
}
else if ErrorLevel = -1
Skipped++
else
Copied++
}
}
SetWorkingDir %A_ScriptDir%
}
Else
{
; Folder got deleted in the meantime, remove it from backup
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/datexe0, Removing data directory %CurFile% ...
FileSetAttrib -RSH, %U3_APP_DATA_PATH%\%CurFile%
FileSetAttrib -RSH, %U3_APP_DATA_PATH%\%CurFile%\*.*, 1, 1
FileRemoveDir %U3_APP_DATA_PATH%\%CurFile%, 1
}
} }
Else Loop %CurMask%, 1, 1
{ {
; CurFile is a file CurFile := A_LoopFileFullPath
IfExist %U3_HOST_EXEC_PATH%\%CurFile% TargFile := U3_APP_DATA_PATH . "\" . CurFile
FileGetAttrib FAttr, %CurFile%
IfInString FAttr, D
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/datexe0, Saving data file %CurFile% ... ; also create empty directories
FileCopyNewer(U3_HOST_EXEC_PATH . "\" . CurFile, U3_APP_DATA_PATH . "\" . CurFile) Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Creating directory %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / ERR:%Errors%)
If ErrorLevel > 0 FileCreateDir %TargFile%
CopyErrors .= "File: " . CurFile . "`n" Dirs++
} }
Else Else
{ {
; File got deleted in the meantime, remove it from backup Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Copying data %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / ERR:%Errors%)
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/datexe0, Removing data file %CurFile% ... FileCopyNewer(CurFile, TargFile)
FileSetAttrib -RSH, %U3_APP_DATA_PATH%\%CurFile% If ErrorLevel = 2
FileDelete %U3_APP_DATA_PATH%\%CurFile% {
CopyErrors .= "Dir-entry: " . CurFile . "\" . A_LoopFileFullPath . " (Error while copying)`n"
Errors++
}
Else If ErrorLevel = 1
{
CopyErrors .= "Dir-entry: " . CurFile . "\" . A_LoopFileFullPath . " (File does not exist)`n"
Errors++
}
Else If ErrorLevel = -1
Skipped++
Else
Copied++
} }
} }
} }
SetWorkingDir %A_ScriptDir%
If (CopyErrors <> "") If (CopyErrors <> "")
MsgBox 4112, Error while copying, Following files could not be backed up:`n`n%CopyErrors%`n`nTry to manually save them now.`n`n%U3_HOST_EXEC_PATH%`n`nAfter pressing OK, those files will be deleted. MsgBox 4112, Error while copying, Following files could not be backed up:`n`n%CopyErrors%`n`nTry to manually save them now.`n`n%U3_HOST_EXEC_PATH%`n`nAfter pressing OK, those files will be deleted.
@ -174,72 +152,75 @@ Else
If datexe0 > 0 If datexe0 > 0
StepsPos++ StepsPos++
;******************************************************************************
;Cleaning deleted files from stick
SetWorkingDir %U3_APP_DATA_PATH%
Loop %datexe0% Loop %datexe0%
{ {
CurFile := datexe%A_Index% OutIndex = %A_Index%
FileGetAttrib FilAttr, %U3_APP_DATA_PATH%\%CurFile% CurMask := datexe%A_Index%
IfInString FilAttr, D Deleted = 0
Skipped = 0
Errors = 0
FileGetAttrib FAttr, %CurMask%
IfInString FAttr, D
CurMask .= "\*.*"
FileCount = 0
Loop %CurMask%, 1, 1
{ {
; CurFile is a directory FileCount++
IfExist %U3_APP_DATA_PATH%\%CurFile% }
Loop %CurMask%, 1, 1
{
CurFile := A_LoopFileFullPath
Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Cleaning data %CurFile% ... (DEL:%Deleted% / SKP:%Skipped% / ERR:%Errors%)
TargFile := U3_HOST_EXEC_PATH . "\" . CurFile
IfExist %TargFile%
{ {
Deleted = 0 ; file still exists on host
Skipped = 0 Skipped++
Errors = 0 Continue
OutIndex = %A_Index%
FileCount = 0
SetWorkingDir %U3_APP_DATA_PATH%\%CurFile%
Loop *.*, 1, 1
{
FileCount++
}
Loop *.*, 1, 1
{
Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Cleaning data directory %CurFile% ... (DEL:%Deleted% / SKP:%Skipped% / ERR:%Errors%)
IfNotExist %U3_HOST_EXEC_PATH%\%CurFile%\%A_LoopFileFullPath%
{
; file doesn't exist on host, also delete on U3 drive
FileGetAttrib FAttr, %A_LoopFileLongPath%
IfInString FAttr, D
{
FileSetAttrib -RSH, %A_LoopFileLongPath%
FileSetAttrib -RSH, %A_LoopFileLongPath%\*.*, 1, 1
FileRemoveDir %A_LoopFileLongPath%, 1
If ErrorLevel
Errors++
Else
Deleted++
}
Else
{
FileSetAttrib -RSH, %A_LoopFileLongPath%
FileDelete %A_LoopFileLongPath%
If ErrorLevel
Errors++
Else
Deleted++
}
}
Else
{
; file still exists on host, leave it also on U3 drive
Skipped++
}
}
SetWorkingDir %A_ScriptDir%
} }
} ; target directory or file doesn't exist anymore, delete on U3
FileSetAttrib -RSH, %CurFile%
FileGetAttrib FAttr, %CurFile%
IfInString FAttr, D
{
; target is a directory
FileSetAttrib -RSH, %CurFile%\*.*, 1, 1
FileRemoveDir %CurFile%, 1
If ErrorLevel
Errors++
Else
Deleted++
}
Else
{
; target is a single file only
FileDelete %CurFile%
If ErrorLevel
Errors++
Else
Deleted++
}
}
} }
SetWorkingDir %A_ScriptDir%
If datexe0 > 0 If datexe0 > 0
StepsPos++ StepsPos++
;******************************************************************************
;Translate paths in text files ;Translate paths in text files
SetWorkingDir %U3_APP_DATA_PATH%
Loop %dattxt0% Loop %dattxt0%
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/dattxt0, Translating paths in file %CurFile% ... Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/dattxt0, Translating paths in file %CurFile% ...
CurMask := dattxt%A_Index% CurMask := dattxt%A_Index%
SetWorkingDir %U3_APP_DATA_PATH%
Loop %CurMask% Loop %CurMask%
{ {
CurFile := A_LoopFileFullPath CurFile := A_LoopFileFullPath
@ -266,13 +247,15 @@ Else
MsgBox 4112, Error while translating, The datafile %CurFile% could not be translated. The original state has been restored (hopefully). MsgBox 4112, Error while translating, The datafile %CurFile% could not be translated. The original state has been restored (hopefully).
} }
} }
SetWorkingDir %A_ScriptDir%
} }
SetWorkingDir %A_ScriptDir%
If dattxt0 > 0 If dattxt0 > 0
StepsPos++ StepsPos++
} }
;******************************************************************************
IniRead KeepSettings, %INIFile%, U3Helper, KeepSettings, 0 IniRead KeepSettings, %INIFile%, U3Helper, KeepSettings, 0
RevertSettings := "0" RevertSettings := "0"
If (KeepSettings <> "0") If (KeepSettings <> "0")
@ -313,8 +296,13 @@ If (KeepSettings = "0" or RevertSettings = "1")
If regbak0 > 0 If regbak0 > 0
StepsPos++ StepsPos++
;******************************************************************************
If (KeepSettings = "0" or Unattended = "1") If (KeepSettings = "0" or Unattended = "1")
{ {
;******************************************************************************
Loop %regdel0% Loop %regdel0%
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/regdel0, Removing add. registry settings #%A_Index% from host ... Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/regdel0, Removing add. registry settings #%A_Index% from host ...
@ -326,6 +314,8 @@ If (KeepSettings = "0" or Unattended = "1")
If regdel0 > 0 If regdel0 > 0
StepsPos++ StepsPos++
;******************************************************************************
; regsvr32 stuff ; regsvr32 stuff
Loop %regsvr0% Loop %regsvr0%
{ {
@ -337,29 +327,66 @@ If (KeepSettings = "0" or Unattended = "1")
If regsvr0 > 0 If regsvr0 > 0
StepsPos++ StepsPos++
;******************************************************************************
; remove files ; remove files
; if not specified, all file operations run on A_ScriptDir which is U3_HOST_EXEC_PATH
Loop %fildel0% Loop %fildel0%
{ {
CurFile := fildel%A_Index% OutIndex = %A_Index%
CurFile := EnvParseStr(CurFile) CurMask := fildel%A_Index%
FileGetAttrib FilAttr, %CurFile% Deleted = 0
IfInString FilAttr, D Errors = 0
Skipped = 0
CurMask := EnvParseStr(CurFile)
FileGetAttrib FAttr, %CurMask%
IfInString FAttr, D
CurMask .= "\*.*"
FileCount = 0
Loop %CurMask%, 1, 1
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/fildel0, Removing directory #%A_Index% from host ... FileCount++
FileSetAttrib -RSH, %CurFile%
FileSetAttrib -RSH, %CurFile%\*.*, 1, 1
FileRemoveDir %CurFile%, 1
} }
Else Loop %CurMask%, 1, 1
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/fildel0, Removing file #%A_Index% from host ... CurFile := A_LoopFileFullPath
Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/fildel0, Removing data %CurFile% from host ... (DEL:%Deleted% / SKP:%Skipped% / ERR:%Errors%)
IfNotExist %CurFile%
{
Skipped++
Continue
}
FileSetAttrib -RSH, %CurFile% FileSetAttrib -RSH, %CurFile%
FileDelete %CurFile% FileGetAttrib FAttr, %CurFile%
IfInString FAttr, D
{
; target is a directory
FileSetAttrib -RSH, %CurFile%\*.*, 1, 1
FileRemoveDir %CurFile%, 1
If ErrorLevel
Errors++
Else
Deleted++
}
Else
{
; target is a single file only
FileDelete %CurFile%
If ErrorLevel
Errors++
Else
Deleted++
}
} }
} }
If fildel0 > 0 If fildel0 > 0
StepsPos++ StepsPos++
;******************************************************************************
} }
Else Else
{ {
@ -371,6 +398,8 @@ Else
StepsPos++ StepsPos++
} }
;******************************************************************************
Progress 100, hostCleanUp done. Progress 100, hostCleanUp done.
If (U3_IS_DEVICE_AVAILABLE = "true") If (U3_IS_DEVICE_AVAILABLE = "true")

View File

@ -31,6 +31,8 @@ IfNotExist %U3_HOST_EXEC_PATH%\%A_ScriptName%
StepsPos++ StepsPos++
} }
;******************************************************************************
Progress % StepsPos*StepsStep, Checking registry settings... Progress % StepsPos*StepsStep, Checking registry settings...
keycount = 0 keycount = 0
;Registry stuff ;Registry stuff
@ -106,12 +108,14 @@ If (ForeignSettings = "0")
StepsPos++ StepsPos++
} }
;******************************************************************************
;Translate paths in text files ;Translate paths in text files
SetWorkingDir %U3_APP_DATA_PATH%
Loop %dattxt0% Loop %dattxt0%
{ {
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/dattxt0, Translating paths in file %CurFile% ... Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/dattxt0, Translating paths in file %CurFile% ...
CurMask := dattxt%A_Index% CurMask := dattxt%A_Index%
SetWorkingDir %U3_APP_DATA_PATH%
Loop %CurMask% Loop %CurMask%
{ {
CurFile := A_LoopFileFullPath CurFile := A_LoopFileFullPath
@ -139,63 +143,63 @@ Loop %dattxt0%
MsgBox 4112, Error while translating, The datafile %CurFile% could not be translated. The original state has been restored (hopefully). MsgBox 4112, Error while translating, The datafile %CurFile% could not be translated. The original state has been restored (hopefully).
} }
} }
SetWorkingDir %A_ScriptDir%
} }
SetWorkingDir %A_ScriptDir%
If dattxt0 > 0 If dattxt0 > 0
StepsPos++ StepsPos++
;******************************************************************************
;Copy data files ;Copy data files
SetWorkingDir %U3_APP_DATA_PATH%
Loop %datexe0% Loop %datexe0%
{ {
CurFile := datexe%A_Index% OutIndex = %A_Index%
FileGetAttrib FilAttr, %U3_APP_DATA_PATH%\%CurFile% CurMask := datexe%A_Index%
IfInString FilAttr, D Copied = 0
Errors = 0
Dirs = 0
FileGetAttrib FAttr, %CurMask%
IfInString FAttr, D
CurMask .= "\*.*"
FileCount = 0
Loop %CurMask%, 1, 1
{ {
Copied = 0 FileCount++
Errors = 0 }
OutIndex = %A_Index% Loop %CurMask%, 1, 1
FileCount = 0 {
SetWorkingDir %U3_APP_DATA_PATH%\%CurFile% CurFile := A_LoopFileFullPath
Loop *.*, 1, 1 TargFile := U3_HOST_EXEC_PATH . "\" . CurFile
FileGetAttrib FAttr, %CurFile%
IfInString FAttr, D
{ {
FileCount++ ; also create empty directories
Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Creating directory %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / ERR:%Errors%)
FileCreateDir %TargFile%
Dirs++
} }
IfNotExist %U3_HOST_EXEC_PATH%\%CurFile% Else
FileCreateDir %U3_HOST_EXEC_PATH%\%CurFile% {
Loop *.*, 1, 1 Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Copying data %CurFile% ... (CPY:%Copied% / DIR:%Dirs% / ERR:%Errors%)
{ FileCopyNewer(CurFile, TargFile)
Progress % StepsPos*StepsStep+StepsStep*(OutIndex-1.00+(A_Index/FileCount))/datexe0, Copying data directory %CurFile% ... (CPY:%Copied% / ERR:%Errors%) If ErrorLevel > 0
FileGetAttrib FAttr, %A_LoopFileLongPath%
IfInString FAttr, D
{
IfNotExist %U3_HOST_EXEC_PATH%\%CurFile%\%A_LoopFileFullPath%
FileCreateDir %U3_HOST_EXEC_PATH%\%CurFile%\%A_LoopFileFullPath%
}
Else
{
IfNotExist %U3_HOST_EXEC_PATH%\%CurFile%\%A_LoopFileDir%
FileCreateDir %U3_HOST_EXEC_PATH%\%CurFile%\%A_LoopFileDir%
FileCopy %A_LoopFileLongPath%, %U3_HOST_EXEC_PATH%\%CurFile%\%A_LoopFileFullPath%, 1
}
If ErrorLevel
Errors++ Errors++
Else Else
Copied++ Copied++
} }
SetWorkingDir %A_ScriptDir%
; FileCopyDir %U3_APP_DATA_PATH%\%CurFile%, %U3_HOST_EXEC_PATH%\%CurFile%, 1
}
Else
{
Progress % StepsPos*StepsStep+StepsStep*(A_Index-1)/datexe0, Copying data file %CurFile% ...
FileCopy %U3_APP_DATA_PATH%\%CurFile%, %U3_HOST_EXEC_PATH%\%CurFile%, 1
} }
} }
SetWorkingDir %A_ScriptDir%
If datexe0 > 0 If datexe0 > 0
StepsPos++ StepsPos++
;******************************************************************************
; regsvr32 stuff ; regsvr32 stuff
IniRead KeepSettings, %INIFile%, U3Helper, KeepSettings, 0 IniRead KeepSettings, %INIFile%, U3Helper, KeepSettings, 0
If (KeepSettings = "0") If (KeepSettings = "0")
@ -211,4 +215,6 @@ If (KeepSettings = "0")
If regsvr0 > 0 If regsvr0 > 0
StepsPos++ StepsPos++
;******************************************************************************
Progress 100, hostConfigure done. Progress 100, hostConfigure done.

View File

@ -136,6 +136,8 @@ FileCopyNewer(srcf, dstf)
return true return true
} }
;******************************************************************************
IfExist %AppExe% IfExist %AppExe%
Menu Tray, Icon, %AppExe% Menu Tray, Icon, %AppExe%

View File

@ -29,18 +29,18 @@ CCListBar.ocx
[DataToExecDir] [DataToExecDir]
; enter filenames or foldernames to be copied to the %U3_HOST_EXEC_PATH% ; enter filenames or foldernames to be copied to the %U3_HOST_EXEC_PATH%
; and copied back to %U3_APP_DATA_PATH% afterwards ; and copied back to %U3_APP_DATA_PATH% afterwards
; ONLY SIMPLE NAMES, NO PATHS OR WHATSOEVER! ; ONLY SIMPLE NAMES OR WILDCARDS, NO PATHS OR WHATSOEVER!
safe.dat safe.dat
safe.ind safe.ind
[ParseFiles] [ParseFiles]
; enter filenames of textfiles (mostly .ini or .xml) to be parsed for env vars ; enter filenames of textfiles (mostly .ini or .xml) to be parsed for env vars
; on hostConfigure and re-replace the paths by envvars on hostCleanUp. The ; on hostConfigure and re-replace the paths by envvars on hostCleanUp. The
; files should reside in %U3_APP_DATA_PATH% ; files should reside in %U3_APP_DATA_PATH% . Wildcards allowed.
test.ini test.ini
[FileDelete] [FileDelete]
; enter filenames or foldernames to be deleted on eject ; enter filenames or foldernames to be deleted on eject. Wildcards allowed.
; (To get a complete list of working environment variables, ; (To get a complete list of working environment variables,
; run U3Helper.exe without any parameters.) ; run U3Helper.exe without any parameters.)
%ALLUSERSPROFILE%\%U3H_AppData%\Spybot - Search & Destroy %ALLUSERSPROFILE%\%U3H_AppData%\Spybot - Search & Destroy