Index: dev/install_python_gtk.bat ================================================================== --- dev/install_python_gtk.bat +++ dev/install_python_gtk.bat @@ -1,25 +1,6 @@ @echo off ->nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system" - -if '%errorlevel%' NEQ '0' ( - goto goUAC -) else goto goADMIN - -:goUAC - echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs" - set params = %*:"="" - echo UAC.ShellExecute "cmd.exe", "/c %~s0 %params%", "", "runas", 1 >> "%temp%\getadmin.vbs" - "%temp%\getadmin.vbs" - del "%temp%\getadmin.vbs" - exit /B - -:goADMIN - pushd "%CD%" - CD /D "%~dp0" - - echo ----------------------------------------------------------------------------- echo ^| ^| echo ^| _____/\\\\\\\\\\\____/\\\\\\\\\\\\\\\____/\\\\\\\\\_____ ^| echo ^| ___/\\\/////////\\\_\///////\\\/////___/\\\///////\\\___ ^| echo ^| __\//\\\______\///________\/\\\_______\///______\//\\\__ ^| @@ -30,15 +11,9 @@ echo ^| _\///\\\\\\\\\\\/_________\/\\\________/\\\\\\\\\\\\\\\_ ^| echo ^| ___\///////////___________\///________\///////////////__ ^| echo ^| ^| echo ^| Streamtuner2 for Windows Version 2.2.0 ^| echo ^| ^| -echo ^| Installer for Python 2.7.12 & Gtk 2.24.2 ^| +echo ^| Installer for Python 2.7.12 ^& Gtk 2.24.2 ^| echo ----------------------------------------------------------------------------- echo. -@setlocal enableextensions -@cd /d "%~dp0" -@echo off -cls -PowerShell Set-ExecutionPolicy -ExecutionPolicy ByPass -Scope CurrentUser -PowerShell.exe -File install_python_gtk.ps1 -PowerShell Set-ExecutionPolicy -ExecutionPolicy Undefined -Scope CurrentUser +PowerShell.exe -Command "& {Start-Process Powershell.exe -ArgumentList '-ExecutionPolicy ByPass -File ""%~dpn0.ps1""' -Verb RunAs}" Index: dev/install_python_gtk.ps1 ================================================================== --- dev/install_python_gtk.ps1 +++ dev/install_python_gtk.ps1 @@ -30,37 +30,26 @@ $pythonPathLM = (Get-ItemProperty -path ($regPathLM.substring(0,$regPathLM.indexOf("\Microsoft"))+ "\Python\PythonCore\2.7\InstallPath\")).'(default)' 2> $null $pythonPathCU = (Get-ItemProperty -path ($regPathCU.substring(0,$regPathCU.indexOf("\Microsoft"))+ "\Python\PythonCore\2.7\InstallPath\")).'(default)' 2> $null #-- what and how to install -# each row is a list of (title,url,cmd,msi args,regkey,reghive,optional) +# each row is a list of (title,url,cmd,msi args,regkey,optional) $tasks = @( - <# - @( - "Package Dependencies", - "", - "Check-Prerequisites", - "", - "", - "", - "" - ), - #> @( "Python 2.7.12", # title "https://www.python.org/ftp/python/2.7.12/python-2.7.12.msi", # url "", # custom cmd - 'TARGETDIR="#PYTHON#" /qb-!', # msi args + 'TARGETDIR="{PYTHON}" /qb-!', # msi args "$regPathLM\{9DA28CE5-0AA5-429E-86D8-686ED898C665}", # registry - "#PYTHON#\pythonw.exe", # installed check - "" # optional component + "{PYTHON}\pythonw.exe", # installed check + "" # is optional? ), @( "PyGtk 2.24.2", "http://ftp.gnome.org/pub/GNOME/binaries/win32/pygtk/2.24/pygtk-all-in-one-2.24.2.win32-py2.7.msi", "", - 'TARGETDIR="#PYTHON#" ADDLOCAL=ALL REMOVE=PythonExtensionModulePyGtkSourceview2,PythonExtensionModulePyGoocanvas,PythonExtensionModulePyRsvg,DevelopmentTools /qb-!', + 'TARGETDIR="{PYTHON}" ADDLOCAL=ALL REMOVE=PythonExtensionModulePyGtkSourceview2,PythonExtensionModulePyGoocanvas,PythonExtensionModulePyRsvg,DevelopmentTools /qb-!', "$regPathLM\{09F82967-D26B-48AC-830E-33191EC177C8}", "$regPathLM\{09F82967-D26B-48AC-830E-33191EC177C8}", "" ), @( @@ -67,47 +56,47 @@ "Python requests", "requests", # no download url, pip handles this "easy_install", "", "", - "#PYTHON#\Lib\site-packages\requests-2.12.1-py2.7.egg", + "{PYTHON}\Lib\site-packages\requests-2.12.1-py2.7.egg", "" ), @( "LXML 2.3", "https://pypi.python.org/packages/3d/ee/affbc53073a951541b82a0ba2a70de266580c00f94dd768a60f125b04fca/lxml-2.3.win32-py2.7.exe", "", "", "$regPathCU\lxml-py2.7", - "#PYTHON#\Lib\site-packages\lxml-2.3-py2.7.egg-info", + "{PYTHON}\Lib\site-packages\lxml-2.3-py2.7.egg-info", "" ), @( "PyQuery 1.2.1", "https://pypi.python.org/packages/62/71/8ac1f5c0251e51714d20e4b102710d5eee1683c916616129552b0a025ba5/pyquery-1.2.17-py2.py3-none-any.whl", "pip", "--disable-pip-version-check", "", - "#PYTHON#\Lib\site-packages\pyquery-1.2.17.dist-info", + "{PYTHON}\Lib\site-packages\pyquery-1.2.17.dist-info", "" ), @( "PIL 1.1.7", "http://effbot.org/downloads/PIL-1.1.7.win32-py2.7.exe", "", "", "$regPathCU\PIL-py2.7", - "#PYTHON#\Lib\site-packages\PIL", + "{PYTHON}\Lib\site-packages\PIL", "" ), @( "Streamripper 1.64.6", "http://downloads.sourceforge.net/project/streamripper/streamripper%20%28current%29/1.64.6/streamripper-windows-installer-1.64.6.exe?r=https%3A%2F%2Fsourceforge.net%2Fprojects%2Fstreamripper%2Ffiles%2Fstreamripper%2520%2528current%2529%2F1.64.6%2F&ts=1480104543&use_mirror=kent" "", "", "$regPathLM\Streamripper", - "#STREAMRIPPER#\streamripper.exe", + "{STREAMRIPPER}\streamripper.exe", '($true)' ), @( "Uninstall script", "", @@ -169,21 +158,22 @@ "", "", "", "" ), + @( + "Basic configuration", "", 'Create-StreamtunerJSON', "", "", "", "" + ), @( "FINISHED", "", 'Any-Key Green', "", "", "", "" ) ) #-- startup messages function Display-Logo { -# Clear-Host -# Console-MaxHeight Write-Host -b DarkBlue @" _____________________________________________________________________________ | | | _____/\\\\\\\\\\\____/\\\\\\\\\\\\\\\____/\\\\\\\\\_____ | | ___/\\\/////////\\\_\///////\\\/////___/\\\///////\\\___ | @@ -200,59 +190,35 @@ | | | Installer for Python 2.7.12 & Gtk 2.24.2 | ––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––– "@ } -<# -function Warn-NonElevated { - if (Test-IsElevated) { - return - } - Write-Host "" - Write-Host -f red " ___________________________________________________________________________" - Write-Host -f red "| If you run this script in non-elevated mode you will not be able to |" - Write-Host -f red "| uninstall Streamtuner2, Python and Gtk |" - Write-Host -f red "| using the control panels´ software list. |" - Write-Host -f red " ___________________________________________________________________________" -} -#> function Ask-First { Write-Host "" - Write-Host -f Yellow "Do you want to install Python 2.7.12 and Gtk dependencies now?" - Write-Host -f Yellow "––––––––––––––––––––––––––––––––––––---–––––––––––––––––––––––" - Write-Host "" - if ((Read-Host "[Y/n]") -notmatch "^[yY]|^$") { + if ((Ask "Do you want to install Python 2.7.12 and Gtk dependencies now? [Y/n] ") -notmatch "^[yY]|^$") { exit; # or $tasks = $tasks[7..($tasks.length-1)] } - Write-Host "" - Write-Host -f Yellow "Do you want to reuse any cached setup files?" - Write-Host -f Yellow "--------------------------------------------" - $reuseCachedFiles = Read-Host "[r]euse/[I]gnore)" -match "^[Rr]" - Write-Host "" - Write-Host -f Yellow "Do you want to check optional components?" - Write-Host -f Yellow "-----------------------------------------" - $optionalInstall = Read-Host "[y/N]" -match "^[Yy]" - Write-Host "" - $reuseCachedFiles - $optionalInstall - return + $reuseCachedFiles = (Ask "Do you want to reuse any cached setup files? [r]euse/[I]gnore) ") -match "^[Rr]" + $optionalInstall = (Ask "Do you want to check optional components? [y/N] ") -match "^[Yy]" + Write-Host "" + return $reuseCachedFiles, $optionalInstall } function Console-MaxHeight { - if ($Host.Name -match "console") { - $MaxHeight = $host.UI.RawUI.MaxPhysicalWindowSize.Height - $MaxWidth = $host.UI.RawUI.MaxPhysicalWindowSize.Width - $MyBuffer = $Host.UI.RawUI.BufferSize - $MyWindow = $Host.UI.RawUI.WindowSize - $MyWindow.Height = ($MaxHeight) - $MyWindow.Width = (80) - $MyBuffer.Height = (9999) - #$MyBuffer.Width = (80) - $host.UI.RawUI.set_bufferSize($MyBuffer) - $host.UI.RawUI.set_windowSize($MyWindow) - } + if ($Host.Name -match "console") { + $MaxHeight = $host.UI.RawUI.MaxPhysicalWindowSize.Height + $MaxWidth = $host.UI.RawUI.MaxPhysicalWindowSize.Width + $MyBuffer = $Host.UI.RawUI.BufferSize + $MyWindow = $Host.UI.RawUI.WindowSize + $MyWindow.Height = ($MaxHeight) + $MyWindow.Width = (80) + $MyBuffer.Height = (9999) + #$MyBuffer.Width = (80) + $host.UI.RawUI.set_bufferSize($MyBuffer) + $host.UI.RawUI.set_windowSize($MyWindow) + } } #-- create Desktop/Startmenu shortcuts function Make-Shortcut { [CmdletBinding()] @@ -299,26 +265,57 @@ New-ItemProperty -Path . -Name Publisher -PropertyType String -Value "Mario Salzer" > $null New-ItemProperty -Path . -Name NoModify -PropertyType DWord -Value 1 > $null New-ItemProperty -Path . -Name NoRepair -PropertyType DWord -Value 1 > $null #} } + +#-- prefill settings.json +function Create-StreamtunerJSON { + $dir = "$env:APPDATA\streamtuner2" + if (!(Test-Path $dir)) { + New-Item -Path $dir -ItemType directory + } + if (($STREAMRIPPER) -AND !(Test-Path ($fn = "$dir/settings.json"))) { + $dq = '^"' + $json = @{ + "windows" = $True; + "play" = @{ + "audio/*" = "wmplayer.exe %asx"; + "video/*" = "wmplayer.exe %asx" + }; + "record" = @{ + "audio/*" = "/D $($dq)$($STREAMRIPPER)$($dq) streamripper.exe %srv -d $Home\Desktop" + } + } + $json | ConvertTo-Json | Out-File $fn -Encoding ASCII + } +} function Any-Key($color) { Write-Host -f $color "[Press any key]" $null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown") } + +#-- colorized Read-Host +function Ask($str) { + if ($str -cmatch "^(.+?)(\[[a-z/]*)([A-Z]+)([\w/]*\])(.*)$") { + Write-Host -n -f Yellow $matches[1] # Want to install + Write-Host -n -f DarkYellow $matches[2] # [n/ + Write-Host -n -f Green $matches[3] # Y + Write-Host -n -f DarkYellow $matches[4] # /a] + Write-Host -n -f Yellow $matches[5] # ? + } + else { + Write-Host -n -f Yellow $str + } + Read-Host ; Write-Host "" +} #-- ensure ST2 startup script exists in relative path to this install script function Check-Package { if (!(Test-Path -Path("$UsrFolder\bin\streamtuner2"))) { - Write-Host -b DarkRed -f White @" -The bin\streamtuner2 start script could not be found. -The installation cannot continue. -Do not change the folder structure of the Streamtuner2 package! -If you want to run the install_python_gtk.ps1 script post-install, -please use the -UsrFolder parameter. -"@ + Write-Host -b DarkRed -f White "`nThe bin\streamtuner2 start script could not be found.`nThe installation cannot continue.`nDo not change the folder structure of the Streamtuner2 package!`nIf you want to run the install_python_gtk.ps1 script post-install,`nplease use the -UsrFolder parameter.`n" Any-Key Red ; exit } } @@ -345,12 +342,11 @@ Continuing this setup might result in loss of functionality for other Python applications on your computer! "@ Write-Host "" - Write-Host "Do you want to continue with the setup anyway?" - if ((Read-Host "[y/N]") -notmatch "[yY]") { + if ((Ask "Do you want to continue with the setup anyway? [y/N]") -notmatch "[yY]") { exit; } } } return $PYTHON @@ -361,11 +357,11 @@ [CmdletBinding()] param($result = 1) Check-Package ForEach ($task in $tasks) { $title, $url, $cmd, $args, $regkey, $check, $optionalComp = $task; - if ($optionalComp and $optionalInstall) { + if ($optionalComp -and $optionalInstall) { if ($title -match "Streamripper") { $StreamripperPath = (get-itemproperty -path HKCU:\Software\Streamripper).'(default)' 2> $null if (!(Test-Path -Path ($StreamripperPath + "\streamripper.exe"))) { write-host " - $title not found" } @@ -384,16 +380,16 @@ #Write-Host (Get-ItemProperty -Path $regkey -Name "DisplayName".DisplayName).DisplayName " found" Write-Host " + $title found" } } elseif ($title -match "requests|PyQuery") { - if (!(Test-Path -Path ($check -replace "#PYTHON#","$PYTHON"))) { + if (!(Test-Path -Path ($check -replace "{PYTHON}","$PYTHON"))) { write-Host " - $title not found" $result = 0 } else { - Write-Host " + $title found" + Write-Host " + $title found in $PYTHON" } } } } if ($result) { @@ -413,29 +409,29 @@ } #-- ask before running +Clear-Host Console-MaxHeight Display-Logo $UsrFolder = $MyInvocation.MyCommand.Path -replace ("([\\/][^\\/]+){4}$","") #temp fix for running on Windows 10 $PYTHON = Check-PythonInstall $reuseCachedFiles, $optionalInstall = Ask-First $STREAMRIPPER = Check-Prerequisites -Clear-Host -Display-Logo - +#Clear-Host +#Display-Logo #-- process ForEach ($task in $tasks) { - ForEach ($key in $task.keys()) { $task[$key] = [regex]::Replace($task[$key], "#(\w+)#", { param($m) Invoke-Expression ("$"+$m.Groups[1].Value) }) } - $title, $url, $cmd, $args, $regkey, $testpath, $optional = $task; + $title, $url, $cmd, $args, $regkey, $testpath, $optional = $task | + % { [regex]::Replace($_, "[#{](\w+)[}#]", { param($m) Invoke-Expression ("$"+$m.Groups[1].Value) }) } # options if ($optional -AND (Invoke-Expression $optional) -AND !$optionalInstall) { - continue # ↑ expression test + continue # optional expression test } # print step if ($title -match "\d+\.\d+") { $title = "Installing $title" } Write-Host -b DarkBlue "`n $title `n" @@ -445,13 +441,11 @@ if ($reinstall -eq "all") { } elseif ($testpath -AND (Test-Path -Path $testpath)) { if ($reinstall -eq "none") {Write-Host " → Kept as is."; continue } Write-Host -f Green -NoNewline " → Is already present." - #if ($title -match "Python 2.7.12") {Write-Host -f Green " (in $PYTHON)"} - #if ($title -match "Streamripper 1.64.6") {Write-Host -f Green " (in $STREAMRIPPER)"} - Write-Host -f Yellow -NoNewline " Reinstall [y/N/all/none]? " ; $y = Read-Host ; Write-Host "" + $y = Ask " Reinstall [y/N/all/none]? " if ($y -match "^all|always|re|^A") { $reinstall = "all" } elseif ($y -match "never|none|skip|^S") { $reinstall = "none"; continue } elseif ($y -match "^y|yes|1|go|^R") { } # YES else { continue } # everything else counts as NO } @@ -480,11 +474,10 @@ } Invoke-Expression "$cmd" } # msi elseif ($file -match ".+.msi$") { - $args = $args -replace "#PYTHON#","$PYTHON" Write-Host -f DarkYellow (" → msiexec /i " + "$file " + $args) Start-Process -Wait msiexec -ArgumentList /i,"$TEMP\$file", $args if ($regkey) { Set-ItemProperty -Path "$regkey" -Name "WindowsInstaller" -Value "0" -ErrorAction SilentlyContinue }