tools/installer/nsis/includes/qtcommon.nsh
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       
     2 ;;
       
     3 ;; Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ;; All rights reserved.
       
     5 ;; Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 ;;
       
     7 ;; This file is part of the tools applications of the Qt Toolkit.
       
     8 ;;
       
     9 ;; $QT_BEGIN_LICENSE:LGPL$
       
    10 ;; No Commercial Usage
       
    11 ;; This file contains pre-release code and may not be distributed.
       
    12 ;; You may use this file in accordance with the terms and conditions
       
    13 ;; contained in the Technology Preview License Agreement accompanying
       
    14 ;; this package.
       
    15 ;;
       
    16 ;; GNU Lesser General Public License Usage
       
    17 ;; Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ;; General Public License version 2.1 as published by the Free Software
       
    19 ;; Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ;; packaging of this file.  Please review the following information to
       
    21 ;; ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ;; will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 ;;
       
    24 ;; In addition, as a special exception, Nokia gives you certain additional
       
    25 ;; rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ;; version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 ;;
       
    28 ;; If you have questions regarding the use of this file, please contact
       
    29 ;; Nokia at qt-info@nokia.com.
       
    30 ;;
       
    31 ;;
       
    32 ;;
       
    33 ;;
       
    34 ;;
       
    35 ;;
       
    36 ;;
       
    37 ;;
       
    38 ;; $QT_END_LICENSE$
       
    39 ;;
       
    40 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
       
    41 !ifndef QTCOMMON_INCLUDE
       
    42 !define QTCOMMON_INCLUDE
       
    43 
       
    44 !macro MakeQtDirectory UN
       
    45 Function ${UN}MakeQtDirectory
       
    46   exch $0
       
    47 
       
    48   push $0
       
    49   push " "  #replace
       
    50   push "-" #with
       
    51   call ${UN}ReplaceString
       
    52   pop $0
       
    53 
       
    54   push $0
       
    55   push "("  #replace
       
    56   push "" #with
       
    57   call ${UN}ReplaceString
       
    58   pop $0
       
    59 
       
    60   push $0
       
    61   push ")"  #replace
       
    62   push "" #with
       
    63   call ${UN}ReplaceString
       
    64   pop $0
       
    65 
       
    66   exch $0
       
    67 FunctionEnd
       
    68 !macroend
       
    69 !insertmacro MakeQtDirectory ""
       
    70 !insertmacro MakeQtDirectory "un."
       
    71 
       
    72 Function AddStartmenuApplication
       
    73   exch $0
       
    74   IfFileExists "$0\assistant.exe" 0 +2
       
    75     CreateShortCut "$SMPROGRAMS\$STARTMENU_STRING\Assistant.lnk" "$0\assistant.exe"
       
    76   IfFileExists "$0\designer.exe" 0 +2
       
    77     CreateShortCut "$SMPROGRAMS\$STARTMENU_STRING\Designer.lnk" "$0\designer.exe"
       
    78   IfFileExists "$0\linguist.exe" 0 +2
       
    79     CreateShortCut "$SMPROGRAMS\$STARTMENU_STRING\Linguist.lnk" "$0\linguist.exe"
       
    80   IfFileExists "$0\qtdemo.exe" 0 +2
       
    81     CreateShortCut "$SMPROGRAMS\$STARTMENU_STRING\Examples and Demos.lnk" "$0\qtdemo.exe"
       
    82   IfFileExists "$0\..\README" 0 ReadMeShortCutFinished
       
    83     IfFileExists "$WINDIR\notepad.exe" +3
       
    84       CreateShortCut "$SMPROGRAMS\$STARTMENU_STRING\Qt Readme.lnk" "$SYSDIR\notepad.exe" "$0\..\README"
       
    85     goto ReadMeShortCutFinished
       
    86       CreateShortCut "$SMPROGRAMS\$STARTMENU_STRING\Qt Readme.lnk" "$WINDIR\notepad.exe" "$0\..\README"
       
    87   ReadMeShortCutFinished:
       
    88   pop $0
       
    89 FunctionEnd
       
    90 
       
    91 Function un.RemoveStartmenuApplication
       
    92   Delete "$SMPROGRAMS\$STARTMENU_STRING\Assistant.lnk"
       
    93   Delete "$SMPROGRAMS\$STARTMENU_STRING\Designer.lnk"
       
    94   Delete "$SMPROGRAMS\$STARTMENU_STRING\Linguist.lnk"
       
    95   Delete "$SMPROGRAMS\$STARTMENU_STRING\Examples and Demos.lnk"
       
    96   Delete "$SMPROGRAMS\$STARTMENU_STRING\Qt Readme.lnk"
       
    97 FunctionEnd
       
    98 
       
    99 #patch the licence information
       
   100 Function PatchLicenseInformation
       
   101   exch $0
       
   102   push $1
       
   103   push $2
       
   104   
       
   105   DetailPrint "Patching license information..."
       
   106 
       
   107   IfFileExists "$0\src\corelib\global\qconfig.h" 0 +3
       
   108   strcpy $2 "$0\src\corelib\global\qconfig.h"
       
   109   goto PatchLicensee
       
   110 
       
   111   IfFileExists "$0\include\Qt\qconfig.h" 0 PatchConfigPriFile
       
   112   strcpy $2 "$0\include\Qt\qconfig.h"
       
   113 
       
   114   PatchLicensee:
       
   115   push $2
       
   116   push '#define QT_PRODUCT_LICENSEE "'
       
   117   push '#define QT_PRODUCT_LICENSEE "$LICENSEE"$\r$\n'
       
   118   call PatchLine
       
   119 
       
   120   push $2
       
   121   push '#define QT_PRODUCT_LICENSE "'
       
   122   push '#define QT_PRODUCT_LICENSE "$LICENSE_PRODUCT"$\r$\n'
       
   123   call PatchLine
       
   124 
       
   125   push $2
       
   126   ${StrCase} $1 "$LICENSE_PRODUCT" "U"
       
   127   push '#  define QT_EDITION QT_EDITION_'
       
   128   push '#  define QT_EDITION QT_EDITION_$1$\r$\n'
       
   129   call PatchLine
       
   130   
       
   131   PatchConfigPriFile:
       
   132   IfFileExists "$0\mkspecs\qconfig.pri" 0 PatchLicenseProductDone
       
   133   push "$0\mkspecs\qconfig.pri"
       
   134   push "QT_EDITION = "
       
   135   push "QT_EDITION = $LICENSE_PRODUCT$\r$\n"
       
   136   call PatchLine
       
   137 
       
   138   PatchLicenseProductDone:
       
   139   pop $2
       
   140   pop $1
       
   141   pop $0
       
   142 FunctionEnd
       
   143 
       
   144 Function PatchCommonBinaryFiles
       
   145   exch $2
       
   146   push $0
       
   147   push $1
       
   148 
       
   149   IfFileExists "$2\bin\qmake.exe" 0 +5
       
   150   DetailPrint "Patching paths in qmake..."
       
   151   push $2
       
   152   push "$2\bin\qmake.exe"
       
   153   call PatchBinaryPaths
       
   154 
       
   155   DetailPrint "Patching paths in core..."
       
   156   FindFirst $0 $1 "$2\bin\QtCore*.dll"
       
   157   StrCmp $1 "" ErrorPatching
       
   158   push $2
       
   159   push "$2\bin\$1"
       
   160   call PatchBinaryPaths
       
   161 
       
   162   FindNext $0 $1
       
   163   StrCmp $1 "" ErrorPatching
       
   164   push $2
       
   165   push "$2\bin\$1"
       
   166   call PatchBinaryPaths
       
   167 
       
   168   ErrorPatching:
       
   169 
       
   170   pop $1
       
   171   pop $0
       
   172   pop $2
       
   173 FunctionEnd
       
   174 
       
   175 Function PatchBinaryPaths
       
   176   exch $0
       
   177   exch
       
   178   exch $2
       
   179   push $1
       
   180 
       
   181 !ifndef OPENSOURCE_BUILD
       
   182   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_prfxpath=" "qt_prfxpath=$2"
       
   183   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_docspath=" "qt_docspath=$2\doc"
       
   184   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_hdrspath=" "qt_hdrspath=$2\include"
       
   185   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_libspath=" "qt_libspath=$2\lib"
       
   186   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_binspath=" "qt_binspath=$2\bin"
       
   187   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_plugpath=" "qt_plugpath=$2\plugins"
       
   188   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_datapath=" "qt_datapath=$2"
       
   189   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_trnspath=" "qt_trnspath=$2\translations"
       
   190   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_xmplpath=" "qt_xmplpath=$2\examples"
       
   191 !ifdef MODULE_LICENSECHECK
       
   192   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_lcnsuser=" "qt_lcnsuser=$LICENSEE"
       
   193   qtnsisext::PatchBinary /NOUNLOAD $0 "qt_lcnsprod=" "qt_lcnsprod=$LICENSE_PRODUCT"
       
   194 !endif
       
   195   qtnsisext::PatchBinary $0 "qt_demopath=" "qt_demopath=$2\demos"
       
   196 !endif
       
   197 
       
   198   pop $1
       
   199   pop $2
       
   200   pop $0
       
   201 FunctionEnd
       
   202 
       
   203 #patching the prl files
       
   204 Function PatchPrlFiles
       
   205   exch $2
       
   206   exch
       
   207   exch $3 ;buildDir
       
   208   push $0
       
   209   push $1
       
   210 
       
   211   FindFirst $0 $1 "$2\lib\*.prl"
       
   212   loop:
       
   213     StrCmp $1 "" done
       
   214     DetailPrint "Patching $1..."
       
   215 
       
   216     push "$2\lib\$1"
       
   217     push $3
       
   218     push $2
       
   219     call PatchPath
       
   220 
       
   221     FindNext $0 $1
       
   222     Goto loop
       
   223   done:
       
   224   pop $1
       
   225   pop $0
       
   226   pop $3
       
   227   pop $2
       
   228 FunctionEnd
       
   229 
       
   230 #
       
   231 # patch line in text files
       
   232 # push "qtcore4.prl"  #Filename
       
   233 # push "#define ..." #START WITH
       
   234 # push "c:\qt"  #REPLACE WITH
       
   235 # call PatchLine
       
   236 #
       
   237 Function PatchLine
       
   238   exch $2 ;replacement line
       
   239   exch 2
       
   240   exch $1 ;Filename
       
   241   exch
       
   242   exch $0 ;start with
       
   243   push $3 ; tmp filename
       
   244   push $4 ; handle (tmp)
       
   245   push $5 ; handle (org)
       
   246   push $6 ; string
       
   247 
       
   248   ClearErrors
       
   249   GetTempFileName $3
       
   250   IfErrors done
       
   251   FileOpen $4 $3 w
       
   252   IfErrors done
       
   253   FileOpen $5 $1 r
       
   254   IfErrors done
       
   255 
       
   256 nextline:
       
   257   FileRead $5 $6
       
   258   IfErrors renameFile
       
   259   push $6
       
   260   push $0
       
   261   push $2
       
   262   call ReplaceLine
       
   263   pop $6
       
   264   FileWrite $4 $6
       
   265   goto nextline
       
   266 
       
   267 renameFile:
       
   268   FileClose $4
       
   269   FileClose $5
       
   270   SetDetailsPrint none
       
   271   Delete $1
       
   272   Rename $3 $1
       
   273   SetDetailsPrint both
       
   274 
       
   275   done:
       
   276   pop $6
       
   277   pop $5
       
   278   pop $4
       
   279   pop $3
       
   280   pop $0
       
   281   pop $1
       
   282   pop $2
       
   283 FunctionEnd
       
   284 
       
   285 #
       
   286 # replaces a string that starts with something, with another string
       
   287 # push string
       
   288 # push "#define ..." #START WITH
       
   289 # push "c:\qt"  #REPLACE WITH
       
   290 # call ReplaceLine
       
   291 # pop $0 #new string
       
   292 #
       
   293 Function ReplaceLine
       
   294   exch $2 ;new line
       
   295   exch 2
       
   296   exch $1 ;string
       
   297   exch
       
   298   exch $0 ;start with
       
   299 
       
   300   push $3 ; tmp string
       
   301   push $4 ; counter
       
   302   push $5 ; strlen
       
   303 
       
   304   StrCpy $4 "-1"
       
   305   StrLen $5 $1
       
   306 
       
   307   loop:
       
   308   IntOp $4 $4 + 1 ;increase counter
       
   309   StrCpy $3 $1 $4 ;get substring
       
   310   IntCmp $4 $5 copystring ; check for end
       
   311   StrCmp $3 $0 done ;start with found
       
   312   goto loop
       
   313 
       
   314   copystring:
       
   315   StrCpy $2 $1
       
   316   goto done
       
   317 
       
   318   done:
       
   319   pop $5
       
   320   pop $4
       
   321   pop $3
       
   322   pop $0
       
   323   pop $1
       
   324   exch $2
       
   325 FunctionEnd
       
   326 
       
   327 #
       
   328 # patch paths in text files
       
   329 # push "qtcore4.prl"  #Filename
       
   330 # push "c:\compile" #OLD_QTDIR
       
   331 # push "c:\qt"  #QTDIR
       
   332 # call PatchPath
       
   333 #
       
   334 Function PatchPath
       
   335   exch $2 ;NEW
       
   336   exch 2
       
   337   exch $1 ;Filename
       
   338   exch
       
   339   exch $0 ;OLD
       
   340   push $3 ;readline
       
   341   push $4 ;file 1
       
   342   push $5 ;file 2
       
   343   push $6 ;tmpfilename
       
   344 
       
   345   push $7 ;forward slash NEW
       
   346   push $8 ;forward slash OLD
       
   347 
       
   348   push $2
       
   349   push "\"
       
   350   push "/"
       
   351   call ReplaceString
       
   352   pop $7
       
   353 
       
   354   push $0
       
   355   push "\"
       
   356   push "/"
       
   357   call ReplaceString
       
   358   pop $8
       
   359 
       
   360   ClearErrors
       
   361   GetTempFileName $6
       
   362   IfErrors done
       
   363   FileOpen $5 $6 w
       
   364   IfErrors done
       
   365   FileOpen $4 $1 r
       
   366   IfErrors done
       
   367 
       
   368 nextline:
       
   369   FileRead $4 $3
       
   370   IfErrors renameFile
       
   371   push $3
       
   372   push $0
       
   373   push $2
       
   374   call ReplaceString ;replace backward slash path
       
   375   push $8
       
   376   push $7
       
   377   call ReplaceString ;replace forward slash path
       
   378   pop $3
       
   379   FileWrite $5 $3
       
   380   goto nextline
       
   381 
       
   382 renameFile:
       
   383   FileClose $5
       
   384   FileClose $4
       
   385   SetDetailsPrint none
       
   386   Delete $1
       
   387   Rename $6 $1
       
   388   SetDetailsPrint both
       
   389 
       
   390 done:
       
   391   pop $8
       
   392   pop $7
       
   393   pop $6
       
   394   pop $5
       
   395   pop $4
       
   396   pop $3
       
   397   pop $0
       
   398   pop $1
       
   399   pop $2
       
   400 FunctionEnd
       
   401 
       
   402 #
       
   403 # replaces a string with another string
       
   404 # push string
       
   405 # push "c:\qt"  #replace
       
   406 # push "c:\compile" #with
       
   407 # call ReplaceString
       
   408 # pop $0 #new string
       
   409 #
       
   410 !macro ReplaceString UN
       
   411 Function ${UN}ReplaceString
       
   412   exch $2 ;NEW
       
   413   exch 2
       
   414   exch $1 ;string
       
   415   exch
       
   416   exch $0 ;OLD
       
   417 
       
   418   push $3 ; tmp string
       
   419   push $4 ; counter
       
   420   push $5 ; result
       
   421 
       
   422   push $6 ; old strlen
       
   423 
       
   424   StrCpy $4 "-1"
       
   425   StrCpy $5 ""
       
   426 
       
   427   StrLen $6 $0
       
   428 
       
   429   loop:
       
   430   IntOp $4 $4 + 1 ;increase counter
       
   431   StrCpy $3 $1 $6 $4 ;get substring
       
   432   StrCmp $3 "" done ; check for end
       
   433   StrCmp $3 $0 replace ;replace if old
       
   434   StrCpy $3 $1 "1" $4
       
   435   StrCpy $5 $5$3 ;append character to result
       
   436   goto loop
       
   437 
       
   438   replace:
       
   439   StrCpy $5 $5$2 ;insert new qtdir
       
   440   IntOp $4 $4 + $6 ;increase offset
       
   441   IntOp $4 $4 - 1 ;decrease offset one more
       
   442   goto loop
       
   443 
       
   444   done:
       
   445   StrCpy $2 $5
       
   446   pop $6
       
   447   pop $5
       
   448   pop $4
       
   449   pop $3
       
   450   pop $0
       
   451   pop $1
       
   452   exch $2
       
   453 FunctionEnd
       
   454 !macroend
       
   455 !insertmacro ReplaceString ""
       
   456 !insertmacro ReplaceString "un."
       
   457 
       
   458 Function CommonCheckDirectory
       
   459   exch $4
       
   460   exch
       
   461   exch $5
       
   462   push $0
       
   463   push $1
       
   464   push $2
       
   465   push $3
       
   466 
       
   467   ; check if qt is already installed
       
   468   IfFileExists "$4\bin\qmake.exe" 0 +2
       
   469   IfFileExists "$4\uninst.exe" qtExistsError
       
   470   
       
   471   ; check if directory is empty
       
   472   FindFirst $0 $1 "$4\*"
       
   473   CommonCheckDirectory_FileSearchLoop:
       
   474     StrCmp $1 "" CommonCheckDirectory_DirDoesNotExist
       
   475     StrCmp $1 "." CommonCheckDirectory_ContinueSearchLoop
       
   476     StrCmp $1 ".." CommonCheckDirectory_ContinueSearchLoop
       
   477     goto CommonCheckDirectory_FoundFile
       
   478     CommonCheckDirectory_ContinueSearchLoop:
       
   479     FindNext $0 $1
       
   480     goto CommonCheckDirectory_FileSearchLoop
       
   481 
       
   482 CommonCheckDirectory_FoundFile:
       
   483   FindClose $0
       
   484   MessageBox MB_YESNO|MB_ICONEXCLAMATION "This directory already has contents. Are you sure you want to use this directory?" IDYES CommonCheckDirectory_DirDoesNotExist
       
   485   Goto errorInDirectory
       
   486 CommonCheckDirectory_DirDoesNotExist:
       
   487   FindClose $0
       
   488 
       
   489   GetInstDirError $0
       
   490   IntCmp 0 $0 0 instDirError
       
   491 
       
   492   StrLen $0 $4
       
   493 
       
   494 !ifdef USE_NODIRLENGTHCHECK
       
   495   StrCpy $1 "400"
       
   496 !else
       
   497   StrLen $1 $5
       
   498 !endif
       
   499 
       
   500   IntCmp $1 $0 0 directoryToLong
       
   501 
       
   502   ;check for spaces
       
   503   StrCpy $2 "-1"
       
   504   StrCpy $3 ""
       
   505 
       
   506   loop:
       
   507   IntOp $2 $2 + 1 ;increase counter
       
   508   StrCpy $3 $4 "1" $2 ;get char
       
   509   StrCmp $3 "" directoryOk ; check for end
       
   510   StrCmp $3 " " spaceInDirectory ;check for space
       
   511   goto loop
       
   512 
       
   513 qtExistsError:
       
   514   MessageBox MB_OK|MB_ICONEXCLAMATION "Qt is already installed in this directory. Please uninstall the previous version and try again."
       
   515   Goto errorInDirectory
       
   516 
       
   517 instDirError:
       
   518   MessageBox MB_OK|MB_ICONEXCLAMATION "This is not a valid installation directory."
       
   519   Goto errorInDirectory
       
   520 
       
   521 spaceInDirectory:
       
   522   MessageBox MB_OK|MB_ICONEXCLAMATION "The installation path can't contain spaces."
       
   523   Goto errorInDirectory
       
   524 
       
   525 directoryToLong:
       
   526   MessageBox MB_OK|MB_ICONEXCLAMATION "The installation directory is to long."
       
   527   Goto errorInDirectory
       
   528 
       
   529 errorInDirectory:
       
   530   pop $3
       
   531   pop $2
       
   532   pop $1
       
   533   pop $0
       
   534   pop $5
       
   535   pop $4
       
   536   Abort
       
   537   goto done
       
   538 
       
   539 directoryOk:
       
   540   pop $3
       
   541   pop $2
       
   542   pop $1
       
   543   pop $0
       
   544   pop $5
       
   545   pop $4
       
   546 done:
       
   547 FunctionEnd
       
   548 
       
   549 !endif ;QTCOMMON_INCLUDE