-
Notifications
You must be signed in to change notification settings - Fork 0
/
installer_script.nsi
98 lines (75 loc) · 2.82 KB
/
installer_script.nsi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
!include "MUI2.nsh"
!define MUI_ICON "Assets\setup.ico"
!define APP_NAME "Epic Switcher"
!define APP_SHORTCUT_NAME "Epic Switcher"
!define REGISTRY_KEY "Software\${APP_NAME}"
Name "Epic Switcher"
InstallDir "$LOCALAPPDATA\${APP_NAME}"
OutFile "EpicSwitcherSetup.exe"
Unicode True
# Request application privileges for Windows Vista
RequestExecutionLevel user
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
# Customize the finish page text to include attribution
!define MUI_FINISHPAGE_TEXT "Thank you for installing Epic Switcher.$\r$\nSetup icon by Freepic (https://www.freepik.com)."
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_CHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Run ${APP_SHORTCUT_NAME}"
!define MUI_FINISHPAGE_RUN_FUNCTION "StartApp"
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
# Check if the application is already installed
Function CheckIfInstalled
# Read the install directory from the registry
ReadRegStr $0 HKCU "${REGISTRY_KEY}" "InstallDir"
# If the install directory is found, display a custom large message
StrCmp $0 "" 0 already_installed
Goto install
already_installed:
# Show message in a large, customized window
MessageBox MB_ICONINFORMATION|MB_OK "The application is already installed at: $0$\r$\n$\r$\nPlease click OK to exit the installer." IDOK end_install
end_install:
# Exit the installer after showing the message
Quit
install:
FunctionEnd
# Call the CheckIfInstalled function at the start of installation
Function .onInit
Call CheckIfInstalled
FunctionEnd
Section
# Create installation directory
SetOutPath $INSTDIR
# Copy files directly into the installation directory
File /r "bin\Release\net8.0-windows\win-x64\publish\*.*"
# Create a shortcut to the main application
CreateShortCut "$INSTDIR\${APP_SHORTCUT_NAME}.lnk" "$INSTDIR\AccountSwitcher.exe"
# Copy shortcuts to Desktop and Start Menu
CopyFiles "$INSTDIR\${APP_SHORTCUT_NAME}.lnk" "$DESKTOP"
CopyFiles "$INSTDIR\${APP_SHORTCUT_NAME}.lnk" "$SMPROGRAMS"
# Store installation folder in the registry for uninstaller access
WriteRegStr HKCU "${REGISTRY_KEY}" "InstallDir" $INSTDIR
# Create uninstaller
WriteUninstaller "$INSTDIR\Uninstall.exe"
SectionEnd
Section "Uninstall"
# Remove all files in the installation directory
Delete "$INSTDIR\*.*"
Delete "$INSTDIR\*.dll"
Delete "$INSTDIR\*.exe"
Delete "$INSTDIR\*.lnk"
# Remove shortcuts
Delete "$DESKTOP\${APP_SHORTCUT_NAME}.lnk"
Delete "$SMPROGRAMS\${APP_SHORTCUT_NAME}.lnk"
# Remove installation directory
RMDir /r "$INSTDIR"
# Remove registry entry for the install directory
DeleteRegKey HKCU "${REGISTRY_KEY}"
SectionEnd
Function StartApp
ExecShell "" "$INSTDIR\AccountSwitcher.exe"
FunctionEnd