[svn] / branches / release-1_3-branch / xvidextra / src / installer / CheckUpdate.ps1 Repository:
ViewVC logotype

Annotation of /branches/release-1_3-branch/xvidextra/src/installer/CheckUpdate.ps1

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2110 - (view) (download)

1 : Isibaar 2110 Function Get-IniContent {
2 :     <#
3 :     .Synopsis
4 :     Gets the content of an INI file
5 :    
6 :     .Description
7 :     Gets the content of an INI file and returns it as a hashtable
8 :    
9 :     .Notes
10 :     Author : Oliver Lipkau <oliver@lipkau.net>
11 :     Blog : http://oliver.lipkau.net/blog/
12 :     Source : https://github.com/lipkau/PsIni
13 :     http://gallery.technet.microsoft.com/scriptcenter/ea40c1ef-c856-434b-b8fb-ebd7a76e8d91
14 :     Version : 1.0 - 2010/03/12 - Initial release
15 :     1.1 - 2014/12/11 - Typo (Thx SLDR)
16 :     Typo (Thx Dave Stiff)
17 :    
18 :     #Requires -Version 2.0
19 :    
20 :     .Inputs
21 :     System.String
22 :    
23 :     .Outputs
24 :     System.Collections.Hashtable
25 :    
26 :     .Parameter FilePath
27 :     Specifies the path to the input file.
28 :    
29 :     .Example
30 :     $FileContent = Get-IniContent "C:\myinifile.ini"
31 :     -----------
32 :     Description
33 :     Saves the content of the c:\myinifile.ini in a hashtable called $FileContent
34 :    
35 :     .Example
36 :     $inifilepath | $FileContent = Get-IniContent
37 :     -----------
38 :     Description
39 :     Gets the content of the ini file passed through the pipe into a hashtable called $FileContent
40 :    
41 :     .Example
42 :     C:\PS>$FileContent = Get-IniContent "c:\settings.ini"
43 :     C:\PS>$FileContent["Section"]["Key"]
44 :     -----------
45 :     Description
46 :     Returns the key "Key" of the section "Section" from the C:\settings.ini file
47 :    
48 :     .Link
49 :     Out-IniFile
50 :     #>
51 :    
52 :     [CmdletBinding()]
53 :     Param(
54 :     [ValidateNotNullOrEmpty()]
55 :     [ValidateScript({(Test-Path $_) -and ((Get-Item $_).Extension -eq ".ini")})]
56 :     [Parameter(ValueFromPipeline=$True,Mandatory=$True)]
57 :     [string]$FilePath
58 :     )
59 :    
60 :     Begin
61 :     {Write-Verbose "$($MyInvocation.MyCommand.Name):: Function started"}
62 :    
63 :     Process
64 :     {
65 :     Write-Verbose "$($MyInvocation.MyCommand.Name):: Processing file: $Filepath"
66 :    
67 :     $ini = @{}
68 :     switch -regex -file $FilePath
69 :     {
70 :     "^\[(.+)\]$" # Section
71 :     {
72 :     $section = $matches[1]
73 :     $ini[$section] = @{}
74 :     $CommentCount = 0
75 :     }
76 :     "^(;.*)$" # Comment
77 :     {
78 :     if (!($section))
79 :     {
80 :     $section = "No-Section"
81 :     $ini[$section] = @{}
82 :     }
83 :     $value = $matches[1]
84 :     $CommentCount = $CommentCount + 1
85 :     $name = "Comment" + $CommentCount
86 :     $ini[$section][$name] = $value
87 :     }
88 :     "(.+?)\s*=\s*(.*)" # Key
89 :     {
90 :     if (!($section))
91 :     {
92 :     $section = "No-Section"
93 :     $ini[$section] = @{}
94 :     }
95 :     $name,$value = $matches[1..2]
96 :     $ini[$section][$name] = $value
97 :     }
98 :     }
99 :     Write-Verbose "$($MyInvocation.MyCommand.Name):: Finished Processing file: $FilePath"
100 :     Return $ini
101 :     }
102 :    
103 :     End
104 :     {Write-Verbose "$($MyInvocation.MyCommand.Name):: Function ended"}
105 :     }
106 :    
107 :     function Get-WebClient
108 :     {
109 :     $wc = New-Object Net.WebClient
110 :     $wc.UseDefaultCredentials = $true
111 :     $wc.Proxy.Credentials = $wc.Credentials
112 :     $wc
113 :     }
114 :    
115 :     # http://blogs.msdn.com/b/jasonn/archive/2008/06/13/downloading-files-from-the-internet-in-powershell-with-progress.aspx
116 :     function downloadFile($my_url, $targetFile)
117 :     {
118 :     $ret = 0
119 :     $request = [System.Net.WebRequest]::Create($my_url)
120 :     $request.set_Timeout(15000) #15 second timeout
121 :     $response = $request.GetResponse()
122 :     If (!$response) {
123 :     return 1
124 :     }
125 :    
126 :     $totalLength = [System.Math]::Floor($response.get_ContentLength() / 1000)
127 :     $responseStream = $response.GetResponseStream()
128 :     $targetStream = New-Object -TypeName System.IO.FileStream -ArgumentList $targetFile, Create
129 :     $progressBar.Value = 0
130 :     $buffer = new-object byte[] 64KB
131 :     $count = $responseStream.Read($buffer, 0, $buffer.length)
132 :     $downloadedBytes = $count
133 :    
134 :     while ($count -gt 0)
135 :     {
136 :     $progressBar.Value = [System.Math]::Floor([System.Math]::Floor($downloadedBytes/10) / $totalLength)
137 :     $targetStream.Write($buffer, 0, $count)
138 :     $count = $responseStream.Read($buffer, 0, $buffer.length)
139 :     $downloadedBytes = $downloadedBytes + $count
140 :     $form.Refresh()
141 :     [System.Windows.Forms.Application]::DoEvents()
142 :    
143 :     if($script:canceledDownload -eq $true)
144 :     {
145 :     # Exit the loop
146 :     $ret = 1
147 :     break
148 :     }
149 :    
150 :     start-sleep -Milliseconds 100
151 :     }
152 :    
153 :     $targetStream.Flush()
154 :     $targetStream.Close()
155 :     $targetStream.Dispose()
156 :     $responseStream.Dispose()
157 :     $response.Close()
158 :    
159 :     return $ret
160 :     }
161 :    
162 :    
163 :     # Main
164 :    
165 :     $scriptpath = $MyInvocation.MyCommand.Path
166 :     $script:xvid_dir = Split-Path $scriptpath
167 :     $tmp = $env:temp
168 :    
169 :     $FileContent = Get-IniContent "$script:xvid_dir\update.ini"
170 :     If (!$FileContent) {
171 :     Exit 0
172 :     }
173 :    
174 :     $url = $FileContent["Update"]["url"]
175 :     $object = Get-WebClient
176 :     $localPath = “$tmp\update.xml”
177 :     $object.DownloadFile($url, $localPath)
178 :    
179 :     $xml = [xml](Get-Content $localPath)
180 :    
181 :     $script:local_xvid_version = $FileContent["Update"]["version_id"]
182 :    
183 :     # Now check if Update file from the server has a newer version than we have locally
184 :     If (!$xml -or $xml.installerInformation.versionId -le $script:local_xvid_version) {
185 :     Exit 0
186 :     }
187 :    
188 :     # Check if the current update is skipped by user-choice
189 :     If (test-path $env:userprofile\.xvid\skip_update.log) {
190 :     $skip_str = Get-Content $env:userprofile\.xvid\skip_update.log
191 :     If ($skip_str -and $xml.installerInformation.versionId -le [System.Decimal]::Parse($skip_str)) {
192 :     Exit 0
193 :     }
194 :     }
195 :    
196 :     $script:remote_xvid_version = $xml.installerInformation.versionId
197 :    
198 :     # Parse the xml child elements
199 :     $xml_root = $xml.get_DocumentElement()
200 :     $fileList = $xml_root.platformFileList
201 :     $serverList = $xml_root.downloadLocationList
202 :    
203 :     $newItem = $null
204 :     foreach($newItem in $fileList.ChildNodes)
205 :     {
206 :     $script:newInstallerFile = $newItem.filename
207 :     $platform = $newItem.platform
208 :    
209 :     If ($platform -eq "windows" -or $platform -eq "Windows") {
210 :     Break
211 :     }
212 :     }
213 :    
214 :     $newItem = $null
215 :     foreach($newItem in $serverList.ChildNodes)
216 :     {
217 :     $script:newDownloadURL = $newItem.url
218 :     Break # Go with the first always
219 :     }
220 :    
221 :     If (!$script:newInstallerFile -or !$script:newDownloadURL) {
222 :     Exit 0
223 :     }
224 :    
225 :     # We have an Update! Show the Dialogs...
226 :    
227 :     # Loosely based on http://www.vistax64.com/powershell/202216-display-image-powershell.html
228 :     [void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
229 :    
230 :     $xvid_file = (get-item "$script:xvid_dir\xvid.png")
231 :     $xvid_img = [System.Drawing.Image]::Fromfile($xvid_file);
232 :    
233 :     # This tip from http://stackoverflow.com/questions/3358372/windows-forms-look-different-in-powershell-and-powershell-ise-why/3359274#3359274
234 :     [System.Windows.Forms.Application]::EnableVisualStyles();
235 :     $form = new-object Windows.Forms.Form
236 :     $form.Text = "Xvid Software Update"
237 :     $form.Size = New-Object System.Drawing.Size(640,480)
238 :     $form.StartPosition = "CenterScreen"
239 :     $form.FormBorderStyle = 'Fixed3D'
240 :     $form.MaximizeBox = $false
241 :     $form.MinimizeBox = $False
242 :     $form.WindowState = "Normal"
243 :    
244 :     $Icon = New-Object system.drawing.icon ("$script:xvid_dir\XVID.ICO")
245 :     $Form.Icon = $Icon
246 :    
247 :     $pictureBox = new-object Windows.Forms.PictureBox
248 :     $pictureBox.Width = $xvid_img.Size.Width;
249 :     $pictureBox.Height = $xvid_img.Size.Height;
250 :     $pictureBox.Location = New-Object System.Drawing.Size(20, 12)
251 :    
252 :     $pictureBox.Image = $xvid_img;
253 :     $form.controls.add($pictureBox)
254 :    
255 :     $label1 = New-Object System.Windows.Forms.Label
256 :     $label1.Text = "A new version of the Xvid software is available!"
257 :     If ($xml.installerInformation.mainScreenHeader) {
258 :     $label1.Text = $xml.installerInformation.mainScreenHeader
259 :     }
260 :     $label1.AutoSize = $True
261 :     $label1.ForeColor = "#0c3384"
262 :     $label1.Location = New-Object System.Drawing.Size(96, 12)
263 :     $font = New-Object System.Drawing.Font("Arial",14,[System.Drawing.FontStyle]::Regular)
264 :     $label1.Font = $font
265 :     $form.Controls.Add($label1)
266 :    
267 :     $label2 = New-Object System.Windows.Forms.Label
268 :     $new_version = $xml.installerInformation.version
269 :     $label2.Text = "We're proud to announce the new Xvid $new_version release."
270 :     If ($xml.installerInformation.mainScreenText) {
271 :     $label2.Text = $xml.installerInformation.mainScreenText
272 :     }
273 :     $label2.AutoSize = $True
274 :     $label2.Location = New-Object System.Drawing.Size(96, 40)
275 :     $font = New-Object System.Drawing.Font("Arial",10,[System.Drawing.FontStyle]::Regular)
276 :     $label2.Font = $font
277 :     $form.Controls.Add($label2)
278 :    
279 :     $pictureBox = new-object Windows.Forms.PictureBox
280 :     $pictureBox.Width = 500;
281 :     $pictureBox.Height = 300;
282 :     $pictureBox.Location = New-Object System.Drawing.Size(96, 72)
283 :    
284 :     $script:download_banner_link = $xml.installerInformation.downloadBannerLink
285 :     $script:banner_link = $xml.installerInformation.mainBannerLink
286 :     $pictureBox.Add_Click({ If ($script:banner_link) { Invoke-Expression “cmd.exe /C start $script:banner_link”} })
287 :    
288 :     $script:download_banner_url = $xml.installerInformation.downloadBannerURI
289 :     $script:error_banner_url = $xml.installerInformation.errorBannerURI
290 :     $main_banner_url = $xml.installerInformation.mainBannerURI
291 :    
292 :     If ($main_banner_url) {
293 :     $object = Get-WebClient
294 :     $localPath = “$tmp\xvid_main_banner.png”
295 :     $object.DownloadFile($main_banner_url, $localPath)
296 :     $update_file = (get-item "$tmp\xvid_main_banner.png")
297 :     $main_banner = [System.Drawing.Image]::Fromfile($update_file);
298 :     $pictureBox.Image = $main_banner;
299 :     }
300 :     $form.controls.add($pictureBox)
301 :    
302 :     $SkipButton = New-Object System.Windows.Forms.Button
303 :     $SkipButton.Text = "Skip this version"
304 :     $LaterButton = New-Object System.Windows.Forms.Button
305 :     $LaterButton.Text = "Remind me later"
306 :     $InstallButton = New-Object System.Windows.Forms.Button
307 :     $InstallButton.Text = "Install update"
308 :    
309 :     $SkipButton.Location = New-Object System.Drawing.Size(96, 400)
310 :     $SkipButton.Size = New-Object System.Drawing.Size(100, 25)
311 :     $form.controls.add($SkipButton)
312 :    
313 :     $LaterButton.Location = New-Object System.Drawing.Size(380, 400)
314 :     $LaterButton.Size = New-Object System.Drawing.Size(100, 25)
315 :     $form.controls.add($LaterButton)
316 :    
317 :     $InstallButton.Location = New-Object System.Drawing.Size(496, 400)
318 :     $InstallButton.Size = New-Object System.Drawing.Size(100, 25)
319 :     $form.controls.add($InstallButton)
320 :    
321 :     $SkipButton.Add_Click(
322 :     {
323 :     New-Item -ItemType Directory -Force -Path $env:userprofile\.xvid
324 :     "$script:remote_xvid_version" | Out-File $env:userprofile\.xvid\skip_update.log
325 :     $form.Close()
326 :     }
327 :     )
328 :    
329 :     $LaterButton.Add_Click(
330 :     {
331 :     If ($script:downloadSuccessful -eq 0 -or $script:canceledDownload -eq $true) {
332 :     $form.Close()
333 :     }
334 :    
335 :     $script:canceledDownload = $true;
336 :     }
337 :     )
338 :    
339 :     $InstallButton.Add_Click(
340 :     {
341 :     $label1.Text = "Preparing the Xvid Update"
342 :     $label2.Text = "Please stay tuned while the update is downloading..."
343 :     $form.Refresh()
344 :     $LaterButton.Location = New-Object System.Drawing.Size(496, 400)
345 :     $LaterButton.Text = "Cancel"
346 :     If ($script:download_banner_link) {
347 :     $script:banner_link = $script:download_banner_link
348 :     }
349 :     else {
350 :     $script:banner_link = $null
351 :     }
352 :     If ($script:download_banner_url) {
353 :     $object = Get-WebClient
354 :     $localPath = “$tmp\xvid_download_banner.png”
355 :     $object.DownloadFile($script:download_banner_url, $localPath)
356 :     $download_img = (get-item "$tmp\xvid_download_banner.png")
357 :     $download_banner = [System.Drawing.Image]::Fromfile($download_img);
358 :     $pictureBox.Image = $download_banner;
359 :     }
360 :     else {
361 :     $pictureBox.Image = $null
362 :     }
363 :     $pictureBox.Height = 220;
364 :     $form.controls.remove($InstallButton)
365 :     $form.controls.remove($SkipButton)
366 :    
367 :     $progressBar = New-Object System.Windows.Forms.ProgressBar
368 :     $progressBar.Name = 'progressBar00'
369 :     $progressBar.Value = 0
370 :     $progressBar.Style="Continuous"
371 :     $progressBar.Size = New-Object System.Drawing.Size(500, 30)
372 :     $progressBar.Left = 96
373 :     $progressBar.Top = 330
374 :     $form.Controls.Add($progressBar)
375 :     $labelDownload = New-Object System.Windows.Forms.Label
376 :     $labelDownload.Text = "Downloading $script:newInstallerFile..."
377 :     $labelDownload.AutoSize = $True
378 :     $labelDownload.Location = New-Object System.Drawing.Size(96, 310)
379 :     $form.Controls.Add($labelDownload)
380 :     $label0 = New-Object System.Windows.Forms.Label
381 :     $label0.Text = "0%"
382 :     $label0.AutoSize = $True
383 :     $label0.Location = New-Object System.Drawing.Size(96, 368)
384 :     $form.Controls.Add($label0)
385 :     $label100 = New-Object System.Windows.Forms.Label
386 :     $label100.Text = "100%"
387 :     $label100.AutoSize = $True
388 :     $label100.Location = New-Object System.Drawing.Size(564, 368)
389 :     $form.Controls.Add($label100)
390 :     $form.Refresh()
391 :    
392 :     $script:downloadSuccessful = 1
393 :     $downloadUrl = "$script:newDownloadURL$script:newInstallerFile"
394 :     $ret = (downloadFile "$downloadUrl" “$tmp\$script:newInstallerFile”)
395 :    
396 :     If ($ret -ne 0) {
397 :     If ($script:canceledDownload -eq $false) {
398 :     $label1.Text = "Download Error!"
399 :     $label2.Text = "We're sorry but the download failed. Please try again later."
400 :     }
401 :     else {
402 :     $label1.Text = "Update Canceled!"
403 :     $label2.Text = "We've stopped the update at your request. You may try again later."
404 :     }
405 :    
406 :     $LaterButton.Text = "OK"
407 :     $form.controls.remove($progressBar)
408 :     $form.controls.remove($labelDownload)
409 :     $form.controls.remove($label0)
410 :     $form.controls.remove($label100)
411 :    
412 :     If ($script:error_banner_url) {
413 :     $object = Get-WebClient
414 :     $localPath = “$tmp\xvid_error_banner.png”
415 :     $object.DownloadFile($script:error_banner_url, $localPath)
416 :     $error_img = (get-item "$tmp\xvid_error_banner.png")
417 :     $error_banner = [System.Drawing.Image]::Fromfile($error_img)
418 :     $pictureBox.Image = $error_banner
419 :     }
420 :     else {
421 :     $pictureBox.Image = $null
422 :     }
423 :     $script:banner_link = $null
424 :     $pictureBox.Height = 300;
425 :     $form.Refresh()
426 :     }
427 :     else {
428 :     $script:downloadSuccessful = 2
429 :     $form.Close();
430 :     }
431 :     })
432 :    
433 :     $form.Add_Closing({$script:canceledDownload = $true})
434 :    
435 :     $script:downloadSuccessful = 0
436 :     $script:canceledDownload = $false
437 :    
438 :     $form.Add_Shown( { $form.Activate(); $InstallButton.focus() } )
439 :     $ret = $form.ShowDialog()
440 :    
441 :     if ($script:downloadSuccessful -eq 2) {
442 :     $cmd="$tmp\$script:newInstallerFile"
443 :     Try {
444 :     $key = 'HKCU:\SOFTWARE\GNU\XviD'
445 :     $key = (Get-ItemProperty -Path $key -Name Supported_4CC).Supported_4CC
446 :    
447 :     $other = $divx = $3ivx = 0
448 :     If ($key -band 4) {
449 :     $other = 1
450 :     }
451 :     If ($key -band 1) {
452 :     $3ivx = 1
453 :     }
454 :     If ($key -band 2) {
455 :     $divx = 1
456 :     }
457 :    
458 :     If ((start-process $cmd -ArgumentList "--mode unattended --unattendedmodeui minimalWithDialogs --decode_divx $divx --decode_3ivx $3ivx --decode_other $other" -PassThru -Wait).ExitCode -ne 0) {
459 :     $ret = [System.Windows.Forms.MessageBox]::Show("Unfortunately, the Xvid update failed! Please try again." , "Xvid Update Error", 16)
460 :     }
461 :     else {
462 :     $ret = [System.Windows.Forms.MessageBox]::Show("The Xvid update got installed successfully. Have fun!" , "Xvid Update Success", 0, 64)
463 :     }
464 :     }
465 :     Catch {
466 :     $ret = [System.Windows.Forms.MessageBox]::Show("The Xvid update could not be run. Please try again." , "Xvid Update Error", 0, 16)
467 :     }
468 :     }
469 :     Exit 1

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4