Advertisement
Guest User

Untitled

a guest
Jun 20th, 2010
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ${SegmentFile}
  2.  
  3. # Custom code for the TopOCR Portable Launcher (20 June 2010)
  4. # Based upon the PortableApps.com Launcher's 'FilesMove' segment.
  5. #
  6. # TopOCR uses an INI file stored in the Windows folder (C:\Windows).
  7. #
  8. # When run from a standard account on a Vista or Windows 7 system
  9. # the OS prevents TopOCR from writing directly to the Windows folder
  10. # and uses File Virtualisation instead. TopOCR will still think it is
  11. # using a file stored in the Windows folder so it will work properly.
  12. #
  13. # The PortableApps.com Launcher is a well-behaved program so the OS will
  14. # not use File Virtualisation for it. This means the [FilesMove] code in
  15. # the launcher will be unable to copy the TopOCR INI file to/from the
  16. # Windows folder. This custom code ensures the launcher can restore/save
  17. # the TopOCR INI file properly, so TopOCR Portable will work as expected.
  18.  
  19. !macro _TopOCR_CustomCode_Start
  20.   StrCpy $0 settings\TopOCR.ini
  21.   StrCpy $1 $LOCALAPPDATA\VirtualStore\Windows
  22.     ; By the end:
  23.     ; $0 = full path to source
  24.     ; $1 = full path to target
  25.     ; $2 = file name (only used as a temporary variable)
  26.     ; $4 = target directory
  27.     ${ParseLocations} $1
  28.     ${GetFileName} $0 $2
  29.     StrCpy $0 $DataDirectory\$0
  30.     StrCpy $4 $1
  31.     StrCpy $1 $1\$2
  32. !macroend
  33.  
  34. ${SegmentPreExec}
  35.   ${If} ${UAC_IsAdmin}
  36.     ; TopOCR Portable has been started with administrator rights therefore
  37.     ; the launcher (and the portable version of TopOCR) can write directly
  38.     ; to $WINDIR so the launcher's normal [FilesMove] code will work.
  39.     ${DebugMsg} "Running with admin rights so File Virtualisation does not apply"
  40.   ${ElseIf} ${FileExists} "$LOCALAPPDATA\VirtualStore"
  41.     ; TopOCR Portable has not been started with administrator rights therefore
  42.     ; the launcher's normal [FileMove] code will be unable to copy the TopOCR.ini
  43.     ; file to $WINDIR. File Virtualisation is used to make TopOCR.ini appear to be
  44.     ; in $WINDIR so that TopOCR Portable will work properly on Vista and Windows 7.
  45.     ${DebugMsg} "File Virtualisation detected on this system"
  46.  
  47.     !insertmacro _TopOCR_CustomCode_Start
  48.  
  49.         ; Backup data from a local installation
  50.         ${IfNot} ${FileExists} $1-BackupBy$AppID
  51.         ${AndIf} ${FileExists} $1
  52.             ${DebugMsg} "Backing up $1 to $1-BackupBy$AppID"
  53.             Rename $1 $1-BackupBy$AppID
  54.         ${EndIf}
  55.  
  56.         ; If portable data exists move/copy it to the target directory.  If the
  57.         ; target directory doesn't exist, note down for the end to remove it
  58.         ; again if it's empty.
  59.         ${If} ${FileExists} $0
  60.             ${DebugMsg} "Copying $0 to $1"
  61.             ${IfNot} ${FileExists} $4
  62.                 CreateDirectory $4
  63.                 WriteINIStr $DataDirectory\PortableApps.comLauncherRuntimeData-$BaseName.ini FilesMove RemoveIfEmpty:$4 true
  64.             ${EndIf}
  65.             ${GetRoot} $0 $2 ; compare
  66.             ${GetRoot} $1 $3 ; drive
  67.             ${If} $2 == $3   ; letters
  68.                 Rename $0 $1 ; same volume, rename OK
  69.             ${Else}
  70.                 CopyFiles /SILENT $0 $1
  71.             ${EndIf}
  72.         ${EndIf}
  73.   ${EndIf}
  74. !macroend
  75.  
  76. ${SegmentPost}
  77.   ${If} ${UAC_IsAdmin}
  78.     ; TopOCR Portable has been started with administrator rights therefore
  79.     ; the launcher (and the portable version of TopOCR) can write directly
  80.     ; to $WINDIR so the launcher's normal [FilesMove] code will work.
  81.     ${DebugMsg} "Running with admin rights so File Virtualisation does not apply"
  82.   ${Else}
  83.     ${If} ${FileExists} "$LOCALAPPDATA\VirtualStore\Windows\TopOCR.ini"
  84.       ${DebugMsg} "File Virtualisation was used for TopOCR.ini"
  85.  
  86.       !insertmacro _TopOCR_CustomCode_Start
  87.  
  88.       ; If not in Live mode, copy the data back to the Data directory.
  89.       ${If} $RunLocally != true
  90.         ${DebugMsg} "Copying file from $1 to $0"
  91.         ${GetRoot} $0 $2 ; compare
  92.         ${GetRoot} $1 $3 ; drive
  93.         ${If} $2 == $3   ; letters
  94.           Rename $1 $0 ; same volume, rename OK
  95.         ${ElseIf} ${FileExists} $1
  96.           Delete $0
  97.           ;${GetParent} $0 $0
  98.           CopyFiles /SILENT $1 $0
  99.         ${EndIf}
  100.       ${EndIf}
  101.       ; And then remove it from the runtime location
  102.       ${DebugMsg} "Removing portable settings file $1 from run location."
  103.       Delete $1
  104.  
  105.       ; If the local directory we put it in didn't exist before, delete it if
  106.       ; it's empty.
  107.       ReadINIStr $2 $DataDirectory\PortableApps.comLauncherRuntimeData-$BaseName.ini FilesMove RemoveIfEmpty:$4
  108.       ${If} $2 == true
  109.         RMDir $4
  110.       ${EndIf}
  111.  
  112.       ; And move that backup of any local data from earlier if it exists.
  113.       ${If} ${FileExists} $1-BackupBy$AppID
  114.         ${DebugMsg} "Moving local settings file from $1-BackupBy$AppID to $1"
  115.         Rename $1-BackupBy$AppID $1
  116.       ${EndIf}
  117.     ${EndIf}
  118.   ${EndIf}
  119. !macroend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement