You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

rollback.nsh 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. #########################################################3
  2. ## Archiver Include Routines.
  3. ##
  4. ## Refined: Aug 17 2008. Andrew Wallo, Microneil, ArmResearch All Rights Reserved.
  5. ##########################################################
  6. # Main objectives is as follows:
  7. # Enable rollback of a folder to a previous folder state.
  8. # Create the log, and store it in the archive so that it understands what it nees to rollback.
  9. # Log should Contain, target directories, date and other relevent information.
  10. # Dependencies:
  11. # 1: Requires ${GetTime} to be defined in the master install script.
  12. # 2: Requires ${GetBetwee} to be defined in the master install script. Used to parse file lines.
  13. Var /GLOBAL SRS_CurrentArchiveFolder
  14. Var /GLOBAL SRS_Rollback_FileHandle
  15. Var /GLOBAL SRS_Rollback_FileCount
  16. Var /GLOBAL SRS_LogName
  17. !macro StartRollbackSession _ArchivePath _LogName _RootKey _RegistryKey
  18. StrCpy $SRS_LogName ${_LogName}
  19. StrCpy $SRS_CurrentArchiveFolder ${_ArchivePath}
  20. StrCpy $SRS_Rollback_FileCount "0"
  21. ; Now put the values onto the stack for the Rollback engine.
  22. Push `${_ArchivePath}`
  23. Push `${_LogName}`
  24. Call OpenRollback
  25. ;MessageBox MB_OK "Opened rollback with: $SRS_LogName / ${_ArchivePath} / $SRS_CurrentArchiveFolder"
  26. ${IF} "${_RootKey}" != ""
  27. ${IF} "${_RegistryKey}" != ""
  28. ${SetRegistry_with_RollbackControl} "${_RootKey}" "${_RegistryKey}" "SRS_RollbackPath" "$SRS_CurrentArchiveFolder"
  29. ${SetRegistry_with_RollbackControl} "${_RootKey}" "${_RegistryKey}" "SRS_LogName" "$SRS_LogName"
  30. ${ENDIF}
  31. ${ENDIF}
  32. !macroend
  33. !define StartRollbackSession "!insertmacro StartRollbackSession"
  34. #test
  35. !macro EndRollbackSession _RootKey _RegistryKey
  36. ${IF} "${_RootKey}" != ""
  37. ${IF} "${_RegistryKey}" != ""
  38. ${SetRegistry_with_RollbackControl} "${_RootKey}" "${_RegistryKey}" "SRS_COMPLETE" "1"
  39. ${SetRegistry_with_RollbackControl} "${_RootKey}" "${_RegistryKey}" "SRS_INSTDIR" "$INSTDIR"
  40. ${SetRegistry_with_RollbackControl} "${_RootKey}" "${_RegistryKey}" "SRS_SERVDIR" "$SNFServerInstallDir"
  41. ${ENDIF}
  42. ${ENDIF}
  43. FileWrite $SRS_Rollback_FileHandle "<FILECOUNT>$SRS_Rollback_FileCount</FILECOUNT>$\r$\n"
  44. StrCpy $SRS_Rollback_FileCount "0"
  45. FileWrite $SRS_Rollback_FileHandle "<END ROLLBACK FILE>$\r$\n"
  46. FileClose $SRS_Rollback_FileHandle ; close this file
  47. StrCpy $SRS_Rollback_FileHandle "" ;and clear for new rollback session.
  48. !macroend
  49. !define EndRollbackSession "!insertmacro EndRollbackSession"
  50. Function OpenRollback
  51. ; First determine if we're trying to open a second consecutive rollback session... ( this would be bad. )
  52. ;StrCmp $SRS_Rollback_FileHandle "" runOpenRollback 0 ; if cleared, then we can start a Rollback Session. If not clear, then set errors.
  53. ; push $1 ; saves $1
  54. ; Exch
  55. ; pop $1 ; removes ArchivePath off stack
  56. ; Exch
  57. ; pop $1 ; removes LogNme off stack
  58. ; pop $1 ; restores $1
  59. ; SetErrors
  60. ; MessageBox MB_OK "Archive in progress?"
  61. ; return ; sorry, can't do this right now....
  62. ;runOpenRollback: ; ok, clear for take-off:
  63. ; First protect the stack by saving the values of the registers we're going to use.
  64. ; But they're covering the parameters that were passed......
  65. ######################################## Stack Protection ###################################
  66. push $9 ; Save Register $9;
  67. Exch ; Swap Zeroth element in stack with the top most, which will be _LogName from the macro
  68. pop $9 ; put Log into register $9
  69. push $8 ; Save register $8
  70. Exch 2 ; Swap with position 1 from the top. So.... before exch was $1 $0 _ArchivePath
  71. ; After Exch was _ArchvePath $0 $1
  72. pop $8 ; $8 holds ArchivePath
  73. push $7 ; Used Locally.... save on stack....
  74. push $6
  75. push $5
  76. push $4
  77. push $3
  78. push $2
  79. push $1
  80. push $0
  81. ###################################### End Stack Protection #################################
  82. ; Ok,
  83. ifFileExists "$8\*.*" SRS_FolderExists 0 ; if the folder exists, skip create, otherwise create directory.
  84. CreateDirectory $8
  85. SRS_FolderExists:
  86. StrCpy $SRS_CurrentArchiveFolder $8 ; Save master variable for local var.
  87. ${GetTime} "" "L" $0 $1 $2 $3 $4 $5 $6 ; set vars for oldfilerename
  88. ; $0="01" day
  89. ; $1="04" month
  90. ; $2="2005" year
  91. ; $3="Friday" day of week name
  92. ; $4="16" hour
  93. ; $5="05" minute
  94. ; $6="50" seconds
  95. ; Create the specific archive folder path.
  96. StrCpy $7 "Archive_$2$1$0$4$5$6" ; for keying the folder.
  97. ; Test for valid name... otherwise use default.
  98. StrCmp $9 "" 0 +2
  99. StrCpy $9 "$7_rllbck.log"
  100. FileOpen $SRS_Rollback_FileHandle $8\$9 w ; Log File created for tracking rollback
  101. FileWrite $SRS_Rollback_FileHandle "<COMMENT>Started Rollback Log</COMMENT>$\r$\n"
  102. FileWrite $SRS_Rollback_FileHandle "<STARTDATE>$2.$1.$0,$4:$5:$6</STARTDATE>$\r$\n"
  103. ###################################### Restore the Stack ####################################
  104. pop $0
  105. pop $1
  106. pop $2
  107. pop $3
  108. pop $4
  109. pop $5
  110. pop $6
  111. pop $7
  112. pop $8
  113. pop $9
  114. return
  115. FunctionEnd
  116. #####################################################################################################################################################
  117. ## ${SetRegistry_RollbackControl} sets a registry entry to a new value, and stores the old one.
  118. #####################################################################################################################################################
  119. !macro SetRegistry_with_RollbackControl _RootKey _RegistryKey _SubKey _Value
  120. push $1
  121. ${Switch} "${_RootKey}"
  122. ${Case} "HKLM"
  123. ReadRegStr $1 HKLM "${_RegistryKey}" "${_SubKey}" ; get keys value...
  124. ${Case} "HKCR"
  125. ReadRegStr $1 HKCR "${_RegistryKey}" "${_SubKey}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  126. ${Case} "HKCU"
  127. ReadRegStr $1 HKCU "${_RegistryKey}" "${_SubKey}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  128. ${Case} "HKU"
  129. ReadRegStr $1 HKU "${_RegistryKey}" "${_SubKey}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  130. ${Case} "HKCC"
  131. ReadRegStr $1 HKCC "${_RegistryKey}" "${_SubKey}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  132. ${Case} "HKDD"
  133. ReadRegStr $1 HKDD "${_RegistryKey}" "${_SubKey}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  134. ${Case} "HKPD"
  135. ReadRegStr $1 HKPD "${_RegistryKey}" "${_SubKey}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  136. ${Case} "SHCTX"
  137. ReadRegStr $1 SHCTX "${_RegistryKey}" "${_SubKey}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  138. ${EndSwitch}
  139. StrCmp $1 "" 0 +4
  140. ; String is empty. Test for no key.
  141. ifErrors 0 +3 ; Means its a DWORD or something, but I'm not handling that here.
  142. ; Key didn't exist.
  143. FileWrite $SRS_Rollback_FileHandle "<REGISTRY><NEW>1</NEW><ROOT>${_RootKey}</ROOT><KEY>${_RegistryKey}</KEY><SUBKEY>${_SubKey}</SUBKEY><VALUE>${_Value}</VALUE></REGISTRY>$\r$\n"
  144. Goto +2 ; skip duplicate line and alter registry....
  145. ; Else the key existed.
  146. FileWrite $SRS_Rollback_FileHandle "<REGISTRY><NEW>0</NEW><ROOT>${_RootKey}</ROOT><KEY>${_RegistryKey}</KEY><SUBKEY>${_SubKey}</SUBKEY><VALUE>$1</VALUE></REGISTRY>$\r$\n"
  147. ${Switch} "${_RootKey}"
  148. ${Case} "HKLM"
  149. WriteRegStr HKLM "${_RegistryKey}" "${_SubKey}" "${_Value}" ; get keys value...
  150. ${Case} "HKCR"
  151. WriteRegStr HKCR "${_RegistryKey}" "${_SubKey}" "${_Value}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  152. ${Case} "HKCU"
  153. WriteRegStr HKCU "${_RegistryKey}" "${_SubKey}" "${_Value}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  154. ${Case} "HKU"
  155. WriteRegStr HKU "${_RegistryKey}" "${_SubKey}" "${_Value}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  156. ${Case} "HKCC"
  157. WriteRegStr HKCC "${_RegistryKey}" "${_SubKey}" "${_Value}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  158. ${Case} "HKDD"
  159. WriteRegStr HKDD "${_RegistryKey}" "${_SubKey}" "${_Value}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  160. ${Case} "HKPD"
  161. WriteRegStr HKPD "${_RegistryKey}" "${_SubKey}" "${_Value}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  162. ${Case} "SHCTX"
  163. WriteRegStr SHCTX "${_RegistryKey}" "${_SubKey}" "${_Value}" ;$R1 $R2 $R3Goto EndSNFServiceTest
  164. ${EndSwitch}
  165. pop $1
  166. !macroend
  167. !define SetRegistry_with_RollbackControl "!insertmacro SetRegistry_with_RollbackControl"
  168. #####################################################################################################################################################
  169. ## ${Install_with_RollbackControl} assumes you have set your INSTALL Directory as it will call File _someFilename and put it
  170. ## wherever the SetOutPath is pointing....
  171. #####################################################################################################################################################
  172. !macro Install_with_RollbackControl _someFileName _CallbackHandler _onFailCommand
  173. StrCmp "1" "0" 0 +2
  174. File ${_someFileName} ; can't ever happen but we need it here to force the compiler to include the file.
  175. IfFileExists `$OUTDIR\${_someFileName}` 0 +4
  176. ; File exists. We need to make a copy of the original file.
  177. CopyFiles /SILENT `$OUTDIR\${_someFileName}` `$SRS_CurrentArchiveFolder\${_someFileName}`
  178. ; We need to save the target path seperately because later when we're rolling it back, we'll need to setOutPath for each file seperately.
  179. ; If a file has a potential of being tied up, we can specify the action to take on an overwrite failure.
  180. FileWrite $SRS_Rollback_FileHandle "<FILE><NEW>0</NEW><NAME>${_someFileName}</NAME><TARGETPATH>$OUTDIR</TARGETPATH><CALLBACK>${_CallbackHandler}</CALLBACK><ONFAIL>${_onFailCommand}</ONFAIL></FILE>$\r$\n"
  181. Goto +2
  182. ; +4 jumps to here.....just Put The File
  183. FileWrite $SRS_Rollback_FileHandle "<FILE><NEW>1</NEW><NAME>${_someFileName}</NAME><TARGETPATH>$OUTDIR</TARGETPATH><CALLBACK>${_CallbackHandler}</CALLBACK><ONFAIL>${_onFailCommand}</ONFAIL></FILE>$\r$\n"
  184. File `${_someFileName}` ; ok, output the file into the install directory.
  185. IntOp $SRS_Rollback_FileCount $SRS_Rollback_FileCount + 1
  186. !macroend
  187. !define Install_with_RollbackControl "!insertmacro Install_with_RollbackControl"
  188. ###################################################################################################################################################
  189. ## The difference here is that the macro doesn't rely on the SetOutPath or call the File "filename" command. It just archives a file into rollback
  190. ## based on the the fully qualified path name supplied.
  191. ################################################################################################################################################
  192. !macro Copy_with_RollbackControl _someFileName _Path _CallbackHandler _onFailCommand
  193. ifFileExists ${_Path}\${_someFileName} 0 +5
  194. CopyFiles /SILENT `${_Path}\${_someFileName}` `$SRS_CurrentArchiveFolder\${_someFileName}`
  195. CopyFiles /SILENT `${_Path}\${_someFileName}` `${_Path}\${_someFileName}_pre_sniffer_install.log`
  196. ; We need to save the target path seperately because later when we're rolling it back, we'll need to setOutPath for each file seperately.
  197. ; If a file has a potential of being tied up, we can specify the action to take on an overwrite failure.
  198. FileWrite $SRS_Rollback_FileHandle "<FILE><NEW>0</NEW><NAME>${_someFileName}</NAME><TARGETPATH>${_Path}</TARGETPATH><CALLBACK>${_CallbackHandler}</CALLBACK><ONFAIL>${_onFailCommand}</ONFAIL></FILE>$\r$\n"
  199. IntOp $SRS_Rollback_FileCount $SRS_Rollback_FileCount + 1
  200. !macroend
  201. !define Copy_with_RollbackControl "!insertmacro Copy_with_RollbackControl"
  202. !macro RollBackTo _rollbackLocalPath _rollbackLogName
  203. push `${_rollbackLocalPath}`
  204. push `${_rollbackLogName}`
  205. Call RollBack
  206. !macroend
  207. !define RollBackTo "!insertmacro RollBackTo"
  208. Function RollBack
  209. push $0 ; save register 0 on stack. ( So stack looks like $0 "_rollbackLogName" _rollbackLocalPath Rest of Stack.....
  210. Exch ; swap the top two objects on the stack.... _rollbackLogName $0 _rollbackLocalPath
  211. pop $0 ; stack looks like $0.._rollbackLocalPath ...Rest of Stack.... Using $0 to hld the RollBackLogName
  212. push $1 ; stack looks like $1 $0.._rollbackLocalPath Rest of Stack Use this var for handling readlines.
  213. Exch 2 ; stack looks like _rollbackLocalPath $0 $1 Rest of Stack
  214. pop $1 ; Use this var for handling the local path of the list of archived files.
  215. Exch ; stack looks like $1 $0 Rest of Stack
  216. push $2 ; stack look like $2 $1 $0 Rest of stack. Use $2 to hold read lines.....
  217. push $3 ; stack looks like $3 $2 $1 $0 RestofStack. Use this var for handling tag parsing of lines....
  218. push $4 ; saving $4 too... use this var for holding filename of file.
  219. push $5 ; saving $5 too... use this var for holding target path.
  220. push $6 ; use this var for the command line to exeute if failed to copy....
  221. push $7 ; use this var for temp file handle
  222. ; registry temp vars....
  223. push $R1 ; protect this and use for the Root of the registry handles...
  224. push $R2 ; protect this and use for the Key
  225. push $R3 ; protect this and use for the subkey
  226. push $R4 ; protected this and use for the Value.....
  227. ; Not sure what the situation would be..... but theoretically, if the file is open... then.... its still open and the caller wasn't careful about
  228. ; ending the rollback.
  229. StrCmp $SRS_Rollback_FileHandle "" ProceedToRollBack 0
  230. ; File is open... crap... ok..well, reguardless of what our filename is, ( and it SHOULD be the same file, logically.... ) we want the other closed properly.
  231. MessageBox MB_OK "Had to close the file?"
  232. !insertmacro EndRollbackSession "" "" ; so end it cleanly. THEN open our rollback log. ; We're skipping the registry keys that record
  233. ; where the logfile and rollbackpath is... if this happens.
  234. ProceedToRollBack:
  235. ifFileExists "$1\$0" StartRollBack 0
  236. SetErrors
  237. MessageBox MB_OK "Unable to find rollback file: $1\$0"
  238. Goto SRS_DONE
  239. Return ; perhaps the user just gave the file folder.... try to locate the .rllbck file in the folder.... if it exists.
  240. StartRollBack:
  241. clearerrors
  242. FileOpen $SRS_Rollback_FileHandle "$1\$0" r ; open file for read.
  243. IfErrors 0 SRS_RESTORE_ReadLine
  244. MessageBox MB_OK "Error opening the file for rollback: $1\$0"
  245. Goto SRS_DONE
  246. SRS_RESTORE_ReadLine:
  247. ClearErrors
  248. FileRead $SRS_Rollback_FileHandle $2 ; get line for parsing.
  249. ;MessageBox MB_OK $2
  250. IfErrors SRS_DONE ; if errors, then EOF. Cleanup stack and exit.
  251. ; otherise parse line.
  252. StrCpy $3 $2 6 ;if this line is a file line, then the first six chars should be <FILE>
  253. ;Handle Registry Alterations:
  254. StrCmp $3 "<REGIS" 0 SRS_RESTORE_TestForFileLine
  255. FileOpen $7 "$1\SRS_TempFile.txt" w
  256. FileWrite $7 $2
  257. FileClose $7
  258. ;<FILE><NEW>1</NEW><NAME>${_someFileName}</NAME><TARGETPATH>$OUTDIR</TARGETPATH><ONFAIL>${_onFailCommand}</ONFAIL></FILE>
  259. ;<REGISTRY><NEW>1</NEW><ROOT>${_RootKey}</ROOT><KEY>${_RegistryKey}</KEY><SUBKEY>${_SubKey}</SUBKEY><VALUE>${_Value}</VALUE></REGISTRY>
  260. #MessageBox MB_OK "$2"
  261. ; Because GetBetween only uses files as sources.... ( stupid, that I'm using that here, but I am.... )
  262. ${GetBetween} "<NEW>" "</NEW>" "$1\SRS_TempFile.txt" $4 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  263. #MessageBox MB_OK $4
  264. ${GetBetween} "<ROOT>" "</ROOT>" "$1\SRS_TempFile.txt" $R1 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  265. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  266. ${GetBetween} "<KEY>" "</KEY>" "$1\SRS_TempFile.txt" $R2 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  267. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  268. ${GetBetween} "<SUBKEY>" "</SUBKEY>" "$1\SRS_TempFile.txt" $R3 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  269. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  270. ${GetBetween} "<VALUE>" "</VALUE>" "$1\SRS_TempFile.txt" $R4 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  271. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  272. #MessageBox MB_OK "$1, $4 , $R1 , $R2 , $R3 , $R4"
  273. StrCmp $4 "SRS_RollbackPath" RemoveIt 0
  274. StrCmp $4 "SRS_Logname" RemoveIt 0
  275. StrCmp $4 "1" 0 SRS_RESTORE_WRITE ; if the new marker is set to 1 then a rollback means remove it entirely.....
  276. RemoveIt:
  277. ${Switch} $R1
  278. ${Case} "HKLM"
  279. DeleteRegValue HKLM $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  280. ${Case} "HKCR"
  281. DeleteRegValue HKCR $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  282. ${Case} "HKCU"
  283. DeleteRegValue HKCU $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  284. ${Case} "HKU"
  285. DeleteRegValue HKU $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  286. ${Case} "HKCC"
  287. DeleteRegValue HKCC $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  288. ${Case} "HKDD"
  289. DeleteRegValue HKDD $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  290. ${Case} "HKPD"
  291. DeleteRegValue HKPD $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  292. ${Case} "SHCTX"
  293. DeleteRegValue SHCTX $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  294. ${EndSwitch}
  295. Goto SRS_RESTORE_ReadLine
  296. SRS_RESTORE_WRITE:
  297. ; if not then we need to restore the key.....
  298. ${Switch} $R1
  299. ${Case} "HKLM"
  300. WriteRegStr HKLM $R2 $R3 $R4
  301. ${Case} "HKCR"
  302. WriteRegStr HKCR $R2 $R3 $R4
  303. ${Case} "HKCU"
  304. WriteRegStr HKCU $R2 $R3 $R4
  305. ${Case} "HKU"
  306. WriteRegStr HKU $R2 $R3 $R4
  307. ${Case} "HKCC"
  308. WriteRegStr HKCC $R2 $R3 $R4
  309. ${Case} "HKDD"
  310. WriteRegStr HKDD $R2 $R3 $R4
  311. ${Case} "HKPD"
  312. WriteRegStr HKPD $R2 $R3 $R4
  313. ${Case} "SHCTX"
  314. WriteRegStr SHCTX $R2 $R3 $R4
  315. ${EndSwitch}
  316. Goto SRS_RESTORE_ReadLine
  317. SRS_RESTORE_TestForFileLine:
  318. StrCmp $3 "<FILE>" 0 SRS_RESTORE_ReadLine ; if its a file, then handle rolling back the file, otherwise get the next line.
  319. FileOpen $7 "$1\SRS_TempFile.txt" w
  320. FileWrite $7 $2
  321. FileClose $7
  322. ; Because GetBetween only uses files as sources.... ( stupid, that I'm using that here, but I am.... )
  323. ${GetBetween} "<NAME>" "</NAME>" "$1\SRS_TempFile.txt" $4 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  324. ${GetBetween} "<NEW>" "</NEW>" "$1\SRS_TempFile.txt" $R1 ; Get the marker that informed us if there WAS something to be copied, or if it was just installed.
  325. ;MessageBox MB_OK "Name:$4"
  326. ${GetBetween} "<TARGETPATH>" "</TARGETPATH>" "$1\SRS_TempFile.txt" $5 ; Get the targetpath between the file tags of the read_line_in->$2 and stick it in $5
  327. ;MessageBox MB_OK "Target:$5"
  328. clearerrors
  329. ${GetBetween} "<CALLBACK>" "</CALLBACK>" "$1\SRS_TempFile.txt" $6 ; Get the CALLBACK name between the file tags of the read_line_in->$2 and stick it in $6
  330. iferrors NoCallbackAvailable 0
  331. StrCmp $6 "" NoCallbackAvailable 0
  332. ; Ok, we have a callback, so we don't copy, we call file, and pass the filename.
  333. ;MessageBox MB_OK "Pushing $1\$4"
  334. push "$1\$4" ; push the file and path onto the stack.
  335. push $6 ; push the calback value onto the stack,
  336. Call ResolveFunction ; call the resolveFunction Call.
  337. Goto SRS_RESTORE_ReadLine ; No copy, just return for next line handle.
  338. NoCallbackAvailable:
  339. ; now deal with new vs archived files...
  340. StrCmp $R1 "1" 0 SRS_NOTNEW_RESTOREIT ; test to see if it was new, or if it required backin gup...
  341. ifFileExists "$5\$4" 0 SRS_RESTORE_ReadLine ; if it WAS new... test to see if file still exists...
  342. Delete "$5\$4" ; Since it was new we'll remove it on a restore....
  343. Goto SRS_RESTORE_ReadLine
  344. SRS_NOTNEW_RESTOREIT:
  345. CopyFiles /SILENT "$1\$4" "$5\$4"
  346. iferrors 0 SRS_RESTORE_ReadLine
  347. clearerrors
  348. ${GetBetween} "<ONFAIL>" "</ONFAIL>" "$1\SRS_TempFile.txt" $6 ; Get the onfail name between the file tags of the read_line_in->$2 and stick it in $6
  349. ; if we're here, then we need to rexecute the copy after executing the command line
  350. push "$1\$4" ; push the file and path onto the stack.
  351. push $6 ; push the callback value onto the stack,
  352. Call ResolveFunction ; call the resolveFunction Call.
  353. clearerrors
  354. CopyFiles /SILENT "$1\$4" "$5\$4"
  355. iferrors 0 SRS_RESTORE_ReadLine
  356. ; if still an error, then notify and try next line.
  357. ; MessageBox MB_OK "Error in rolling back file: $1\$4 to $5\$4"
  358. Goto SRS_RESTORE_ReadLine
  359. ; ok, either we parsed the file, or we quit with errors... either way. clean the stack....
  360. SRS_DONE: ; done with readling lines from the file.
  361. Delete "$1\SRS_TempFile.txt"
  362. FileClose $SRS_Rollback_FileHandle
  363. ; Now parse the file name
  364. pop $R4
  365. pop $R3
  366. pop $R2
  367. pop $R1
  368. pop $7
  369. pop $6
  370. pop $5
  371. pop $4
  372. pop $3
  373. pop $2 ;restore $2
  374. pop $1 ;restore $1
  375. pop $0 ; restore $0 to previous value....
  376. return ; end
  377. FunctionEnd
  378. ;!macro moveRollbackArchive _ExistingPath _ExistingLogFile _NewPath
  379. ; ifFileExists "${_ExistingPath}" 0 +2
  380. ; Delete "${_ExistingPath}\*.*"
  381. ; RMDir "${_ExistingPath}"
  382. ; rename "${_ExistingPath}\*.*" "${_NewPath}\*.*"
  383. ; Push "${_ExistingPath}" #text to be replaced
  384. ; Push "${_NewPath}" #replace with
  385. ; Push 0 #replace command
  386. ; Push 1 #replace but only one occurance.. not all close network references....
  387. ; Push "${_NewPath}\${_ExistingLogFile}" #file to replace in
  388. ; Call AdvReplaceInFile ;; it reads the pushed variables as parameters.... ( Hey... I didn't design that interface... its confusing. )
  389. ;
  390. ;!macroend
  391. !macro un.RollBackTo _rollbackLocalPath _rollbackLogName
  392. push `${_rollbackLocalPath}`
  393. push `${_rollbackLogName}`
  394. Call un.RollBack
  395. !macroend
  396. !define un.RollBackTo "!insertmacro un.RollBackTo"
  397. Function un.RollBack
  398. push $0 ; save register 0 on stack. ( So stack looks like $0 "_rollbackLogName" _rollbackLocalPath Rest of Stack.....
  399. Exch ; swap the top two objects on the stack.... _rollbackLogName $0 _rollbackLocalPath
  400. pop $0 ; stack looks like $0.._rollbackLocalPath ...Rest of Stack.... Using $0 to hld the RollBackLogName
  401. push $1 ; stack looks like $1 $0.._rollbackLocalPath Rest of Stack Use this var for handling readlines.
  402. Exch 2 ; stack looks like _rollbackLocalPath $0 $1 Rest of Stack
  403. pop $1 ; Use this var for handling the local path of the list of archived files.
  404. Exch ; stack looks like $1 $0 Rest of Stack
  405. push $2 ; stack look like $2 $1 $0 Rest of stack. Use $2 to hold read lines.....
  406. push $3 ; stack looks like $3 $2 $1 $0 RestofStack. Use this var for handling tag parsing of lines....
  407. push $4 ; saving $4 too... use this var for holding filename of file.
  408. push $5 ; saving $5 too... use this var for holding target path.
  409. push $6 ; use this var for the command line to exeute if failed to copy....
  410. push $7 ; use this var for temp file handle
  411. ; registry temp vars....
  412. push $R1 ; protect this and use for the Root of the registry handles...
  413. push $R2 ; protect this and use for the Key
  414. push $R3 ; protect this and use for the subkey
  415. push $R4 ; protected this and use for the Value.....
  416. ifFileExists "$1\$0" StartRollBack 0
  417. SetErrors
  418. MessageBox MB_OK "Unable to find rollback file for uninstall: $1\$0"
  419. Goto SRS_DONE
  420. Return ; perhaps the user just gave the file folder.... try to locate the .rllbck file in the folder.... if it exists.
  421. StartRollBack:
  422. clearerrors
  423. FileOpen $SRS_Rollback_FileHandle "$1\$0" r ; open file for read.
  424. IfErrors 0 SRS_RESTORE_ReadLine
  425. MessageBox MB_OK "Error opening the file for rollback: $1\$0"
  426. Goto SRS_DONE
  427. SRS_RESTORE_ReadLine:
  428. ClearErrors
  429. FileRead $SRS_Rollback_FileHandle $2 ; get line for parsing.
  430. ;MessageBox MB_OK $2
  431. IfErrors SRS_DONE ; if errors, then EOF. Cleanup stack and exit.
  432. ; otherise parse line.
  433. StrCpy $3 $2 6 ;if this line is a file line, then the first six chars should be <FILE>
  434. ;Handle Registry Alterations:
  435. StrCmp $3 "<REGIS" 0 SRS_RESTORE_TestForFileLine
  436. FileOpen $7 "$1\SRS_TempFile.txt" w
  437. FileWrite $7 $2
  438. FileClose $7
  439. ;<FILE><NEW>1</NEW><NAME>${_someFileName}</NAME><TARGETPATH>$OUTDIR</TARGETPATH><ONFAIL>${_onFailCommand}</ONFAIL></FILE>
  440. ;<REGISTRY><NEW>1</NEW><ROOT>${_RootKey}</ROOT><KEY>${_RegistryKey}</KEY><SUBKEY>${_SubKey}</SUBKEY><VALUE>${_Value}</VALUE></REGISTRY>
  441. #MessageBox MB_OK "$2"
  442. ; Because GetBetween only uses files as sources.... ( stupid, that I'm using that here, but I am.... )
  443. ${un.GetBetween} "<NEW>" "</NEW>" "$1\SRS_TempFile.txt" $4 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  444. #MessageBox MB_OK $4
  445. ${un.GetBetween} "<ROOT>" "</ROOT>" "$1\SRS_TempFile.txt" $R1 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  446. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  447. ${un.GetBetween} "<KEY>" "</KEY>" "$1\SRS_TempFile.txt" $R2 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  448. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  449. ${un.GetBetween} "<SUBKEY>" "</SUBKEY>" "$1\SRS_TempFile.txt" $R3 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  450. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  451. ${un.GetBetween} "<VALUE>" "</VALUE>" "$1\SRS_TempFile.txt" $R4 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  452. #MessageBox MB_OK "$R1,$R2,$R3,$R4"
  453. #MessageBox MB_OK "$1, $4 , $R1 , $R2 , $R3 , $R4"
  454. StrCmp $4 "SRS_RollbackPath" RemoveIt 0
  455. StrCmp $4 "SRS_Logname" RemoveIt 0
  456. StrCmp $4 "1" 0 SRS_RESTORE_WRITE ; if the new marker is set to 1 then a rollback means remove it entirely.....
  457. RemoveIt:
  458. ${Switch} $R1
  459. ${Case} "HKLM"
  460. DeleteRegValue HKLM $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  461. ${Case} "HKCR"
  462. DeleteRegValue HKCR $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  463. ${Case} "HKCU"
  464. DeleteRegValue HKCU $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  465. ${Case} "HKU"
  466. DeleteRegValue HKU $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  467. ${Case} "HKCC"
  468. DeleteRegValue HKCC $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  469. ${Case} "HKDD"
  470. DeleteRegValue HKDD $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  471. ${Case} "HKPD"
  472. DeleteRegValue HKPD $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  473. ${Case} "SHCTX"
  474. DeleteRegValue SHCTX $R2 $R3 ;$R1 $R2 $R3Goto EndSNFServiceTest
  475. ${EndSwitch}
  476. Goto SRS_RESTORE_ReadLine
  477. SRS_RESTORE_WRITE:
  478. ; if not then we need to restore the key.....
  479. ${Switch} $R1
  480. ${Case} "HKLM"
  481. WriteRegStr HKLM $R2 $R3 $R4
  482. ${Case} "HKCR"
  483. WriteRegStr HKCR $R2 $R3 $R4
  484. ${Case} "HKCU"
  485. WriteRegStr HKCU $R2 $R3 $R4
  486. ${Case} "HKU"
  487. WriteRegStr HKU $R2 $R3 $R4
  488. ${Case} "HKCC"
  489. WriteRegStr HKCC $R2 $R3 $R4
  490. ${Case} "HKDD"
  491. WriteRegStr HKDD $R2 $R3 $R4
  492. ${Case} "HKPD"
  493. WriteRegStr HKPD $R2 $R3 $R4
  494. ${Case} "SHCTX"
  495. WriteRegStr SHCTX $R2 $R3 $R4
  496. ${EndSwitch}
  497. Goto SRS_RESTORE_ReadLine
  498. SRS_RESTORE_TestForFileLine:
  499. StrCmp $3 "<FILE>" 0 SRS_RESTORE_ReadLine ; if its a file, then handle rolling back the file, otherwise get the next line.
  500. FileOpen $7 "$1\SRS_TempFile.txt" w
  501. FileWrite $7 $2
  502. FileClose $7
  503. ; Because GetBetween only uses files as sources.... ( stupid, that I'm using that here, but I am.... )
  504. ${un.GetBetween} "<NAME>" "</NAME>" "$1\SRS_TempFile.txt" $4 ; Get the file name between the file tags of the read_line_in->$2 and stick it in $4
  505. ${un.GetBetween} "<NEW>" "</NEW>" "$1\SRS_TempFile.txt" $R1 ; Get the marker that informed us if there WAS something to be copied, or if it was just installed.
  506. ;MessageBox MB_OK "Name:$4"
  507. ${un.GetBetween} "<TARGETPATH>" "</TARGETPATH>" "$1\SRS_TempFile.txt" $5 ; Get the targetpath between the file tags of the read_line_in->$2 and stick it in $5
  508. ;MessageBox MB_OK "Target:$5"
  509. clearerrors
  510. ${un.GetBetween} "<CALLBACK>" "</CALLBACK>" "$1\SRS_TempFile.txt" $6 ; Get the CALLBACK name between the file tags of the read_line_in->$2 and stick it in $6
  511. iferrors NoCallbackAvailable 0
  512. StrCmp $6 "" NoCallbackAvailable 0
  513. ; Ok, we have a callback, so we don't copy, we call file, and pass the filename.
  514. ;MessageBox MB_OK "Pushing $1\$4"
  515. push "$1\$4" ; push the file and path onto the stack.
  516. push $6 ; push the calback value onto the stack,
  517. Call un.ResolveFunction ; call the resolveFunction Call.
  518. Goto SRS_RESTORE_ReadLine ; No copy, just return for next line handle.
  519. NoCallbackAvailable:
  520. ; now deal with new vs archived files...
  521. StrCmp $R1 "1" 0 SRS_NOTNEW_RESTOREIT ; test to see if it was new, or if it required backin gup...
  522. ifFileExists "$5\$4" 0 SRS_RESTORE_ReadLine ; if it WAS new... test to see if file still exists...
  523. Delete "$5\$4" ; Since it was new we'll remove it on a restore....
  524. Goto SRS_RESTORE_ReadLine
  525. SRS_NOTNEW_RESTOREIT:
  526. CopyFiles /SILENT "$1\$4" "$5\$4"
  527. iferrors 0 SRS_RESTORE_ReadLine
  528. clearerrors
  529. ${un.GetBetween} "<ONFAIL>" "</ONFAIL>" "$1\SRS_TempFile.txt" $6 ; Get the onfail name between the file tags of the read_line_in->$2 and stick it in $6
  530. ; if we're here, then we need to rexecute the copy after executing the command line
  531. push "$1\$4" ; push the file and path onto the stack.
  532. push $6 ; push the callback value onto the stack,
  533. Call un.ResolveFunction ; call the resolveFunction Call.
  534. clearerrors
  535. CopyFiles /SILENT "$1\$4" "$5\$4"
  536. iferrors 0 SRS_RESTORE_ReadLine
  537. ; if still an error, then notify and try next line.
  538. ; MessageBox MB_OK "Error in rolling back file: $1\$4 to $5\$4"
  539. Goto SRS_RESTORE_ReadLine
  540. ; ok, either we parsed the file, or we quit with errors... either way. clean the stack....
  541. SRS_DONE: ; done with readling lines from the file.
  542. Delete "$1\SRS_TempFile.txt"
  543. FileClose $SRS_Rollback_FileHandle
  544. ; Now parse the file name
  545. pop $R4
  546. pop $R3
  547. pop $R2
  548. pop $R1
  549. pop $7
  550. pop $6
  551. pop $5
  552. pop $4
  553. pop $3
  554. pop $2 ;restore $2
  555. pop $1 ;restore $1
  556. pop $0 ; restore $0 to previous value....
  557. return ; end
  558. FunctionEnd