summaryrefslogtreecommitdiff
path: root/usbclerk.nsis.in
blob: 22ca7b3668a3f490509aedbf78b35a92c2f96e50 (plain)
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!Nsis Installer Command Script
#
# This is an NSIS Installer Command Script generated automatically
# by the Fedora nsiswrapper program.  For more information see:
#
#   http://nsis.sourceforge.net
#
# To build an installer from the script you would normally do:
#
#   makensis usbclerk-installer.nsis
#
# which will generate the output file 'usbclerk-installer.exe' which is a Windows
# installer containing your program.

# Modern UI example script
!include MUI.nsh
!include x64.nsh

!define MyName usbclerk
!define MySetup ${MyName}-setup

!define VERSION @VERSION@

!define SpiceRegKey    "Software\Spice"
!define UsbClerkRegKey "Software\Spice\${MyName}"
!define RemoveRegKey   "Software\Microsoft\Windows\CurrentVersion\Uninstall\${MyName}"

Name ${MyName}
OutFile ${MySetup}.exe

InstallDir "$WINDIR\Installer\${MyName}"
InstallDirRegKey HKLM ${UsbClerkRegKey} InstallDir


RequestExecutionLevel admin
ShowInstDetails hide
ShowUninstDetails hide

SetCompressor lzma

XPStyle on

#!define MUI_ABORTWARNING
#!define MUI_FINISHPAGE_NOAUTOCLOSE
#!define MUI_UNFINISHPAGE_NOAUTOCLOSE

!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE LICENSE
# !insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_LANGUAGE "English"

#DirText "Please select the installation folder."

#--------------------------------
#Version Information
  VIProductVersion ${VERSION}
  VIAddVersionKey "ProductName" "${MySetup}"
  VIAddVersionKey "CompanyName" "Red Hat"
  VIAddVersionKey "LegalCopyright" "Red Hat Inc   2012"
  VIAddVersionKey "FileDescription" "An installer for usbclerk service"
  VIAddVersionKey "FileVersion" ${VERSION}
#--------------------------------

# abort if not admin
!macro verify_admin id
  DetailPrint "Checking admin privileges"

  #  ClearErrors
  #  UserInfo::GetName
  #  IfErrors usbclerk_install_fail_get_user
  UserInfo::GetAccountType
  Pop $0
  StrCmp $0 "Admin" ${id}_user_is_admin ${id}_user_is_not_admin
${id}_user_is_not_admin:
  DetailPrint "User does not have admin privileges ... aborting"
  messageBox MB_OK "User does not have admin privileges ... aborting"
  Abort
${id}_user_is_admin:
  DetailPrint "User has admin privileges"
!macroend

# work on 64 bit OS too.
!macro work_on_64
  ${If} ${RunningX64}
    ${DisableX64FSRedirection}
    SetRegView 64
  ${EndIf}
!macroend

Function .onInit
  !insertmacro verify_admin "onInit"
  !insertmacro work_on_64
FunctionEnd

Function un.onInit
  !insertmacro verify_admin "un.onInit"
  !insertmacro work_on_64
FunctionEnd

!macro compare_versions f
  IfFileExists ${f} +1 compare_versions_done

  ${GetFileVersion} ${f} $0

  ${VersionCompare} $0 ${VERSION} $1

  StrCmp $1 2 compare_versions_done # a newer version is now being installed

  # we are here ==> a newer version is installed so bail out
  DetailPrint "About to install ${MyName} of version ${VERSION}"
  DetailPrint "${MyName} of version $0 is already installed"
  DetailPrint "A Newer (or equal) version is already installed -- aborting"
  Abort

compare_versions_done:
  DetailPrint "Go on with ${MyName} installation"
!macroend

!macro stop_and_remove_service
  ReadRegStr $1 HKLM ${UsbClerkRegKey} InstDir
  ReadEnvStr $0 COMSPEC
  nsExec::ExecToLog '$0 /C net stop usbclerk'
  nsExec::ExecToLog '$0 /C "$1\usbclerk.exe" uninstall'
  Delete "$1\Uninstall_usbclerk.exe"
  Delete "$1\usbclerk.exe"
  Delete "$1\license.rtf"
  Delete "$1\GPL"
  Delete "$1\LICENSE"
!macroend


#
# FixMe check  version
Function uninstall_if_needed
  ReadRegStr $0 HKLM ${UsbClerkRegKey} Uninstall
  StrCmp $0 "" uninstall_is_not_needed uninstall_is_needed
uninstall_is_needed:
  DetailPrint "Removing already installed ${MyName} service"
  !insertmacro stop_and_remove_service
  DetailPrint "Done, installation of new ${MyName} continues"
uninstall_is_not_needed:
FunctionEnd



Section "Install"
  SectionIn RO

  # !insertmacro verify_admin install

  # uncomment this when usbclerk.exe gets a real version
  # ReadRegStr $0 HKLM ${UsbClerkRegKey} InstDir
  # !insertmacro compare_versions $0\usbclerk.exe

  Call uninstall_if_needed

  SetOutPath "$INSTDIR"

  File usbclerk.exe
  File license.rtf
  File GPL
  File LICENSE
  ReadEnvStr $0 COMSPEC
  nsExec::ExecToLog '$0 /C "$INSTDIR\usbclerk.exe" install'
  nsExec::ExecToLog '$0 /C net start usbclerk'
  WriteUninstaller Uninstall_usbclerk.exe
  WriteRegStr HKLM ${UsbClerkRegKey} "Uninstall" "$INSTDIR\Uninstall_usbclerk.exe"
  WriteRegStr HKLM ${UsbClerkRegKey} "InstDir" "$INSTDIR"

  # add uninstall info
  WriteRegStr HKLM "${RemoveRegKey}" "DisplayName" \
                   "UsbClerk -- A service for installing WinUSB drivers"
  WriteRegStr HKLM "${RemoveRegKey}" "UninstallString" \
                   "$\"$INSTDIR\Uninstall_usbclerk.exe$\""
SectionEnd

Section "Uninstall"
  # !insertmacro verify_admin uninstall
  !insertmacro stop_and_remove_service
  RMDir "$INSTDIR"
  DeleteRegKey HKLM "${UsbClerkRegKey}\Uninstall"
  DeleteRegKey HKLM "${UsbClerkRegKey}\InstDir"
  DeleteRegKey /ifempty HKLM "${UsbClerkRegKey}"
  DeleteRegKey /ifempty HKLM "${SpiceRegKey}"

  # delete uninstall info
  DeleteRegKey HKLM "${RemoveRegKey}\DisplayName"
  DeleteRegKey HKLM "${RemoveRegKey}\UninstallString"
  DeleteRegKey /ifempty HKLM "${RemoveRegKey}"
SectionEnd