2012-10-12 16:37:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#coding:utf8
|
2012-12-30 13:07:07 +00:00
|
|
|
from distutils.core import setup
|
|
|
|
from py2exe.build_exe import py2exe
|
2013-01-15 18:27:21 +00:00
|
|
|
from string import Template
|
2012-10-12 16:37:12 +00:00
|
|
|
|
|
|
|
import syncplay
|
2012-12-24 18:15:32 +00:00
|
|
|
import sys
|
2013-01-15 18:27:21 +00:00
|
|
|
import os
|
|
|
|
import subprocess
|
2012-10-12 16:37:12 +00:00
|
|
|
|
2013-01-26 19:30:43 +00:00
|
|
|
p = "C:\\Program Files\\NSIS\\makensis.exe" #TODO: how to move that into proper place, huh
|
2013-01-16 14:00:57 +00:00
|
|
|
NSIS_COMPILE = p if os.path.isfile(p) else "makensis.exe"
|
|
|
|
OUT_DIR = "syncplay v{}".format(syncplay.version)
|
2013-01-15 18:27:21 +00:00
|
|
|
SETUP_SCRIPT_PATH = "syncplay_setup.nsi"
|
|
|
|
NSIS_SCRIPT_TEMPLATE = r"""
|
|
|
|
!include LogicLib.nsh
|
|
|
|
!include nsDialogs.nsh
|
2013-01-26 21:10:28 +00:00
|
|
|
!include FileFunc.nsh
|
2013-01-16 14:00:57 +00:00
|
|
|
|
2013-01-15 18:27:21 +00:00
|
|
|
LoadLanguageFile "$${NSISDIR}\Contrib\Language files\English.nlf"
|
|
|
|
LoadLanguageFile "$${NSISDIR}\Contrib\Language files\Polish.nlf"
|
|
|
|
|
2013-01-26 20:37:51 +00:00
|
|
|
Name "Syncplay $version"
|
|
|
|
OutFile "Syncplay $version Setup.exe"
|
2013-01-15 18:27:21 +00:00
|
|
|
InstallDir $$PROGRAMFILES\Syncplay
|
|
|
|
RequestExecutionLevel admin
|
|
|
|
XPStyle on
|
|
|
|
Icon resources\icon.ico ;Change DIR
|
|
|
|
SetCompressor /SOLID lzma
|
|
|
|
|
2013-01-16 14:00:57 +00:00
|
|
|
VIProductVersion "$version.0"
|
2013-01-15 18:27:21 +00:00
|
|
|
VIAddVersionKey /LANG=$${LANG_ENGLISH} "ProductName" "Syncplay"
|
2013-01-16 14:00:57 +00:00
|
|
|
VIAddVersionKey /LANG=$${LANG_ENGLISH} "FileVersion" "$version.0"
|
2013-01-15 18:27:21 +00:00
|
|
|
VIAddVersionKey /LANG=$${LANG_ENGLISH} "LegalCopyright" "Syncplay"
|
|
|
|
VIAddVersionKey /LANG=$${LANG_ENGLISH} "FileDescription" "Syncplay"
|
|
|
|
|
|
|
|
VIAddVersionKey /LANG=$${LANG_POLISH} "ProductName" "Syncplay"
|
2013-01-16 14:00:57 +00:00
|
|
|
VIAddVersionKey /LANG=$${LANG_POLISH} "FileVersion" "$version.0"
|
2013-01-15 18:27:21 +00:00
|
|
|
VIAddVersionKey /LANG=$${LANG_POLISH} "LegalCopyright" "Syncplay"
|
|
|
|
VIAddVersionKey /LANG=$${LANG_POLISH} "FileDescription" "Syncplay"
|
|
|
|
|
|
|
|
PageEx license
|
|
|
|
LicenseData resources\license.txt
|
|
|
|
PageExEnd
|
|
|
|
Page directory
|
|
|
|
Page instFiles
|
|
|
|
|
|
|
|
UninstPage uninstConfirm
|
|
|
|
UninstPage instFiles
|
|
|
|
|
|
|
|
!macro APP_ASSOCIATE EXT FileCLASS DESCRIPTION COMMANDTEXT COMMAND
|
|
|
|
WriteRegStr HKCR ".$${EXT}" "" "$${FileCLASS}"
|
|
|
|
WriteRegStr HKCR "$${FileCLASS}" "" `$${DESCRIPTION}`
|
|
|
|
WriteRegStr HKCR "$${FileCLASS}\shell" "" "open"
|
|
|
|
WriteRegStr HKCR "$${FileCLASS}\shell\open" "" `$${COMMANDTEXT}`
|
|
|
|
WriteRegStr HKCR "$${FileCLASS}\shell\open\command" "" `$${COMMAND}`
|
|
|
|
!macroend
|
|
|
|
|
|
|
|
!macro APP_UNASSOCIATE EXT FileCLASS
|
|
|
|
; Backup the previously associated File class
|
|
|
|
ReadRegStr $$R0 HKCR ".$${EXT}" `$${FileCLASS}_backup`
|
|
|
|
WriteRegStr HKCR ".$${EXT}" "" "$$R0"
|
|
|
|
DeleteRegKey HKCR `$${FileCLASS}`
|
|
|
|
!macroend
|
|
|
|
|
|
|
|
;Associates extensions with Syncplay
|
|
|
|
Function Associate
|
|
|
|
!insertmacro APP_ASSOCIATE "mkv" "Syncplay.mkv" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "mp4" "Syncplay.mp4" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "avi" "Syncplay.avi" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "flv" "Syncplay.flv" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "mpg" "Syncplay.mpg" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "rmvb" "Syncplay.rmvb" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "vob" "Syncplay.vob" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "swf" "Syncplay.swf" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
!insertmacro APP_ASSOCIATE "wmv" "Syncplay.wmv" "$$INSTDIR\Syncplay.exe,%1%" \
|
|
|
|
"Open with Syncplay" "$$INSTDIR\Syncplay.exe $$\"%1$$\""
|
|
|
|
FunctionEnd
|
|
|
|
|
|
|
|
Function WriteRegistry
|
2013-01-26 21:10:28 +00:00
|
|
|
$${GetSize} "$$INSTDIR" "/S=0K" $$0 $$1 $$2
|
|
|
|
IntFmt $$0 "0x%08X" $$0
|
2013-01-15 18:27:21 +00:00
|
|
|
WriteRegStr HKLM SOFTWARE\Syncplay "Install_Dir" "$$INSTDIR"
|
|
|
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "DisplayName" "Syncplay"
|
|
|
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "UninstallString" '"$$INSTDIR\uninstall.exe"'
|
2013-01-26 21:10:28 +00:00
|
|
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "DisplayIcon" "$$INSTDIR\resources\icon.ico"
|
2013-01-15 18:27:21 +00:00
|
|
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "Publisher" "Syncplay"
|
2013-01-26 21:10:28 +00:00
|
|
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "DisplayVersion" "$version"
|
2013-01-15 18:27:21 +00:00
|
|
|
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "URLInfoAbout" "http://syncplay.pl/"
|
|
|
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "NoModify" 1
|
|
|
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "NoRepair" 1
|
2013-01-26 21:10:28 +00:00
|
|
|
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay" "EstimatedSize" "$$0"
|
2013-01-15 18:27:21 +00:00
|
|
|
FunctionEnd
|
|
|
|
|
|
|
|
Function un.AssociateDel
|
|
|
|
!insertmacro APP_UNASSOCIATE "mkv" "Syncplay.mkv"
|
|
|
|
!insertmacro APP_UNASSOCIATE "mp4" "Syncplay.mp4"
|
|
|
|
!insertmacro APP_UNASSOCIATE "avi" "Syncplay.avi"
|
|
|
|
!insertmacro APP_UNASSOCIATE "flv" "Syncplay.flv"
|
|
|
|
!insertmacro APP_UNASSOCIATE "mpg" "Syncplay.mpg"
|
|
|
|
!insertmacro APP_UNASSOCIATE "rmvb" "Syncplay.rmvb"
|
|
|
|
!insertmacro APP_UNASSOCIATE "vob" "Syncplay.vob"
|
|
|
|
!insertmacro APP_UNASSOCIATE "swf" "Syncplay.swf"
|
|
|
|
!insertmacro APP_UNASSOCIATE "wmv" "Syncplay.wmv"
|
|
|
|
FunctionEnd
|
|
|
|
|
|
|
|
;Prevents from running more than one instance of installer
|
|
|
|
Function .onInit
|
|
|
|
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "myMutex") i .r1 ?e'
|
|
|
|
Pop $$R0
|
|
|
|
StrCmp $$R0 0 +3
|
|
|
|
MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
|
|
|
|
Abort
|
|
|
|
Call Language
|
|
|
|
FunctionEnd
|
|
|
|
|
|
|
|
;Language selection dialog
|
|
|
|
Function Language
|
|
|
|
Push ""
|
|
|
|
Push $${LANG_ENGLISH}
|
|
|
|
Push English
|
|
|
|
Push $${LANG_POLISH}
|
|
|
|
Push Polski
|
|
|
|
Push A ; A means auto count languages
|
|
|
|
LangDLL::LangDialog "Installer Language" "Please select the language of the installer"
|
|
|
|
Pop $$LANGUAGE
|
|
|
|
StrCmp $$LANGUAGE "cancel" 0 +2
|
|
|
|
Abort
|
|
|
|
FunctionEnd
|
|
|
|
|
|
|
|
Section "Install"
|
|
|
|
SetOverwrite on
|
|
|
|
SetOutPath $$INSTDIR
|
|
|
|
WriteUninstaller uninstall.exe
|
|
|
|
|
2013-01-16 14:00:57 +00:00
|
|
|
$installFiles
|
2013-01-26 21:10:28 +00:00
|
|
|
|
|
|
|
Call Associate
|
|
|
|
Call WriteRegistry
|
2013-01-15 18:27:21 +00:00
|
|
|
SectionEnd
|
|
|
|
|
|
|
|
Section "Uninstall"
|
|
|
|
Call un.AssociateDel
|
2013-01-26 19:30:43 +00:00
|
|
|
$uninstallFiles
|
2013-01-15 18:27:21 +00:00
|
|
|
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Syncplay"
|
|
|
|
DeleteRegKey HKLM SOFTWARE\Syncplay
|
|
|
|
Delete $$INSTDIR\uninstall.exe
|
|
|
|
RMDir $$INSTDIR
|
|
|
|
SectionEnd
|
|
|
|
"""
|
|
|
|
|
|
|
|
class NSISScript(object):
|
|
|
|
def create(self):
|
2013-01-16 14:00:57 +00:00
|
|
|
fileList = self.getBuildDirContents(OUT_DIR)
|
|
|
|
installFiles = self.prepareInstallListTemplate(fileList)
|
|
|
|
uninstallFiles = self.prepareDeleteListTemplate(fileList)
|
|
|
|
|
2013-01-15 18:27:21 +00:00
|
|
|
if(os.path.isfile(SETUP_SCRIPT_PATH)):
|
|
|
|
raise RuntimeError("Cannot create setup script, file exists at {}".format(SETUP_SCRIPT_PATH))
|
2013-01-16 14:00:57 +00:00
|
|
|
contents = Template(NSIS_SCRIPT_TEMPLATE).substitute(
|
|
|
|
version = syncplay.version,
|
|
|
|
uninstallFiles = uninstallFiles,
|
|
|
|
installFiles = installFiles,
|
|
|
|
)
|
2013-01-15 18:27:21 +00:00
|
|
|
with open(SETUP_SCRIPT_PATH, "w") as outfile:
|
|
|
|
outfile.write(contents)
|
|
|
|
|
|
|
|
def compile(self):
|
|
|
|
subproc = subprocess.Popen([NSIS_COMPILE, SETUP_SCRIPT_PATH], env=os.environ)
|
|
|
|
subproc.communicate()
|
|
|
|
retcode = subproc.returncode
|
|
|
|
os.remove(SETUP_SCRIPT_PATH)
|
|
|
|
if retcode:
|
|
|
|
raise RuntimeError("NSIS compilation return code: %d" % retcode)
|
2013-01-16 14:00:57 +00:00
|
|
|
|
|
|
|
def getBuildDirContents(self, path):
|
|
|
|
fileList = {}
|
|
|
|
for root, _, files in os.walk(path):
|
|
|
|
for file_ in files:
|
|
|
|
new_root = root.replace(OUT_DIR, "").strip("\\")
|
|
|
|
if(not fileList.has_key(new_root)):
|
|
|
|
fileList[new_root] = []
|
|
|
|
fileList[new_root].append(file_)
|
|
|
|
return fileList
|
|
|
|
|
|
|
|
|
|
|
|
def prepareInstallListTemplate(self, fileList):
|
|
|
|
create = []
|
|
|
|
for dir_ in fileList.iterkeys():
|
|
|
|
create.append('SetOutPath "$INSTDIR\\{}"'.format(dir_))
|
|
|
|
for file_ in fileList[dir_]:
|
|
|
|
create.append('FILE "{}\\{}\\{}"'.format(OUT_DIR, dir_, file_))
|
|
|
|
return "\n".join(create)
|
|
|
|
|
|
|
|
def prepareDeleteListTemplate(self, fileList):
|
|
|
|
delete = []
|
|
|
|
for dir_ in fileList.iterkeys():
|
|
|
|
for file_ in fileList[dir_]:
|
|
|
|
delete.append('DELETE "$INSTDIR\\{}\\{}"'.format(dir_, file_))
|
|
|
|
delete.append('RMdir "$INSTDIR\\{}"'.format(file_))
|
|
|
|
return "\n".join(delete)
|
|
|
|
|
2013-01-15 18:27:21 +00:00
|
|
|
class build_installer(py2exe):
|
|
|
|
def run(self):
|
|
|
|
py2exe.run(self)
|
|
|
|
script = NSISScript()
|
|
|
|
script.create()
|
|
|
|
print "*** compiling the NSIS setup script***"
|
|
|
|
script.compile()
|
|
|
|
print "*** DONE ***"
|
|
|
|
|
|
|
|
|
2012-10-12 16:37:12 +00:00
|
|
|
common_info = dict(
|
2012-10-15 18:33:24 +00:00
|
|
|
name='Syncplay',
|
|
|
|
version=syncplay.version,
|
2012-12-26 16:03:57 +00:00
|
|
|
author='Uriziel',
|
|
|
|
author_email='urizieli@gmail.com',
|
2012-10-15 18:33:24 +00:00
|
|
|
description='Syncplay',
|
2012-10-12 16:37:12 +00:00
|
|
|
)
|
2013-01-15 18:27:21 +00:00
|
|
|
|
2012-10-12 16:37:12 +00:00
|
|
|
info = dict(
|
|
|
|
common_info,
|
2012-12-30 13:07:07 +00:00
|
|
|
console=[{"script":"syncplayClient.py", "icon_resources":[(1, "resources\\icon.ico")], 'dest_base': "Syncplay"}, 'syncplayServer.py'],
|
2012-10-15 18:33:24 +00:00
|
|
|
options={'py2exe': {
|
2013-01-16 14:00:57 +00:00
|
|
|
'dist_dir': OUT_DIR,
|
2012-12-30 13:07:07 +00:00
|
|
|
'includes': 'cairo, pango, pangocairo, atk, gobject, twisted',
|
|
|
|
'excludes': 'venv, _ssl, doctest, pdb, unittest, difflib, win32clipboard, win32event, win32file, win32pdh, win32security, win32trace, win32ui, winxpgui, win32pipe, win32process',
|
2012-12-26 16:03:57 +00:00
|
|
|
'dll_excludes': 'msvcr71.dll',
|
2012-10-12 16:37:12 +00:00
|
|
|
'optimize': 2,
|
|
|
|
'compressed': 1
|
|
|
|
}
|
2012-12-30 13:07:07 +00:00
|
|
|
},
|
2013-01-16 14:00:57 +00:00
|
|
|
data_files = [("resources", ["resources/icon.ico",])],
|
2012-12-30 13:07:07 +00:00
|
|
|
zipfile = "lib/libsync",
|
2013-01-15 18:27:21 +00:00
|
|
|
cmdclass = {"py2exe": build_installer},
|
2012-10-12 16:37:12 +00:00
|
|
|
)
|
|
|
|
|
2013-01-15 18:27:21 +00:00
|
|
|
sys.argv.extend(['py2exe', '-p win32com ', '-i twisted.web.resource'])
|
2012-10-12 16:37:12 +00:00
|
|
|
setup(**info)
|
|
|
|
|