!include "MUI.nsh"

;--------------------------------
;Product Info

!define MUI_PRODUCT "S7-OPC-Server"
!define MUI_VERSION "1.00"
!define MUI_COMPANY "Systeme Helmholz"
;--------------------------------
;Configuration

  ;General
  OutFile "${MUI_PRODUCT} Setup.exe"
  BrandingText ""
  LicenseText "License Page" "Acccept"
  LicenseData "license.txt"

  ;Folder selection page
  InstallDir "$PROGRAMFILES\${MUI_COMPANY}\${MUI_PRODUCT}"
  
  ;Get install folder from registry if available
  InstallDirRegKey HKCU "Software\${MUI_COMPANY}\${MUI_PRODUCT}" ""
  
;--------------------------------
;Pages

  !insertmacro MUI_PAGE_LICENSE
;  !insertmacro MUI_PAGE_COMPONENTS
;  !insertmacro MUI_PAGE_STARTMENU

  ;Page license license
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_INSTFILES
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES
  
;--------------------------------
;Modern UI Configuration

  ;Remember the installer language
  !define MUI_LANGDLL_REGISTRY_ROOT "HKLM" 
  ;if the language have been selected once it`ll be saved here further setups could use this 
  ;predefined language
  ;!define MUI_LANGDLL_REGISTRY_KEY "Software\Softing\Products\22" 
  !define MUI_LANGDLL_REGISTRY_VALUENAME "Installer Language"

  !define MUI_ABORTWARNING

;--------------------------------
;Languages

  !insertmacro MUI_LANGUAGE "English"
  !insertmacro MUI_LANGUAGE "German"
  
;--------------------------------
;Reserve Files
  
  ;Things that need to be extracted on first (keep these lines before any File command!)
  ;Only for BZIP2 compression
  !insertmacro MUI_RESERVEFILE_LANGDLL

;--------------------------------
;Installer Sections

Section "Dummy Test File" SecCopyUI
  ;ADD YOUR OWN STUFF HERE!
      
      
    call GetWindowsVersion
    StrCmp $0 'NO' lbl_Berror
  
  
  ;multilingual files here
  SetOutPath $INSTDIR\Netlink_IP
    File "C:\OPC\Installer\OPC\German\ProgramDir\Netlink_IP\Netlink_IP.exe"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Netlink_IP\Netlink_IP.ini"

  ;non multilingual files here
  StrCmp $LANGUAGE 'English' lbl_eng

    SetOutPath $INSTDIR   
    File "C:\OPC\Installer\OPC\German\ProgramDir\fc_slbase20.dll"
    File "C:\OPC\Installer\OPC\German\ProgramDir\AGLink.DLL"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPC.cnt"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPC.dll"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPC.hlp"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCCfg.cnt"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCCfg.exe"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCCfg.hlp"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCLicMan.cnt"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCLicMan.exe"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCLicMan.hlp"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCSrv.exe"
    File "C:\OPC\Installer\OPC\German\ProgramDir\S7OPCSvc.exe"
    File "C:\OPC\Installer\OPC\German\ProgramDir\InProcReg.bat"
    File "C:\OPC\Installer\OPC\German\ProgramDir\OutProcReg.bat"
    File "C:\OPC\Installer\OPC\German\ProgramDir\ServiceReg.bat"
    File "C:\OPC\Installer\OPC\German\ProgramDir\unregisterservices.bat"
    File "C:\OPC\Installer\OPC\German\ProgramDir\SOWatch.exe"
    File "C:\OPC\Installer\OPC\German\ProgramDir\SOWatchE.chm"
    File "C:\OPC\Installer\OPC\German\ProgramDir\SOWatchG.chm"
    
    SetOutPath $SYSDIR
    ifFileExists "$SYSDIR\HilIp32.dll" lbl_exist1
    File "C:\OPC\Installer\OPC\German\SystemDir\HilIp32.dll"
    lbl_exist1:
    ifFileExists "$SYSDIR\Ip32Drv.dll" lbl_exist2
    File "C:\OPC\Installer\OPC\German\SystemDir\Ip32Drv.dll"
    lbl_exist2:
    ifFileExists "$SYSDIR\NetIdentCfg.dll" lbl_exist3
    File "C:\OPC\Installer\OPC\German\SystemDir\NetIdentCfg.dll"
    lbl_exist3:
    ifFileExists "$SYSDIR\opccomn_ps.dll" lbl_exist4
    File "C:\OPC\Installer\OPC\German\SystemDir\opccomn_ps.dll"
    lbl_exist4:
    ifFileExists "$SYSDIR\OpcEnum.exe" lbl_exist5
    File "C:\OPC\Installer\OPC\German\SystemDir\OpcEnum.exe"
    lbl_exist5:
    ifFileExists "$SYSDIR\opcproxy.dll" lbl_exist6
    File "C:\OPC\Installer\OPC\German\SystemDir\opcproxy.dll"
    lbl_exist6:
    ifFileExists "$SYSDIR\SOProxy.dll" lbl_exist7
    File "C:\OPC\Installer\OPC\German\SystemDir\SOProxy.dll"
    lbl_exist7:
    
    
    
    ;***************************************
    ;File "C:\OPC\Installer\OPC\German\ProgramDir\AGLink.DLL"
    ;***************************************
    
    SetOutPath $INSTDIR\Netlink_IP
    File "C:\OPC\Installer\OPC\German\ProgramDir\Netlink_IP\Netlink_IP_D.ltf"
    WriteINIStr "$INSTDIR\Netlink_IP\Netlink_IP.ini" "Application" "Language" D   
    
    SetOutPath "$INSTDIR\Softing OPC Toolbox Demo Client"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure1.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure2.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure3.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure4.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure5.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure6.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure7.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure8.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure9.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure10.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure11.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure12.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure13.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure14.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\figure15.gif"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\LiesMich.htm"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\opcAutoSofting.dll"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\SOClient.exe"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\SOClientE.chm"
    File "C:\OPC\Installer\OPC\German\ProgramDir\Softing OPC Toolbox Demo Client\SOClientG.chm"

    GoTo lbl_regDlls  
  ;- E - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
  lbl_eng:
    SetOutPath $INSTDIR
    File "C:\OPC\Installer\OPC\English\ProgramDir\AGLink.DLL"
    File "C:\OPC\Installer\OPC\English\ProgramDir\fc_slbase20.dll"
    File "C:\OPC\Installer\OPC\English\ProgramDir\InProcReg.bat"
    File "C:\OPC\Installer\OPC\English\ProgramDir\OutProcReg.bat"
    File "C:\OPC\Installer\OPC\English\ProgramDir\ServiceReg.bat"
    File "C:\OPC\Installer\OPC\English\ProgramDir\unregisterservices.bat"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPC.cnt"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPC.dll"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPC.hlp"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCCfg.cnt"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCCfg.exe"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCCfg.hlp"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCLicMan.cnt"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCLicMan.exe"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCLicMan.hlp"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCSrv.exe"
    File "C:\OPC\Installer\OPC\English\ProgramDir\S7OPCSvc.exe"
    File "C:\OPC\Installer\OPC\English\ProgramDir\SOWatch.exe"
    File "C:\OPC\Installer\OPC\English\ProgramDir\SOWatchE.chm"
    File "C:\OPC\Installer\OPC\English\ProgramDir\SOWatchG.chm"
    
    SetOutPath $INSTDIR\Netlink_IP
    File "C:\OPC\Installer\OPC\English\ProgramDir\Netlink_IP\Netlink_IP_E.ltf"
    WriteINIStr "$INSTDIR\Netlink_IP\Netlink_IP.ini" "Application" "Language" E
    
    SetOutPath "$INSTDIR\Softing OPC Toolbox Demo Client"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure1.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure2.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure3.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure4.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure5.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure6.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure7.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure8.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure9.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure10.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure11.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure12.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure13.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure14.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\figure15.gif"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\LiesMich.htm"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\opcAutoSofting.dll"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\SOClient.exe"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\SOClientE.chm"
    File "C:\OPC\Installer\OPC\English\ProgramDir\Softing OPC Toolbox Demo Client\SOClientG.chm"
    
    SetOutPath $SYSDIR
    File "C:\OPC\Installer\OPC\English\SystemDir\HilIp32.dll"
    File "C:\OPC\Installer\OPC\English\SystemDir\Ip32Drv.dll"
    File "C:\OPC\Installer\OPC\English\SystemDir\NetIdentCfg.dll"
    File "C:\OPC\Installer\OPC\English\SystemDir\opccomn_ps.dll"
    File "C:\OPC\Installer\OPC\English\SystemDir\OpcEnum.exe"
    File "C:\OPC\Installer\OPC\English\SystemDir\opcproxy.dll"
    File "C:\OPC\Installer\OPC\English\SystemDir\SOProxy.dll"

  lbl_regDlls:
    ;system dependent registration of services and servers

    ;for debug output of os
    ;MessageBox MB_YESNO "$0 detected"

    StrCmp $0 '98' lbl_98
    StrCmp $0 'ME' lbl_98
    StrCmp $0 'NT' lbl_NT
    StrCmp $0 '2K' lbl_NT
    StrCmp $0 'XP' lbl_NT
    StrCmp $0 'NO' lbl_Berror
  
    lbl_98:
      Exec '"$INSTDIR\S7OPCSrv.exe" -RegServer'
      Exec '"$SYSDIR\OpcEnum.exe" -RegServer'
      
      WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_COMPANY} ${MUI_PRODUCT}" "DisplayName" "${MUI_COMPANY} ${MUI_PRODUCT}"
      WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_COMPANY} ${MUI_PRODUCT}" "UninstallString" "$INSTDIR\Uninstall.exe"
      
    GoTo lbl_finish

    lbl_NT:    
      Exec '"$INSTDIR\S7OPCSvc.exe" -RegServer'
      ;Exec '"$SYSDIR\OpcEnum.exe" -Service'
    GoTo lbl_finish
  
  lbl_Berror:
    Abort
      
  lbl_finish:
 
    RegDll $SYSDIR\opccomn_ps.dll  ;foundation files
    RegDll $SYSDIR\opcproxy.dll
    RegDll $SYSDIR\SOProxy.dll  
         
    Exec '"$SYSDIR\regsvr32.exe" -s $INSTDIR\S7OPC.dll'
    
    RegDll "$INSTDIR\Softing OPC Toolbox Demo Client\opcAutoSofting.dll"
  
    SetOutPath "$INSTDIR"
    ;File "${NSISDIR}\Contrib\UIs\modern.exe"
  
   ;Store install folder
   WriteRegStr HKCU "Software\${MUI_COMPANY}\${MUI_PRODUCT}" "" $INSTDIR
  
   ;Create uninstaller
   WriteUninstaller "$INSTDIR\Uninstall.exe"
   
  ;Write prog registry keys
  
  WriteRegStr HKLM "SOFTWARE\Softing\Products\22"  "Name"    "S7 OPC Server"
  WriteRegStr HKLM "SOFTWARE\Softing\Products\22"  "Version" "1.00"


  WriteRegStr HKLM "SOFTWARE\Softing\S7 OPC Server" "LicManEmailSendTo" "vertrieb@helmholz.de"
  WriteRegStr HKLM "SOFTWARE\Softing\S7 OPC Server" "LicManEmailSubject""Registrierung Helmholz ${MUI_PRODUCT}"
  WriteRegStr HKLM "SOFTWARE\Softing\S7 OPC Server" "LicManEmailBody"   "Lizenznehmer:\\n!!!Bitte hier Ihre komplette Anschrift eintragen!!!\\n\\nAuftragsnummer: !!!Bitte hier die Auftragsnummer eintragen!!!\\n\\nInstallationsschluessel: %s"
  WriteRegStr HKLM "SOFTWARE\Softing\S7 OPC Server" "InstDir"           "$INSTDIR"
  WriteRegStr HKLM "SOFTWARE\Softing\S7 OPC Server" "InstVersion"       "1.00"


  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev0" "ScanBus" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev0" "MonOn" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev0" "MonReconnectTimeout" 10
  
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev1" "ScanBus" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev1" "MonOn" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev1" "MonReconnectTimeout" 10
  
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev2" "ScanBus" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev2" "MonOn" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev2" "MonReconnectTimeout" 10
  
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev3" "ScanBus" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev3" "MonOn" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev3" "MonReconnectTimeout" 10
  
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev4" "ScanBus" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev4" "MonOn" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev4" "MonReconnectTimeout" 10
  
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev5" "ScanBus" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev5" "MonOn" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev5" "MonReconnectTimeout" 10
  
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev6" "ScanBus" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev6" "MonOn" 00000000
  WriteRegDWORD HKLM "SOFTWARE\Softing\S7 OPC Server\Dev6" "MonReconnectTimeout" 10
  
  ;Add Shortcuts
  CreateDirectory "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}"
  CreateShortCut "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Hilfe ${MUI_PRODUCT}.lnk"         "$INSTDIR\S7OPC.hlp"   "" "$INSTDIR\S7OPC.hlp" 0
  CreateShortCut "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Konfiguration ${MUI_PRODUCT}.lnk" "$INSTDIR\S7OPCCfg.exe"   "" "$INSTDIR\S7OPCCfg.exe" 0
  CreateShortCut "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Lizenzmaker ${MUI_PRODUCT}.lnk"   "$INSTDIR\S7OPCLicMan.exe"   "" "$INSTDIR\S7OPCLicMan.exe" 0
  CreateShortCut "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\OPC Demo Watch.lnk"               "$INSTDIR\SOWatch.exe"   "" "$INSTDIR\SOWatch.exe" 0
  CreateShortCut "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\OPC Toolbox Demo Client.lnk"      "$INSTDIR\Softing OPC Toolbox Demo Client\SOClient.exe"   "" "$INSTDIR\Softing OPC Toolbox Demo Client\SOClient.exe" 0
  CreateShortCut "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Netlink_IP.lnk"                   "$INSTDIR\Netlink_IP\Netlink_IP.exe"   "" "$INSTDIR\Netlink_IP\Netlink_IP.exe" 0
  CreateShortCut "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Uninstall.lnk"                    "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0

SectionEnd
;------------------------------------------------------------------------------
; GetWindows Version
;
; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
; Returns:
;
; $0 - Windows Version (95, 98, ME, NT, 2K, XP, NO)    ;modified
; or
; $0 - '' (Unknown Windows Version)
;
; last modified: 17.07.03
; by           : Michael Sonst
; adress       : focus01@gmx.de
; added        : XP Support

Function GetWindowsVersion

  Push $9
  ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  StrCmp $0 "" 0 lbl_winnt
  ; we are not NT.
  ReadRegStr $0 HKLM SOFTWARE\Microsoft\Windows\CurrentVersion VersionNumber

;  StrCpy $9 $0 1
;  StrCmp $9 '4' 0 lbl_error

  StrCpy $9 $0 3

  StrCmp $9 '4.0' lbl_win32_95
  StrCmp $9 '4.9' lbl_win32_ME lbl_win32_98

  lbl_win32_95:
    StrCpy $0 '95'
  Goto lbl_done

  lbl_win32_98:
    StrCpy $0 '98'
  Goto lbl_done

  lbl_win32_ME:
    StrCpy $0 'ME'
  Goto lbl_done

  lbl_winnt:

    StrCpy $9 $0 1
    StrCmp $9 '4'   lbl_winnt_x
    
    StrCpy $9 $0 3                           ;modified
    StrCmp $9 '5.0' lbl_winnt_2K             ;modified
    StrCmp $9 '5.1' lbl_winnt_XP lbl_error   ;modified

    lbl_winnt_x:
      StrCpy $0 'NT' 2
    Goto lbl_done

    lbl_winnt_2k:                            ;modified
      Strcpy $0 '2K' 2
    Goto lbl_done
    
    lbl_winnt_XP:                            ;modified
      Strcpy $0 'XP' 2
    Goto lbl_done
    
  lbl_error:
    Strcpy $0 'NO'
  
  lbl_done:
  Pop $9
  
FunctionEnd
;------------------------------------------------------------------------------
;Descriptions

LangString DESC_SecCopyUI ${LANG_ENGLISH} "modern.exe: English description"
LangString DESC_SecCopyUI ${LANG_GERMAN} "modern.exe: German description"


!insertmacro MUI_FUNCTIONS_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecCopyUI} $(DESC_SecCopyUI)
!insertmacro MUI_FUNCTIONS_DESCRIPTION_END
 
;--------------------------------
;Uninstaller Section

Section "Uninstall"
    
    ;system dependent registration of services and servers
    call un.GetWindowsVersion
    
    StrCmp $0 '98' lbl_98
    StrCmp $0 'ME' lbl_98
    StrCmp $0 'NT' lbl_NT
    StrCmp $0 '2K' lbl_NT
    StrCmp $0 'XP' lbl_NT 
    StrCmp $0 'NO' lbl_Berror
  
    lbl_98:
    
      Exec '"$INSTDIR\S7OPCSrv.exe" -UnRegServer'
      Sleep 1000
      
    GoTo lbl_finish

    lbl_NT:       
      
      Exec '"$INSTDIR\S7OPCSvc.exe" -UnRegServer'
      
      ExecWait '"$INSTDIR\unregisterservices.bat"-s'
      sleep 3000
      
    GoTo lbl_finish

  
  lbl_Berror:
    Abort  
  lbl_finish:

  Exec '"$SYSDIR\regsvr32.exe" -u -s $INSTDIR\S7OPC.dll'
  sleep 3000 
  ;UnRegDll $INSTDIR\fc_slbase20.dll
  ;sleep 2000 
  ;UnRegDll $SYSDIR\SOProxy.dll
  ;sleep 2000 
  
  ;********************
  ;opc foundation dlls und exe wurden nicht gelöscht
  ;********************
  
  UnRegDll "$INSTDIR\Softing OPC Toolbox Demo Client\opcAutoSofting.dll" 
  
  
  Delete "$INSTDIR\S7OPCLicMan.GID"
  Delete "$INSTDIR\S7OPC.GID"
  Delete "$INSTDIR\S7OPCCfg.GID" 
  
  Delete "$INSTDIR\S7OPCLicMan.FTS"
  Delete "$INSTDIR\S7OPC.FTS"
  Delete "$INSTDIR\S7OPCCfg.FTS"
  
  Delete "$INSTDIR\AGLink.DLL"  
  Delete "$INSTDIR\S7OPC.dll"  
  Delete "$INSTDIR\InProcReg.bat" 
  Delete "$INSTDIR\ServiceReg.bat" 
  Delete "$INSTDIR\OutProcReg.bat" 
  Delete "$INSTDIR\S7OPC.hlp"  
  Delete "$INSTDIR\S7OPC.cnt"  
  Delete "$INSTDIR\S7OPCSrv.exe"  
  Delete "$INSTDIR\S7OPCSvc.exe"
  Delete "$INSTDIR\SOWatch.exe"
  Delete "$INSTDIR\SOWatchE.chm"
  Delete "$INSTDIR\SOWatchG.chm"
  Delete "$INSTDIR\S7OPCCfg.exe"
  Delete "$INSTDIR\S7OPCCfg.hlp"
  Delete "$INSTDIR\S7OPCCfg.cnt"
  Delete "$INSTDIR\S7OPCLicMan.exe"
  Delete "$INSTDIR\S7OPCLicMan.hlp"
  Delete "$INSTDIR\S7OPCLicMan.cnt"
  Delete "$INSTDIR\fc_slbase20.dll"
  Delete "$INSTDIR\unregisterservices.bat"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\SOClient.exe"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\SOClientE.chm"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\SOClientG.chm"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\opcAutoSofting.dll"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\LiesMich.htm"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure1.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure2.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure3.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure4.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure5.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure6.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure7.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure8.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure9.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure10.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure11.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure12.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure13.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure14.gif"
  Delete "$INSTDIR\Softing OPC Toolbox Demo Client\figure15.gif"  
  
  Delete "$INSTDIR\Netlink_IP\Netlink_IP_D.ltf"  ;faster to delete both instead of searching
  Delete "$INSTDIR\Netlink_IP\Netlink_IP_E.ltf"  ;for each file
  Delete "$INSTDIR\Netlink_IP\Netlink_IP.exe"
  Delete "$INSTDIR\Netlink_IP\Netlink_IP.ini"    
  
  ;Delete Links
  Delete "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Hilfe ${MUI_PRODUCT}.lnk"  
  Delete "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\OPC Demo Watch.lnk"       
  Delete "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Konfiguration ${MUI_PRODUCT}.lnk" 
  Delete "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Lizenzmaker ${MUI_PRODUCT}.lnk"                
  Delete "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\OPC Toolbox Demo Client.lnk"
  Delete "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Netlink_IP.lnk"                  
  Delete "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}\Uninstall.lnk"   
  
  RMDir "$SMPROGRAMS\${MUI_COMPANY}\${MUI_PRODUCT}"
  RMDir "$SMPROGRAMS\${MUI_COMPANY}"
  
  
  ;Delete "$SYSDIR\HilIp32.dll"
  ;Delete "$SYSDIR\Ip32Drv.dll"
  ;Delete "$SYSDIR\NetIdentCfg.dll"
  ;Delete "$SYSDIR\SOProxy.dll"

  ;delete registry stuff
  ;delete uninstaller registry stuff
  
  DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_COMPANY}\${MUI_PRODUCT}"      

  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev0" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev0" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev0"
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev1" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev1" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev1" 
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev2" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev2" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev2"  
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev3" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev3" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev3"  
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev4" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev4" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev4" 
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev5" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev5" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev5"
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev6"
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev6" 
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server\Dev6" 
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_COMPANY} ${MUI_PRODUCT}"
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\${MUI_COMPANY} ${MUI_PRODUCT}"
  
  DeleteRegKey HKEY_LOCAL_MACHINE  "SOFTWARE\Softing\S7 OPC Server"  
  DeleteRegKey /ifempty HKCU "Software\${MUI_COMPANY}\${MUI_PRODUCT}"

  RMDir "$INSTDIR\Softing OPC Toolbox Demo Client"
  RMDir "$INSTDIR\Netlink_IP"
  
  ;Delete "$INSTDIR\modern.exe"
  Delete "$INSTDIR\Uninstall.exe"
  
  RMDir "$INSTDIR"
  RMDir "$PROGRAMFILES\${MUI_COMPANY}"

SectionEnd
;------------------------------------------------------------------------------
; GetWindows Version
;
; Based on Yazno's function, http://yazno.tripod.com/powerpimpit/
; Returns:
;
; $0 - Windows Version (95, 98, ME, NT, 2K, XP, NO)    ;modified
; or
; $0 - '' (Unknown Windows Version)
;
; last modified: 17.07.03
; by           : Michael Sonst
; adress       : focus01@gmx.de
; added        : XP Support

Function un.GetWindowsVersion

  Push $9
  ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
  StrCmp $0 "" 0 lbl_winnt
  ; we are not NT.
  ReadRegStr $0 HKLM SOFTWARE\Microsoft\Windows\CurrentVersion VersionNumber

;  StrCpy $9 $0 1
;  StrCmp $9 '4' 0 lbl_error

  StrCpy $9 $0 3

  StrCmp $9 '4.0' lbl_win32_95
  StrCmp $9 '4.9' lbl_win32_ME lbl_win32_98

  lbl_win32_95:
    StrCpy $0 '95'
  Goto lbl_done

  lbl_win32_98:
    StrCpy $0 '98'
  Goto lbl_done

  lbl_win32_ME:
    StrCpy $0 'ME'
  Goto lbl_done

  lbl_winnt:

    StrCpy $9 $0 1
    StrCmp $9 '4'   lbl_winnt_x
    
    StrCpy $9 $0 3                           ;modified
    StrCmp $9 '5.0' lbl_winnt_2K             ;modified
    StrCmp $9 '5.1' lbl_winnt_XP lbl_error   ;modified

    lbl_winnt_x:
      StrCpy $0 'NT' 2
    Goto lbl_done

    lbl_winnt_2k:                            ;modified
      Strcpy $0 '2K' 2
    Goto lbl_done
    
    lbl_winnt_XP:                            ;modified
      Strcpy $0 'XP' 2
    Goto lbl_done
      
  lbl_error:
    Strcpy $0 'NO'
  
  lbl_done:
  Pop $9
  
FunctionEnd
;------------------------------------------------------------------------------
;Uninstaller Functions

Function un.onInit

  !insertmacro MUI_UNGETLANGUAGE
  
FunctionEnd

;Installer Functions

Function .onInit

  !insertmacro MUI_LANGDLL_DISPLAY

FunctionEnd