|
| 1 | +; NetworkMonitor Installer Script |
| 2 | +; One-Click Installation for Non-Technical Users |
| 3 | + |
| 4 | +!include "MUI2.nsh" |
| 5 | +!include "LogicLib.nsh" |
| 6 | +!include "WinVer.nsh" |
| 7 | +!include "x64.nsh" |
| 8 | + |
| 9 | +; Product info |
| 10 | +!define PRODUCT_NAME "NetworkMonitor" |
| 11 | +!define PRODUCT_VERSION "0.1.0" |
| 12 | +!define PRODUCT_PUBLISHER "NetworkMonitor" |
| 13 | +!define PRODUCT_WEB_SITE "https://github.com/umerfarok/networkmonitor" |
| 14 | +!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\NetworkMonitor.exe" |
| 15 | +!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" |
| 16 | + |
| 17 | +; Modern UI settings |
| 18 | +!define MUI_ABORTWARNING |
| 19 | +!define MUI_ICON "assets\icon.ico" |
| 20 | +!define MUI_UNICON "assets\icon.ico" |
| 21 | + |
| 22 | +; Welcome page customization |
| 23 | +!define MUI_WELCOMEPAGE_TITLE "Welcome to NetworkMonitor" |
| 24 | +!define MUI_WELCOMEPAGE_TEXT "This wizard will install NetworkMonitor on your computer.$\r$\n$\r$\nNetworkMonitor lets you:$\r$\n• See all devices on your network$\r$\n• Control device connections$\r$\n• Monitor bandwidth usage$\r$\n$\r$\nClick Next to continue." |
| 25 | + |
| 26 | +; Finish page - auto launch |
| 27 | +!define MUI_FINISHPAGE_RUN "$INSTDIR\NetworkMonitor.exe" |
| 28 | +!define MUI_FINISHPAGE_RUN_TEXT "Launch NetworkMonitor now" |
| 29 | +!define MUI_FINISHPAGE_SHOWREADME "" |
| 30 | +!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED |
| 31 | +!define MUI_FINISHPAGE_LINK "Visit NetworkMonitor Website" |
| 32 | +!define MUI_FINISHPAGE_LINK_LOCATION "${PRODUCT_WEB_SITE}" |
| 33 | + |
| 34 | +; Installer pages - simplified for non-technical users |
| 35 | +!insertmacro MUI_PAGE_WELCOME |
| 36 | +!insertmacro MUI_PAGE_INSTFILES |
| 37 | +!insertmacro MUI_PAGE_FINISH |
| 38 | + |
| 39 | +; Uninstaller pages |
| 40 | +!insertmacro MUI_UNPAGE_CONFIRM |
| 41 | +!insertmacro MUI_UNPAGE_INSTFILES |
| 42 | + |
| 43 | +; Language |
| 44 | +!insertmacro MUI_LANGUAGE "English" |
| 45 | + |
| 46 | +; Installer attributes |
| 47 | +Name "${PRODUCT_NAME}" |
| 48 | +OutFile "dist\NetworkMonitor-Setup-${PRODUCT_VERSION}.exe" |
| 49 | +InstallDir "$PROGRAMFILES64\NetworkMonitor" |
| 50 | +InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" "" |
| 51 | +ShowInstDetails nevershow ; Hide details for non-technical users |
| 52 | +ShowUnInstDetails nevershow |
| 53 | +RequestExecutionLevel admin |
| 54 | + |
| 55 | +; Variables |
| 56 | +Var NpcapInstalled |
| 57 | + |
| 58 | +Function .onInit |
| 59 | + ; Check Windows version |
| 60 | + ${IfNot} ${AtLeastWin10} |
| 61 | + MessageBox MB_OK|MB_ICONSTOP "NetworkMonitor requires Windows 10 or later.$\r$\n$\r$\nPlease upgrade your Windows version." |
| 62 | + Abort |
| 63 | + ${EndIf} |
| 64 | + |
| 65 | + ; Check if running on 64-bit Windows |
| 66 | + ${IfNot} ${RunningX64} |
| 67 | + MessageBox MB_OK|MB_ICONSTOP "NetworkMonitor requires 64-bit Windows.$\r$\n$\r$\nYour system appears to be 32-bit." |
| 68 | + Abort |
| 69 | + ${EndIf} |
| 70 | + |
| 71 | + ; Check if running with admin privileges |
| 72 | + UserInfo::GetAccountType |
| 73 | + Pop $0 |
| 74 | + ${If} $0 != "admin" |
| 75 | + MessageBox MB_OK|MB_ICONSTOP "Please right-click the installer and select 'Run as administrator'." |
| 76 | + Abort |
| 77 | + ${EndIf} |
| 78 | + |
| 79 | + ; Check if Npcap is already installed |
| 80 | + StrCpy $NpcapInstalled "0" |
| 81 | + |
| 82 | + ; Check for Npcap DLL |
| 83 | + IfFileExists "$SYSDIR\Npcap\wpcap.dll" 0 +2 |
| 84 | + StrCpy $NpcapInstalled "1" |
| 85 | + |
| 86 | + ; Also check WinPcap compatibility location |
| 87 | + IfFileExists "$SYSDIR\wpcap.dll" 0 +3 |
| 88 | + StrCpy $NpcapInstalled "1" |
| 89 | +FunctionEnd |
| 90 | + |
| 91 | +Section "NetworkMonitor" SEC_CORE |
| 92 | + SectionIn RO |
| 93 | + |
| 94 | + ; Show progress |
| 95 | + DetailPrint "Installing NetworkMonitor..." |
| 96 | + SetOutPath "$INSTDIR" |
| 97 | + |
| 98 | + ; Main executable (single-file build) |
| 99 | + File "dist\NetworkMonitor.exe" |
| 100 | + |
| 101 | + ; Copy icon for shortcuts |
| 102 | + File "assets\icon.ico" |
| 103 | + |
| 104 | + ; Create shortcuts |
| 105 | + DetailPrint "Creating shortcuts..." |
| 106 | + CreateDirectory "$SMPROGRAMS\NetworkMonitor" |
| 107 | + CreateShortCut "$SMPROGRAMS\NetworkMonitor\NetworkMonitor.lnk" "$INSTDIR\NetworkMonitor.exe" "" "$INSTDIR\NetworkMonitor.exe" 0 |
| 108 | + CreateShortCut "$SMPROGRAMS\NetworkMonitor\Uninstall.lnk" "$INSTDIR\uninstall.exe" |
| 109 | + CreateShortCut "$DESKTOP\NetworkMonitor.lnk" "$INSTDIR\NetworkMonitor.exe" "" "$INSTDIR\NetworkMonitor.exe" 0 |
| 110 | + |
| 111 | + ; Write registry keys |
| 112 | + WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "" "$INSTDIR\NetworkMonitor.exe" |
| 113 | + WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayName" "${PRODUCT_NAME}" |
| 114 | + WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninstall.exe" |
| 115 | + WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\NetworkMonitor.exe" |
| 116 | + WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" |
| 117 | + WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}" |
| 118 | + WriteRegStr HKLM "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}" |
| 119 | + WriteRegDWORD HKLM "${PRODUCT_UNINST_KEY}" "NoModify" 1 |
| 120 | + WriteRegDWORD HKLM "${PRODUCT_UNINST_KEY}" "NoRepair" 1 |
| 121 | + |
| 122 | + ; Create uninstaller |
| 123 | + WriteUninstaller "$INSTDIR\uninstall.exe" |
| 124 | + |
| 125 | + ; Install Npcap if not present |
| 126 | + ${If} $NpcapInstalled == "0" |
| 127 | + DetailPrint "Installing network driver (Npcap)..." |
| 128 | + DetailPrint "This may take a minute..." |
| 129 | + |
| 130 | + SetOutPath "$TEMP\NetworkMonitor" |
| 131 | + File "bundled_resources\Npcap\npcap-installer.exe" |
| 132 | + |
| 133 | + ; Silent install with WinPcap compatibility mode |
| 134 | + ExecWait '"$TEMP\NetworkMonitor\npcap-installer.exe" /S /winpcap_mode=yes' $0 |
| 135 | + |
| 136 | + ${If} $0 != 0 |
| 137 | + MessageBox MB_OK|MB_ICONEXCLAMATION "Npcap installation may have failed.$\r$\n$\r$\nIf NetworkMonitor doesn't work, please install Npcap manually from npcap.com" |
| 138 | + ${EndIf} |
| 139 | + |
| 140 | + Delete "$TEMP\NetworkMonitor\npcap-installer.exe" |
| 141 | + RMDir "$TEMP\NetworkMonitor" |
| 142 | + ${Else} |
| 143 | + DetailPrint "Network driver already installed (Npcap/WinPcap found)" |
| 144 | + ${EndIf} |
| 145 | + |
| 146 | + ; Install VC++ Runtime if bundled |
| 147 | + IfFileExists "bundled_resources\vcruntime\vc_redist.x64.exe" 0 SkipVCRuntime |
| 148 | + DetailPrint "Installing Visual C++ Runtime..." |
| 149 | + SetOutPath "$TEMP\NetworkMonitor" |
| 150 | + File "bundled_resources\vcruntime\vc_redist.x64.exe" |
| 151 | + ExecWait '"$TEMP\NetworkMonitor\vc_redist.x64.exe" /quiet /norestart' |
| 152 | + Delete "$TEMP\NetworkMonitor\vc_redist.x64.exe" |
| 153 | + RMDir "$TEMP\NetworkMonitor" |
| 154 | + SkipVCRuntime: |
| 155 | + |
| 156 | + ; Add firewall exception |
| 157 | + DetailPrint "Configuring firewall..." |
| 158 | + nsExec::ExecToLog 'netsh advfirewall firewall add rule name="NetworkMonitor API" dir=in action=allow program="$INSTDIR\NetworkMonitor.exe" enable=yes' |
| 159 | + nsExec::ExecToLog 'netsh advfirewall firewall add rule name="NetworkMonitor Port 5000" dir=in action=allow protocol=TCP localport=5000' |
| 160 | + |
| 161 | + DetailPrint "Installation complete!" |
| 162 | +SectionEnd |
| 163 | + |
| 164 | +Section "Uninstall" |
| 165 | + ; Remove firewall rules |
| 166 | + nsExec::ExecToLog 'netsh advfirewall firewall delete rule name="NetworkMonitor API"' |
| 167 | + nsExec::ExecToLog 'netsh advfirewall firewall delete rule name="NetworkMonitor Port 5000"' |
| 168 | + |
| 169 | + ; Remove application files |
| 170 | + Delete "$INSTDIR\NetworkMonitor.exe" |
| 171 | + Delete "$INSTDIR\uninstall.exe" |
| 172 | + RMDir /r "$INSTDIR" |
| 173 | + |
| 174 | + ; Remove shortcuts |
| 175 | + Delete "$SMPROGRAMS\NetworkMonitor\NetworkMonitor.lnk" |
| 176 | + Delete "$SMPROGRAMS\NetworkMonitor\Uninstall.lnk" |
| 177 | + Delete "$DESKTOP\NetworkMonitor.lnk" |
| 178 | + RMDir "$SMPROGRAMS\NetworkMonitor" |
| 179 | + |
| 180 | + ; Remove registry keys |
| 181 | + DeleteRegKey HKLM "${PRODUCT_UNINST_KEY}" |
| 182 | + DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}" |
| 183 | +SectionEnd |
| 184 | + |
| 185 | +; Description for components (not shown but required) |
| 186 | +!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN |
| 187 | + !insertmacro MUI_DESCRIPTION_TEXT ${SEC_CORE} "NetworkMonitor application and all required components" |
| 188 | +!insertmacro MUI_FUNCTION_DESCRIPTION_END |
| 189 | + |
0 commit comments