;Setup script

!define VER_MAJOR 0.1
!define VER_MINOR beta

!macro ReplaceInFile SOURCE_FILE SEARCH_TEXT REPLACEMENT
  Push "${SOURCE_FILE}"
  Push "${SEARCH_TEXT}"
  Push "${REPLACEMENT}"
  Call RIF
!macroend

Function RIF
  ClearErrors  ; wanna be a newborn
  Exch $0      ; REPLACEMENT
  Exch
  Exch $1      ; SEARCH_TEXT
  Exch 2
  Exch $2      ; SOURCE_FILE
  Push $R0     ; SOURCE_FILE file handle
  Push $R1     ; temporary file handle
  Push $R2     ; unique temporary file name
  Push $R3     ; a line to sar/save
  Push $R4     ; shift puffer
  IfFileExists $2 +1 RIF_error      ; knock-knock
  FileOpen $R0 $2 "r"               ; open the door
  GetTempFileName $R2               ; who's new?
  FileOpen $R1 $R2 "w"              ; the escape, please!
  RIF_loop:                         ; round'n'round we go
    FileRead $R0 $R3                ; read one line
    IfErrors RIF_leaveloop          ; enough is enough
    RIF_sar:                        ; sar - search and replace
      Push "$R3"                    ; (hair)stack
      Push "$1"                     ; needle
      Push "$0"                     ; blood
      Call StrReplace               ; do the bartwalk
      StrCpy $R4 "$R3"              ; remember previous state
      Pop $R3                       ; gimme s.th. back in return!
      StrCmp "$R3" "$R4" +1 RIF_sar ; loop, might change again!
    FileWrite $R1 "$R3"             ; save the newbie
  Goto RIF_loop                     ; gimme more
  RIF_leaveloop:                    ; over'n'out, Sir!
    FileClose $R1                   ; S'rry, Ma'am - clos'n now
    FileClose $R0                   ; me 2
    Delete "$2.old"                 ; go away, Sire
    Rename "$2" "$2.old"            ; step aside, Ma'am
    Rename "$R2" "$2"               ; hi, baby!
    ClearErrors                     ; now i AM a newborn
    Goto RIF_out                    ; out'n'away
  RIF_error:                        ; ups - s.th. went wrong...
    SetErrors                       ; ...so cry, boy!
  RIF_out:                          ; your wardrobe?
  Pop $R4
  Pop $R3
  Pop $R2
  Pop $R1
  Pop $R0
  Pop $2
  Pop $0
  Pop $1
FunctionEnd

;--------------------------------
;Compile CVS Data Setup

;!system '"${NSISDIR}\Bin\InstallCVSData.exe" nooverwrite'
;!system '"${NSISDIR}\makensis.exe" cvsdata.nsi' = 0

;--------------------------------
;Configuration

OutFile ..\hostweb${VER_MAJOR}${VER_MINOR}.exe
SetCompressor bzip2

InstType "Full (apache, php and mysql)"

ShowInstDetails show
ShowUninstDetails show
SetDateSave on

InstallDir "$PROGRAMFILES\Hostweb Support\"
InstallDirRegKey HKLM SOFTWARE\Hostweb\Support "InstallPath"

;--------------------------------
!ifndef CLASSIC_UI

  ;Include Modern UI Macro's
  !include "${NSISDIR}\Contrib\Modern UI\System.nsh"

  ;--------------------------------
  ;Modern UI Configuration

  !define MUI_PRODUCT "Hostweb Support"
  !define MUI_VERSION "0.1 beta"

  !define MUI_NAME "Hostweb Support System Installer" ;Installer name

  !define MUI_WELCOMEPAGE
  ;!define MUI_LICENSEPAGE
  !define MUI_COMPONENTSPAGE
    !define MUI_COMPONENTSPAGE_SMALLDESC
  !define MUI_DIRECTORYPAGE
  !define MUI_FINISHPAGE
  ;!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\html\configure.html"
    !define MUI_FINISHPAGE_NOREBOOTSUPPORT
  
  !define MUI_ABORTWARNING
  
  !define MUI_UNINSTALLER
  !define MUI_UNCONFIRMPAGE

  !define MUI_HEADERBITMAP "${NSISDIR}\Contrib\Icons\modern-header.bmp"
  ;!define MUI_SPECIALBITMAP "${NSISDIR}\Contrib\Icons\modern-wizard nsis llama.bmp"

  ;--------------------------------
  ;Languages

  !define MUI_TEXT_WELCOME_INFO_TEXT "This wizard will install the Hostweb Support system to a windows machine. Please ensure you are running NT5 or above (2000 or XP) and do not have php, mysql, apache or any other httpd running, such as IIS.\r\n\Click next to continue.\r\n\r\n\r\n"

  !insertmacro MUI_LANGUAGE "English"
  
  ;--------------------------------
  ;Reserve Files
  
  !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
  !insertmacro MUI_RESERVEFILE_SPECIALINI
  !insertmacro MUI_RESERVEFILE_SPECIALBITMAP
  
!endif

;--------------------------------
;Data

;LicenseData ..\license.txt

;--------------------------------
;Installer Sections

!define SF_SELECTED 1

Section "PHP files (required)" SecCore

  SectionIn 1 2 3 RO
  ;SetOutPath $INSTDIR
  RMDir /r "$SMPROGRAMS\Hostweb Support"

  SetOverwrite on
  ;Delete $INSTDIR\makensis-bz2.exe
  ;File ..\makensis.exe
  ;File ..\makensisw.exe
  ;File ..\makensis.htm
  ;File ..\license.txt
  ;IfFileExists $INSTDIR\nsisconf.nsi "" +2
  ;Rename $INSTDIR\nsisconf.nsi $INSTDIR\nsisconf.nsh
  ;SetOverwrite off
  ;File ..\nsisconf.nsh
  ;SetOverwrite on

  SetOutPath $INSTDIR
  File /r ..\html\

  ClearErrors

  SetOutPath $INSTDIR
  ;File uninstall.exe
  File hostweb.ico

SectionEnd


Section "Apache" SecApache

  SectionIn 1 2
  SetOutPath $INSTDIR
  File /r ..\Apache\

  CreateDirectory $INSTDIR\logs

 !insertmacro ReplaceInFile "$INSTDIR\Apache\conf\httpd.conf" "§DocumentRoot§" "$INSTDIR\html\docroot"
 !insertmacro ReplaceInFile "$INSTDIR\Apache\conf\httpd.conf" "§ServerRoot§" "$INSTDIR\apache"

  GetFullPathName $1 $TEMP
 !insertmacro ReplaceInFile "$INSTDIR\Apache\php.ini" "§Temp§" "$1"

SectionEnd

Section "PHP" SecPHP

  SectionIn 1 2
  SetOutPath $INSTDIR
  File /r ..\PHP\

  SetOutPath $SYSDIR
  File /r ..\PHP\*.dll


SectionEnd

Section "mysql" Secmysql

  SectionIn 1 2
  SetOutPath $INSTDIR
  File /r ..\mysql\


;ExecWait "$INSTDIR\mysql\bin\mysqlwatch" "-install"
Push "$INSTDIR\mysql\bin\mysqlwatch"
Push "exe"
Push ""
Push "-install"
Call ExecWaitWithParameters

;ExecWait "$INSTDIR\mysql\bin\mysqld" ""
Push "$INSTDIR\mysql\bin\mysqld"
Push "exe"
Push ""
Push ""
Call ExecWaitWithParameters



SectionEnd

;!ifndef NO_STARTMENUSHORTCUTS
;Section "Start Menu + Desktop Shortcuts" SecIcons
;!else
;Section "Desktop Shortcut" SecIcons
;!endif
;  SectionIn 1 2
;  SetOutPath $INSTDIR
;!ifndef NO_STARTMENUSHORTCUTS
;  CreateDirectory $SMPROGRAMS\Hostweb Support
;  
;  IfFileExists "$INSTDIR\NSIS.exe" "" +2
;    CreateShortCut "$SMPROGRAMS\NSIS\NSIS Menu.lnk" "$INSTDIR\NSIS.exe" ""
;    
;  CreateShortCut "$SMPROGRAMS\NSIS\MakeNSISW (Compiler GUI).lnk" "$INSTDIR\makensisw.exe"
;  
;  IfFileExists "$INSTDIR\Bin\NSISUpdate.exe" "" +2
;    CreateShortCut "$SMPROGRAMS\NSIS\NSIS Update.lnk" "$INSTDIR\Bin\NSISUpdate.exe"
;  
;  WriteINIStr "$SMPROGRAMS\NSIS\NSIS Development Site.url" "InternetShortcut" "URL" "http://nsis.sourceforge.net/"
;  CreateShortCut "$SMPROGRAMS\NSIS\Uninstall NSIS.lnk" "$INSTDIR\uninst-nsis.exe"
;  CreateShortCut "$SMPROGRAMS\NSIS\NSIS Documentation.lnk" "$INSTDIR\Docs\index.html"
;!endif
;  
;  IfFileExists "$INSTDIR\NSIS.exe" "" +3
;    CreateShortCut "$DESKTOP\Nullsoft Install System.lnk" "$INSTDIR\NSIS.exe"
;    Goto +2
;  CreateShortCut "$DESKTOP\Nullsoft Install System.lnk" "$INSTDIR\makensisw.exe"
;  
;SectionEnd

Section -post

  ; When Modern UI is installed:
  ; * Always install the English language file
  ; * Always install default icons / bitmaps

;  SectionGetFlags ${SecContribModernUI} $R0
;  IntOp $R0 $R0 & ${SF_SELECTED}
;	IntCmp $R0 ${SF_SELECTED} "" nomui nomui

;    SectionGetFlags ${SecContribLang} $R0
;    IntOp $R0 $R0 & ${SF_SELECTED}
;    IntCmp $R0 ${SF_SELECTED} langfiles
	
;      SetOutPath "$INSTDIR\NSIS\Contrib\Modern UI\Language files"
;      File "..\NSIS\Contrib\Modern UI\Language files\English.nsh"
    
;    langfiles:
    
;    SectionGetFlags ${SecContribGraphics} $R0
;    IntOp $R0 $R0 & ${SF_SELECTED}
;    IntCmp $R0 ${SF_SELECTED} graphics
    
;      SetOutPath $INSTDIR\Contrib\Icons
;      File "..\NSIS\Contrib\Icons\modern-install.ico"
;      File "..\NSIS\Contrib\Icons\modern-uninstall.ico"
;      File "..\NSIS\Contrib\Icons\modern-wizard.bmp"
      
;    graphics:
    
;  nomui:
  

  SetOutPath $INSTDIR
  
  ;WriteRegStr HKLM "SOFTWARE\Hostweb\Support" "InstallPath" $INSTDIR
  WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "UninstallString" "$INSTDIR\uninstall.exe"
  WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "InstallLocation" "$INSTDIR"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "DisplayName" "Hostweb Support Infrastructure"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "DisplayIcon" "$INSTDIR\hostweb.ico"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "DisplayVersion" "${MUI_VERSION}"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "VersionMajor" "0.1"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "VersionMinor" "beta"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "NoModify" "1"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support" "NoRepair" "1"



;ExecWait "$INSTDIR\apache\apache" "-i -n supportapache"
Push "$INSTDIR\apache\apache"
Push "exe"
Push ""
Push "-i -n supportapache"
Call ExecWaitWithParameters

;ExecWait "net" "start supportapache"
Push "net"
Push "exe"
Push ""
Push "start supportapache"
Call ExecWaitWithParameters


  
;!ifndef NO_STARTMENUSHORTCUTS
;  IfFileExists $SMPROGRAMS\NSIS "" nofunshit
;
;  IfFileExists $INSTDIR\Examples 0 +2
;    CreateShortCut "$SMPROGRAMS\NSIS\NSIS Examples Directory.lnk" "$INSTDIR\Examples"
;
;  IfFileExists "$INSTDIR\Source" 0 +2
;    CreateShortCut "$SMPROGRAMS\NSIS\MakeNSIS project workspace.lnk" "$INSTDIR\source\makenssi.dsw";
;
;  CreateDirectory $SMPROGRAMS\NSIS\Contrib\Source
;
  ; MakeNSISW
;  CreateDirectory $SMPROGRAMS\NSIS\Contrib
;    CreateShortCut "$SMPROGRAMS\NSIS\Contrib\MakeNSISW readme.lnk" "$INSTDIR\contrib\MakeNsisw\readme.txt"

;  Push "MakeNSISW"
;  Call AddWorkspaceToStartMenu

  ; ExDLL
;  Push "ExDLL"
;  Call AddWorkspaceToStartMenu

  ; InstallOptions
;  Push "InstallOptions\install options.html"
;  Push "InstallOptions readme"
;  Call AddContribToStartMenu

;  Push "InstallOptions\io.dsw"
;  Push "Source\InstallOptions project workspace"
;  Call AddContribToStartMenu

  ; ZIP2EXE
;  IfFileExists "$INSTDIR\Bin\zip2exe.exe" 0 +2
;    CreateShortCut "$SMPROGRAMS\NSIS\Contrib\ZIP 2 EXE converter.lnk" "$INSTDIR\Bin\zip2exe.exe"

;  Push ZIP2EXE
;  Call AddWorkspaceToStartMenu

  ; Modern UI
;  Push "Modern UI\Readme.html"
;  Push "Modern UI readme"
;  Call AddContribToStartMenu

  ; Splash
;  Push Splash
;  Call AddReadmeToStartMenu;

;  Push Splash
;  Call AddWorkspaceToStartMenu

  ; Advanced splash
;  Push AdvSplash
;  Call AddReadmeToStartMenu

;  Push AdvSplash
;  Call AddWorkspaceToStartMenu

  ; NSISdl
;  Push NSISdl
;  Call AddReadmeToStartMenu

;  Push NSISdl
;  Call AddWorkspaceToStartMenu

  ; UserInfo
;  Push UserInfo
;  Call AddWorkspaceToStartMenu

  ; nsExec
;  Push nsExec
;  Call AddReadmeToStartMenu

;  Push nsExec
;  Call AddWorkspaceToStartMenu

  ; LangDLL
;  Push LangDLL
;  Call AddWorkspaceToStartMenu

  ; StartMenu
;  Push StartMenu
;  Call AddReadmeToStartMenu

;  Push StartMenu
;  Call AddWorkspaceToStartMenu

  ; BgImage
;  Push BgImage
;  Call AddReadmeToStartMenu

;  Push BgImage
;  Call AddWorkspaceToStartMenu

  ; Banner
;  Push Banner
;  Call AddReadmeToStartMenu

;  Push Banner
;  Call AddWorkspaceToStartMenu

  ; System
;  Push System
;  Call AddReadmeToStartMenu

;  Push System\Source\System.sln
;  Push "Source\System project workspace"
;  Call AddContribToStartMenu

;  nofunshit:
;!endif
  
  ; will only be removed if empty
  SetDetailsPrint none
;  RMDir $INSTDIR\Contrib\Source
  SetDetailsPrint lastused

  Delete $INSTDIR\uninstall.exe
  WriteUninstaller $INSTDIR\uninstall.exe

SectionEnd

;--------------------------------
;Descriptions

!ifndef CLASSIC_UI

!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
  !insertmacro MUI_DESCRIPTION_TEXT ${SecCore} "The core files required to use this system"
  !insertmacro MUI_DESCRIPTION_TEXT ${SecApache} "Apache v1.3 with configuration included"
  !insertmacro MUI_DESCRIPTION_TEXT ${SecPHP} "PHP v3 including configuration for apache 1.3"
  !insertmacro MUI_DESCRIPTION_TEXT ${Secmysql} "mySQL v2.3.23 with configuration and passwords preset for integration"
!insertmacro MUI_FUNCTIONS_DESCRIPTION_END
 
!endif

;--------------------------------
;Installer Functions

!macro secSelected SEC
  SectionGetFlags ${SEC} $R7
  IntOp $R7 $R7 & ${SF_SELECTED}
  IntCmp $R7 ${SF_SELECTED} 0 +2 +2
    IntOp $R0 $R0 + 1
!macroend

;Function .onSelChange
;  ;Plugins are linked to ExDLL
;  StrCpy $R0 0
;  !insertmacro secSelected ${SecContribSplashTS}
;  !insertmacro secSelected ${SecContribBannerS}
;  !insertmacro secSelected ${SecContribBgImageS}
;  !insertmacro secSelected ${SecContribIOS}
;  !insertmacro secSelected ${SecContribLangDLLS}
;  !insertmacro secSelected ${SecContribnsExecS}
;  !insertmacro secSelected ${SecContribNSISdlS}
;  !insertmacro secSelected ${SecContribSplashS}
;  !insertmacro secSelected ${SecContribStartMenuS}
;  !insertmacro secSelected ${SecContribUserInfoS}
;  !insertmacro secSelected ${SecContribDialerS}
;  SectionGetFlags ${SecSrcEx} $R7
;  StrCmp $R0 0 notRequired
;    IntOp $R7 $R7 | ${SF_SELECTED}
;    SectionSetFlags ${SecSrcEx} $R7
;    SectionSetText ${SecSrcEx} "ExDLL Source (required)"
;    Goto done
;  notRequired:
;    SectionSetText ${SecSrcEx} "ExDLL Source"
;  done:
;FunctionEnd

function StrReplace
  Exch $0 ;this will replace wrong characters
  Exch
  Exch $1 ;needs to be replaced
  Exch
  Exch 2
  Exch $2 ;the orginal string
  Push $3 ;counter
  Push $4 ;temp character
  Push $5 ;temp string
  Push $6 ;length of string that need to be replaced
  Push $7 ;length of string that will replace
  Push $R0 ;tempstring
  Push $R1 ;tempstring
  Push $R2 ;tempstring
  StrCpy $3 "-1"
  StrCpy $5 ""
  StrLen $6 $1
  StrLen $7 $0
  Loop:
  IntOp $3 $3 + 1
  StrCpy $4 $2 $6 $3
  StrCmp $4 "" ExitLoop
  StrCmp $4 $1 Replace
  Goto Loop
  Replace:
  StrCpy $R0 $2 $3
  IntOp $R2 $3 + $6
  StrCpy $R1 $2 "" $R2
  StrCpy $2 $R0$0$R1
  IntOp $3 $3 + $7
  Goto Loop
  ExitLoop:
  StrCpy $0 $2
  Pop $R2
  Pop $R1
  Pop $R0
  Pop $7
  Pop $6
  Pop $5
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $0
FunctionEnd

Function ExecWaitWithParameters
 # Preparing Variables
 Exch $0 ;Parameters
 Exch
 Exch $1 ;Action
 Exch
 Exch 2
 Exch $2 ;Extension
 Exch 2
 Exch 3
 Exch $3 ;File Name
 Exch 3
 StrCmp $1 "" 0 +2
   StrCpy $1 open
 StrCmp $2 "" 0 +2
   StrCpy $2 $3 "" -3
 # Search at Registry for the extension
 Push $2
 ReadRegStr $2 HKCR ".$2" ""
 ReadRegStr $2 HKCR "$2\shell\$1\command" ""
 # Search and Replace "%1" in string $2 - Uses StrReplace
 Push $2
 Push %1
 Push $3
 Call StrReplace
 Pop $1
 StrCmp $1 "" 0 +6
 # Search and Replace "%L" in string $2 - Uses StrReplace
 Push $1
 Push %1
 Push $3
 Call StrReplace
 Pop $1
 StrCpy $2 $1
 Pop $1
 StrCmp $1 exe 0 +3
   StrCpy $2 $2 -4
   StrCpy $2 '$2"'
 # Run with Wait option!
 ExecWait '$2 $0'
 Pop $3
 Pop $2
 Pop $1
 Pop $0
 FunctionEnd


function un.StrReplace
  Exch $0 ;this will replace wrong characters
  Exch
  Exch $1 ;needs to be replaced
  Exch
  Exch 2
  Exch $2 ;the orginal string
  Push $3 ;counter
  Push $4 ;temp character
  Push $5 ;temp string
  Push $6 ;length of string that need to be replaced
  Push $7 ;length of string that will replace
  Push $R0 ;tempstring
  Push $R1 ;tempstring
  Push $R2 ;tempstring
  StrCpy $3 "-1"
  StrCpy $5 ""
  StrLen $6 $1
  StrLen $7 $0
  Loop:
  IntOp $3 $3 + 1
  StrCpy $4 $2 $6 $3
  StrCmp $4 "" ExitLoop
  StrCmp $4 $1 Replace
  Goto Loop
  Replace:
  StrCpy $R0 $2 $3
  IntOp $R2 $3 + $6
  StrCpy $R1 $2 "" $R2
  StrCpy $2 $R0$0$R1
  IntOp $3 $3 + $7
  Goto Loop
  ExitLoop:
  StrCpy $0 $2
  Pop $R2
  Pop $R1
  Pop $R0
  Pop $7
  Pop $6
  Pop $5
  Pop $4
  Pop $3
  Pop $2
  Pop $1
  Exch $0
FunctionEnd

Function un.ExecWaitWithParameters
 # Preparing Variables
 Exch $0 ;Parameters
 Exch
 Exch $1 ;Action
 Exch
 Exch 2
 Exch $2 ;Extension
 Exch 2
 Exch 3
 Exch $3 ;File Name
 Exch 3
 StrCmp $1 "" 0 +2
   StrCpy $1 open
 StrCmp $2 "" 0 +2
   StrCpy $2 $3 "" -3
 # Search at Registry for the extension
 Push $2
 ReadRegStr $2 HKCR ".$2" ""
 ReadRegStr $2 HKCR "$2\shell\$1\command" ""
 # Search and Replace "%1" in string $2 - Uses StrReplace
 Push $2
 Push %1
 Push $3
 Call un.StrReplace
 Pop $1
 StrCmp $1 "" 0 +6
 # Search and Replace "%L" in string $2 - Uses StrReplace
 Push $1
 Push %1
 Push $3
 Call un.StrReplace
 Pop $1
 StrCpy $2 $1
 Pop $1
 StrCmp $1 exe 0 +3
   StrCpy $2 $2 -4
   StrCpy $2 '$2"'
 # Run with Wait option!
 ExecWait '$2 $0'
 Pop $3
 Pop $2
 Pop $1
 Pop $0
FunctionEnd


!ifndef NO_STARTMENUSHORTCUTS
Function AddContribToStartMenu
  Pop $0 ; link
  Pop $1 ; file
  IfFileExists $INSTDIR\Contrib\$1 0 +2
    CreateShortCut $SMPROGRAMS\NSIS\Contrib\$0.lnk $INSTDIR\Contrib\$1
FunctionEnd

Function AddWorkspaceToStartMenu
  Pop $0
  IfFileExists $INSTDIR\Contrib\$0\$0.dsw 0 done
    Push $0\$0.dsw
    Push "Source\$0 project workspace"
    Call AddContribToStartMenu
  done:
FunctionEnd

Function AddReadmeToStartMenu
  Pop $0
  IfFileExists $INSTDIR\Contrib\$0\$0.txt 0 +3
    Push $0\$0.txt
    Goto create
  IfFileExists $INSTDIR\Contrib\$0\Readme.txt 0 done
    Push $0\Readme.txt
  create:
    Push "$0 readme"
    Call AddContribToStartMenu
  done:
FunctionEnd
!endif

;--------------------------------
;Uninstaller Section

Section Uninstall
  IfFileExists $INSTDIR\uninstall.exe skip_confirmation
    MessageBox MB_YESNO "It does not appear that the Hostweb Support software is installed in the directory '$INSTDIR'.$\r$\nContinue anyway (not recommended)" IDYES skip_confirmation
    Abort "Uninstall aborted by user"
  skip_confirmation:

;ExecWait "net stop supportapache"
Push "net"
Push "exe"
Push ""
Push "stop supportapache"
Call un.ExecWaitWithParameters

;ExecWait "$INSTDIR\apache\apache -u -n supportapache"
Push "$INSTDIR\apache\apache"
Push "exe"
Push ""
Push "-u -n supportapache"
Call un.ExecWaitWithParameters

;ExecWait "$INSTDIR\mysql\bin\mysqlwatch -remove"
Push "$INSTDIR\mysql\bin\mysqlwatch"
Push "exe"
Push ""
Push "-remove"
Call un.ExecWaitWithParameters


  ReadRegStr $1 HKCR ".nsi" ""
  StrCmp $1 "NSISFile" 0 NoOwn ; only do this if we own it
    ReadRegStr $1 HKCR ".nsi" "backup_val"
    StrCmp $1 "" 0 RestoreBackup ; if backup == "" then delete the whole key
      DeleteRegKey HKCR ".nsi"
    Goto NoOwn
    RestoreBackup:
      WriteRegStr HKCR ".nsi" "" $1
      DeleteRegValue HKCR ".nsi" "backup_val"
  NoOwn:

  ReadRegStr $1 HKCR ".nsh" ""
  StrCmp $1 "NSHFile" 0 NoOwn2 ; only do this if we own it
    ReadRegStr $1 HKCR ".nsh" "backup_val"
    StrCmp $1 "" 0 RestoreBackup2 ; if backup == "" then delete the whole key
      DeleteRegKey HKCR ".nsh"
    Goto NoOwn
    RestoreBackup2:
      WriteRegStr HKCR ".nsh" "" $1
      DeleteRegValue HKCR ".nsh" "backup_val"
  NoOwn2:

  DeleteRegKey HKCR "NSISFile"
  DeleteRegKey HKCR "NSHFile"
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Hostweb Support"
  DeleteRegKey HKLM "SOFTWARE\Hostweb Support"

  RMDir /r "$INSTDIR\Apache"
  RMDir /r "$INSTDIR\html"
  RMDir /r "$INSTDIR\mysql"
  RMDir /r "$INSTDIR\php"
  Delete "$INSTDIR\hostweb.ico"
  Delete "$INSTDIR\uninstall.exe"
  RMDir $INSTDIR

  ;Delete "$DESKTOP\Nullsoft Install System.lnk"
  ;Delete $INSTDIR\makensis.exe
  ;Delete $INSTDIR\makensisw.exe
  ;Delete $INSTDIR\makensis.htm
  ;Delete $INSTDIR\NSIS.exe
  ;Delete $INSTDIR\license.txt
  ;Delete $INSTDIR\uninst-nsis.exe
  ;Delete $INSTDIR\nsisconf.nsi
  ;Delete $INSTDIR\nsisconf.nsh
  ;RMDir /r $INSTDIR\Contrib
  ;RMDir /r $INSTDIR\Menu
  ;RMDir /r $INSTDIR\Source
  ;RMDir /r $INSTDIR\Bin
  ;RMDir /r $INSTDIR\Plugins
  ;RMDir /r $INSTDIR\Examples
  ;RMDir /r $INSTDIR\Include
  ;RMDir /r $INSTDIR\Docs
  ;RMDir $INSTDIR

  ;!ifndef CLASSIC_UI
  ;  ;Modern UI Finish Header
  ;  !insertmacro MUI_UNFINISHHEADER
  ;!endif

SectionEnd


