Last active
December 25, 2015 06:19
-
-
Save sheeeng/6931416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
######################################################################## | |
# File : UpdateJom.ps1 | |
# Version : 1.0.1 | |
# Purpose : Downloads and updates jom tool. | |
# Synopsis: http://qt-project.org/wiki/jom | |
# Usage : .\UpdateJom.ps1 | |
# Author: Leonard Lee <sheeeng@gmail.com> | |
######################################################################## | |
# References: | |
# Manage BITS (Background Intelligent Transfer Service) with Windows PowerShell | |
# http://technet.microsoft.com/en-us/magazine/ff382721.aspx | |
# Using Windows PowerShell to Create BITS Transfer Jobs | |
# http://msdn.microsoft.com/en-us/library/windows/desktop/ee663885(v=vs.85).aspx | |
# Copying Folders by Using the Shell Folder Object | |
# http://technet.microsoft.com/en-us/library/ee176633.aspx | |
######################################################################## | |
Import-Module BitsTransfer | |
$DebugPreference = "SilentlyContinue" #Continue | |
Write-Debug $DebugPreference | |
#(Get-Location).tostring() or [string](Get-Location) | |
#Write-Host "`$HOME.GetType():" $HOME.GetType() | |
Set-Location $HOME | |
$currentDirectory = $HOME | |
$zipFile = "jom.zip" | |
$sourceZipFile = $currentDirectory + "\" + $zipFile | |
#Write-Host "`$sourceZipFile:" $sourceZipFile | |
#Write-Host "`$targetDirectory:" $targetDirectory | |
$targetDirectory = $HOME.ToString() + "\" + "jom" | |
if (Test-Path -path $targetDirectory) { | |
Write-Host "The" $targetDirectory "directory exist." | |
} | |
else { | |
Write-Host "Creating" $targetDirectory "directory since it does not exist." | |
New-Item -ItemType directory -Path $targetDirectory | |
} | |
Start-BitsTransfer -Source "http://download.qt-project.org/official_releases/jom/jom.zip" | |
function Expand-ZIPFile($file, $destination) | |
{ | |
#Write-Host "`$file:" $file | |
#Write-Host "`$destination:" $destination | |
$shell = New-Object -ComObject Shell.Application | |
$zip = $shell.NameSpace($file) | |
foreach($item in $zip.items()) | |
{ | |
$shell.Namespace($destination).CopyHere($item, 0x14) | |
} | |
} | |
$processName = "jom" | |
if (Get-Process $processName -ErrorAction SilentlyContinue) { | |
#Write-Host "The" $processName "process exist. Trying to stop..." | |
Stop-Process -processname $processName | |
} | |
else { | |
#Write-Host "The" $processName "process does not exist." | |
} | |
Expand-ZIPFile –File $sourceZipFile $targetDirectory | |
Write-Host "Update completed." | |
#Invoke-Item $targetDirectory |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment