Skip to content

Commit

Permalink
Added QtIfwExternalOp.CreateWindowsAppFoundTempFile. Split up QtIfwEx…
Browse files Browse the repository at this point in the history
…ternalOp.UninstallWindowsAppScript into pieces to share code with CreateWindowsAppFoundTempFileScript.
  • Loading branch information
BuvinJ committed Jan 5, 2021
1 parent 6375644 commit 85a3233
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 16 deletions.
69 changes: 54 additions & 15 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5209,6 +5209,14 @@ def CreateStartupEntry( pkg=None,
# Some thoughts:
# https://stackoverflow.com/questions/630382/how-to-access-the-64-bit-registry-from-a-32-bit-powershell-instance

@staticmethod
def CreateWindowsAppFoundTempFile( event, appName, fileName,
isAutoBitContext=True ):
return QtIfwExternalOp.__genScriptOp( event,
script=QtIfwExternalOp.CreateWindowsAppFoundTempFileScript(
appName, fileName, isAutoBitContext ),
isReversible=False, isElevated=True )

@staticmethod
def UninstallWindowsApp( event, appName, arguments=None,
isSynchronous=True, isHidden=True,
Expand Down Expand Up @@ -5457,9 +5465,8 @@ def __psSetBitContext( isAutoBitContext ):
QtIfwExternalOp.__PS_32_TO_64_BIT_CONTEXT_HEADER )

@staticmethod
def UninstallWindowsAppScript( appName, arguments=None,
isSynchronous=True, isHidden=True,
isAutoBitContext=True ):
def __psFindWindowsAppUninstallCmd( appName, isAutoBitContext,
isExitOnNotFound=False ):
psScriptTemplate=(
r"""
{setBitContext}
Expand Down Expand Up @@ -5487,14 +5494,51 @@ def UninstallWindowsAppScript( appName, arguments=None,
if( $app.UninstallString ){ $UninstallCmd = $app.UninstallString }
}
# Exit with error if no command found
# Log command found / optionally exit with error
if( !$UninstallCmd ){
Write-Error "Uninstall command not found for: $APP_NAME"
[Environment]::Exit( {NOT_FOUND_EXIT_CODE} )
Write-Error "Uninstall command not found for {appName}"
{exitOnNotFound}
}
else{
Write-Host "OS registered uninstall command for {appName}: $UninstallCmd"
}
""")
exitOnNotFound =( "[Environment]::Exit( %d )" %
(QtIfwExternalOp.__NOT_FOUND_EXIT_CODE,)
if isExitOnNotFound else "" )
return str( ExecutableScript( "", script=psScriptTemplate,
replacements={
"setBitContext": QtIfwExternalOp.__psSetBitContext(
isAutoBitContext )
, "appName" : appName
, "exitOnNotFound": exitOnNotFound
} ) )

Write-Host "OS registered uninstall command: $UninstallCmd"
@staticmethod
def CreateWindowsAppFoundTempFileScript( appName, fileName,
isAutoBitContext=True ):
psScriptTemplate=(
QtIfwExternalOp.__psFindWindowsAppUninstallCmd(
appName, isAutoBitContext ) +
r"""
if( $UninstallCmd ){ Out-File -FilePath "{tempFilePath}" }
else { Remove-Item "{tempFilePath}" }
[Environment]::Exit( 0 )
""")
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"createAppFoundFile" ), extension="ps1",
script=psScriptTemplate, replacements={
"tempFilePath": qtIfwTempDataFilePath( fileName )
})

@staticmethod
def UninstallWindowsAppScript( appName, arguments=None,
isSynchronous=True, isHidden=True,
isAutoBitContext=True ):
psScriptTemplate=(
QtIfwExternalOp.__psFindWindowsAppUninstallCmd(
appName, isAutoBitContext, isExitOnNotFound=True ) +
r"""
# Tweak QtIFW / Distbuilder commands
if( $UninstallCmd.tolower().Contains( "maintenancetool.exe" ) ){
# Run in QtIFW verbose mode, in case distbuilder built - specify auto pilot / removeall
Expand Down Expand Up @@ -5538,15 +5582,10 @@ def UninstallWindowsAppScript( appName, arguments=None,
else: addArgs = ""
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"uninstallApp" ), extension="ps1", script=psScriptTemplate,
replacements={
"setBitContext": QtIfwExternalOp.__psSetBitContext(
isAutoBitContext )
, "appName" : appName
, "addArgs": addArgs
replacements={
"addArgs": addArgs
, "wait": ("-Wait " if isSynchronous else "")
, "hide": ("-WindowStyle Hidden " if isHidden else "")
, "NOT_FOUND_EXIT_CODE":
str( QtIfwExternalOp.__NOT_FOUND_EXIT_CODE )
, "hide": ("-WindowStyle Hidden " if isHidden else "")
} )

# Creates the key, if it does not exists.
Expand Down
14 changes: 14 additions & 0 deletions examples/hello_qtifw_ops/cascading_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ def getVaribaleCascadeOp( fileName, destFilePath ):
return QtIfwExternalOp( script=createFileScript,
uninstScript=QtIfwExternalOp.RemoveFileScript( destFilePath ) )

if IS_WINDOWS:
def setAppFoundFileOp( appName, is32Bit, fileName ):
return QtIfwExternalOp.CreateWindowsAppFoundTempFile(
QtIfwExternalOp.ON_BOTH,
appName, fileName, isAutoBitContext=(not is32Bit) )

BOOL_FILE_NAME = "boolData"
BOOL_EVAL_FILE_NAME = "cascadingBool.txt"
VAR_NAME = "myDynamicPath"
Expand All @@ -112,6 +118,14 @@ def getVaribaleCascadeOp( fileName, destFilePath ):
getVaribaleCascadeOp( TIME_FILE_NAME,
joinPath( QT_IFW_DESKTOP_DIR, TIME_FETCH_FILE_NAME ) ),
]

if IS_WINDOWS:
APP_NAME = "Hello World Tk Example"
IS_32BIT_APP = True
APP_FOUND_FILENAME = "HelloWorldTkInstalled"
pkg.pkgScript.externalOps += [
setAppFoundFileOp( APP_NAME, IS_32BIT_APP, APP_FOUND_FILENAME )
]

p = BuildProcess( configFactory, isDesktopTarget=True )
p.isInstallTest = True
Expand Down
5 changes: 4 additions & 1 deletion examples/hello_qtifw_ops/convenience_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ def addCreateExeFromVbs( pkg ):
'Set oShell = Nothing'
])

# The "Hello World Tk Example" app must be installed to test this.
# In order to actually test the uninstall operation, the
# "Hello World Tk Example" app must be installed first!
# (By default, however, it should NOT cause an error if it is not).
# Note this operation is being done on both install and uninstall
# and may therefore be tested during either.
Expand Down Expand Up @@ -107,4 +108,6 @@ def addRunProgramOp( pkg ):

p = BuildProcess( configFactory, isDesktopTarget=True )
p.isInstallTest = True
# uncomment to leave scripts in temp directory, post any dynamic modifications
# p.isScriptDebugInstallTest = True
p.run()

0 comments on commit 85a3233

Please sign in to comment.