;NSIS Modern User Interface
;priPrinter installer
;Based on Joost Verburg

; Define source code Unicode (not ANSI)
Unicode True

!define OMUI_THEME_PATH "Resources"

; In the moment of writing this, NSIS don't support well Vista icons with PNG compression.
; We provide both, compressed and uncompressed (-nopng) icons.

	!define MUI_ICON "${OMUI_THEME_PATH}\view.ico"
	!define MUI_UNICON "${OMUI_THEME_PATH}\uninstaller.ico"
 
; MUI Settings / Header
	!define MUI_HEADERIMAGE
	!define MUI_HEADERIMAGE_RIGHT
	!define MUI_HEADERIMAGE_BITMAP "${OMUI_THEME_PATH}\header-r.bmp"
	!define MUI_HEADERIMAGE_UNBITMAP "${OMUI_THEME_PATH}\header-r-un.bmp"
	;!define MUI_WELCOMEPAGE_TITLE_3LINES

; MUI Settings / Wizard		
	!define MUI_WELCOMEFINISHPAGE_BITMAP "${OMUI_THEME_PATH}\wizard.bmp"
	!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${OMUI_THEME_PATH}\wizard-un.bmp"


SetCompressor /solid /final lzma

;--------------------------------
;Include Modern UI

!include "MUI.nsh"

!include "x64.nsh"
!include "registerExtension.nsh"
!include "FileFunc.nsh"
;--------------------------------

!include "version.nsh"

!define ps_REG_PATH "Software\Pelikan Software KFT\priPrinter"
!define ps_PROG_NAME "priPrinter"


!define MULTIUSER_EXECUTIONLEVEL Admin
!include MultiUser.nsh
;General

RequestExecutionLevel admin
;Name and file
Name "priPrinter ${PE_SUB_EDITION} ${PE_SUB_STATUS}"
OutFile "..\bin\priPrinter ${PE_SUB_EDITION} ${PE_SUB_STATUS} ${PE_APP_VER_MAJOR_str}.${PE_APP_VER_MINOR_str}.${PE_APP_VER_FIX_str}.${PE_APP_BUILD_str}.exe"

;Default installation folder
InstallDir "$PROGRAMFILES\priPrinter"

;Get installation folder from registry if available

BrandingText "Pelikan Software KFT"

UninstallIcon "${OMUI_THEME_PATH}\uninstaller.ico"


  InstallDirRegKey HKCU "${ps_REG_PATH}" ""

;--------------------------------
;Variables
	Var MUI_TEMP
	Var STARTMENU_FOLDER
	Var VAR_SET_DEFAULT_PRINTER
	Var PP_X64
; Additional options for terminal server
	Var Dialog
	var var_ts_checkbox
	var var_ts_state
	var var_inst_mode


Function MyDirectoryShow
FindWindow $Dialog "#32770" "" $HWNDPARENT
GetDlgItem $var_ts_checkbox $Dialog 1008
SendMessage $var_ts_checkbox ${WM_SETTEXT} 0 "STR:$(LSTR_15)"
ShowWindow $var_ts_checkbox "${SW_SHOW}"
${If} $var_ts_state <> 0
   SendMessage $var_ts_checkbox ${BM_SETCHECK} ${BST_CHECKED} 0
${EndIf}
FunctionEnd

Function MyDirectoryLeave
;${NSD_GetState} $var_ts_checkbox $var_ts_state
SendMessage $var_ts_checkbox ${BM_GETCHECK} 0 0 $var_ts_state

${If} $var_ts_state <> 0
StrCpy $var_inst_mode "in_notray"
${else}
StrCpy $var_inst_mode "in"
${EndIf}
FunctionEnd

;--------------------------------
;Interface Settings

!define MUI_ABORTWARNING

;!define MUI_HEADERIMAGE
;!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange.bmp" ; optional

!define MUI_WELCOMEPAGE_TITLE "$(LSTR_01)"

;Start Menu Folder Page Configuration
!define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKCU" 
!define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\Pelikan Software KFT\priPrinter"
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "Start Menu Folder"


;--------------------------------
;Pages

!insertmacro MUI_PAGE_WELCOME
;!insertmacro MUI_PAGE_LICENSE "license_00.txt"
!insertmacro MUI_PAGE_LICENSE $(LSTR_14)
!define MUI_PAGE_CUSTOMFUNCTION_SHOW MyDirectoryShow
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE MyDirectoryLeave

!insertmacro MUI_PAGE_DIRECTORY

!insertmacro MUI_PAGE_STARTMENU Application $STARTMENU_FOLDER
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH

!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

;--------------------------------
;Languages

!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "Italian"

; LANG: 1033 - English
LangString LSTR_01 1033 "Instllation of '${ps_PROG_NAME} ${PE_SUB_EDITION} ${PE_SUB_STATUS} ${PE_APP_VERSION_INFO}'"
LangString LSTR_02 1033 "Installing printer driver"
LangString LSTR_03 1033 "Install printer drivers"
LangString LSTR_04 1033 "Uninstall priPrinter"
LangString LSTR_05 1033 "priPrinter Help"
LangString LSTR_06 1033 "Uninstall"
LangString LSTR_07 1033 "Would you like to make '${ps_PROG_NAME}' as default printer?"
LangString LSTR_08 1033 "Set '$1' as default printer"
LangString LSTR_09 1033 "Please close '${ps_PROG_NAME}' application"
LangString LSTR_10 1033 "The installer is already running."
LangString LSTR_11 1033 "We are sorry, but Windows 95/98/ME are not supported!$\r$\n$\r$\nShould we setup anyway?"
LangString LSTR_12 1033 "A previous installation or uninstallation of '${ps_PROG_NAME}' is still pending.$\r$\n$\r$\nYou must restart your computer before you can install again."
LangString LSTR_13 1033 "Uninstall printer drivers"
LangString LSTR_14 1033 "license_00.txt"
LangString LSTR_15 1033 "Install for MS Terminal Server"

; LANG: 1040 - Italian
LangString LSTR_01 1040 "Installazione di '${ps_PROG_NAME} ${PE_SUB_EDITION} ${PE_SUB_STATUS} ${PE_APP_VERSION_INFO}'"
LangString LSTR_02 1040 "Installazione driver stampante"
LangString LSTR_03 1040 "Installa driver stampante"
LangString LSTR_04 1040 "Disinstalla priPrinter"
LangString LSTR_05 1040 "Guida in linea priPrinter"
LangString LSTR_06 1040 "Dinsistalla"
LangString LSTR_07 1040 "Vuoi impostare '${ps_PROG_NAME}' come stampante predefinita?"
LangString LSTR_08 1040 "Imposta '$1' come stampante predefinita"
LangString LSTR_09 1040 "Chiudi l'applicazione '${ps_PROG_NAME}'"
LangString LSTR_10 1040 "L'installazione e gia in corso."
LangString LSTR_11 1040 "Ci spiace ma Windows 95/98/ME non sono supportati!$\r$\n$\r$\nVuoi installare comunque il programma?"
LangString LSTR_12 1040 "Non e stata completata una precedente installazione o disinstallazione di '${ps_PROG_NAME}'.$\r$\n$\r$\nPrima di poter effettuare una nuova installazione devi riavviare il computer."
LangString LSTR_13 1040 "Dinstallazione driver stampante"
LangString LSTR_14 1040 "license_ita.txt"
LangString LSTR_15 1040 "Installa per MS Terminal Server"

;--------------------------------
;Installer Sections

; we have to remove existing tray first and extract it only after that
Section "tray"
	SetShellVarContext all
	SetOutPath "$INSTDIR\drv"
	File "..\ins\drv\plkhelp.chm"

strcmp $PP_X64 "1" 0 tray_32
;64 bit
	File "..\ins\drv\install.exe"    
	File "..\ins\drv\plkdrv64.dll"
	File "..\ins\drv\plkui64.dll"
	File "..\ins\drv\plkmon64.dll"

	ExecWait '"$INSTDIR\drv\install.exe" removetray'
	SetOutPath "$INSTDIR"
    File "..\ins\64\pritray.exe"
	goto done_tray

;32 bit
tray_32:

	File "..\ins\drv\install.dll"    
	File "..\ins\drv\plkdrv32.dll"
	File "..\ins\drv\plkui32.dll"
	File "..\ins\drv\plkmon32.dll"

	StrCpy $0 "removetray"
	StrCpy $1 ""
	StrCpy $2 ""
	CallInstDLL $INSTDIR\drv\install.dll nsisfunc
    SetOutPath "$INSTDIR"
	File "..\ins\32\pritray.exe"

done_tray:
SectionEnd

; 32 bit driver
Section "-driver_32" sec_drv_32
strcmp $PP_X64 "1" afterCallInstDLL 0
       SetShellVarContext all

	DetailPrint "$(LSTR_02)"
	StrCpy $0 $var_inst_mode
	StrCpy $1 ""
	StrCpy $2 ""
	CallInstDLL $INSTDIR\drv\install.dll nsisfunc
	
	StrCmp $1 "0" +2 0
		SetRebootFlag true
		
	StrCmp $2 "" afterCallInstDLL
		MessageBox MB_OK "$2"			; reporting about error, should we return right after that ?
	
afterCallInstDLL:
SectionEnd

; 64 bit driver
Section "-driver_64" sec_drv_64
strcmp $PP_X64 "1" 0 afterCallInstDLL

        SetShellVarContext all

	DetailPrint "$(LSTR_03)"
	
	ExecWait '"$INSTDIR\drv\install.exe" $var_inst_mode $HWNDPARENT'  $0

;	MessageBox MB_OK "Our exe on IN return $0"

;// "in"   "un"
;// 101 - отложеное удаление
;// 100 - было сообщение о ошибке

	StrCmp $0 "101" 0 +2
		SetRebootFlag true
	
	;StrCmp $0 "100" 0 +2
	;	Abort ; causes installer to quit.
	
	;  раз уж ошибка, то не спрашивать юзера о установке в дефаултный наш принтер
	StrCmp $0 "100" 0 +2
		StrCpy $VAR_SET_DEFAULT_PRINTER "0"
	
afterCallInstDLL:

SectionEnd


; common 32 or 64 bit code
Section "-Common_32_64_start"
	SetShellVarContext all

	SetOutPath "$INSTDIR\ln"
	File /r "..\Bin\ins\ln\*.txt"
	File "..\Bin\ins\ln\en_us.000"

	SetOutPath "$INSTDIR"
	File "..\Bin\ins\help.chm"
;	File "..\view\res\autocfg.xml"

SectionEnd

Section "-Viewer" view_32_64

	SetShellVarContext all

        SetOutPath "$INSTDIR"

; Delete Old modules 
	Delete "$INSTDIR\modules\zip.pem"
	Delete "$INSTDIR\modules\pdf.pem"
	Delete "$INSTDIR\modules\3ds.pem"
	Delete "$INSTDIR\modules\script.pem"


strcmp $PP_X64 "1" 0 copy_32
;64

	File "..\bin\ins\64\*.dll"
    File "..\bin\ins\64\*.thm"
    File "..\bin\ins\64\priPrinter.exe"
	SetOutPath "$INSTDIR\modules"
	File /r "..\bin\ins\64\modules\*.pem"

	SetRegView 64
	goto done_copy_files
;32
copy_32:
	;File "..\bin\ins\32\*.*"
    File "..\bin\ins\32\*.dll"
    File "..\bin\ins\32\*.thm"
    File "..\bin\ins\32\priPrinter.exe"
	SetOutPath "$INSTDIR\modules"
	

	File /r "..\bin\ins\32\modules\*.pem"

done_copy_files:

;Create uninstaller
	WriteUninstaller "$INSTDIR\Uninstall.exe"


	WriteRegStr HKLM "${ps_REG_PATH}" "FullPathExe" "$INSTDIR\priPrinter.exe"
	WriteRegStr HKCU "${ps_REG_PATH}" "FullPathExe" "$INSTDIR\priPrinter.exe"	
	WriteRegStr HKCU "${ps_REG_PATH}" "" $INSTDIR
	!insertmacro MUI_STARTMENU_WRITE_BEGIN Application

	;Create shortcuts
	CreateDirectory "$SMPROGRAMS\$STARTMENU_FOLDER"

	CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\$(LSTR_04).lnk" "$INSTDIR\Uninstall.exe"
	CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\$(LSTR_05).lnk" "$INSTDIR\help.chm"
	CreateShortCut "$SMPROGRAMS\$STARTMENU_FOLDER\priPrinter.lnk" "$INSTDIR\priPrinter.exe"	
	Delete "$SMPROGRAMS\$STARTMENU_FOLDER\$(LSTR_06).lnk"

  WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "UninstallString" '"$INSTDIR\uninstall.exe"'
  WriteRegExpandStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "InstallLocation" "$INSTDIR"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "DisplayName" "priPrinter"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "Publisher" "Pelikan Software KFT"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "DisplayIcon" "$INSTDIR\priPrinter.exe,0"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "DisplayVersion" "${PE_APP_VERSION_INFO}"

  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "URLInfoAbout" "http://www.priprinter.com/"
  WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "HelpLink" "http://www.priprinter.com/contact.php"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "NoModify" "1"
  WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "NoRepair" "1"

; Computing EstimatedSize
 ${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
 IntFmt $0 "0x%08X" $0
 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter" "EstimatedSize" "$0"
;Computing EstimatedSize

${registerExtension} "$INSTDIR\priPrinter.exe" ".priPrinter" "priPrinter File"

IfFileExists "$INSTDIR\modules\script.pem" 0 +2
${registerExtensionScript} "$INSTDIR\modules\script.pem" ".psf" "priPrinter Script File"

System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'

	StrCmp $VAR_SET_DEFAULT_PRINTER "1" 0 endKok
		MessageBox MB_YESNO|MB_ICONQUESTION "$(LSTR_07)" /SD IDYES IDNO endKok
			DetailPrint "$(LSTR_08)"
strcmp $PP_X64 "1" 0 view_32_3
		ExecWait '"$INSTDIR\drv\install.exe" def.set'
		goto endKok
view_32_3:
		StrCpy $0 "def.set"
		CallInstDLL $INSTDIR\drv\install.dll nsisfunc

endKok:

	!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd



; вернёт '' если мы не можем под этой версией
Function GetWindowsVersion

	Push $R0
	Push $R1
 
	StrCpy $R0 ''

	ClearErrors

	ReadRegStr $R0 HKLM \
	"SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion

	IfErrors 0 lbl_winnt

	; we are not NT
	ReadRegStr $R0 HKLM \
	"SOFTWARE\Microsoft\Windows\CurrentVersion" VersionNumber

	StrCpy $R1 $R0 1
	StrCmp $R1 '4' 0 lbl_error

	StrCpy $R1 $R0 3

	StrCmp $R1 '4.0' lbl_win32_95
	StrCmp $R1 '4.9' lbl_win32_ME lbl_win32_98

	lbl_win32_95:
;		StrCpy $R0 '95'
	Goto lbl_done

	lbl_win32_98:
;		StrCpy $R0 '98'
	Goto lbl_done

	lbl_win32_ME:
;		StrCpy $R0 'ME'
	Goto lbl_done

	lbl_winnt:

	StrCpy $R1 $R0 1

	StrCmp $R1 '3' lbl_winnt_x
	StrCmp $R1 '4' lbl_winnt_x

	StrCpy $R1 $R0 3

	StrCmp $R1 '5.0' lbl_winnt_2000
	StrCmp $R1 '5.1' lbl_winnt_XP
	StrCmp $R1 '5.2' lbl_winnt_2003
	StrCmp $R1 '6.0' lbl_winnt_vista lbl_error

	lbl_winnt_x:
		StrCpy $R0 "NT $R0" 6
	Goto lbl_done

	lbl_winnt_2000:
		Strcpy $R0 '2000'
	Goto lbl_done

	lbl_winnt_XP:
		Strcpy $R0 'XP'
	Goto lbl_done

	lbl_winnt_2003:
		Strcpy $R0 '2003'
	Goto lbl_done

	lbl_winnt_vista:
		Strcpy $R0 'Vista'
	Goto lbl_done

	lbl_winnt_win7:
		Strcpy $R0 'Windows 7'
	Goto lbl_done
	lbl_error:
		StrCpy $R0 "NT $R0" 6
	lbl_done:

	Pop $R1
	Exch $R0

FunctionEnd


Function .onInit
	!insertmacro MUI_LANGDLL_DISPLAY
	StrCpy $var_inst_mode "in"
	${If} ${RunningX64}
		StrCpy $PP_X64 "1"

		ReadRegStr $INSTDIR HKCU  "${ps_REG_PATH}" ""
		StrCmp $INSTDIR "" def_path64 fin_64
def_path64:
		StrCpy $INSTDIR "$PROGRAMFILES64\priPrinter"
fin_64:
		;SectionSetFlags ${sec_drv_64} 0x80000000
	${Else}
		StrCpy $PP_X64 "0"
		;SectionSetFlags ${sec_drv_32} 0x80000000
	${EndIf}

;-------------- проверка на запущеный priPrinter ----------------------
 m_retry:
	FindWindow $0 "pe::{904A4260-1AE7-4BDF-AA8B-5CC8DA963E23}"
	strcmp $0 "0" m_install 0
		MessageBox MB_RETRYCANCEL|MB_ICONQUESTION "$(LSTR_09)" /SD IDCANCEL  IDRETRY m_retry
		Abort
m_install:		
;------------------------------------
; this one is for terminal server
StrCpy $var_ts_state 0

	!insertmacro MULTIUSER_INIT
	StrCpy $VAR_SET_DEFAULT_PRINTER "0"

	System::Call 'kernel32::CreateMutexA(i 0, i 0, t "Mutex.install of ${ps_PROG_NAME}.1") i .r1 ?e'
	Pop $R0
	StrCmp $R0 0 +3
	MessageBox MB_OK|MB_ICONINFORMATION "$(LSTR_10)"
		Abort

	Call GetWindowsVersion
	Pop $R0

		
	strcmp $R0 "" 0 GetWindowsVersion_next
		MessageBox MB_YESNO|MB_ICONQUESTION "$(LSTR_11)" IDYES true IDNO false
		true:
			Goto GetWindowsVersion_next
		false:
			Abort

GetWindowsVersion_next:

	SetOutPath $TEMP

strcmp $PP_X64 "1" 0 OnInitx32
;OnInitx64
	;MessageBox MB_OK "X64:2"
	File "..\Bin\ins\drv\install.exe"
	ExecWait '"install.exe" onInit' $0

	strcmp $0 "200" 0 mGo102
		Delete "$TEMP\install.exe"
		MessageBox MB_OK "$(LSTR_12)"
		Abort ; causes installer to quit.
mGo102:
	strcmp $0 "102" 0 NoAbort0
		StrCpy $VAR_SET_DEFAULT_PRINTER "1"
	goto NoAbort0

OnInitx32:
	;MessageBox MB_OK "X32:2"
	File "..\bin\ins\drv\install.dll"

	StrCpy $0 "onInit"
	CallInstDLL "install.dll" nsisfunc
	
	StrCpy $VAR_SET_DEFAULT_PRINTER "$1"

	strcmp $0 "1" 0 NoAbort0
		Delete "$TEMP\install.dll"
		MessageBox MB_OK "$(LSTR_12)"
		Abort ; causes installer to quit.


NoAbort0:

FunctionEnd

Function un.onInit

;-------------- check for running priPrinter ----------------------
 m_retry:
	FindWindow $0 "pe::{904A4260-1AE7-4BDF-AA8B-5CC8DA963E23}"
	strcmp $0 "0" m_install 0
		MessageBox MB_RETRYCANCEL|MB_ICONQUESTION "$(LSTR_09)" /SD IDCANCEL  IDRETRY m_retry
		Abort
m_install:
;------------------------------------

System::Call 'kernel32::CreateMutexA(i 0, i 0, t "Mutex.install of ${ps_PROG_NAME}.1") i .r1 ?e'
	Pop $R0
	StrCmp $R0 0 +3
	MessageBox MB_OK|MB_ICONINFORMATION "$(LSTR_10)"
		Abort


!insertmacro MULTIUSER_UNINIT
FunctionEnd

;--------------------------------
;Descriptions

;Language strings
;LangString DESC_SecDriver 1033 "A printer driver required for printer."
;LangString DESC_SecView 1033 "Viewer and printer application"

;Assign language strings to sections
;!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
;	!insertmacro MUI_DESCRIPTION_TEXT ${SecDriver} $(DESC_SecDriver)
;	!insertmacro MUI_DESCRIPTION_TEXT ${SecView} $(DESC_SecView)
;!insertmacro MUI_FUNCTION_DESCRIPTION_END


;--------------------------------
;Uninstaller Section

Section "Uninstall"

    SetShellVarContext all
    DetailPrint "$(LSTR_13)"

${If} ${RunningX64}
		StrCpy $PP_X64 "1"
		SetRegView 64
		
		ExecWait '"$INSTDIR\drv\install.exe" un $HWNDPARENT'  $0
	
		StrCmp $0 "101" 0 afterCallInstDLL
			SetRebootFlag true
		
${Else}
		StrCpy $PP_X64 "0"			
	StrCpy $0 "un"
	StrCpy $1 ""
	StrCpy $2 ""
	CallInstDLL $INSTDIR\drv\install.dll nsisfunc
	
	StrCmp $1 "0" +2 0
		SetRebootFlag true
		
	StrCmp $2 "" afterCallInstDLL 0
		MessageBox MB_OK "$2"			; информируем о ошибке		
${EndIf}

		
afterCallInstDLL:

	Delete "$INSTDIR\Uninstall.exe"

	RMDir /r  /REBOOTOK "$INSTDIR"

	!insertmacro MUI_STARTMENU_GETFOLDER Application $MUI_TEMP

	Delete "$SMPROGRAMS\$MUI_TEMP\priPrinter.lnk"
	Delete "$SMPROGRAMS\$MUI_TEMP\$(LSTR_05).lnk"

	Delete "$SMPROGRAMS\$MUI_TEMP\$(LSTR_04).lnk"

	;Delete empty start menu parent diretories
	StrCpy $MUI_TEMP "$SMPROGRAMS\$MUI_TEMP"

 startMenuDeleteLoop:
	ClearErrors
	RMDir $MUI_TEMP
	GetFullPathName $MUI_TEMP "$MUI_TEMP\.."

	IfErrors startMenuDeleteLoopDone

	StrCmp $MUI_TEMP $SMPROGRAMS startMenuDeleteLoopDone startMenuDeleteLoop
startMenuDeleteLoopDone:

	${unregisterExtension} ".priPrinter" "priPrinter File"
	${unregisterExtension} ".psf" "priPrinter Script File"
	System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v (0x08000000, 0, 0, 0)'

;SetRegView 64
	ClearErrors
	EnumRegKey $1 HKCU "Software\Pelikan Software KFT\priPrinter\reg" 0
	IfErrors  Delete NoDelete
Delete:
	DeleteRegKey HKCU "${ps_REG_PATH}"
	DeleteRegKey /ifempty HKCU "Software\Pelikan Software KFT"
NoDelete:
        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\priPrinter"

strcmp $PP_X64 "1" 0 NoReg32
	SetRegView 32
NoReg32:

SectionEnd
