Advertisement
tolikpunkoff

NSIS: Patch/Restore code fragment

Mar 29th, 2023
1,691
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;Patch/Restore...
  2. ${If} $FILEMD5 == $MD5ORIG ;Original file. Patch.
  3.     MessageBox MB_YESNO|MB_ICONQUESTION "Patch file?" IDYES 0 IDNO EndProg
  4.     !insertmacro BackupFile
  5.     GetTempFileName $R0
  6.     vpatch::vpatchfile "change.pat" "$INSTDIR\$TARGETFILE" "$R0"
  7.     Pop $R1
  8.     DetailPrint "Patch:"
  9.     DetailPrint "$R1"
  10.     CopyFiles "$R0" "$INSTDIR\$TARGETFILE"
  11.     IfErrors CopyError 0 ;check copy file error
  12.     Delete "$R0" ;remove temporary file
  13. ${Else}
  14.     ${If} $FILEMD5 == $MD5PATCH ; Patched file. Restore.
  15.         MessageBox MB_YESNO|MB_ICONQUESTION "File patched! Restore original?"  IDYES 0 IDNO EndProg
  16.         !insertmacro BackupFile
  17.         GetTempFileName $R0
  18.         vpatch::vpatchfile "restore.pat" "$INSTDIR\$TARGETFILE" "$R0"
  19.         Pop $R1
  20.         DetailPrint "Restore:"
  21.         DetailPrint "$R1"
  22.         CopyFiles "$R0" "$INSTDIR\$TARGETFILE"
  23.         IfErrors CopyError 0 ;check copy file error
  24.         Delete "$R0" ;remove temporary file
  25.     ${Else} ;Other checksum, wrong file
  26.         MessageBox MB_ICONSTOP "Unknown or wrong file $INSTDIR\$TARGETFILE. Bad checksum."
  27.         DetailPrint "ERROR: Unknown or wrong file $TARGETFILE. Bad checksum. "
  28.         Goto EndProg
  29.     ${EndIf}
  30. ${EndIf}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement