Skip to content

Instantly share code, notes, and snippets.

@wedesoft
Last active December 22, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wedesoft/6497084 to your computer and use it in GitHub Desktop.
Save wedesoft/6497084 to your computer and use it in GitHub Desktop.
NSIS script for creating Qt4-QtRuby installer
;----------------------------------------
; based upon a script of "Written by KiCHiK 2003-01-18 05:57:02"
;----------------------------------------
!verbose 3
!include "WinMessages.NSH"
!verbose 4
;====================================================
; get_NT_environment
; Returns: the selected environment
; Output : head of the stack
;====================================================
!macro select_NT_profile UN
Function ${UN}select_NT_profile
MessageBox MB_YESNO|MB_ICONQUESTION "Change the environment for all users?$\r$\nSaying no here will change the envrironment for the current user only.$\r$\n(Administrator permissions required for all users)" \
IDNO environment_single
DetailPrint "Selected environment for all users"
Push "all"
Return
environment_single:
DetailPrint "Selected environment for current user only."
Push "current"
Return
FunctionEnd
!macroend
!insertmacro select_NT_profile ""
!insertmacro select_NT_profile "un."
;----------------------------------------------------
!define NT_current_env 'HKCU "Environment"'
!define NT_all_env 'HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"'
;====================================================
; IsNT - Returns 1 if the current system is NT, 0
; otherwise.
; Output: head of the stack
;====================================================
!macro IsNT UN
Function ${UN}IsNT
Push $0
ReadRegStr $0 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" CurrentVersion
StrCmp $0 "" 0 IsNT_yes
; we are not NT.
Pop $0
Push 0
Return
IsNT_yes:
; NT!!!
Pop $0
Push 1
FunctionEnd
!macroend
!insertmacro IsNT ""
!insertmacro IsNT "un."
;====================================================
; AddToPath - Adds the given dir to the search path.
; Input - head of the stack
; Note - Win9x systems requires reboot
;====================================================
Function AddToPath
Exch $0
Push $1
Push $2
Call IsNT
Pop $1
StrCmp $1 1 AddToPath_NT
; Not on NT
StrCpy $1 $WINDIR 2
FileOpen $1 "$1\autoexec.bat" a
FileSeek $1 0 END
GetFullPathName /SHORT $0 $0
FileWrite $1 "$\r$\nSET PATH=%PATH%;$0$\r$\n"
FileClose $1
Goto AddToPath_done
AddToPath_NT:
Push $4
Call select_NT_profile
Pop $4
AddToPath_NT_selection_done:
StrCmp $4 "current" read_path_NT_current
ReadRegStr $1 ${NT_all_env} "PATH"
Goto read_path_NT_resume
read_path_NT_current:
ReadRegStr $1 ${NT_current_env} "PATH"
read_path_NT_resume:
StrCpy $2 $0
StrCmp $1 "" AddToPath_NTdoIt
StrCpy $2 "$1;$0"
AddToPath_NTdoIt:
StrCmp $4 "current" write_path_NT_current
ClearErrors
WriteRegExpandStr ${NT_all_env} "PATH" $2
IfErrors 0 write_path_NT_resume
MessageBox MB_YESNO|MB_ICONQUESTION "The path could not be set for all users$\r$\nShould I try for the current user?" \
IDNO write_path_NT_failed
; change selection
StrCpy $4 "current"
Goto AddToPath_NT_selection_done
write_path_NT_current:
ClearErrors
WriteRegExpandStr ${NT_current_env} "PATH" $2
IfErrors 0 write_path_NT_resume
MessageBox MB_OK|MB_ICONINFORMATION "The path could not be set for the current user."
Goto write_path_NT_failed
write_path_NT_resume:
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
DetailPrint "added path for user ($4), $0"
write_path_NT_failed:
Pop $4
AddToPath_done:
Pop $2
Pop $1
Pop $0
FunctionEnd
;====================================================
; RemoveFromPath - Remove a given dir from the path
; Input: head of the stack
;====================================================
Function un.RemoveFromPath
Exch $0
Push $1
Push $2
Push $3
Push $4
Call un.IsNT
Pop $1
StrCmp $1 1 unRemoveFromPath_NT
; Not on NT
StrCpy $1 $WINDIR 2
FileOpen $1 "$1\autoexec.bat" r
GetTempFileName $4
FileOpen $2 $4 w
GetFullPathName /SHORT $0 $0
StrCpy $0 "SET PATH=%PATH%;$0"
SetRebootFlag true
Goto unRemoveFromPath_dosLoop
unRemoveFromPath_dosLoop:
FileRead $1 $3
StrCmp $3 "$0$\r$\n" unRemoveFromPath_dosLoop
StrCmp $3 "$0$\n" unRemoveFromPath_dosLoop
StrCmp $3 "$0" unRemoveFromPath_dosLoop
StrCmp $3 "" unRemoveFromPath_dosLoopEnd
FileWrite $2 $3
Goto unRemoveFromPath_dosLoop
unRemoveFromPath_dosLoopEnd:
FileClose $2
FileClose $1
StrCpy $1 $WINDIR 2
Delete "$1\autoexec.bat"
CopyFiles /SILENT $4 "$1\autoexec.bat"
Delete $4
Goto unRemoveFromPath_done
unRemoveFromPath_NT:
StrLen $2 $0
Call un.select_NT_profile
Pop $4
StrCmp $4 "current" un_read_path_NT_current
ReadRegStr $1 ${NT_all_env} "PATH"
Goto un_read_path_NT_resume
un_read_path_NT_current:
ReadRegStr $1 ${NT_current_env} "PATH"
un_read_path_NT_resume:
Push $1
Push $0
Call un.StrStr ; Find $0 in $1
Pop $0 ; pos of our dir
IntCmp $0 -1 unRemoveFromPath_done
; else, it is in path
StrCpy $3 $1 $0 ; $3 now has the part of the path before our dir
IntOp $2 $2 + $0 ; $2 now contains the pos after our dir in the path (';')
IntOp $2 $2 + 1 ; $2 now containts the pos after our dir and the semicolon.
StrLen $0 $1
StrCpy $1 $1 $0 $2
StrCpy $3 "$3$1"
StrCmp $4 "current" un_write_path_NT_current
WriteRegExpandStr ${NT_all_env} "PATH" $3
Goto un_write_path_NT_resume
un_write_path_NT_current:
WriteRegExpandStr ${NT_current_env} "PATH" $3
un_write_path_NT_resume:
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000
unRemoveFromPath_done:
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Uninstall sutff
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;====================================================
; StrStr - Finds a given string in another given string.
; Returns -1 if not found and the pos if found.
; Input: head of the stack - string to find
; second in the stack - string to find in
; Output: head of the stack
;====================================================
Function un.StrStr
Push $0
Exch
Pop $0 ; $0 now have the string to find
Push $1
Exch 2
Pop $1 ; $1 now have the string to find in
Exch
Push $2
Push $3
Push $4
Push $5
StrCpy $2 -1
StrLen $3 $0
StrLen $4 $1
IntOp $4 $4 - $3
unStrStr_loop:
IntOp $2 $2 + 1
IntCmp $2 $4 0 0 unStrStrReturn_notFound
StrCpy $5 $1 $3 $2
StrCmp $5 $0 unStrStr_done unStrStr_loop
unStrStrReturn_notFound:
StrCpy $2 -1
unStrStr_done:
Pop $5
Pop $4
Pop $3
Exch $2
Exch 2
Pop $0
Pop $1
FunctionEnd
;====================================================
[Settings]
NumFields=5
Title=Specify location of Qt4 and Ruby
[Field 1]
Type=CheckBox
Left=10
Right=-10
Top=10
Bottom=24
Text=Add Qt binary directory to path
State=1
[Field 2]
Type=Label
Left=10
Right=80
Top=30
Bottom=44
Text=Qt binaries path:
[Field 3]
Type=DirRequest
Left=85
Right=-10
Top=30
Bottom=44
State=C:\Qt\4.3.4\bin
[Field 4]
Type=Label
Left=10
Right=90
Top=50
Bottom=64
Text=Ruby main directory:
[Field 5]
Type=DirRequest
Left=95
Right=-10
Top=50
Bottom=64
State=C:\ruby\bin
; rbqtapi is missing!!!
!include Library.nsh
!include nsDialogs.nsh
!include AddToPath.nsh
Name "qtruby4installer"
Caption "Qt4-QtRuby Installer"
Icon "qtruby4.ico"
OutFile "qtruby4installer.exe"
ReserveFile "${NSISDIR}\Plugins\InstallOptions.dll"
ReserveFile "qtdir.ini"
LicenseText "License page"
LicenseData "gpl2.txt"
XPStyle on
InstallDir $PROGRAMFILES\QtRuby4
Page license
Page components
Page custom qtdirDialog
Page instfiles
Uninstallicon "qtruby4.ico"
UninstPage uninstConfirm
UninstPage instfiles
Section "Qt4-QtRuby for Qt4.3.4 (OpenSource)"
SectionIn RO
SetOutPath $INSTDIR
WriteRegStr HKLM SOFTWARE\QtRuby4 "Install_Dir" "$INSTDIR"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "DisplayName" "Qt4-QtRuby"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "DisplayIcon" '"$INSTDIR\uninstall.exe"'
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "DisplayVersion" "1.4.10"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "Publisher" "korundum.rubyforge.org"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "URLInfoAbout" "http://rubyforge.org/projects/korundum/"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4" "NoRepair" 1
DetailPrint "Creating uninstaller $INSTDIR\uninstall.exe"
WriteUninstaller "uninstall.exe"
File "qtruby4uninstall.rbw"
ReadINIStr $1 "$PLUGINSDIR\qtdir.ini" "Field 5" "State"
DetailPrint "Ruby directory specified by user is $1"
WriteRegStr HKLM "SOFTWARE\QtRuby4" "Ruby_Dir" $1
SetOutPath $TEMP
File "qtruby4install.rbw"
File "active_item_model.rb"
File "active_table_model.rb"
File "qtruby4.rb"
File "Qt.rb"
File "Qt3.rb"
File "Qt4.rb"
File "qtruby4.so"
DetailPrint "Running Ruby script to install Qt4-QtRuby"
ExecWait '"$1\rubyw.exe" qtruby4install.rbw'
IfErrors 0 +2
Abort "Failed to install Qt4-QtRuby!"
;ExecShell "open" "gem" 'install "$TEMP\qtruby4-1.4.9-mswin32.gem"' SW_SHOWNORMAL
;ExecWait '"$TEMP\qtruby4.bat"'
;IfErrors 0 +2
; Abort "Failed to install Qt4-QtRuby Rubygem!"
!insertmacro InstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED libsmokeqt.dll $SYSDIR\libsmokeqt.dll $SYSDIR
ReadINIStr $1 "$PLUGINSDIR\qtdir.ini" "Field 1" "State"
WriteRegDWORD HKLM SOFTWARE\QtRuby4 "UnsetQtPath" $1
StrCmp $1 "1" 0 +5
ReadINIStr $1 "$PLUGINSDIR\qtdir.ini" "Field 3" "State"
WriteRegStr HKLM SOFTWARE\QtRuby4 "QtPath" $1
Push $1
Call AddToPath
SectionEnd
Section "Ruby User Interface Compiler"
SetOutPath $SYSDIR
File "rbuic4.exe"
SectionEnd
Section "Ruby Resource Compiler"
SetOutPath $SYSDIR
File "rbrcc.exe"
SectionEnd
; Uninstallation of gem does not work when called from Start-Menu.
;Section "Start Menu Shortcuts"
;
; SetShellVarContext All
; CreateDirectory "$SMPROGRAMS\QtRuby4"
; CreateShortCut "$SMPROGRAMS\QtRuby4\Uninstall.lnk" "$INSTDIR\uninstall.exe" 0
;
;SectionEnd
Section "Uninstall"
ReadRegDWORD $1 HKLM SOFTWARE\QtRuby4 "UnsetQtPath"
StrCmp $1 "1" 0 +4
ReadRegStr $1 HKLM SOFTWARE\QtRuby4 "QtPath"
Push $1
Call un.RemoveFromPath
ReadRegStr $1 HKLM SOFTWARE\QtRuby4 "Ruby_Dir"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\QtRuby4"
DeleteRegKey HKLM SOFTWARE\QtRuby4
!insertmacro UnInstallLib DLL NOTSHARED NOREBOOT_NOTPROTECTED $SYSDIR\libsmokeqt.dll
; ExecShell "open" "gem" 'uninstall qtruby4' SW_SHOWNORMAL
; ExecWait '"$INSTDIR\qtruby4un.bat"'
ExecWait '"$1\rubyw.exe" "$INSTDIR\qtruby4uninstall.rbw"'
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\qtruby4uninstall.rbw
RMDir "$INSTDIR"
Delete "$SYSDIR\rbuic4.exe"
Delete "$SYSDIR\rbrcc.exe"
; SetShellVarContext All
; Delete "$SMPROGRAMS\QtRuby4\*.*"
; RMDIR "$SMPROGRAMS\QtRuby4"
SectionEnd
Function qtdirDialog
Push $1
InstallOptions::dialog "$PLUGINSDIR\qtdir.ini"
Pop $1
Pop $1
FunctionEnd
Function .onInit
InitPluginsDir
File /oname=$PLUGINSDIR\qtdir.ini "qtdir.ini"
FunctionEnd
; Copy of forum posting at http://rubyforge.org/forum/forum.php?thread_id=31155&forum_id=723
; Hi,
; I've created a new version of the QtRuby4-installer [1] which uses NSIS. The new version is for using Qt-4.3.4 under Microsoft Windows. The source files of the installer can be found on the HornetsEye source repository [2].
; I want to give the feedback on how I got QtRuby4 compiled using MSYS/MinGW.
; * I installed Qt-4.3.4 binary release for Windows
; * export QTDIR=/c/Qt/4.3.4
; * export PATH=$PATH:$QTDIR/bin
; * cmake -G "MSYS Makefiles" -DCMAKE_INSTALL_PREFIX=/mingw -Wno-dev -DT_CORE_INCLUDE_DIR:PATH=/c/Qt/4.3.4/include/QtCore -DQT_MKSPECS_DIR:PATH=/c/Qt/4.3.4/mkspecs -DQT_PLUGINS_DIR:PATH=/c/Qt/4.3.4/plugins -DRUBY_LIBRARY:FILEPATH=C:/MinGW/lib/libmsvcrt-ruby18.dll.a -DENABLE_KORUNDUM=off .
; * set QT_QTDBUS_LIBRARY_FILE_PATH to empty string in CMakeCache.txt and rerun cmake
; * fix linking order in smoke/qt/qtguess.pl:
; my $alllib = '-LC:/Qt/4.3.4/lib -lQtNetwork4 -lQtOpenGL4 -lQtSql4 -lQtSvg4 -lQtUiTools -lQtXml4 -lQt3Support4 -lQtGui4 -lQtCore4';
; my $ccmd = "$cc $ccflags $allinc -o $tmp $tmp.cpp $alllib";
; * smoke/qt/generate.pl:
; problem with @qtinc containing c:/... (replace with /c/...), also remove trailing comma of list
; problem with 'system "perl -IC:/..."' because ':' is a path-delimiter, replace with 'system "perl -I/C/..."'
; * furthermore collapse path in generate.pl.cmake:
; if ($line =~ /^#include "(.*)"/) {
; $problem = $File::Find::dir . substr($1, 2);
; $problem =~ s/\.\.\//\.\.\/\.\.\//;
; push ( @headers, $problem );
; * remove qdbus* headers from @qtinc in smoke/qt/generate.pl, remove qtdbus from header_list
; * wrong linking order in smoke/qt/CMakeFiles/smokeqt.dir/build.make (use same linking order as mentioned above), also "-lQtUiTools" missing
; * added "#undef read" to ruby/qtruby/src/Qt.cpp after ruby.h is included
; * Problem with compiling ruby/qtruby/tools/rbuic/ui4.h (fixing "... is defined afer prior declaration as dllimport: attribute ignored"):
; #define QDESIGNER_UILIB_EXTERN
; #define QDESIGNER_UILIB_IMPORT
;
; [1] http://vision.eng.shu.ac.uk/mmvlwiki/index.php/Qt4-QtRuby_installer_for_Microsoft_Windows
; [2] http://bazaar.launchpad.net/~wedesoft/hornetseye/trunk/files
begin
require 'mkmf'
require 'ftools'
File.mkpath( "#{Config::CONFIG['sitelibdir']}/Qt" )
File.copy( "active_item_model.rb",
"#{Config::CONFIG['sitelibdir']}/Qt/active_item_model.rb" )
File.copy( "active_table_model.rb",
"#{Config::CONFIG['sitelibdir']}/Qt/active_table_model.rb" )
File.copy( "qtruby4.rb", "#{Config::CONFIG['sitelibdir']}/Qt/qtruby4.rb" )
File.copy( "Qt.rb", "#{Config::CONFIG['sitelibdir']}/Qt.rb" )
File.copy( "Qt3.rb", "#{Config::CONFIG['sitelibdir']}/Qt3.rb" )
File.copy( "Qt4.rb", "#{Config::CONFIG['sitelibdir']}/Qt4.rb" )
File.copy( "qtruby4.so", "#{Config::CONFIG['sitearchdir']}/qtruby4.so" )
rescue Exception => e
require 'dl'
MB_OK = 0x00
MB_ICONERROR = 0x10
user32 = DL.dlopen( 'user32' )
form = user32[ 'MessageBoxA', 'ILSSI' ]
form.call( 0, e.to_s, "Error", MB_OK | MB_ICONERROR )
throw e
end
begin
require 'mkmf'
require 'ftools'
File.delete( "#{Config::CONFIG['sitelibdir']}/Qt/active_item_model.rb" )
File.delete( "#{Config::CONFIG['sitelibdir']}/Qt/active_table_model.rb" )
File.delete( "#{Config::CONFIG['sitelibdir']}/Qt/qtruby4.rb" )
File.delete( "#{Config::CONFIG['sitelibdir']}/Qt.rb" )
File.delete( "#{Config::CONFIG['sitelibdir']}/Qt3.rb" )
File.delete( "#{Config::CONFIG['sitelibdir']}/Qt4.rb" )
File.delete( "#{Config::CONFIG['sitearchdir']}/qtruby4.so" )
rescue Exception => e
require 'dl'
MB_OK = 0x00
MB_ICONERROR = 0x10
user32 = DL.dlopen( 'user32' )
form = user32[ 'MessageBoxA', 'ILSSI' ]
form.call( 0, e.to_s, "Error", MB_OK | MB_ICONERROR )
throw e
end
[Settings]
NumFields=2
Title=Specify location of Ruby
[Field 1]
Type=Label
Left=10
Right=90
Top=10
Bottom=24
Text=Select Ruby directory:
[Field 2]
Type=DirRequest
Left=95
Right=-10
Top=10
Bottom=24
State=C:\ruby\bin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment