Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ${SegmentFile}
  2.  
  3. !macro _DirectoriesMove_Start
  4.     ${IfThen} $0 != - ${|} StrCpy $0 $DataDirectory\$0 ${|}
  5.     ${ParseLocations} $1
  6. !macroend
  7.  
  8. ${SegmentPrePrimary}
  9.     ${ForEachINIPair} DirectoriesMove $0 $1
  10.         !insertmacro _DirectoriesMove_Start
  11.  
  12.         ; Backup data from a local installation
  13.         ${ForEachDirectory} $4 $3 $1
  14.             ${DebugMsg} "Backing up $4 to $4.BackupBy$AppID"
  15.             Rename $4 $4.BackupBy$AppID
  16.         ${NextDirectory}
  17.  
  18.         ; If the key is -, don't move/copy to the target directory.
  19.         ; If portable data exists move/copy it to the target directory.
  20.         ${If} $0 == -
  21.             ${IfNot} ${WildCardFlag} ; can not create folders with wild-cards (obviously)
  22.                 CreateDirectory $1
  23.                 ${DebugMsg} "DirectoriesMove key -, so only creating the directory $1 (no file copy)."
  24.             ${EndIf}
  25.         ${Else}
  26.             ; See if the parent local directory exists. If not, create it and
  27.             ; note down to delete it at the end if it's empty.
  28.             ${GetParent} $1 $4
  29.             ${IfNot} ${FileExists} $4
  30.                 CreateDirectory $4
  31.                 ${WriteRuntimeData} DirectoriesMove RemoveIfEmpty:$4 true
  32.             ${EndIf}
  33.  
  34.             ${ForEachDirectory} $3 $2 $0
  35.                 ${IfNotThen} ${WildCardFlag} ${|} ${GetFileName} $1 $2 ${|} ; do not inherit the filename
  36.                 ${GetRoot} $0 $5 ; compare
  37.                 ${GetRoot} $1 $6 ; drive
  38. ;               ${If} $5 == $6   ; letters
  39.                     ${DebugMsg} "Renaming directory $3 to $4\$2"
  40.                     Rename $3 $4\$2 ; same volume, rename OK
  41. ;               ${Else}
  42. ${If} ${Errors}
  43.                     ${DebugMsg} "Copying $3\*.* to $4\$2\*.*"
  44.                     CreateDirectory $4\$2
  45.                     CopyFiles /SILENT $3\*.* $4\$2
  46.                 ${EndIf}
  47.             ${NextDirectory}
  48.             ${If} ${Errors}
  49.                 ${IfNotThen} ${WildCardFlag} ${|} CreateDirectory $1 ${|}
  50.                 ; Nothing to copy, so just create the directory, ready for use.
  51. ${!getdebug}
  52. !ifdef DEBUG
  53.                 StrLen $2 "$DataDirectory\"
  54.                 StrCpy $0 $0 "" $2
  55.                 ${DebugMsg} "$DataDirectory\$0\*.* does not exist, so not copying it to $1.$\r$\n(Note for developers: if you want default data, remember to put files in App\DefaultData\$0)"
  56. !endif
  57.             ${EndIf}
  58.         ${EndIf}
  59.     ${NextINIPair}
  60. !macroend
  61.  
  62. ${SegmentPostPrimary}
  63.     ${ForEachINIPair} DirectoriesMove $0 $1
  64.         !insertmacro _DirectoriesMove_Start
  65.  
  66.         ; If the key is "-", don't copy it back
  67.         ; Also if not in Live mode, copy the data back to the Data directory.
  68.         ${GetParent} $0 $3
  69.         ${ForEachDirectory} $4 $2 $1
  70.             ${IfNotThen} ${WildCardFlag} ${|} ${GetFileName} $0 $2 ${|} ; do not inherit the filename
  71.             ${If} $0 == -
  72.                 ${DebugMsg} "DirectoriesMove key -, so not keeping data from $1."
  73.             ${ElseIf} $RunLocally != true
  74.                 ${GetRoot} $0 $5 ; compare
  75.                 ${GetRoot} $1 $6 ; drive
  76. ;               ${If} $5 == $6   ; letters
  77.                     ${DebugMsg} "Renaming directory $4 to $3\$2"
  78.                     Rename $4 $3\$2 ; same volume, rename OK
  79. ;               ${Else}
  80. ${If} ${Errors}
  81.                     ${DebugMsg} "Copying $4\*.* to $3\$2\*.*"
  82.                     RMDir /R $3\$2
  83.                     CreateDirectory $3\$2
  84.                     CopyFiles /SILENT $4\*.* $3\$2
  85.                 ${EndIf}
  86.             ${EndIf}
  87.             ; And then remove it from the runtime location
  88.             ${DebugMsg} "Removing portable settings directory from run location ($4)."
  89.             RMDir /R $4
  90.         ${NextDirectory}
  91.  
  92.         ; If the parent directory we put the directory in locally didn't exist
  93.         ; before, delete it if it's empty.
  94.         ${GetParent} $1 $4
  95.         ${ReadRuntimeData} $2 DirectoriesMove RemoveIfEmpty:$4
  96.         ${If} $2 == true
  97.             RMDir $4
  98.         ${EndIf}
  99.  
  100.         ; And move that backup of any local data from earlier if it exists.
  101.         ${ForEachDirectory} $3 $2 $1.BackupBy$AppID
  102.             ${GetBaseName} $2 $2
  103.             ${DebugMsg} "Moving local settings from $3 to $4\$2"
  104.             Rename $3 $4\$2
  105.         ${NextDirectory}
  106.     ${NextINIPair}
  107. !macroend
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement