Advertisement
Guest User

Tobbe

a guest
Nov 29th, 2007
1,246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;_____________________________ HEADER FILE BEGIN ____________________________
  2.  
  3. # Advanced Uninstall Log NSIS header
  4. # Version 1.0 2007-01-31
  5. # By Red Wine (http://nsis.sf.net/User:Red_Wine)
  6.  
  7. # Usage: See included examples Uninstall_Log_Default_UI.nsi - Uninstall_Log_Modern_UI.nsi
  8.  
  9. !verbose push
  10. !verbose 3
  11.  
  12. !ifndef ADVANCED_UNINSTALL.LOG_NSH
  13.     !define ADVANCED_UNINSTALL.LOG_NSH
  14.  
  15.     !ifndef INSTDIR_REG_ROOT | INSTDIR_REG_KEY
  16.         !error "You must properly define both INSTDIR_REG_ROOT and INSTDIR_REG_KEY"
  17.     !endif
  18.  
  19.     !ifndef UNINSTALL_LOG
  20.         !define UNINSTALL_LOG "Uninstall"
  21.     !endif
  22.  
  23.     !ifndef UNINST_LOG_VERBOSE
  24.         !define UNINST_LOG_VERBOSE "3"
  25.     !endif
  26.  
  27.     !verbose pop
  28.  
  29.     !echo "Advanced Uninstall Log NSIS header v1.0 2007-01-31 by Red Wine (http://nsis.sf.net/User:Red_Wine)"
  30.  
  31.     !verbose push
  32.     !verbose ${UNINST_LOG_VERBOSE}
  33.  
  34.     var unlog_header
  35.     var unlog_dat_not_found
  36.     var unlog_del_file
  37.     var unlog_del_dir
  38.     var unlog_empty_dir
  39.     var unlog_error_log
  40.     var unlog_error_create
  41.  
  42.     !define UNINST_EXE "$INSTDIR\${UNINSTALL_LOG}.exe"
  43.     !define UNINST_DAT "$INSTDIR\${UNINSTALL_LOG}.dat"
  44.     !define UNLOG_PART "$PLUGINSDIR\part."
  45.     !define UNLOG_TEMP "$PLUGINSDIR\unlog.tmp"
  46.     !define EXCLU_LIST "$PLUGINSDIR\exclude.tmp"
  47.     !define UNLOG_HEAD "$unlog_header"
  48.  
  49.     var unlog_tmp_0
  50.     var unlog_tmp_1
  51.     var unlog_tmp_2
  52.     var unlog_tmp_3
  53.     var unlog_error
  54.  
  55.     !include FileFunc.nsh
  56.     !include TextFunc.nsh
  57.    
  58.     !insertmacro Locate
  59.     !insertmacro un.Locate
  60.     !insertmacro DirState
  61.     !insertmacro un.DirState
  62.     !insertmacro FileJoin
  63.     !insertmacro TrimNewLines
  64.     !insertmacro un.TrimNewLines
  65.    
  66.     ;.............................. Uninstaller Macros ..............................
  67.    
  68.     !macro UNINSTALL.LOG_BEGIN_UNINSTALL
  69.         !verbose push
  70.         !verbose ${UNINST_LOG_VERBOSE}
  71.    
  72.         IfFileExists "${UNINST_DAT}" +3
  73.         MessageBox MB_ICONSTOP|MB_OK $unlog_dat_not_found /SD IDOK
  74.         Quit
  75.    
  76.         StrCmp "$PLUGINSDIR" "" 0 +2
  77.         InitPluginsDir
  78.    
  79.         CopyFiles "${UNINST_DAT}" "${UNLOG_TEMP}"
  80.         FileOpen $unlog_tmp_2 "${UNLOG_TEMP}" r
  81.    
  82.         !verbose pop
  83.     !macroend
  84.    
  85.     !macro UNINSTALL.LOG_END_UNINSTALL
  86.         !verbose push
  87.         !verbose ${UNINST_LOG_VERBOSE}
  88.    
  89.         FileClose $unlog_tmp_2
  90.         DeleteRegValue ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}.dat"
  91.         DeleteRegValue ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}Directory"
  92.    
  93.         !verbose pop
  94.     !macroend
  95.    
  96.     !macro UNINSTALL.LOG_UNINSTALL TargetDir
  97.         !verbose push
  98.         !verbose ${UNINST_LOG_VERBOSE}
  99.    
  100.         !ifndef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
  101.             !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
  102.         !endif
  103.    
  104.         !ifdef INTERACTIVE_UNINSTALL
  105.             GetTempFileName $unlog_tmp_5 "$PLUGINSDIR"
  106.             FileOpen $unlog_tmp_4 "$unlog_tmp_5" a
  107.         !endif
  108.    
  109.         ${PerfomUninstall} "${TargetDir}" "${UnLog_Uninstall_CallBackFunc}"
  110.    
  111.         !ifdef INTERACTIVE_UNINSTALL
  112.             FileClose $unlog_tmp_4
  113.         !endif
  114.    
  115.         !verbose pop
  116.     !macroend
  117.    
  118.     !define PerfomUninstall "!insertmacro PERFORMUNINSTALL"
  119.    
  120.     !macro PERFORMUNINSTALL TargetDir UninstCallBackFunc
  121.         !verbose push
  122.         !verbose ${UNINST_LOG_VERBOSE}
  123.    
  124.         !define ID ${__LINE__}
  125.    
  126.         ${un.Locate} "${TargetDir}" "/L=F" "${UninstCallBackFunc}"
  127.    
  128.         loop_${ID}:
  129.    
  130.         StrCpy $unlog_tmp_1 0
  131.    
  132.         ${un.Locate} "${TargetDir}" "/L=DE" "${UninstCallBackFunc}"
  133.         StrCmp $unlog_tmp_1 "0" 0 loop_${ID}
  134.    
  135.         ${un.DirState} "${TargetDir}" $unlog_tmp_0
  136.         StrCmp "$unlog_tmp_0" "0" 0 +2
  137.         RmDir "${TargetDir}"
  138.    
  139.         IfErrors 0 +2
  140.         MessageBox MB_ICONEXCLAMATION|MB_OK "$unlog_error_log" /SD IDOK
  141.    
  142.         !undef ID
  143.    
  144.         !verbose pop
  145.     !macroend
  146.    
  147.     !macro INTERACTIVE_UNINSTALL
  148.         !verbose push
  149.         !verbose ${UNINST_LOG_VERBOSE}
  150.    
  151.         !ifdef INTERACTIVE_UNINSTALL
  152.             !error "INTERACTIVE_UNINSTALL is already defined"
  153.         !endif
  154.    
  155.         var unlog_tmp_4
  156.         var unlog_tmp_5
  157.    
  158.         !define INTERACTIVE_UNINSTALL
  159.    
  160.         !ifdef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
  161.             !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
  162.         !endif
  163.    
  164.         !ifdef UnLog_Uninstall_CallBackFunc
  165.             !undef UnLog_Uninstall_CallBackFunc
  166.         !endif
  167.    
  168.         !ifndef UnLog_Uninstall_CallBackFunc
  169.             !insertmacro UNINSTALL.LOG_UNINSTALL_INTERACTIVE
  170.             !define UnLog_Uninstall_CallBackFunc "un._LocateCallBack_Function_Interactive"
  171.         !endif
  172.    
  173.         !verbose pop
  174.     !macroend
  175.    
  176.     !macro UNATTENDED_UNINSTALL
  177.         !verbose push
  178.         !verbose ${UNINST_LOG_VERBOSE}
  179.    
  180.         !ifdef UNATTENDED_UNINSTALL
  181.             !error "UNATTENDED_UNINSTALL is already defined"
  182.         !endif
  183.    
  184.         !define UNATTENDED_UNINSTALL
  185.    
  186.         !ifdef INTERACTIVE_UNINSTALL & UNATTENDED_UNINSTALL
  187.             !error "You must insert either Interactive or Unattended Uninstall neither both, neither none."
  188.         !endif
  189.    
  190.         !ifdef UnLog_Uninstall_CallBackFunc
  191.             !undef UnLog_Uninstall_CallBackFunc
  192.         !endif
  193.    
  194.         !ifndef UnLog_Uninstall_CallBackFunc
  195.             !insertmacro UNINSTALL.LOG_UNINSTALL_UNATTENDED
  196.             !define UnLog_Uninstall_CallBackFunc "un._LocateCallBack_Function_Unattended"
  197.         !endif
  198.    
  199.         !verbose pop
  200.     !macroend
  201.    
  202.     !macro UNINSTALL.LOG_UNINSTALL_UNATTENDED
  203.         Function un._LocateCallBack_Function_Unattended
  204.             start:
  205.                 FileRead $unlog_tmp_2 "$unlog_tmp_3" ${NSIS_MAX_STRLEN}
  206.                 ${un.TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
  207.                 StrCmp "$unlog_tmp_3" "$R9" islog
  208.                 IfErrors nolog
  209.                 goto start
  210.        
  211.             islog:
  212.                 IfFileExists "$R9\*.*" isdir
  213.        
  214.             isfile:
  215.                 Delete "$R9"
  216.                 goto end
  217.        
  218.             isdir:
  219.                 RmDir "$R9"
  220.                 IntOp $unlog_tmp_1 $unlog_tmp_1 + 1
  221.                 goto end
  222.        
  223.             nolog:
  224.                 ClearErrors
  225.                 StrCmp "$R9" "${UNINST_EXE}" isfile
  226.                 StrCmp "$R9" "${UNINST_DAT}" isfile
  227.        
  228.             end:
  229.             FileSeek $unlog_tmp_2 0 SET
  230.             Push $unlog_tmp_0
  231.         FunctionEnd
  232.     !macroend
  233.    
  234.     !macro UNINSTALL.LOG_UNINSTALL_INTERACTIVE
  235.         Function un._LocateCallBack_Function_Interactive
  236.             start:
  237.                 FileRead $unlog_tmp_2 "$unlog_tmp_3" ${NSIS_MAX_STRLEN}
  238.                 ${un.TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
  239.                 StrCmp "$unlog_tmp_3" "$R9" islog
  240.                 IfErrors nolog
  241.                 goto start
  242.    
  243.             islog:
  244.                 IfFileExists "$R9\*.*" isdir
  245.    
  246.             isfile:
  247.                 Delete "$R9"
  248.                 goto end
  249.    
  250.             isdir:
  251.                 RmDir "$R9"
  252.                 IntOp $unlog_tmp_1 $unlog_tmp_1 + 1
  253.                 goto end
  254.    
  255.             nolog:
  256.                 ClearErrors
  257.                 FileSeek $unlog_tmp_4 0 SET
  258.             read:
  259.                 FileRead $unlog_tmp_4 "$unlog_tmp_3"
  260.                 ${un.TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
  261.                 StrCmp "$unlog_tmp_3" "$R9" end
  262.                 IfErrors +2
  263.                 goto read
  264.                 ClearErrors
  265.                 StrCmp "$R9" "${UNINST_EXE}" isfile
  266.                 StrCmp "$R9" "${UNINST_DAT}" isfile
  267.                 IfFileExists "$R9\*.*" msgdir
  268.    
  269.                 MessageBox MB_ICONQUESTION|MB_YESNO "$unlog_del_file" /SD IDNO IDYES isfile IDNO nodel
  270.                 msgdir:
  271.                     MessageBox MB_ICONQUESTION|MB_YESNO "$unlog_del_dir" /SD IDNO IDYES isdir IDNO nodel
  272.    
  273.             nodel:
  274.                 FileSeek $unlog_tmp_4 0 END
  275.                 FileWrite $unlog_tmp_4 "$R9$\r$\n"
  276.    
  277.             end:
  278.             FileSeek $unlog_tmp_2 0 SET
  279.             Push $unlog_tmp_0
  280.         FunctionEnd
  281.     !macroend
  282.    
  283.     ;................................. Installer Macros .................................
  284.    
  285.     !macro UNINSTALL.LOG_INSTALL_UNATTENDED
  286.         Function _LocateCallBack_Function_Install
  287.             loop:
  288.                 FileRead $unlog_tmp_2 "$unlog_tmp_3" ${NSIS_MAX_STRLEN}
  289.                 ${TrimNewLines} "$unlog_tmp_3" "$unlog_tmp_3"
  290.                 IfErrors 0 +4
  291.                 ClearErrors
  292.                 FileSeek $unlog_tmp_2 0 SET
  293.                 goto next
  294.                 StrCmp "$R9" "$unlog_tmp_3" end
  295.                 goto loop
  296.             next:
  297.                 FileWrite $unlog_tmp_1 "$R9$\r$\n"
  298.             end:
  299.             Push $unlog_tmp_0
  300.         FunctionEnd
  301.     !macroend
  302.    
  303.     !ifdef UnLog_Install_Func_CallBack
  304.         !undef UnLog_Install_Func_CallBack
  305.     !endif
  306.    
  307.     !ifndef UnLog_Install_Func_CallBack
  308.         !insertmacro UNINSTALL.LOG_INSTALL_UNATTENDED
  309.         !define UnLog_Install_Func_CallBack "_LocateCallBack_Function_Install"
  310.     !endif
  311.    
  312.     !macro UNINSTALL.LOG_PREPARE_INSTALL
  313.         !verbose push
  314.         !verbose ${UNINST_LOG_VERBOSE}
  315.    
  316.         Push $0
  317.         Push $1
  318.         ClearErrors
  319.         ReadRegStr "$0"  ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}Directory"
  320.         IfErrors next
  321.         ${DirState} "$0" $1
  322.         StrCmp "$1" "-1" next
  323.         StrCmp "$1" "0" next
  324.         IfFileExists "$0\${UNINSTALL_LOG}.dat" next
  325.         MessageBox MB_ICONEXCLAMATION|MB_OK "$unlog_empty_dir" /SD IDOK
  326.         StrCpy $unlog_error "error"
  327.    
  328.         next:
  329.         ClearErrors
  330.         StrCmp "$PLUGINSDIR" "" 0 +2
  331.             InitPluginsDir
  332.  
  333.         StrCpy $unlog_header "=========== Uninstaller Log please do not edit this file ==========="
  334.         StrCpy $unlog_dat_not_found "${UNINST_DAT} not found, unable to perform uninstall."
  335.         StrCpy $unlog_del_file 'Delete File "$R9"?'
  336.         StrCpy $unlog_del_dir 'Delete Directory "$R9"?'
  337.         StrCpy $unlog_empty_dir "Previous installation detected at $0.$\nRequired file ${UNINSTALL_LOG}.dat is missing.$\n$\nIt is highly recommended to select an empty directory and perform a fresh installation."
  338.         StrCpy $unlog_error_log "Error in log ${UNINSTALL_LOG}."
  339.         StrCpy $unlog_error_create "Error creating ${UNINSTALL_LOG}."
  340.  
  341.         !ifdef UNINSTALLOG_LOCALIZE ; Needed to get rid of compiler warnings when not doing any localization
  342.             StrCmp $(UNLOG_HEADER) "" +2 0
  343.                 StrCpy $unlog_header $(UNLOG_HEADER)
  344.             StrCmp $(UNLOG_DAT_NOT_FOUND) "" +2 0
  345.                 StrCpy $unlog_dat_not_found $(UNLOG_DAT_NOT_FOUND)
  346.             StrCmp $(UNLOG_DEL_FILE) "" +2 0
  347.                 StrCpy $unlog_del_file $(UNLOG_DEL_FILE)
  348.             StrCmp $(UNLOG_DEL_DIR) "" +2 0
  349.                 StrCpy $unlog_del_dir $(UNLOG_DEL_DIR)
  350.             StrCmp $(UNLOG_EMPTY_DIR) "" +2 0
  351.                 StrCpy $unlog_empty_dir $(UNLOG_EMPTY_DIR)
  352.             StrCmp $(UNLOG_ERROR_LOG) "" +2 0
  353.                 StrCpy $unlog_error_log $(UNLOG_ERROR_LOG)
  354.             StrCmp $(UNLOG_ERROR_CREATE) "" +2 0
  355.                 StrCpy $unlog_error_create $(UNLOG_ERROR_CREATE)
  356.         !endif
  357.  
  358.         GetTempFileName "$1"
  359.         FileOpen $0 "$1" w
  360.         FileWrite $0 "${UNLOG_HEAD}$\r$\n"
  361.         FileClose $0
  362.         Rename "$1" "${UNLOG_TEMP}"
  363.         Pop $1
  364.         Pop $0
  365.    
  366.         !verbose pop
  367.     !macroend
  368.    
  369.     !macro UNINSTALL.LOG_UPDATE_INSTALL
  370.         !verbose push
  371.         !verbose ${UNINST_LOG_VERBOSE}
  372.    
  373.         Delete "${UNINST_DAT}"
  374.         Rename "${UNLOG_TEMP}" "${UNINST_DAT}"
  375.         WriteUninstaller "${UNINST_EXE}"
  376.         WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}.dat" "${UNINST_DAT}"
  377.         WriteRegStr ${INSTDIR_REG_ROOT} "${INSTDIR_REG_KEY}" "${UNINSTALL_LOG}Directory" "$INSTDIR"
  378.    
  379.         !verbose pop
  380.     !macroend
  381.    
  382.     !define uninstall.log_install "!insertmacro UNINSTALL.LOG_INSTALL"
  383.    
  384.     !macro UNINSTALL.LOG_INSTALL FileOpenWrite FileOpenRead TargetDir
  385.         !verbose push
  386.         !verbose ${UNINST_LOG_VERBOSE}
  387.    
  388.         FileOpen $unlog_tmp_1 "${FileOpenWrite}" w
  389.         FileOpen $unlog_tmp_2 "${FileOpenRead}" r
  390.    
  391.         ${Locate} "${TargetDir}" "/L=FD" "${UnLog_Install_Func_CallBack}"
  392.    
  393.         StrCmp $unlog_error "error" 0 +2
  394.         ClearErrors
  395.    
  396.         IfErrors 0 +2
  397.         MessageBox MB_ICONEXCLAMATION|MB_OK "$unlog_error_create" /SD IDOK
  398.    
  399.         FileClose $unlog_tmp_1
  400.         FileClose $unlog_tmp_2
  401.    
  402.         !verbose pop
  403.     !macroend
  404.    
  405.     !define uninstall.log_mergeID "!insertmacro UNINSTALL.LOG_MERGE"
  406.    
  407.     !macro UNINSTALL.LOG_MERGE UnlogPart
  408.         !verbose push
  409.         !verbose ${UNINST_LOG_VERBOSE}
  410.    
  411.         ${FileJoin} "${UNLOG_TEMP}" "${UnlogPart}" "${UNLOG_TEMP}"
  412.    
  413.         !verbose pop
  414.     !macroend
  415.    
  416.     !macro UNINSTALL.LOG_OPEN_INSTALL
  417.         !verbose push
  418.         !verbose ${UNINST_LOG_VERBOSE}
  419.    
  420.         StrCmp $unlog_error "error" +2
  421.         ${uninstall.log_install} "${EXCLU_LIST}" "${UNINST_DAT}" "$OUTDIR"
  422.    
  423.         !verbose pop
  424.     !macroend
  425.    
  426.    
  427.     !macro UNINSTALL.LOG_CLOSE_INSTALL
  428.         !verbose push
  429.         !verbose ${UNINST_LOG_VERBOSE}
  430.    
  431.         !define ID ${__LINE__}
  432.    
  433.         ${uninstall.log_install} "${UNLOG_PART}${ID}" "${EXCLU_LIST}" "$OUTDIR"
  434.         ${uninstall.log_mergeID} "${UNLOG_PART}${ID}"
  435.    
  436.         !undef ID ${__LINE__}
  437.    
  438.         !verbose pop
  439.     !macroend
  440. !endif
  441.  
  442. !verbose pop
  443. ;_____________________________ HEADER FILE END ____________________________
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement