Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » JPSoft Take Command | TCC (4DOS, 4NT)

Модерирует : gyra, Maz

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

Smitis



Silver Member
Редактировать | Профиль | Сообщение | ICQ | Цитировать | Сообщить модератору

Код:
<#
    JPSoft Updater Product version 4.01 2020-05-16
    (c) Smitis, 2017-2020
#>
 
param (
    [Parameter(Mandatory=$false,Position=0)][string] $Src,
    [Parameter(Mandatory=$false)][Alias('S')][switch] $Sync
)
 
#-----------------------------------------------------------------------------------------------------------------------
$unnecessary = @( # эти файлы будут удалены
    "*.txt", "*.msi", "updater.exe"
    "french*.dll", "german*.dll", "italian*.dll", "spanish*.dll"
    "VDEU.dll", "VESP.dll", "VFRA.dll"
    "application.data" # ???
)
$notextra = @( # эти файлы не будут проверяться как лишние
    "stdvcl40.dll"
    "iphlpapi.dll" # crack dll
)
#-----------------------------------------------------------------------------------------------------------------------
 
function Press-AnyKey([string]$Message="Press any key to continue . . ."){Write-Host -NoNewline $Message;while($KeyInfo.VirtualKeyCode -eq $Null){$KeyInfo=$Host.UI.RawUI.ReadKey("NoEcho, IncludeKeyDown")};Write-Host}
function Ask-YN($Msg="Y/N?"){$Y=13,89;$N=27,78,32;$A=$Y+$N;Write-Host -NoNewline $Msg;while($K.VirtualKeyCode -eq $Null -or $A -notcontains $K.VirtualKeyCode){$K=$Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")};if($N -contains $K.VirtualKeyCode){Write-Host " N";return $false};Write-Host " Y";return $true}
function Get-Bitness($F){$R="Unknown";if(Test-Path -lit $F -type Leaf){[byte[]]$D=New-Object System.Byte[] 4096;$S=New-Object System.IO.FileStream $F,'Open','Read';$S.Read($D,0,4096)|Out-Null;$S.Close();[int32]$H=[System.BitConverter]::ToInt32($D,60);[int32]$U=[System.BitConverter]::ToUInt16($D,$H+4);switch($U){0{$R='Native'}0x014c{$R='x86'}0x0200{$R='Itanium'}0x8664{$R='x64'}}}return $R}
 
#-----------------------------------------------------------------------------------------------------------------------
$scriptdir = $MyInvocation.MyCommand.Path | Split-Path -Parent
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::TLS12
$temp = $env:TEMP
Set-Location -Lit ([System.IO.Directory]::GetCurrentDirectory()) # Боремся с глюками PS
 
if ($Sync) { # Копировать новейший сценарий
    $scriptfile = $MyInvocation.MyCommand.Path
    $scriptname = [System.IO.Path]::GetFileName($scriptfile)
    $scripts = @(
        Get-ChildItem -Lit (Join-Path $scriptdir "..") -Dir | where {
            Test-Path -Lit (Join-Path $_.FullName $scriptname)} | foreach {
                Get-ItemProperty -Lit (Join-Path $_.FullName $scriptname)
            } | sort LastWriteTime -Descend
    )
    $srcscript = $scripts[0].FullName
    Write-Host $srcscript
    Write-Host " ->"
    foreach ($dstscript in $scripts[1..($scripts.Count-1)].FullName) {
        Write-Host $dstscript
        Copy-Item -Lit $srcscript $dstscript -Force
    }
    exit
}
 
$productpattern = ">(?<major>\d+)\.(?<minor>\d+) Build (?<build>\d+)<"
# Определение используемого продукта (Take Command, TCC, TCC-RT), версии и разрядности
if (Test-Path -Lit "$scriptdir\tcmd.exe") { # Take Command
    $unpackmsi = $false
    Write-Host "Update Take Command"
    $currentversion_s = (Get-ItemProperty -Lit "$scriptdir\tcc.exe").VersionInfo.FileVersion
    $bitness = Get-Bitness "$scriptdir\tcc.exe"
    #$productpattern = "Take Command v(?<version>\d+).+?>(?<major>\d+\.\d+) Build (?<build>\d+)<"
    $setupexe = "tcmd.exe"
}
elseif (Test-Path -Lit "$scriptdir\ide.exe") { # TCC
    $unpackmsi = $false
    Write-Host "Update TCC"
    $currentversion_s = (Get-ItemProperty -Lit "$scriptdir\tcc.exe").VersionInfo.FileVersion
    $bitness = Get-Bitness "$scriptdir\tcc.exe"
    #$productpattern = "TCC v(?<version>\d+).+?>(?<major>\d+\.\d+) Build (?<build>\d+)<"
    $setupexe = "tcc.exe"
}
elseif (Test-Path -Lit "$scriptdir\tcc.exe") { # TCC-RT
    $unpackmsi = $true
    Write-Host "Update TCC-RT"
    $currentversion_s = (Get-ItemProperty -Lit "$scriptdir\tcc.exe").VersionInfo.FileVersion
    $bitness = Get-Bitness "$scriptdir\tcc.exe"
    #$productpattern = "TCC-RT v(?<version>\d+) .+?>(?<major>\d+\.\d+) Build (?<build>\d+)<"
    $setupexe = "tcc-rt.exe"
}
else {
    # Could not determine type | Unable to determine type ?
    Write-Host "Could not determine type TakeCommand" -For Red
    Press-AnyKey
    exit 1
}
Write-Host "Current version: $currentversion_s $bitness"
$currentversion = [version]$currentversion_s
$setupfile = Join-Path $temp $setupexe
if ($Src) {
    $setupfile = $Src
    $newversion_s = (Get-ItemProperty -Lit $setupfile).VersionInfo.FileVersion
    $newversion = [version]$newversion_s
    if (-not (Ask-YN "Update version from $currentversion_s to $($newversion_s)?")) {
        exit
    }
}
else {
    $web = (Invoke-WebRequest "https://jpsoft.com/all-downloads/downloads.html" -UseBasicParsing).content
    if ($web -match $productpattern) {
        $newversion = [version]"$($matches.major).$($matches.minor).$($matches.build)"
        $setuplink = "https://jpsoft.com/downloads/v$($newversion.major)/$setupexe"
    }
    Write-Host "New version: $newversion"
    if ($newversion -le $currentversion) {
        Write-Host "No need update" -For Green
        Press-AnyKey
        exit
    }
    if ($currentversion.major -lt $newversion.major) { # Обновление на старшую версию
        if (-not (Ask-YN "Update major version from $($currentversion.major) to $($newversion.major)?")) {
            exit
        }
    }
    # Проверка версии инсталятора и загрузка
    if (-not (Test-Path -Lit $setupfile) -or (Get-ItemProperty -Lit $setupfile).VersionInfo.FileVersion -le $newversion) {
        Write-Host "Download $setuplink"
        Invoke-WebRequest $setuplink -Out $setupfile
    }
    else {
        Write-Host ("Found setup file "+(Get-ItemProperty -Lit $setupfile).VersionInfo.FileVersion)
    }
}
 
# Распаковка инсталятора
Write-Host "Extract from setup ..."
Start-Process -Wait $setupfile -ArgumentList "/extract:$temp","/exenoupdates" -WindowStyle Minimized
if( $unpackmsi ) { # !!! не работает !!!
    # ищем новую папку созданную при распаковке
    $dirs = Get-ChildItem $temp -Dir | sort -Property LastWriteTime -Descending
    foreach ($dir in $dirs) {
        $extractdir = $dir.FullName
        if (Test-Path "$extractdir\$msifile") {
            break
        }
    }
    # Распаковка MSI
    if (Test-Path "$extractdir\$msifile") {
        Write-Host "Unpack msi-file ..."
        $msifile = "$extractdir\$msifile"
        $unpackdir = "$extractdir\unpack"
        Start-Process -Wait "msiexec.exe" -ArgumentList "/quiet","/norestart","/a",$msifile,"/qn","/log","$extractdir\msi.log","TARGETDIR=$unpackdir"
        if ($bitness -eq "x86" -and (Test-Path "$unpackdir\32-bit" -Type Container)) {
            Move-Item "$unpackdir\32-bit\*" $unpackdir -Force
        }
        $unnecessary | foreach { # удаляем лишнее
            Remove-Item "$unpackdir\$_" -Force -EA Silent
        }
        Get-ChildItem $unpackdir -File | foreach { # копируем
            Write-Host "Copy: $($_.Name)"
            Copy-Item $_.FullName $scriptdir -Force
        }
        if (Test-Path "$unpackdir\styles") { # копируем папку styles
            if (-not (Test-Path "$scriptdir\styles")) {
                New-Item "$scriptdir\styles" -Type Container | Out-Null
            }
            Get-ChildItem "$unpackdir\styles" -File | foreach {
                Write-Host "Copy: styles\$($_.Name)"
                Copy-Item $_.FullName "$scriptdir\styles" -Force
            }
        }
        # Проверить наличие "лишних" файлов exe и dll
        Get-ChildItem -Lit $scriptdir | where { ".exe",".dll" -contains $_.Extension -and $notextra -notcontains $_.Name } | foreach {
            $extra = $_.Name
            if ($notextra -notcontains $extra -and -not (Test-Path "$unpackdir\$extra")) {
                Write-Host "Extra: " -NoNewline
                Write-Host $extra -For Yellow
            }
        }
        Remove-Item "$temp\msi*.log" -Force
        #Remove-Item $setupfile -Force # Не удалять, если задана $Src!
        Remove-Item $extractdir -Recurse -Force
        Write-Host "Done" -For Green
    }
    else {
        Write-Host "Extract error" -For Red
    }
}
else {
    # Новый v26, распаковка не требуется
    # ищем новую папку созданную при распаковке
    foreach ($dir in (Get-ChildItem $temp -Dir | sort -Property LastWriteTime -Descending)) {
        if (Test-Path "$($dir.FullName)\tcc.exe") {
            $unpackdir = $dir.FullName
            break
        }
    }
    if (-not $unpackdir) {
        Write-Host "Unpack directory not found!" -For Red
        exit 1
    }
    foreach ($del in $unnecessary) { # удаляем лишнее
        Remove-Item "$unpackdir\$del" -Force -EA Silent
    }
    foreach ($copy in (Get-ChildItem $unpackdir -File)) { # копируем
        Write-Host "Copy: $($copy.Name)"
        Copy-Item $copy.FullName $scriptdir -Force
    }
    if (Test-Path "$unpackdir\styles") { # копируем папку styles
        if (-not (Test-Path "$scriptdir\styles")) {
            New-Item "$scriptdir\styles" -Type Container | Out-Null
        }
        Get-ChildItem "$unpackdir\styles" -File | foreach {
            Write-Host "Copy: styles\$($_.Name)"
            Copy-Item $_.FullName "$scriptdir\styles" -Force
        }
    }
    # Проверить наличие "лишних" файлов exe и dll
    Get-ChildItem -Lit $scriptdir | where { ".exe",".dll" -contains $_.Extension -and $notextra -notcontains $_.Name } | foreach {
        $extra = $_.Name
        if ($notextra -notcontains $extra -and -not (Test-Path "$unpackdir\$extra")) {
            Write-Host "Extra: " -NoNewline
            Write-Host $extra -For Yellow
        }
    }
    Remove-Item "$temp\msi*.log" -Force
    #Remove-Item $setupfile -Force # Не удалять, если задана $Src!
    Remove-Item $unpackdir -Recurse -Force
    Write-Host "Done" -For Green
}
Press-AnyKey

Всего записей: 3179 | Зарегистр. 09-02-2003 | Отправлено: 23:33 15-05-2020 | Исправлено: Smitis, 10:32 16-05-2020
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » JPSoft Take Command | TCC (4DOS, 4NT)


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru