Skip to content

Commit

Permalink
Added self destruction option to a handful of PowerShell based script…
Browse files Browse the repository at this point in the history
… building functions in QtIfwExternalOp. Will test and then further replicate...
  • Loading branch information
BuvinJ committed Jan 11, 2021
1 parent 6d43a07 commit 5f74720
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 28 deletions.
30 changes: 23 additions & 7 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5658,7 +5658,8 @@ def __psSetBitContext( isAutoBitContext ):

@staticmethod
def __psFindWindowsAppUninstallCmd( appName, isAutoBitContext,
isExitOnNotFound=False ):
isExitOnNotFound=False,
isSelfDestruct=False ):
psScriptTemplate=(
r"""
{setBitContext}
Expand Down Expand Up @@ -5689,6 +5690,7 @@ def __psFindWindowsAppUninstallCmd( appName, isAutoBitContext,
# Log command found / optionally exit with error
if( !$UninstallCmd ){
Write-Error "Uninstall command not found for {appName}"
{selfDestructOnNotFound}
{exitOnNotFound}
}
else{
Expand All @@ -5703,33 +5705,43 @@ def __psFindWindowsAppUninstallCmd( appName, isAutoBitContext,
"setBitContext": QtIfwExternalOp.__psSetBitContext(
isAutoBitContext )
, "appName" : appName
, "exitOnNotFound": exitOnNotFound
, "exitOnNotFound": exitOnNotFound
, "selfDestructOnNotFound" : (
QtIfwExternalOp.powerShellSelfDestructSnippet()
if isSelfDestruct and exitOnNotFound else "" )
} ) )

@staticmethod
def CreateWindowsAppFoundFlagFileScript( appName, fileName,
isAutoBitContext=True ):
isAutoBitContext=True,
isSelfDestruct=False ):
psScriptTemplate=(
QtIfwExternalOp.__psFindWindowsAppUninstallCmd(
appName, isAutoBitContext ) +
r"""
if( $UninstallCmd ){ Out-File -FilePath "{tempFilePath}" }
else { Remove-Item "{tempFilePath}" }
{selfDestruct}
[Environment]::Exit( 0 )
""")
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"createAppFoundFile" ), extension="ps1",
script=psScriptTemplate, replacements={
"tempFilePath": QtIfwExternalOp.opDataPath( fileName )
"tempFilePath": QtIfwExternalOp.opDataPath( fileName )
, "selfDestruct" : (
QtIfwExternalOp.powerShellSelfDestructSnippet()
if isSelfDestruct else "" )
})

@staticmethod
def UninstallWindowsAppScript( appName, arguments=None,
isSynchronous=True, isHidden=True,
isAutoBitContext=True ):
isAutoBitContext=True,
isSelfDestruct=False ):
psScriptTemplate=(
QtIfwExternalOp.__psFindWindowsAppUninstallCmd(
appName, isAutoBitContext, isExitOnNotFound=True ) +
appName, isAutoBitContext, isExitOnNotFound=True,
isSelfDestruct=isSelfDestruct ) +
r"""
# Tweak QtIFW / Distbuilder commands
if( $UninstallCmd.tolower().Contains( "maintenancetool.exe" ) ){
Expand Down Expand Up @@ -5766,6 +5778,7 @@ def UninstallWindowsAppScript( appName, arguments=None,
Write-Host "Running: $prog"
if( $args.Count -gt 0 ){ Write-Host "With arguments: $args" }
Start-Process $prog {wait}{hide}-ArgumentList $args
{selfDestruct}
[Environment]::Exit( 0 )
""")
if arguments:
Expand All @@ -5777,7 +5790,10 @@ def UninstallWindowsAppScript( appName, arguments=None,
replacements={
"addArgs": addArgs
, "wait": ("-Wait " if isSynchronous else "")
, "hide": ("-WindowStyle Hidden " if isHidden else "")
, "hide": ("-WindowStyle Hidden " if isHidden else "")
, "selfDestruct" : (
QtIfwExternalOp.powerShellSelfDestructSnippet()
if isSelfDestruct else "" )
} )

# Creates the key, if it does not exists.
Expand Down
38 changes: 23 additions & 15 deletions docs/ConfigClasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,13 @@ controls.

TODO: Add Linux & macOS implementations

#### QtIfwExternalOp.CreateWindowsAppFoundFlagFile

**WINDOWS ONLY**

CreateWindowsAppFoundFlagFile( event, appName, fileName,
isAutoBitContext=True )
#### QtIfwExternalOp.UninstallWindowsApp

**WINDOWS ONLY**
Expand Down Expand Up @@ -930,15 +937,15 @@ use of SysWow64 nodes.

### QtIfwExternalOp Convenience Scripts

#### Self-destruct Script Snippets
#### Self-Destructing Script Snippets

In some circumstances, e.g. when using scripts with
[QtIfwOnFinishedDetachedExec](#qtifwonfinisheddetachedexec) or
[QtIfwOnFinishedCheckbox](#qtifwonfinishedcheckbox), you may wish for your
scripts to "self-desctruct" (i.e. delete themselves).
scripts to "self-destruct" (i.e. delete themselves).

The following functions return strings that you can append to / weave into
your custom scripts.
The following functions return strings that you may append to / weave into
your custom scripts to serve this purpose.

##### QtIfwExternalOp.batchSelfDestructSnippet

Expand Down Expand Up @@ -1002,16 +1009,6 @@ not remove** a file that already exists.

**Windows Type**: Batch
**Mac/Linux Type**: ShellScript

#### QtIfwExternalOp.UninstallWindowsAppScript

**WINDOWS ONLY**

UninstallWindowsAppScript( appName, arguments=None,
isSynchronous=True, isHidden=True,
isAutoBitContext=True )

**Type**: PowerShell

#### QtIfwExternalOp.CreateRegistryKeyScript

Expand Down Expand Up @@ -1051,6 +1048,16 @@ not remove** a file that already exists.
replacements=None )

**Type**: PowerShell

#### QtIfwExternalOp.CreateWindowsAppFoundFlagFileScript

**WINDOWS ONLY**

CreateWindowsAppFoundFlagFileScript( appName, fileName,
isAutoBitContext=True,
isSelfDestruct=False )

**Type**: PowerShell

#### QtIfwExternalOp.UninstallWindowsAppScript
Expand All @@ -1059,7 +1066,8 @@ not remove** a file that already exists.
UninstallWindowsAppScript( appName, arguments=None,
isSynchronous=True,
isHidden=True,
isAutoBitContext=True )
isAutoBitContext=True,
isSelfDestruct=False )

**Type**: PowerShell

Expand Down
16 changes: 10 additions & 6 deletions examples/hello_dynamic_finish/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,20 @@ def customizeFinishedPage( cfg, tkPkg, cliPkg ):
openLicCommand=(
'open -a {textViewer} "@TargetDir@/{licenseName}"' )
# TODO: Add self-destruction
openLicShellScript = ExecutableScript( "openLic", script=(
'open -a {textViewer} "@TargetDir@/{licenseName}"' ) )
openLicShellScript = ExecutableScript( "openLic", script=([
'open -a {textViewer} "@TargetDir@/{licenseName}"'
,QtIfwExternalOp.shellScriptSelfDestructSnippet()
]) )
scripts.update( { SHELL: openLicShellScript } )
else: # IS_LINUX
textViewer = "gedit" # distro specific...
openLicCommand=(
'screen -d -m {textViewer} "@TargetDir@/{licenseName}"' )
# TODO: Add self-destruction
openLicShellScript = ExecutableScript( "openLic", script=(
'screen -d -m {textViewer} "@TargetDir@/{licenseName}"' ) )
openLicShellScript = ExecutableScript( "openLic", script=([
'screen -d -m {textViewer} "@TargetDir@/{licenseName}"'
,QtIfwExternalOp.shellScriptSelfDestructSnippet()
]) )
scripts.update( { SHELL: openLicShellScript } )
openLicScript = scripts[ DEMO_OPTION ]

Expand Down Expand Up @@ -239,7 +243,7 @@ def showIfInstalled( checkbox, pkg, isChecked=True ):
,QtIfwExternalOp.batchSelfDestructSnippet()]
if IS_WINDOWS else
['touch "%s"' % (EXAMPLE_FILE_PATH,)
,'']) # TODO: Add self-destruction
,QtIfwExternalOp.shellScriptSelfDestructSnippet()])
)
)
removeExampleFileExec = QtIfwOnFinishedDetachedExec(
Expand All @@ -249,7 +253,7 @@ def showIfInstalled( checkbox, pkg, isChecked=True ):
,QtIfwExternalOp.batchSelfDestructSnippet()]
if IS_WINDOWS else
['rm "%s"' % (EXAMPLE_FILE_PATH,)
,'']) # TODO: Add self-destruction
,QtIfwExternalOp.shellScriptSelfDestructSnippet()])
)
)

Expand Down

0 comments on commit 5f74720

Please sign in to comment.