Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ${SegmentFile}
- # Custom code for the TopOCR Portable Launcher (20 June 2010)
- # Based upon the PortableApps.com Launcher's 'FilesMove' segment.
- #
- # TopOCR uses an INI file stored in the Windows folder (C:\Windows).
- #
- # When run from a standard account on a Vista or Windows 7 system
- # the OS prevents TopOCR from writing directly to the Windows folder
- # and uses File Virtualisation instead. TopOCR will still think it is
- # using a file stored in the Windows folder so it will work properly.
- #
- # The PortableApps.com Launcher is a well-behaved program so the OS will
- # not use File Virtualisation for it. This means the [FilesMove] code in
- # the launcher will be unable to copy the TopOCR INI file to/from the
- # Windows folder. This custom code ensures the launcher can restore/save
- # the TopOCR INI file properly, so TopOCR Portable will work as expected.
- !macro _TopOCR_CustomCode_Start
- StrCpy $0 settings\TopOCR.ini
- StrCpy $1 $LOCALAPPDATA\VirtualStore\Windows
- ; By the end:
- ; $0 = full path to source
- ; $1 = full path to target
- ; $2 = file name (only used as a temporary variable)
- ; $4 = target directory
- ${ParseLocations} $1
- ${GetFileName} $0 $2
- StrCpy $0 $DataDirectory\$0
- StrCpy $4 $1
- StrCpy $1 $1\$2
- !macroend
- ${SegmentPreExec}
- ${If} ${UAC_IsAdmin}
- ; TopOCR Portable has been started with administrator rights therefore
- ; the launcher (and the portable version of TopOCR) can write directly
- ; to $WINDIR so the launcher's normal [FilesMove] code will work.
- ${DebugMsg} "Running with admin rights so File Virtualisation does not apply"
- ${ElseIf} ${FileExists} "$LOCALAPPDATA\VirtualStore"
- ; TopOCR Portable has not been started with administrator rights therefore
- ; the launcher's normal [FileMove] code will be unable to copy the TopOCR.ini
- ; file to $WINDIR. File Virtualisation is used to make TopOCR.ini appear to be
- ; in $WINDIR so that TopOCR Portable will work properly on Vista and Windows 7.
- ${DebugMsg} "File Virtualisation detected on this system"
- !insertmacro _TopOCR_CustomCode_Start
- ; Backup data from a local installation
- ${IfNot} ${FileExists} $1-BackupBy$AppID
- ${AndIf} ${FileExists} $1
- ${DebugMsg} "Backing up $1 to $1-BackupBy$AppID"
- Rename $1 $1-BackupBy$AppID
- ${EndIf}
- ; If portable data exists move/copy it to the target directory. If the
- ; target directory doesn't exist, note down for the end to remove it
- ; again if it's empty.
- ${If} ${FileExists} $0
- ${DebugMsg} "Copying $0 to $1"
- ${IfNot} ${FileExists} $4
- CreateDirectory $4
- WriteINIStr $DataDirectory\PortableApps.comLauncherRuntimeData-$BaseName.ini FilesMove RemoveIfEmpty:$4 true
- ${EndIf}
- ${GetRoot} $0 $2 ; compare
- ${GetRoot} $1 $3 ; drive
- ${If} $2 == $3 ; letters
- Rename $0 $1 ; same volume, rename OK
- ${Else}
- CopyFiles /SILENT $0 $1
- ${EndIf}
- ${EndIf}
- ${EndIf}
- !macroend
- ${SegmentPost}
- ${If} ${UAC_IsAdmin}
- ; TopOCR Portable has been started with administrator rights therefore
- ; the launcher (and the portable version of TopOCR) can write directly
- ; to $WINDIR so the launcher's normal [FilesMove] code will work.
- ${DebugMsg} "Running with admin rights so File Virtualisation does not apply"
- ${Else}
- ${If} ${FileExists} "$LOCALAPPDATA\VirtualStore\Windows\TopOCR.ini"
- ${DebugMsg} "File Virtualisation was used for TopOCR.ini"
- !insertmacro _TopOCR_CustomCode_Start
- ; If not in Live mode, copy the data back to the Data directory.
- ${If} $RunLocally != true
- ${DebugMsg} "Copying file from $1 to $0"
- ${GetRoot} $0 $2 ; compare
- ${GetRoot} $1 $3 ; drive
- ${If} $2 == $3 ; letters
- Rename $1 $0 ; same volume, rename OK
- ${ElseIf} ${FileExists} $1
- Delete $0
- ;${GetParent} $0 $0
- CopyFiles /SILENT $1 $0
- ${EndIf}
- ${EndIf}
- ; And then remove it from the runtime location
- ${DebugMsg} "Removing portable settings file $1 from run location."
- Delete $1
- ; If the local directory we put it in didn't exist before, delete it if
- ; it's empty.
- ReadINIStr $2 $DataDirectory\PortableApps.comLauncherRuntimeData-$BaseName.ini FilesMove RemoveIfEmpty:$4
- ${If} $2 == true
- RMDir $4
- ${EndIf}
- ; And move that backup of any local data from earlier if it exists.
- ${If} ${FileExists} $1-BackupBy$AppID
- ${DebugMsg} "Moving local settings file from $1-BackupBy$AppID to $1"
- Rename $1-BackupBy$AppID $1
- ${EndIf}
- ${EndIf}
- ${EndIf}
- !macroend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement