;--------------------------------------------------------------------------------------------- ;General !define AppName "" !define AppVersion "" !define DirName "" !define Vendor "" !define Dir "" !define icon "" !define JRE_VERSION "" ;Variable declared for JRE Var var Var var1 Var var2 ;Algorithm used to compress files/data in the installer ;SetCompressor /SOLID lzma ;Name and output file Name "" OutFile "PTAF.exe" ;Type of the installation InstType "Complete" InstType "Typical" ;Default installation folder InstallDir C:\${DirName} ;Get installation folder from registry if available InstallDirRegKey HKLM "Software\${Vendor}\${DirName}" "" ;Configuration XPStyle On ;--------------------------------------------------------------------------------------------- ;Include UltraModernUI !include "UMUI.nsh" !include "Memento.nsh" !include "Sections.nsh" ;Definitions !define SHCNE_ASSOCCHANGED 0x8000000 !define SHCNF_IDLIST 0 !define WNDCLASS "ConsoleWindowClass" !define WNDTITLE "" ;Memento Settings !define MEMENTO_REGISTRY_ROOT HKLM !define MEMENTO_REGISTRY_KEY "" ;--------------------------------------------------------------------------------------------- ;Interface Settings !define MUI_ABORTWARNING !define MUI_UNABORTWARNING !define UMUI_USE_ALTERNATE_PAGE !define UMUI_USE_UNALTERNATE_PAGE !define MUI_LICENSEPAGE_BGCOLOR "E7E9D7" !define UMUI_TEXT_LIGHTCOLOR "FFFFFF" !define UMUI_LEFTIMAGE_BMP "" ;Set the font of the background text BGFont "Verdana" 30 400 ;BgGradient on BrandingText "." ;--------------------------------------------------------------------------------------------- ;Pages !define MUI_PAGE_CUSTOMFUNCTION_PRE CheckInstalledJRE ;Welcome Page ;!define MUI_WELCOMEPAGE_TITLE "" !define MUI_ICON "${NSISDIR}" !define MUI_UNICON "${NSISDIR}" !define MUI_PAGE_HEADER_TEXT "" !define MUI_PAGE_HEADER_SUBTEXT "" !define MUI_TEXT_COLOR "FFFFFF" !define MUI_BGCOLOR "3d66ab" !define MUI_WELCOMEPAGE_TEXT "This Wizard will install ${AppName}, ${AppVersion} on your computer. To continue, click Next" !insertmacro MUI_PAGE_WELCOME ;License Page !define MUI_PAGE_HEADER_SUBTEXT "" !define MUI_LICENSEPAGE_TEXT_BOTTOM " " !insertmacro MUI_PAGE_LICENSE "${Dir}\" ;page for components !define MUI_PAGE_HEADER_SUBTEXT "" !define MUI_COMPONENTSPAGE_TEXT_TOP " " !insertmacro MUI_PAGE_COMPONENTS ;page for Directory selection !define MUI_PAGE_HEADER_SUBTEXT "" !insertmacro MUI_PAGE_DIRECTORY ;page for installation !define MUI_PAGE_HEADER_SUBTEXT "" !insertmacro MUI_PAGE_INSTFILES !define MUI_PAGE_CUSTOMFUNCTION_PRE SetPath ;finish page !define MUI_FINISHPAGE_HEADER_SUBTEXT "" !define MUI_FINISHPAGE_TEXT "" !define MUI_FINISHPAGE_LINK "" !define MUI_FINISHPAGE_LINK_LOCATION "" !insertmacro MUI_PAGE_FINISH ;unistallation welcome page !define MUI_PAGE_HEADER_TEXT "" !define MUI_PAGE_HEADER_SUBTEXT "" !insertmacro MUI_UNPAGE_WELCOME !define MUI_PAGE_HEADER_SUBTEXT "" !insertmacro MUI_UNPAGE_CONFIRM !define MUI_PAGE_HEADER_SUBTEXT "" !insertmacro MUI_UNPAGE_INSTFILES ;unistallation finish page !define MUI_FINISHPAGE_LINK "" !define MUI_FINISHPAGE_LINK_LOCATION "" !insertmacro MUI_UNPAGE_FINISH ;--------------------------------------------------------------------------------------------- ;Languages !insertmacro MUI_LANGUAGE "" !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS ;--------------------------------------------------------------------------------------------- ;Installer Sections ${MementoSection} "1" ${MementoSectionEnd} ;--------------------------------------------------------------------------------------------- ${MementoSection} "2" ${MementoSectionEnd} ;--------------------------------------------------------------------------------------------- ${MementoSection} "Create shortcuts" CreateShortCut "$SMPROGRAMS\java.lnk" "$SYSDIR\javaw.exe" "My" ${MementoSectionEnd} ;--------------------------------------------------------------------------------------------- ${MementoSection} "4" ${MementoSectionEnd} ${MementoSectionDone} ;--------------------------------------------------------------------------------------------- Section -post SetDetailsPrint textonly DetailPrint "Creating Registry Keys..." SetDetailsPrint listonly SetOutPath $INSTDIR WriteRegStr WriteUninstaller "" ${MementoSectionSave} SetDetailsPrint both SectionEnd ;--------------------------------------------------------------------------------------------- ;Descriptions for the folders !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_FUNCTION_DESCRIPTION_END ;--------------------------------------------------------------------------------------------- ;Uninstaller Section Section "Uninstall" DeleteRegKey Delete "$INSTDIR" Delete $INSTDIR\ Delete "$INSTDIR\" SectionEnd ;-----------------------------------------Function .onInit------------------------------------------------- Function .onInit FunctionEnd ;----------------------------------Function un.onInit------------------------------------------------------- Function un.onInit FunctionEnd ;----------------------------------Function CheckInstalledJRE------------------------------------------------ Function CheckInstalledJRE Push "${JRE_VERSION}" Call DetectJRE Exch $0 ; Get return value from stack FunctionEnd Function DetectJRE Exch $0 ; Get version requested ; Now the previous value of $0 is on the stack, and the asked for version of JDK is in $0 Push $1 ; $1 = Java version string (ie 1.5.0) Push $2 ; $2 = Javahome Push $3 ; $3 and $4 are used for checking the major/minor version of java Push $4 ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment" "CurrentVersion" StrCmp $1 "" DetectTry2 ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Runtime Environment\$1" "JavaHome" StrCpy $var2 $2 ;filepresent: ;filenotpresent: ;MessageBox MB_OK ":: file not present" StrCmp $2 "" DetectTry2 Goto GetJRE DetectTry2: ReadRegStr $1 HKLM "SOFTWARE\JavaSoft\Java Development Kit" "CurrentVersion" StrCmp $1 "" NoFound ReadRegStr $2 HKLM "SOFTWARE\JavaSoft\Java Development Kit\$1" "JavaHome" StrCpy $var2 $2 StrCmp $2 "" NoFound GetJRE: ; $0 = version requested. $1 = version found. $2 = javaHome IfFileExists "$2\bin\java.exe" 0 NoFound StrCpy $3 $0 1 ; Get major version. Example: $1 = 1.5.0, now $3 = 1 StrCpy $4 $1 1 ; $3 = major version requested, $4 = major version found IntCmp $4 $3 0 FoundOld FoundNew StrCpy $3 $0 1 2 StrCpy $4 $1 1 2 ; Same as above. $3 is minor version requested, $4 is minor version installed IntCmp $4 $3 FoundNew FoundOld FoundNew NoFound: MessageBox MB_OK "JRE not found, First install JRE ${JRE_VERSION}" Push "0" Goto DetectJREEnd Call QuitApplication FoundOld: MessageBox MB_OK "JRE too old, First install JRE ${JRE_VERSION}" ; Push ${TEMP2} Push "-1" Goto DetectJREEnd Call QuitApplication FoundNew: Push "$2\bin\java.exe" Goto DetectJREEnd DetectJREEnd: ; Top of stack is return value, then r4,r3,r2,r1 Exch ; => r4,rv,r3,r2,r1,r0 Pop $4 ; => rv,r3,r2,r1r,r0 Exch ; => r3,rv,r2,r1,r0 Pop $3 ; => rv,r2,r1,r0 Exch ; => r2,rv,r1,r0 Pop $2 ; => rv,r1,r0 Exch ; => r1,rv,r0 Pop $1 ; => rv,r0 Exch ; => r0,rv Pop $0 ; => rv FunctionEnd Function QuitApplication Quit FunctionEnd ;----------------------------------Function SetPath------------------------------------------------------- Function SetPath FileOpen $R8 "" r FileSeek $R8 100 FileRead $R8 $var ;MessageBox MB_OK "1:: $var" FileClose $R8 Push $var Push $var2 Push all Push all Push "" Call AdvReplaceInFile FileOpen $R9 "" r FileSeek $R9 100 FileRead $R9 $var1 FileClose $R9 FunctionEnd ;----------------------------------Function AdvReplaceInFile------------------------------------------------ Function AdvReplaceInFile Exch $0 ;file to replace in Exch Exch $1 ;number to replace after Exch Exch 2 Exch $2 ;replace and onwards Exch 2 Exch 3 Exch $3 ;replace with Exch 3 Exch 4 Exch $4 ;to replace Exch 4 Push $5 ;minus count Push $6 ;universal Push $7 ;end string Push $8 ;left string Push $9 ;right string Push $R0 ;file1 Push $R1 ;file2 Push $R2 ;read Push $R3 ;universal Push $R4 ;count (onwards) Push $R5 ;count (after) Push $R6 ;temp file name GetTempFileName $R6 FileOpen $R1 $0 r ;file to search in FileOpen $R0 $R6 w ;temp file StrLen $R3 $4 StrCpy $R4 -1 StrCpy $R5 -1 loop_read: ClearErrors FileRead $R1 $R2 ;read line IfErrors exit StrCpy $5 0 StrCpy $7 $R2 loop_filter: IntOp $5 $5 - 1 StrCpy $6 $7 $R3 $5 ;search StrCmp $6 "" file_write2 StrCmp $6 $4 0 loop_filter StrCpy $8 $7 $5 ;left part IntOp $6 $5 + $R3 IntCmp $6 0 is0 not0 is0: StrCpy $9 "" Goto done not0: StrCpy $9 $7 "" $6 ;right part done: StrCpy $7 $8$3$9 ;re-join IntOp $R4 $R4 + 1 StrCmp $2 all file_write1 StrCmp $R4 $2 0 file_write2 IntOp $R4 $R4 - 1 IntOp $R5 $R5 + 1 StrCmp $1 all file_write1 StrCmp $R5 $1 0 file_write1 IntOp $R5 $R5 - 1 Goto file_write2 file_write1: FileWrite $R0 $7 ;write modified line Goto loop_read file_write2: FileWrite $R0 $R2 ;write unmodified line Goto loop_read exit: FileClose $R0 FileClose $R1 SetDetailsPrint none Delete $0 Rename $R6 $0 Delete $R6 SetDetailsPrint both Pop $R6 Pop $R5 Pop $R4 Pop $R3 Pop $R2 Pop $R1 Pop $R0 Pop $9 Pop $8 Pop $7 Pop $6 Pop $5 Pop $0 Pop $1 Pop $2 Pop $3 Pop $4 FunctionEnd