shawn Posted April 28 Report Share Posted April 28 Hi, all, I've been meaning to rewrite several of my apps for quite a while because there just aren't ways to collect the version number and I hate to have to have a bunch of commands on individual apps just because maintenance becomes a chore. So I came up with a global after-update script to process stuff like that. It's controlled through a new variable assigned to the app called "todo". The idea is that instead of leaving the file details unfilled, let's parse it after it's downloaded from the file itself or perform other post-download actions (extraction, uploading to an FTP server, download from MEGA, copy to another folder and so on). These are now all handled centrally for me with the global after-updating an application script and this new variable. This uses a couple functions based on @Ambimind's code posted here and elsewhere on this forum. #### Support function PKV { Param( $svName ) #### identify variable type and collect stored content $svType = $app.variables.$svName.VariableType; if( $svType -eq "Textual" ){ #### stored text content $svContent = $app.variables.$svName.TextualContent; #### process all child variables if( $svContent -like '*{*' ){ $svContent2 = $app.variables.ReplaceAllInString( "{$svName}", $sfiletime, $sfilename, $true, $false ); if ( $svContent2 -ne '' ){ $svContent = $svContent2; } } }else{ #### other types of variables must be parsed $svContent = $app.variables.ReplaceAllInString( "{$svName}", $sfiletime, $sfilename, $true, $false ); } #### parse version for psversion if it exists if( $svName -eq "version" ){ if( $app.variables."psversion".TextualContent -ne "" ){ $svContent = $app.variables.ReplaceAllInString( "{$svName}", $sfiletime, $sfilename, $true, $false ); } } #### sanitize $svContent = ($svContent -Replace 'http://localhost:48080/', '' | Out-String).Trim() if( $svContent -eq "{$svName}" ){ $svContent = ''; } #### return Write-Information $svName':'$svContent; ($svContent | Out-String).Trim() } #### function NewAppVariable { Param( [Parameter(Mandatory)] $sVarName, [ValidateSet("RegularExpression", "StartEnd", "Textual")] $sVarType = "Textual", $sVarValue = "" ) # Derived access property, ie. app.variables.$sVarName.$varcnt $varcnt = if($sVarType -eq "Textual"){"TextualContent"}Else{"CachedContent"} # If it doesn't exist, then create a new one if(-Not $app.variables.$sVarName){ ECHO "=== $sVarName NOT FOUND, ADDING IT ===" # Add var to job/app $newvar = New-Object -TypeName Ketarin.UrlVariable -ArgumentList $sVarName,$app.variables $newvar.VariableType = $sVarType $app.variables.Add($sVarName, $newvar) $app.Save() } # If it was passed a specific value, assign it if( $sVarValue -ne "" ){ $app.variables.$sVarName.$varcnt = $sVarValue } } #### #### Parse cached variable values $sname = $($App.Name); $sfilename = $($App.CurrentLocation); write-host "Filename:`t$sfilename"; $todo = PKV ( 'todo' ); write-host "ToDo:`t$todo"; Switch ($todo) { { @('fileversion', 'fv') -contains $_ } { $sversion = [System.Diagnostics.FileVersionInfo]::GetVersionInfo($sfilename).FileVersion.toString(); $app.variables.version.TextualContent = $sversion; break; } { @('upload') -contains $_ } { Start-Process -FilePath "Uploader.bat" -ArgumentList $sfilename -Wait -NoNewWindow; break; } { @('extract','extractx','x') -contains $_ } { PUSHD $app.Variables.ReplaceAllInString("{file:directory}"); Start-Process -FilePath "7z.exe" -ArgumentList 'x','-y','-r',$sfilename -Wait -NoNewWindow; POPD; break; } { @('extracte','e') -contains $_ } { PUSHD $app.Variables.ReplaceAllInString("{file:directory}"); Start-Process -FilePath "7z.exe" -ArgumentList 'e','-y','-r',$sfilename -Wait -NoNewWindow; POPD; break; } { @('mega','megaget') -contains $_ } { $sdownload = PKV ( 'sdownload' ); $sdownloadpath = PKV ( 'sdownloadpath' ); if( $sdownloadpath -ieq "" ){ $sdownloadpath = $app.Variables.ReplaceAllInString("{startuppath:directory}"); } Start-Process -FilePath "%localappdata%\MEGAcmd\mega-get.bat" -ArgumentList $sdownload,$sdownloadpath -Wait -NoNewWindow; break; } { @('copy','copyx') -contains $_ } { $copyx = $app.variables.copyx.TextualContent; Switch ($copyx) { { @('tools','gd') -contains $_ } { Copy-Item $sfilename -Destination "G:\Google Drive\Tools" -Force; break; } { @('downloads') -contains $_ } { Copy-Item $sfilename -Destination "C:\Downloads" -Force; break; } default { Copy-Item $sfilename -Destination $copyx -Force; break; } } break } { @('diagnostics','dx') -contains $_ } { $app | Select-Object * | Out-File c:\downloads\ketarin-app.txt -width 400; $app.Variables | Select-Object * | Out-File c:\downloads\ketarin-app-var.txt -width 400; $app.Variables.Keys | Select-Object * | Out-File c:\downloads\ketarin-app-var-keys.txt -width 400; $app.Variables.Values | Select-Object * | Out-File c:\downloads\ketarin-app-var-values.txt -width 400; break; } default { break; } } That's all. I thought some of you might be interested. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now