Skip to content

Commit

Permalink
Continued developing and patching QtIFW Windows registry functions an…
Browse files Browse the repository at this point in the history
…d demo. Reached a good stopping point with that feature set. Will likely circle back at some point down the road to expand the options further. Added "preOpSupport" attribute / implementation to QtIfwPackageScript class.
  • Loading branch information
BuvinJ committed Nov 30, 2020
1 parent 4962e72 commit 11159dd
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 50 deletions.
109 changes: 94 additions & 15 deletions distbuilder/qt_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1418,11 +1418,13 @@ def ifRegistryKeyExistsLike( parentKey, childKeyNameContains,
@staticmethod
def registryEntryValue( key, valueName, isAutoBitContext=True,
isAutoQuote=True ):
valueName =( _QtIfwScript.toNull( valueName ) if valueName is None
else _QtIfwScript._autoQuote( valueName, isAutoQuote ) )
return _QtIfwScript.__REG_ENTRY_VALUE_TMPL % (
_QtIfwScript._autoEscapeBackSlash(
_QtIfwScript._autoQuote( key, isAutoQuote ),
isAutoQuote ).replace(":",""),
_QtIfwScript._autoQuote( valueName, isAutoQuote ),
valueName,
_QtIfwScript.toBool( isAutoBitContext ) )

@staticmethod
Expand All @@ -1437,20 +1439,23 @@ def assignRegistryEntryVar( key, valueName, isAutoBitContext=True,
def setValueFromRegistryEntry( key,
regKey, valueName, isAutoBitContext=True,
isAutoQuote=True ):
return _QtIfwScript.setValue( key,
return _QtIfwScript.setValue(
_QtIfwScript._autoQuote( key, isAutoQuote ),
_QtIfwScript.registryEntryValue(
regKey, valueName, isAutoBitContext=isAutoBitContext,
isAutoQuote=isAutoQuote ),
isAutoQuote=isAutoQuote )
isAutoQuote=False )

@staticmethod
def registryEntryExists( key, valueName, isAutoBitContext=True,
isAutoQuote=True ):
isAutoQuote=True ):
valueName =( _QtIfwScript.toNull( valueName ) if valueName is None
else _QtIfwScript._autoQuote( valueName, isAutoQuote ) )
return _QtIfwScript.__REG_ENTRY_EXISTS_TMPL % (
_QtIfwScript._autoEscapeBackSlash(
_QtIfwScript._autoQuote( key, isAutoQuote ),
isAutoQuote ).replace(":",""),
_QtIfwScript._autoQuote( valueName, isAutoQuote ),
valueName,
_QtIfwScript.toBool( isAutoBitContext ) )

@staticmethod
Expand Down Expand Up @@ -3884,6 +3889,7 @@ def __init__( self, pkgName, pkgVersion, pkgSubDirName=None,
self.shortcuts = shortcuts if shortcuts else []
self.externalOps = externalOps if externalOps else []
self.killOps = []
self.preOpSupport = None
self.customOperations = None
self.bundledScripts = bundledScripts if bundledScripts else []
self.installResources = installResources if installResources else []
Expand Down Expand Up @@ -4135,6 +4141,10 @@ def __genComponentCreateOperationsBody( self ):
EBLK = _QtIfwScript.END_BLOCK

self.componentCreateOperationsBody = "try " + SBLK

if self.preOpSupport:
self.componentCreateOperationsBody += (
"\n%s\n" % (self.preOpSupport,) )

if self.customOperations:
self.componentCreateOperationsBody += (
Expand Down Expand Up @@ -5029,6 +5039,22 @@ def UninstallWindowsApp( event, appName, arguments=None,
arguments, isSynchronous, isHidden, isAutoBitContext ),
isReversible=False, isElevated=True )

@staticmethod
def CreateRegistryKey( event, key, isAutoBitContext=True ):
return QtIfwExternalOp.__genScriptOp( event,
script=QtIfwExternalOp.CreateRegistryKeyScript(
key, isAutoBitContext ),
uninstScript=QtIfwExternalOp.RemoveRegistryKeyScript(
key, isAutoBitContext ),
isElevated=True )

@staticmethod
def RemoveRegistryKey( event, key, isAutoBitContext=True ):
return QtIfwExternalOp.__genScriptOp( event,
script=QtIfwExternalOp.RemoveRegistryKeyScript(
key, isAutoBitContext ),
isReversible=False, isElevated=True )

@staticmethod
def CreateRegistryEntry( event, key, valueName=None,
value="", valueType="String",
Expand Down Expand Up @@ -5315,32 +5341,85 @@ def UninstallWindowsAppScript( appName, arguments=None,
, "hide": ("-WindowStyle Hidden " if isHidden else "")
} )

# See
# https://blog.netwrix.com/2018/09/11/how-to-get-edit-create-and-delete-registry-keys-with-powershell/
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-itemproperty?view=powershell-7
# Creates the key, if it does not exists.
# Recursively creates the parent key, if that does not yet exist.
@staticmethod
def CreateRegistryKeyScript( key, isAutoBitContext=True,
replacements=None ):
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"createRegKey" ), extension="ps1", script=([
QtIfwExternalOp.__psSetBitContext( isAutoBitContext ),
"$key='%s'" % (key,),
"Try{ Get-Item -Path $key -ErrorAction Stop | Out-Null }",
"Catch{ New-Item -Force -Path $key }",
]),
replacements=replacements )

# Removes the key, if it exists.
@staticmethod
def RemoveRegistryKeyScript( key, isAutoBitContext=True,
replacements=None ):
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"removeRegKey" ), extension="ps1", script=([
QtIfwExternalOp.__psSetBitContext( isAutoBitContext ),
"$key='%s'" % (key,),
"Try{ ",
" Get-Item -Path $key -ErrorAction Stop | Out-Null }",
" Remove-Item -Path $key }",
"Catch{}"
]),
replacements=replacements )

# Creates the entry, if it does not exists.
# Overwrites any prior value, if it already exists.
# Recursively creates the parent key, if that does not yet exist.
# valueName=None = Default key value
@staticmethod
def CreateRegistryEntryScript( key, valueName=None,
value="", valueType="String",
isAutoBitContext=True,
replacements=None ):
valueName = "-Name '%s' " % (valueName,) if valueName else ""
valueName = "-Name '%s'" % (valueName,) if valueName else ""
if value is None: value=""
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"createRegEntry" ), extension="ps1", script=([
QtIfwExternalOp.__psSetBitContext( isAutoBitContext ),
"New-ItemProperty -Path '%s' %s-Value '%s' -PropertyType '%s'"
% (key, valueName, value, valueType)] ),
QtIfwExternalOp.__psSetBitContext( isAutoBitContext ),
"$key='%s'" % (key,),
"$value='%s'" % (value,),
"$type='%s'" % (valueType,),
"Try{",
" Get-ItemPropertyValue -Path $key %s -ErrorAction Stop | Out-Null"
% (valueName,),
" Set-ItemProperty -Path $key %s -Value $value -Type $type"
% (valueName,),
"}",
"Catch{",
" Try{ Get-Item -Path $key -ErrorAction Stop | Out-Null }",
" Catch{ New-Item -Force -Path $key }",
" New-ItemProperty -Path $key %s -Value $value -PropertyType $type"
% (valueName,),
"}"
]),
replacements=replacements )


# Removes the entry, if it exists.
# valueName=None = Default key value
@staticmethod
def RemoveRegistryEntryScript( key, valueName=None,
isAutoBitContext=True,
replacements=None ):
valueName = "-Name '%s' " % (valueName,) if valueName else ""
valueName = "-Name '%s'" % (valueName,) if valueName else ""
return ExecutableScript( QtIfwExternalOp.__scriptRootName(
"removeRegEntry" ), extension="ps1", script=([
QtIfwExternalOp.__psSetBitContext( isAutoBitContext ),
"Remove-ItemProperty -Path '%s' %s" % (key, valueName) ]),
"$key='%s'" % (key,),
"Try{",
" Get-ItemPropertyValue -Path $key %s -ErrorAction Stop | Out-Null"
% (valueName,),
" Remove-ItemProperty -Path $key %s" % (valueName,),
"}",
"Catch{}"
]),
replacements=replacements )

@staticmethod
Expand Down
41 changes: 39 additions & 2 deletions docs/ConfigClasses.md
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ Attributes & default values:
externalOps = []
installResources = []
killOps = []
preOpSupport = None
customOperations = None

uiPages = []
Expand Down Expand Up @@ -818,6 +819,26 @@ program from the installer's 32 bit context.
isSynchronous=True, isHidden=True,
isAutoBitContext=True )

#### QtIfwExternalOp.CreateRegistryKey

**WINDOWS ONLY**

CreateRegistryKey( event, key, isAutoBitContext=True )

Set `isAutoBitContext=False` if you need to access 64 bit entries
from the installer's 32 bit context, and/or wish to be explicit in the
use of SysWow64 nodes.

#### QtIfwExternalOp.RemoveRegistryKey

**WINDOWS ONLY**

RemoveRegistryKey( event, key, isAutoBitContext=True )

Set `isAutoBitContext=False` if you need to access 64 bit entries
from the installer's 32 bit context, and/or wish to be explicit in the
use of SysWow64 nodes.

#### QtIfwExternalOp.CreateRegistryEntry

**WINDOWS ONLY**
Expand Down Expand Up @@ -871,20 +892,36 @@ rather embedded within it.
isSynchronous=True, isHidden=True,
isAutoBitContext=True )
### QtIfwExternalOp.CreateRegistryKeyScript

**WINDOWS ONLY**

CreateRegistryKeyScript( key, isAutoBitContext=True,
replacements=None )
### QtIfwExternalOp.RemoveRegistryKeyScript

**WINDOWS ONLY**

RemoveRegistryKeyScript( key, isAutoBitContext=True,
replacements=None )

### QtIfwExternalOp.CreateRegistryEntryScript

**WINDOWS ONLY**

CreateRegistryEntryScript( key, valueName=None,
value="", valueType="String",
isAutoBitContext=True, replacements=None )
isAutoBitContext=True,
replacements=None )
### QtIfwExternalOp.RemoveRegistryEntryScript

**WINDOWS ONLY**

RemoveRegistryEntryScript( key, valueName=None,
isAutoBitContext=True, replacements=None )
isAutoBitContext=True,
replacements=None )
#### QtIfwExternalOp.CreateExeFromScript

Expand Down
8 changes: 6 additions & 2 deletions docs/Examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,11 +317,15 @@ If desired, you may also wish to test running these demo programs post installat

TODO: FILL IN!

### Embedded Script Operations Example
### High Level Convenience Operations Example

TODO: FILL IN!

### Embedded Convenience Operations Example
### Low Level Embedded Script Operations Example

TODO: FILL IN!

### Windows Registry Interactions Example

TODO: FILL IN!

Expand Down

0 comments on commit 11159dd

Please sign in to comment.