installer.nsi 12.8 KB
Newer Older
1
;  Copyright (C) 2009-2012 Centro de Computacao Cientifica e Software Livre
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
;  Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
;
;  This file is part of ProInfoData Windows Installer
;
;  ProInfoData Windows Installer is free software you can redistribute it
;  and/or modify it under the terms of the GNU General Public License as
;  published by the Free Software Foundation; either version 3 of the
;  License, or (at your option) any later version.
;
;  This program is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License
;  along with this program; if not, write to the Free Software
;  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;  USA.

;Used variables
; R0 -> General use
; R1 -> General use
; R2 -> Temp variable
; R3 -> Variable used to set the lock state of the "next" button in INEP page
; R4 -> proxyHost pointer
; R5 -> proxyPort pointer
; R6 -> proxyUser pointer
; R7 -> proxyPass pointer

!define PRODUCT_NAME "ProInfoData"
32
!define PRODUCT_VERSION "0.0.2"
33 34 35 36 37 38
!define PRODUCT_PUBLISHER "C3SL - UFPR"
!define PRODUCT_WEB_SITE "http://seed.c3sl.ufpr.br/"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\\
Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define PRODUCT_UNINST_NAME "Desinstalar ${PRODUCT_NAME}"
39
!define PRODUCT_TASK "$PROGRAMFILES\${PRODUCT_NAME}\bin\agent\proinfodataAgent.exe"
40
!define MUI_FINISHPAGE_NOAUTOCLOSE
41 42 43 44

SetCompressor bzip2
RequestExecutionLevel admin
XPStyle on
45
BrandingText "ProInfoData - C3SL"
46 47 48 49 50

;Installer headers
!include "nsDialogs.nsh"
!include "MUI.nsh"

51 52 53 54 55 56 57 58
;Installer images
!define MUI_ICON "..\images\proinfodata.ico"
!define MUI_UNICON "..\images\proinfodata.ico"
!define MUI_WELCOMEFINISHPAGE_BITMAP "..\images\wizard.bmp"
!define MUI_WELCOMEFINISHPAGE_BITMAP_NOSTRETCH
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_BITMAP "..\images\headerLeft.bmp"

59 60 61 62 63
;MUI Settings
!define MUI_ABORTWARNING

;Installer pages
!insertmacro MUI_PAGE_WELCOME
64
!define MUI_LICENSEPAGE_CHECKBOX
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
!insertmacro MUI_PAGE_LICENSE "../COPYING"
Page custom PROXY_1 proxyLeave
Page custom PROXY_2 proxyInfo
Page custom INEP
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

;Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

;Language files
!insertmacro MUI_LANGUAGE "PortugueseBR"

;Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
;MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
83
OutFile "..\build\${PRODUCT_NAME}.exe"
84
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
85 86 87 88 89 90 91 92 93 94 95

Var Dialog
Var Inep
Var ReturnValue
Var withoutProxy
Var withProxy
Var haveProxyInfo
Var ProxyHost
Var ProxyPort
Var ProxyUser
Var ProxyPass
96
Var RegInep
97
Var InepPointer
98 99 100 101 102 103 104 105 106 107 108

;Installer init function
Function .onInit
    ;Prevent the user from run multiple instances of this installer
    System::Call 'kernel32::CreateMutexA(i 0, i 0, t "Instalador \
    ProInfoData") i .r1 ?e'
    Pop $R0
    StrCmp $R0 0 +3
    MessageBox MB_OK|MB_ICONEXCLAMATION "Uma instância do instalador já \
    está em execução."
    Abort
109

110 111 112
    ;Kill proinfodataAgent.exe process
    KillProcDLL::KillProc "proinfodataAgent.exe"

113 114 115 116 117 118
    ;Verify if INEP exists in Windows registry
    ClearErrors
    ReadRegStr $R2 HKLM "SOFTWARE\${PRODUCT_NAME}" "INEP"
    ${If} ${Errors}
        StrCpy $RegInep "false"
    ${EndIf}
119 120 121 122
FunctionEnd

;Generates a page asking for proxy information
Function PROXY_1
123 124 125
    StrCmp $RegInep "false" 0 NoExecFuncProxy_1
        nsDialogs::Create 1018
        Pop $Dialog
126

127 128 129
        ${if} $Dialog == error
            Abort
        ${EndIf}
130

131 132
        !insertmacro MUI_HEADER_TEXT "Informações de Proxy" "Antes de prosseguir, \
        responda a questão abaixo"
133

134 135
        ${NSD_CreateLabel} 0 0 100% 12u "Você possui informações de proxy?"
        Pop $R2
136

137 138
        ${NSD_CreateRadioButton} 0 9% 40% 6% "Não"
        Pop $withoutProxy
139

140 141
        ${NSD_CreateRadioButton} 0 18% 40% 6% "Sim"
        Pop $withProxy
142

143 144 145
        ;Set the "Não" radio button as default
        ${NSD_AddStyle} $withoutProxy ${WS_GROUP}
        ${NSD_SetState} $withoutProxy 1
146

147 148
        nsDialogs::Show
    NoExecFuncProxy_1:
149 150
FunctionEnd

151
;This function is executed when the user leaves PROXY_1 page. In this function,
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
;the haveProxyInfo variable is set based on user answer about proxy
;information
Function proxyLeave
    ${NSD_GetState} $withProxy $R0
    ${NSD_GetState} $withoutProxy $R1

    ${If} $R0 = 1
        StrCpy $haveProxyInfo 1
    ${ElseIf} $R1 = 1
        StrCpy $haveProxyInfo 0
    ${EndIf}
FunctionEnd

;Generates a page with a form about proxy information
Function PROXY_2
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 193 194 195 196 197 198 199 200 201 202
    StrCmp $RegInep "false" 0 NoExecFuncProxy_2
        ;If the user does not have proxy information, this page is aborted
        ${if} $haveProxyInfo = 0
            Abort
        ${endif}

        nsDialogs::Create 1018
        Pop $Dialog

        ${if} $Dialog == error
            Abort
        ${EndIf}

        !insertmacro MUI_HEADER_TEXT "Informações de Proxy" "Antes de prosseguir, \
        digite as informações de proxy"

        ${NSD_CreateLabel} 0 0 100% 12u "Proxy host:"
        Pop $R2
        ${NSD_CreateLabel} 0 20% 100% 12u "Proxy port:"
        Pop $R2
        ${NSD_CreateLabel} 0 40% 100% 12u "Proxy user:"
        Pop $R2
        ${NSD_CreateLabel} 0 60% 100% 12u "Proxy password:"
        Pop $R2

        ${NSD_CreateText} 0 13u 100% 12u ""
        Pop $R4
        ${NSD_CreateText} 0 30% 100% 12u ""
        Pop $R5
        ${NSD_CreateText} 0 50% 100% 12u ""
        Pop $R6
        ${NSD_CreateText} 0 70% 100% 12u ""
        Pop $R7

        nsDialogs::Show
    NoExecFuncProxy_2:
203 204 205 206 207 208 209 210 211 212 213 214
FunctionEnd

;This function get the proxy information typed by the user in PROXY_2 page
Function proxyInfo
    ${NSD_GetText} $R4 $ProxyHost
    ${NSD_GetText} $R5 $ProxyPort
    ${NSD_GetText} $R6 $ProxyUser
    ${NSD_GetText} $R7 $ProxyPass
FunctionEnd

;Generates inep input page
Function INEP
215 216 217
    StrCmp $RegInep "false" 0 NoExecFuncInep
        nsDialogs::Create 1018
        Pop $Dialog
218

219 220 221
        ${if} $Dialog == error
            Abort
        ${EndIf}
222

223 224
        !insertmacro MUI_HEADER_TEXT "Validação INEP" "Antes de prosseguir tenha \
        certeza de que possui um INEP válido."
225

226 227 228
        ;Disables the 'next' or 'install" button
        GetDlgItem $R3 $HWNDPARENT 1
        EnableWindow $R3 0
229

230 231
        ${NSD_CreateLabel} 0 0 100% 12u "Digite o INEP da instituição"
        Pop $R2
232

233
        ${NSD_CreateText} 0 13u 100% 12u ""
234
        Pop $InepPointer
235

236 237 238 239
        ;Check onClick event on "Validar" button
        ${NSD_CreateButton} 255u 40u 15% 12u "Validar"
        Pop $R2
        ${NSD_OnClick} $R2 validate
240

241 242
        nsDialogs::Show
    NoExecFuncInep:
243 244 245 246 247 248 249
FunctionEnd

;This function validates school INEP
Function validate
    Pop $R2

    SetOutPath "$TEMP"
250
    File "..\bin\getSchoolInfo.exe"
251

252
    ${NSD_GetText} $InepPointer $Inep
253 254 255

    ${if} $haveProxyInfo = 0
        nsExec::Exec "$TEMP\getSchoolInfo.exe http://seed.c3sl.ufpr.br:8888/\
256
        axis/services/Seed2InstallService $Inep"
257 258 259
		Pop $ReturnValue
    ${else}
        nsExec::Exec "$TEMP\getSchoolInfo.exe http://seed.c3sl.ufpr.br:8888/\
260
        axis/services/Seed2InstallService $Inep $ProxyHost $ProxyPort \
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286
        $ProxyUser $ProxyPass"
		Pop $ReturnValue
    ${endif}

    ${If} $ReturnValue == 0
        MessageBox MB_OK "Seu INEP foi verificado e está em nossa base de \
        dados"
        EnableWindow $R3 1
    ${ElseIf} $ReturnValue == 1
        MessageBox MB_OK "ERRO: Parâmetros incorretos"
    ${ElseIf} $ReturnValue == 2
        MessageBox MB_OK "ERRO: Problemas ao conectar ao servidor"
    ${Else}
        MessageBox MB_OK "ERRO: INEP inválido"
    ${EndIf}
FunctionEnd

;Main installer section
Section "SeçãoPrincipal" SEC01
    SetOutPath "$INSTDIR"
    SetOverwrite ifnewer

    ;Verify INEP in Windows registry. If not exists, creates a new one.
	ClearErrors
	ReadRegStr $R2 HKLM "SOFTWARE\${PRODUCT_NAME}" "INEP"
	${If} ${Errors}
287
		WriteRegStr HKLM "SOFTWARE\${PRODUCT_NAME}" "INEP" $Inep
288 289 290 291
	${EndIf}

	;Add ProinfodataAgent task in Windows task scheduler
	nsExec::Exec "schtasks /Create /SC HOURLY /MO 1 /TN ProinfodataAgent \
292
    /TR $\"\$\"${PRODUCT_TASK}$\"\$\" /RU System /F"
293 294 295
	Pop $R2

	File "..\COPYING"
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328
    CreateDirectory "$INSTDIR\conf"
    CreateDirectory "$INSTDIR\data"
    CreateDirectory "$INSTDIR\log"
    CreateDirectory "$INSTDIR\update"
    CreateDirectory "$INSTDIR\..\data"

    SetOutPath "$INSTDIR\bin"
    File "..\bin\client.exe"

    SetOutPath "$INSTDIR\bin\agent"
    File "..\..\windows-coleta\src\dist\API-MS-Win-Core-LocalRegistry-L1-1-0.dll"
    File "..\..\windows-coleta\src\dist\API-MS-Win-Core-ProcessThreads-L1-1-0.dll"
    File "..\..\windows-coleta\src\dist\API-MS-Win-Security-Base-L1-1-0.dll"
    File "..\..\windows-coleta\src\dist\bz2.pyd"
    File "..\..\windows-coleta\src\dist\KERNELBASE.dll"
    File "..\..\windows-coleta\src\dist\library.zip"
    File "..\..\windows-coleta\src\dist\POWRPROF.dll"
    File "..\..\windows-coleta\src\dist\proinfodataAgent.exe"
    File "..\..\windows-coleta\src\dist\pyexpat.pyd"
    File "..\..\windows-coleta\src\dist\python27.dll"
    File "..\..\windows-coleta\src\dist\pythoncom27.dll"
    File "..\..\windows-coleta\src\dist\pywintypes27.dll"
    File "..\..\windows-coleta\src\dist\select.pyd"
    File "..\..\windows-coleta\src\dist\unicodedata.pyd"
    File "..\..\windows-coleta\src\dist\w9xpopen.exe"
    File "..\..\windows-coleta\src\dist\win32api.pyd"
    File "..\..\windows-coleta\src\dist\win32ui.pyd"
    File "..\..\windows-coleta\src\dist\_ctypes.pyd"
    File "..\..\windows-coleta\src\dist\_hashlib.pyd"
    File "..\..\windows-coleta\src\dist\_socket.pyd"
    File "..\..\windows-coleta\src\dist\_ssl.pyd"
    File "..\..\windows-coleta\src\dist\_win32sysloader.pyd"

329
    WriteRegStr HKLM "SOFTWARE\${PRODUCT_NAME}" "Version" ${PRODUCT_VERSION}
330 331 332

    ;Execute Proinfodata Agent
    nsExec::Exec "schtasks /Run /TN ProinfodataAgent"
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367
SectionEnd

;Uninstaller creation
Section -Post
    WriteUninstaller "$INSTDIR\${PRODUCT_UNINST_NAME}.exe"
    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
    "DisplayName" "$(^Name)"
    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
    "UninstallString" "$INSTDIR\${PRODUCT_UNINST_NAME}.exe"
    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
    "DisplayVersion" "${PRODUCT_VERSION}"
    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
    "URLInfoAbout" "${PRODUCT_WEB_SITE}"
    WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" \
    "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

;Uninstaller init function
Function un.onInit
    MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Tem certeza que quer \
    remover completamente $(^Name) e todos os seus componentes?" IDYES +2
    Abort
FunctionEnd

;Shows a messagebox if the uninstall process is succeeded
Function un.onUninstSuccess
    HideWindow
    MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) foi removido com sucesso \
    do seu computador."
FunctionEnd

;Remove proinfodata files
Section Uninstall
    Delete "$INSTDIR\${PRODUCT_UNINST_NAME}.exe"
    Delete "$INSTDIR\COPYING"
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
    Delete "$INSTDIR\bin\client.exe"
    Delete "$INSTDIR\bin\agent\API-MS-Win-Core-LocalRegistry-L1-1-0.dll"
    Delete "$INSTDIR\bin\agent\API-MS-Win-Core-ProcessThreads-L1-1-0.dll"
    Delete "$INSTDIR\bin\agent\API-MS-Win-Security-Base-L1-1-0.dll"
    Delete "$INSTDIR\bin\agent\bz2.pyd"
    Delete "$INSTDIR\bin\agent\KERNELBASE.dll"
    Delete "$INSTDIR\bin\agent\library.zip"
    Delete "$INSTDIR\bin\agent\POWRPROF.dll"
    Delete "$INSTDIR\bin\agent\proinfodataAgent.exe"
    Delete "$INSTDIR\bin\agent\pyexpat.pyd"
    Delete "$INSTDIR\bin\agent\python27.dll"
    Delete "$INSTDIR\bin\agent\pythoncom27.dll"
    Delete "$INSTDIR\bin\agent\pywintypes27.dll"
    Delete "$INSTDIR\bin\agent\select.pyd"
    Delete "$INSTDIR\bin\agent\unicodedata.pyd"
    Delete "$INSTDIR\bin\agent\w9xpopen.exe"
    Delete "$INSTDIR\bin\agent\win32api.pyd"
    Delete "$INSTDIR\bin\agent\win32ui.pyd"
    Delete "$INSTDIR\bin\agent\_ctypes.pyd"
    Delete "$INSTDIR\bin\agent\_hashlib.pyd"
    Delete "$INSTDIR\bin\agent\_socket.pyd"
    Delete "$INSTDIR\bin\agent\_ssl.pyd"
    Delete "$INSTDIR\bin\agent\_win32sysloader.pyd"
    RMDir "$INSTDIR\bin"
    RMDir "$INSTDIR\conf"
    RMDir "$INSTDIR\data"
    RMDir "$INSTDIR\log"
    RMDir "$INSTDIR\update"
    RMDir "$INSTDIR\..\data"
397 398 399 400 401 402 403 404 405 406 407 408 409
    RMDir "$INSTDIR"

    DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
    DeleteRegValue HKLM "SOTWARE\${PRODUCT_NAME}" "Version"
    DeleteRegValue HKLM "SOFTWARE\${PRODUCT_NAME}" "INEP"
    DeleteRegKey HKLM "SOFTWARE\${PRODUCT_NAME}"

	;Delete scheduled task
	nsExec::Exec "schtasks /Delete /TN ProinfodataAgent /F"
	Pop $R2

    SetAutoClose true
SectionEnd