📄 installer.nsi
字号:
FileWrite $0 'smartctl</MITEM>$\r$\n$\t</MENU>$\r$\n</NU2MENU>$\r$\n' FileClose $0 SetOutPath "$UBCDDIR\files" DetailPrint "Create file: smartctl-run.bat" Push "$UBCDDIR\files\smartctl-run.bat" Call CreateSmartctlBat File "${INPDIR}\bin\smartctl.exe" File "${INPDIR}\bin\smartd.exe" File "${INPDIR}\doc\smartctl.8.html" File "${INPDIR}\doc\smartctl.8.txt" File "${INPDIR}\doc\smartd.8.html" File "${INPDIR}\doc\smartd.8.txt" File "${INPDIR}\doc\smartd.conf"SectionEnd;--------------------------------------------------------------------Section "Uninstall" ; Stop & remove service IfFileExists "$INSTDIR\bin\smartd.exe" 0 nosrv ReadRegStr $0 HKLM "System\CurrentControlSet\Services\smartd" "ImagePath" StrCmp $0 "" nosrv ExecWait "net stop smartd" MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Remove smartd service ?" IDYES 0 IDNO nosrv ExecWait "$INSTDIR\bin\smartd.exe remove" nosrv: ; Remove installer registry keys DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\smartmontools" DeleteRegKey HKLM "Software\smartmontools" ; Remove conf and log file IfFileExists "$INSTDIR\bin\smartd.conf" 0 noconf ; Assume unchanged if timestamp is equal to sample file GetFileTime "$INSTDIR\bin\smartd.conf" $0 $1 GetFileTime "$INSTDIR\doc\smartd.conf" $2 $3 StrCmp "$0:$1" "$2:$3" +2 0 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete configuration file$\n$INSTDIR\bin\smartd.conf ?" IDYES 0 IDNO noconf Delete "$INSTDIR\bin\smartd.conf" noconf: IfFileExists "$INSTDIR\bin\smartd.log" 0 +3 MessageBox MB_YESNO|MB_ICONQUESTION|MB_DEFBUTTON2 "Delete log file$\n$INSTDIR\bin\smartd.log ?" IDYES 0 IDNO +2 Delete "$INSTDIR\bin\smartd.log" ; Remove files Delete "$INSTDIR\bin\smartctl.exe" Delete "$INSTDIR\bin\smartd.exe" Delete "$INSTDIR\bin\syslogevt.exe" Delete "$INSTDIR\bin\smartctl-run.bat" Delete "$INSTDIR\bin\smartd-run.bat" Delete "$INSTDIR\bin\net-run.bat" Delete "$INSTDIR\doc\AUTHORS.txt" Delete "$INSTDIR\doc\CHANGELOG.txt" Delete "$INSTDIR\doc\COPYING.txt" Delete "$INSTDIR\doc\INSTALL.txt" Delete "$INSTDIR\doc\NEWS.txt" Delete "$INSTDIR\doc\README.txt" Delete "$INSTDIR\doc\TODO.txt" Delete "$INSTDIR\doc\WARNINGS.txt" Delete "$INSTDIR\doc\smartctl.8.html" Delete "$INSTDIR\doc\smartctl.8.txt" Delete "$INSTDIR\doc\smartd.8.html" Delete "$INSTDIR\doc\smartd.8.txt" Delete "$INSTDIR\doc\smartd.conf" Delete "$INSTDIR\doc\smartd.conf.5.html" Delete "$INSTDIR\doc\smartd.conf.5.txt" Delete "$INSTDIR\uninst-smartmontools.exe" ; Remove shortcuts Delete "$SMPROGRAMS\smartmontools\*.*" Delete "$SMPROGRAMS\smartmontools\Documentation\*.*" Delete "$SMPROGRAMS\smartmontools\smartctl Examples\*.*" Delete "$SMPROGRAMS\smartmontools\smartd Examples\*.*" ; Remove folders RMDir "$SMPROGRAMS\smartmontools\Documentation" RMDir "$SMPROGRAMS\smartmontools\smartctl Examples" RMDir "$SMPROGRAMS\smartmontools\smartd Examples" RMDir "$SMPROGRAMS\smartmontools" RMDir "$INSTDIR\bin" RMDir "$INSTDIR\doc" RMDir "$INSTDIR" ; Remove install dir from PATH IfFileExists "$WINDIR\system32\cmd.exe" 0 +3 Push "$INSTDIR\bin" Call un.RemoveFromPath ; Remove drive menu registry entries !insertmacro DriveMenuRemove ; Check for still existing entries IfFileExists "$INSTDIR\bin\smartd.exe" 0 +3 MessageBox MB_OK|MB_ICONEXCLAMATION "$INSTDIR\bin\smartd.exe could not be removed.$\nsmartd is possibly still running." Goto +3 IfFileExists "$INSTDIR" 0 +2 MessageBox MB_OK "Note: $INSTDIR could not be removed." IfFileExists "$SMPROGRAMS\smartmontools" 0 +2 MessageBox MB_OK "Note: $SMPROGRAMS\smartmontools could not be removed."SectionEnd;--------------------------------------------------------------------; FunctionsFunction .onInit ; Get UBCD4Win install location ReadRegStr $0 HKLM "Software\UBCD4Win" "InstallPath" StrCmp $0 "" 0 +2 StrCpy $0 "C:\UBCD4Win" StrCpy $UBCDDIR "$0\plugin\Disk\Diagnostic\smartmontools" ; Hide "Add install dir to PATH" on 9x/ME IfFileExists "$WINDIR\system32\cmd.exe" +2 0 SectionSetText ${PATH_SECTION} ""FunctionEnd; Directory page callbacks!macro CheckSection section SectionGetFlags ${section} $0 IntOp $0 $0 & 1 IntCmp $0 1 done!macroendFunction SkipProgPath !insertmacro CheckSection ${SMARTCTL_SECTION} !insertmacro CheckSection ${SMARTD_SECTION} !insertmacro CheckSection ${DOC_SECTION} !insertmacro CheckSection ${MENU_SECTION} !insertmacro CheckSection ${PATH_SECTION} !insertmacro CheckSection ${DRIVE_0_SECTION} !insertmacro CheckSection ${DRIVE_1_SECTION} !insertmacro CheckSection ${DRIVE_2_SECTION} !insertmacro CheckSection ${DRIVE_3_SECTION} !insertmacro CheckSection ${DRIVE_4_SECTION} !insertmacro CheckSection ${DRIVE_5_SECTION} Abortdone:FunctionEndFunction SkipUBCDPath !insertmacro CheckSection ${UBCD_SECTION} Abortdone:FunctionEnd; Create smartctl-run.batFunction CreateSmartctlBat Exch $0 FileOpen $0 $0 "w" FileWrite $0 '@echo off$\r$\nif not "%1" == "" goto run$\r$\n' FileWrite $0 'echo Examples (for first drive):$\r$\n' FileWrite $0 'echo smartctl -i sda Show identify information$\r$\n' FileWrite $0 'echo smartctl -H sda Show SMART health status$\r$\n' FileWrite $0 'echo smartctl -c sda Show SMART capabilities$\r$\n' FileWrite $0 'echo smartctl -A sda Show SMART attributes$\r$\n' FileWrite $0 'echo smartctl -l error sda Show error log$\r$\n' FileWrite $0 'echo smartctl -l selftest sda Show self-test log$\r$\n' FileWrite $0 'echo smartctl -a sda Show all of the above$\r$\n' FileWrite $0 'echo smartctl -t short sda Start short self test$\r$\n' FileWrite $0 'echo smartctl -t long sda Start long self test$\r$\n' FileWrite $0 'echo Use "sdb", "sdc", ... for second, third, ... drive.$\r$\n' FileWrite $0 'echo See man page (smartctl.8.*) for further info.$\r$\n' FileWrite $0 'goto end$\r$\n:run$\r$\n' FileWrite $0 'echo smartctl %1 %2 %3 %4 %5$\r$\n' FileWrite $0 'smartctl %1 %2 %3 %4 %5$\r$\n' FileWrite $0 'pause$\r$\n:end$\r$\n' FileClose $0 Pop $0FunctionEnd;--------------------------------------------------------------------; Path functions;; Based on example from:; http://nsis.sourceforge.net/Path_Manipulation;!include "WinMessages.nsh"; Registry Entry for environment (NT4,2000,XP); All users:;!define Environ 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'; Current user only:!define Environ 'HKCU "Environment"'; AddToPath - Appends dir to PATH; (does not work on Win9x/ME);; Usage:; Push "dir"; Call AddToPathFunction AddToPath Exch $0 Push $1 Push $2 Push $3 ReadRegStr $1 ${Environ} "PATH" Push "$1;" Push "$0;" Call StrStr Pop $2 StrCmp $2 "" 0 done Push "$1;" Push "$0\;" Call StrStr Pop $2 StrCmp $2 "" 0 done DetailPrint "Add to PATH: $0" StrCpy $2 $1 1 -1 StrCmp $2 ";" 0 +2 StrCpy $1 $1 -1 ; remove trailing ';' StrCmp $1 "" +2 ; no leading ';' StrCpy $0 "$1;$0" WriteRegExpandStr ${Environ} "PATH" $0 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000done: Pop $3 Pop $2 Pop $1 Pop $0FunctionEnd; RemoveFromPath - Removes dir from PATH;; Usage:; Push "dir"; Call RemoveFromPathFunction un.RemoveFromPath Exch $0 Push $1 Push $2 Push $3 Push $4 Push $5 Push $6 ReadRegStr $1 ${Environ} "PATH" StrCpy $5 $1 1 -1 StrCmp $5 ";" +2 StrCpy $1 "$1;" ; ensure trailing ';' Push $1 Push "$0;" Call un.StrStr Pop $2 ; pos of our dir StrCmp $2 "" done DetailPrint "Remove from PATH: $0" StrLen $3 "$0;" StrLen $4 $2 StrCpy $5 $1 -$4 ; $5 is now the part before the path to remove StrCpy $6 $2 "" $3 ; $6 is now the part after the path to remove StrCpy $3 "$5$6" StrCpy $5 $3 1 -1 StrCmp $5 ";" 0 +2 StrCpy $3 $3 -1 ; remove trailing ';' WriteRegExpandStr ${Environ} "PATH" $3 SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000done: Pop $6 Pop $5 Pop $4 Pop $3 Pop $2 Pop $1 Pop $0FunctionEnd ; StrStr - find substring in a string;; Usage:; Push "this is some string"; Push "some"; Call StrStr; Pop $0 ; "some string"!macro StrStr unFunction ${un}StrStr Exch $R1 ; $R1=substring, stack=[old$R1,string,...] Exch ; stack=[string,old$R1,...] Exch $R2 ; $R2=string, stack=[old$R2,old$R1,...] Push $R3 Push $R4 Push $R5 StrLen $R3 $R1 StrCpy $R4 0 ; $R1=substring, $R2=string, $R3=strlen(substring) ; $R4=count, $R5=tmp loop: StrCpy $R5 $R2 $R3 $R4 StrCmp $R5 $R1 done StrCmp $R5 "" done IntOp $R4 $R4 + 1 Goto loopdone: StrCpy $R1 $R2 "" $R4 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Exch $R1 ; $R1=old$R1, stack=[result,...]FunctionEnd!macroend!insertmacro StrStr ""!insertmacro StrStr "un."
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -