1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
#!/usr/bin/env python
# This file has been modified from:
# NSIS script generator for Performous.
# Copyright (C) 2010 John Stumpo
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import subprocess
import sys
try:
makensis = subprocess.Popen([os.environ['MAKENSIS'], '-'], stdin=subprocess.PIPE)
except KeyError:
makensis = subprocess.Popen(['makensis', '-'], stdin=subprocess.PIPE)
if not os.path.isdir('dist'):
os.mkdir('dist')
os.chdir('stage')
app = 'Composer'
version = '2.0'
makensis.stdin.write(r'''!include "MUI2.nsh"
!define APP "%(app)s"
!define VERSION "%(version)s"
Name "${APP} ${VERSION}"
OutFile "dist\${APP}-${VERSION}.exe"
SetCompressor /SOLID lzma
ShowInstDetails show
ShowUninstDetails show
InstallDir "$PROGRAMFILES\${APP}"
InstallDirRegKey HKLM "Software\${APP}" ""
RequestExecutionLevel admin
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH
!insertmacro MUI_LANGUAGE "English"
Section
''' % {'app': app, 'version': version})
for root, dirs, files in os.walk('.'):
makensis.stdin.write(' SetOutPath "$INSTDIR\\%s"\n' % root.replace('/', '\\'))
for file in files:
makensis.stdin.write(' File "%s"\n' % os.path.join('stage', root, file).replace('/', '\\'))
makensis.stdin.write(r''' WriteRegStr HKLM "Software\${APP}" "" "$INSTDIR"
WriteUninstaller "$INSTDIR\uninst.exe"
SetShellVarContext all
CreateDirectory "$SMPROGRAMS\${APP}"
CreateShortcut "$SMPROGRAMS\${APP}\${APP}.lnk" "$INSTDIR\${APP}.exe"
CreateShortcut "$SMPROGRAMS\${APP}\Uninstall.lnk" "$INSTDIR\uninst.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP}" "DisplayName" "${APP}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP}" "UninstallString" "$\"$INSTDIR\uninst.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP}" "DisplayIcon" "$INSTDIR\${APP}.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP}" "DisplayVersion" "${VERSION}"
SectionEnd
Section Uninstall
''')
for root, dirs, files in os.walk('.', topdown=False):
for dir in dirs:
makensis.stdin.write(' RmDir "$INSTDIR\\%s"\n' % os.path.join(root, dir).replace('/', '\\'))
for file in files:
makensis.stdin.write(' Delete "$INSTDIR\\%s"\n' % os.path.join(root, file).replace('/', '\\'))
makensis.stdin.write(' RmDir "$INSTDIR\\%s"\n' % root.replace('/', '\\'))
makensis.stdin.write(r''' Delete "$INSTDIR\uninst.exe"
RmDir "$INSTDIR"
SetShellVarContext all
Delete "$SMPROGRAMS\${APP}\${APP}.lnk"
Delete "$SMPROGRAMS\${APP}\Uninstall.lnk"
RmDir "$SMPROGRAMS\${APP}"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${APP}"
DeleteRegKey /ifempty HKLM "Software\${APP}"
SectionEnd
''')
makensis.stdin.close()
if makensis.wait() != 0:
print >>sys.stderr, 'Installer compilation failed.'
sys.exit(1)
else:
print 'Installer ready.'
|