Skip to content

Instantly share code, notes, and snippets.

@wincmd64
Last active December 11, 2023 12:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wincmd64/7c0f8550e129a2c79cceb0dd87ee5632 to your computer and use it in GitHub Desktop.
Save wincmd64/7c0f8550e129a2c79cceb0dd87ee5632 to your computer and use it in GitHub Desktop.
<#
.SYNOPSIS
alternative way to update TotalCmd with selected installer
.DESCRIPTION
in this example, all language packs will be updated
and junk files (like 'SIZE!.TXT' or '*.WUL') will not be copied
.EXAMPLE
powershell -ExecutionPolicy Bypass -File "TCupdate.ps1" "x:\path to\totalcmd"
https://t.me/wincmd64 #>
$TCarg=$args[0]
# ps ver must be 5.1+
if ($PSversiontable.psversion -lt "5.1")
{
Write-Warning "POWERSHELL UPDATE NEEDED -- https://microsoft.com/download/details.aspx?id=54616"
$null = $Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');
exit
}
if ($TCarg) {
# first - check cmd param
$TCpath = $TCarg.TrimEnd('"')
} elseif (Get-Process TOTALCMD* -ErrorAction SilentlyContinue) {
# check process 'TOTALCMD*'
$TCpath = (Get-Item(Get-Process -Name TOTALCMD*).path).DirectoryName
} else {
# directly specified path:
$TCpath = 'D:\Program Files\Total Commander 64'
}
# select installer
Clear-Host
Write-Host "Select TotalCmd installer: " -NoNewline
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = New-Object System.Windows.Forms.OpenFileDialog -Property @{
InitialDirectory = (New-Object -ComObject Shell.Application).NameSpace('shell:Downloads').Self.Path
Title = "Select TotalCmd installer"
Filter = 'Select File |*.exe'
}
if($FileBrowser.ShowDialog() -eq "OK")
{
$File = $FileBrowser.Filename
$FileZ = (Get-Item $FileBrowser.Filename).DirectoryName + '\' + (Get-Item $FileBrowser.Filename).Basename + '.zip'
$FileN = (Get-Item $File).Basename
$Folder = (Get-Item $File).DirectoryName
} else { exit }
# user confirm
Write-Host $File -BackgroundColor Black -NoNewline
Write-Host ''(Get-Command $File).FileVersionInfo.ProductVersion -ForegroundColor Yellow
Write-Host 'Path to install: ' -NoNewline
Write-Host $TCpath -BackgroundColor Black -NoNewline
Write-Host ''(Get-Command $TCpath\TOTALCMD*.EXE).FileVersionInfo.ProductVersion -ForegroundColor Yellow -NoNewline
Write-Host `n
pause
# close if running
Get-Process -ErrorAction SilentlyContinue | Where-Object {$_.Path -like "$TCpath\TOTALCMD*.EXE"} | Stop-Process
# unpack and copy
Rename-Item -Path $File -NewName ((Get-Item $File).Basename + '.zip')
Expand-Archive $FileZ -DestinationPath $Folder\$FileN\ -Force
Rename-Item -Path $FileZ -NewName ((Get-Item $FileZ).Basename + '.exe')
Remove-Item -recurse $Folder\$FileN\* -exclude INSTALL.CAB
expand $Folder\$FileN\INSTALL.CAB -f:* $Folder\$FileN\
if (Test-Path $Folder\$FileN\)
{
robocopy "$Folder\$FileN" $TCpath /S /XF "INSTALL.CAB" "*.BAR" "FRERES32.DLL" "*9X*" "WCMICONS.DLL" "SHARE_NT.EXE" "*unin*" "WC32TO16.EXE" "*.TXT" /XD "d" "e" "WINDOWS"
robocopy "$Folder\$FileN\e" $TCpath TOTALCMD.CHM
Remove-Item $Folder\$FileN\ -Recurse
}
pause
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment