diff --git a/rotanconv30.ps1 b/rotanconv30.ps1 deleted file mode 100755 index f213c71..0000000 --- a/rotanconv30.ps1 +++ /dev/null @@ -1,475 +0,0 @@ -[CmdletBinding()] - -Param( -) - -$signature = @" -[DllImport("user32.dll")] -public static extern bool SystemParametersInfo(int uAction, int uParam, ref int lpvParam, int flags ); -"@ - -$systemParamInfo = Add-Type -memberDefinition $signature -Name ScreenSaver -passThru - -Add-Type @" -using System; -using System.Runtime.InteropServices; -using Microsoft.Win32; - -namespace Wallpaper -{ - public enum Style : int - { - Tile, Center, Stretch, NoChange - } - public class Setter { - public const int SetDesktopWallpaper = 20; - public const int UpdateIniFile = 0x01; - public const int SendWinIniChange = 0x02; - [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] - private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni); - - public static void SetWallpaper (string path) { - SystemParametersInfo(SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange); - } - } -} -"@ - -function goget { - Param( - [Parameter(Mandatory=$True,Position=1)] - [string]$strurl, - - [Parameter(Mandatory=$False,Position=2)] - [string]$isdata - ) - Write-Verbose "Load target website $strurl" - $proxy = [System.Net.WebRequest]::GetSystemWebProxy() - $wc = New-Object Net.WebClient - $wc.proxy = $proxy - $wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") - $wc.Headers.Add("User-Agent", "Mozilla/4.0+(compatible;+MSIE+8.0;+Windows+NT+5.1)") - $wc.UseDefaultCredentials = $true - $wc.proxy.Credentials = $wc.Credentials - - $contents = "" - $count = 1 - Do { - if($isdata.contains("yes")) { - [BYTE[]] $contents = $wc.DownloadData($strurl) - } else { - try { - $contents = $wc.DownloadString($strurl) - } catch [Exception] { - Write-Verbose "There appears to be no internet connection." - } - } - # a network connection may not be available yet. Sleep for 7 seconds. - if($contents.length -eq 0) { - $count = $count + 1 - Write-Verbose "Target website returned zero length." - Write-Verbose "Retry in 7 seconds." - sleep -seconds 7 - } - } while($contents.length -eq 0 -and $count -lt 100) - - $wc.Dispose() - - if($contents.length -eq 0) { - Write-Verbose "Target website returned zero length." - Write-Verbose "Exit." - Exit 1 - } else { - return $contents - } -} - -function cutidx { - Param( - [Parameter(Mandatory=$True,Position=1)] - [string]$strtocut, - - [Parameter(Mandatory=$True,Position=2)] - [string]$stridx - ) - $dc = $strtocut.indexof($stridx) - if($dc -ge 0) { - $strtocut = $strtocut.substring($dc) - } - return $strtocut -} - -function getttl { - Param( - [Parameter(Mandatory=$True,Position=1)] - [string]$contents, - - [Parameter(Mandatory=$True,Position=2)] - [string]$marker - ) - $contents = cutidx $contents $marker - $e = $contents.substring($marker.Length).indexof("""") - $Title = $contents.substring(($marker.Length),$e) - return $Title -} - -function procstr { - Param( - [Parameter(Mandatory=$True,Position=1)] - [string]$strtoproc - ) - $strtoproc = $strtoproc -replace ";" , "" - $strtoproc = $strtoproc -replace "|" , "" - $strtoproc = $strtoproc -replace """" , "" - $strtoproc = $strtoproc -replace "\\/" , "/" - $strtoproc = $strtoproc -replace "'", "" - $strtoproc = $strtoproc.trim() - return $strtoproc -} - -function proctitle { - Param( - [Parameter(Mandatory=$True,Position=1)] - [string]$strtoproc - ) - $strtoproc = $strtoproc -replace "&" , "&" - $strtoproc = $strtoproc -replace """ , [char]34 - $strtoproc = $strtoproc -replace "<" , "<" - $strtoproc = $strtoproc -replace ">" , ">" - $strtoproc = $strtoproc -replace ">" , ">" - $strtoproc = $strtoproc -replace "˜" , "˜" - $strtoproc = $strtoproc -replace "ˆ" , "^" - $strtoproc = $strtoproc -replace "–" , "–" - $strtoproc = $strtoproc -replace "—" , "—" - $strtoproc = $strtoproc -replace "‰" , "‰" - $strtoproc = $strtoproc -replace "|" , "" - $strtoproc = $strtoproc.trim() - return $strtoproc -} - -function resizeimg { - Param( - [Parameter(Mandatory=$True,Position=1)] - [string]$rwidth, - - [Parameter(Mandatory=$True,Position=2)] - [string]$rheight, - - [Parameter(Mandatory=$True,Position=3)] - [System.Drawing.Bitmap]$bmpFile - ) - $target_height = [double] $rheight - $target_width = [double] $rwidth - # keep aspect ratio - if($bmpFile.Width/$bmpFile.Height -gt $target_width/$target_height) { - $target_height=$target_width*$bmpFile.Height/$bmpFile.Width - $rheight = [string] $target_height - } - if($bmpFile.Width/$bmpFile.Height -lt $target_width/$target_height) { - $target_width=$target_height*$bmpFile.Width/$bmpFile.Height - $rwidth = [string] $target_width - } - # create resized bitmap - $bmpResized = New-Object System.Drawing.Bitmap([int] ($rwidth), [int] ($rheight)) - $graph = [System.Drawing.Graphics]::FromImage($bmpResized) - $graph.Clear([System.Drawing.Color]::White) - $graph.DrawImage($bmpFile,0, 0, $rwidth, $rheight) - return $bmpResized -} - -function Parse-IniFile ($file) { - $ini = @{} - - # Create a default section if none exist in the file. Like a java prop file. - $section = "NO_SECTION" - $ini[$section] = @{} - - switch -regex -file $file { - "^\[(.+)\]$" { - $section = $matches[1].Trim() - $ini[$section] = @{} - } - "^\s*([^#].+?)\s*=\s*(.*)" { - $name,$value = $matches[1..2] - # skip comments that start with semicolon: - if (!($name.StartsWith(";"))) { - $ini[$section][$name] = $value.Trim() - } - } - } - $ini -} - -function initbang { - # stretch and refresh at startup - $path = [IO.Path]::GetFullPath("bingimagean.bmp") - $registryPath = "HKCU:\Control Panel\Desktop" - if((Test-Path $path) -and (Test-Path $registryPath)) { - - Write-Verbose "Load System.Drawing on init." - [Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null - [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null - $srcImg = [System.Drawing.Bitmap][System.Drawing.Image]::FromFile($path) - - # Resize image if necessary - $CurrentRes = (gwmi Win32_VideoController).VideoModeDescription; - if($CurrentRes.GetType().IsArray) { - $CurrentRes = [String] $CurrentRes - } - $CurrentRes_split = $CurrentRes.Split("x") - $rwidth=$CurrentRes_split[0] - $rwidth=$rwidth.trim() - $rheight=$CurrentRes_split[1] - $rheight=$rheight.trim() - - Write-Verbose "Resize image on init." - $srcOutImg = resizeimg $rwidth $rheight $srcImg - if($srcImg.Wdith -ne $srcOutImg.Wdith -or $srcImg.Height -ne $srcOutImg.Height) { - $srcImg.Dispose() - Write-Verbose "Create a bitmap object on init." - $bmpFile = New-Object System.Drawing.Bitmap(([int]($srcOutImg.width)),([int]($srcOutImg.height))) - Write-Verbose "Intialize graphics object on init." - $Image = [System.Drawing.Graphics]::FromImage($bmpFile) - $Image.SmoothingMode = "AntiAlias" - $Rectangle = New-Object Drawing.Rectangle 0, 0, $srcOutImg.Width, $srcOutImg.Height - $Image.DrawImage($srcOutImg, $Rectangle, 0, 0, $srcOutImg.Width, $srcOutImg.Height, ([Drawing.GraphicsUnit]::Pixel)) - $bmpFile.save($path, [System.Drawing.Imaging.ImageFormat]::Bmp) - $bmpFile.Dispose() - } - $srcImg.Dispose() - $srcOutImg.Dispose() - - Write-Verbose "stretch and refresh" - $nm = "WallpaperStyle" - $value = "0" - New-ItemProperty -Path $registryPath -Name $nm -Value $value -PropertyType STRING -Force | Out-Null - $nm = "TileWallpaper" - $value = "0" - New-ItemProperty -Path $registryPath -Name $nm -Value $value -PropertyType STRING -Force | Out-Null - - Write-Verbose "Refresh explorer." - [Wallpaper.Setter]::SetWallpaper($path) - Write-Verbose "Done with stretch and refresh" - } -} - -function loadandset { - if (Test-Path ".\bang.ini") { - $ini = Parse-IniFile ".\bang.ini" - $hostinfo = $ini["defaults"]["hostinfo"] - $dwnldsrc = $ini["defaults"]["source"] - } - - if ($dwnldsrc -eq "heise") { - $contents = goget "http://www.heise.de/foto/galerie/" - } else { - $contents = goget "http://www.bing.com/" - } - - Write-Verbose "Parse target website" - if ($dwnldsrc -eq "heise") { - $contents = cutidx $contents "figure class=""main_stage""" - $contents = cutidx $contents "") - $imgnxt = $contents.substring(9,$dh-8) - $imgnxt = procstr $imgnxt - $imgnxt = "http://www.heise.de" + $imgnxt - $contents = goget($imgnxt) - $contents = cutidx $contents "
" - $contents = cutidx $contents "