ZiboMod installation folders checker using a PSscript (Powershell)

You can talk about anything flight (simulation) related here

Moderators: russ, Ralph

Post Reply
Message
Author
SimPassion
Posts: 5346
Joined: Thu Jul 27, 2017 12:22 am

ZiboMod installation folders checker using a PSscript (Powershell)

#1 Post by SimPassion »

WARNING !!! : only for those who are aware of Powershell install and running
I will not provide any support here or elsewhere, though this script should run on Windows / Linux / MacOS using PSHost as runtime environment (checked OK on Windows and Linux, but I can't say on MacOS, as not owning any Apple device)

Use it at your own risk and only knowing what you're doing !!!!

Code: Select all

#	Laminar Research / X-Plane install location reference
#	https://developer.x-plane.com/article/how-to-programmatically-locate-x-plane-9-or-10/

#   -----------------------------------------------------------------------------------------------------------------------

#	PowerShell Core Install on Windows
#	https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-7

#	PowerShell Core Install on Linux
#	https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

#	PowerShell Core Install on MacOS
#	https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-7

#   -----------------------------------------------------------------------------------------------------------------------

#	Microsoft PowerShell Core Installation reference
#	https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7

#	=======================================================================================================================

# Scripting Reference
# -------------------
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7
# https://powershell.org/forums/topic/conditional-formatting-in-psobject-output/
# ref : https://social.technet.microsoft.com/Forums/en-US/85f02c92-62f5-4c82-b593-9567aac9f085/adding-headers-to-a-new-file-or-csv?forum=winserverpowershell
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-table?view=powershell-7
# https://www.powershellmagazine.com/2012/09/24/pstip-advanced-object-formatting/

This would produce some results like this, depending on your own rig and install :

ZiboMod_version_checker_01.jpg

ZiboMod_version_checker_not_found_01.jpg

Code: Select all

# enjxp_SimPassion checkB738version PowerShell script
$version = '1.0.2'
# May 09th, 2020
# February 26th, 2020

# Laminar Research / X-Plane install location reference
# https://developer.x-plane.com/article/how-to-programmatically-locate-x-plane-9-or-10/

# -----------------------------------------------------------------------------------------------------------------------

# PowerShell Core Install on Windows
# https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-windows?view=powershell-7

# PowerShell Core Install on Linux
# https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

# PowerShell Core Install on MacOS
# https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-macos?view=powershell-7

# -----------------------------------------------------------------------------------------------------------------------

# Microsoft PowerShell Core Installation reference
# https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7

# =======================================================================================================================

# Scripting Reference
# -------------------
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_hash_tables?view=powershell-7
# https://powershell.org/forums/topic/conditional-formatting-in-psobject-output/
# ref : https://social.technet.microsoft.com/Forums/en-US/85f02c92-62f5-4c82-b593-9567aac9f085/adding-headers-to-a-new-file-or-csv?forum=winserverpowershell
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-table?view=powershell-7
# https://www.powershellmagazine.com/2012/09/24/pstip-advanced-object-formatting/

[console]::ForegroundColor = 'white'
Clear-Host

$tab = [char]9
$esc = [char]27
$B738InstallFound = $false

[console]::ForegroundColor = 'white'
Write-Host "==================================================="
[console]::ForegroundColor = 'yellow'
Write-Host " enjxp ZiboMod version Checker v$version"
[console]::ForegroundColor = 'white'
Write-Host "==================================================="
[console]::ForegroundColor = 'yellow'
if ($IsLinux)
{
Write-Host " Running on Linux PSHost"$PSVersionTable.PSVersion.ToString()
$osRun = 0
}
elseif ($IsMacOS)
{
Write-Host " Running on MacOS PSHost"$PSVersionTable.PSVersion.ToString()
$osRun = 1
}
elseif (($IsWindows) -or ([System.Environment]::OSVersion.Platform -eq 'Win32NT'))
{
Write-Host " Running on Windows PSHost"$PSVersionTable.PSVersion.ToString()
$osRun = 2
}
else
{
[console]::ForegroundColor = 'red'
Write-Host " Unable to determine the Runing OS"
[console]::ForegroundColor = 'yellow'
Write-Host " PSHost"$PSVersionTable.PSVersion.ToString()
[console]::ForegroundColor = 'white'
Return
}
[console]::ForegroundColor = 'white'

Write-Host "==================================================="
Write-Host ""

Write-Host "X-Plane 11 Installation(s) found at the following location(s) :"
Write-Host "---------------------------------------------------------------"
switch ($osRun)
{
0 {$XP11install = Get-Content ~/.x-plane/x-plane_install_11.txt -ErrorAction SilentlyContinue} # install file path on Linux
# Result Sample : /media/usb/X-Plane 11/
1 {$XP11install = Get-Content ~/Library/Preferences/x-plane_install_11.txt -ErrorAction SilentlyContinue} # install file path on MacOS
# Result Sample : /Users/macosusername/Library/Application Support/Steam/steamapps/common/X-Plane 11/
2 {$XP11install = Get-Content $env:LOCALAPPDATA\x-plane_install_11.txt -ErrorAction SilentlyContinue} # install file path on Windows
# Result Sample #1 : D:\X-Plane 11/
# Result Sample #2 : E:\X-Plane 11 Clean/

}

if ($XP11install -eq $nul)
{
[console]::ForegroundColor = 'red'
Write-Host "Install file not found"
}
else
{
[console]::ForegroundColor = 'cyan'
$XP11install
[console]::ForegroundColor = 'white'
Write-Host ""
Write-Host "ZiboMod Install version running check :"
Write-Host "---------------------------------------"
Write-Host "Please wait until check end ..."
Write-Host ""

$table = @()
$objVersion = New-Object PSObject

Foreach ($XP11path in $XP11install)
{
$B738path = Get-ChildItem -Path $XP11path -Filter b738_4k.acf -Recurse -ErrorAction SilentlyContinue -Force
Foreach ($Folderpath in $B738path.Directory.Fullname)
{

if ([System.IO.File]::Exists("$Folderpath\plugins\xlua\scripts\B738.fms\B738.fms.lua") -or [System.IO.File]::Exists("$Folderpath\plugins\xlua\scripts\B738.aaa_fms\B738.aaa_fms.lua") -or [System.IO.File]::Exists("$Folderpath\plugins\xlua\scripts\B738.a_fms\B738.a_fms.lua"))
{
$B738InstallFound = $true
$B738v_old = Get-Content "$Folderpath\plugins\xlua\scripts\B738.fms\B738.fms.lua" -ErrorAction SilentlyContinue | Select-String 'version = "v'
$B738v_prev = Get-Content "$Folderpath\plugins\xlua\scripts\B738.aaa_fms\B738.aaa_fms.lua" -ErrorAction SilentlyContinue | Select-String 'version = "v'
$B738v_new = Get-Content "$Folderpath\plugins\xlua\scripts\B738.a_fms\B738.a_fms.lua" -ErrorAction SilentlyContinue | Select-String 'version = "v'
if ($B738v_old -eq $nul)
{
}
else
{
$B738Version = $B738v_old
}
if ($B738v_prev -eq $nul)
{
}
else
{
$B738Version = $B738v_prev
}
if ($B738v_new -eq $nul)
{
}
else
{
$B738Version = $B738v_new
}

$B738Ver = $B738Version.ToString()
$B738Ver = $B738Ver.Substring(13)
$B738Ver = ($B738Ver.Split('"')) | select -First 1

# Table object
# ------------

$strstatus = " "
$colorstatus = 'white'
$rootpathwin = $Folderpath -match '\\Aircraft\\'
$rootpathux = $Folderpath -match '/Aircraft/'
$DispB738version = "$tab : " + $B738Ver
$pathdisp = $Folderpath | Out-String -Width 60
[console]::ForegroundColor = 'white'
if ($rootpathwin -eq $true -or $rootpathux -eq $true)
{
[console]::ForegroundColor = 'white'
Write-Host 'Folder Path OK : '$Folderpath # Check
$strstatus = "V"
$colorstatus = 'green'
[console]::ForegroundColor = 'green'
Write-Host $Folderpath' '$DispB738Version
[console]::ForegroundColor = 'white'
}
$lrwin = $Folderpath -match '\\X-Plane 11\\Aircraft\\Laminar Research\\Boeing B737-800\\'
$lrux = $Folderpath -match '/X-Plane 11/Aircraft/Laminar Research/Boeing B737-800/'
if ($lrwin -eq $true -or $lrux -eq $true)
{
$strstatus = "X"
$colorstatus = 'red'
[console]::ForegroundColor = 'red'
Write-Host $Folderpath' '$DispB738Version
}
$props = @{'Status' = $strstatus;
'Path' = $Folderpath;
'Version' = $B738Ver;}

$objVersion = New-Object -TypeName PSObject -Property $props

$table += $objVersion

}
}
}

$table | Format-Table -AutoSize @{n="Status";e={'{0:N0}' -f $_.Status};a="center";}, @{n="Path";e={'{0:N0}' -f $_.Path};a="left"}, @{n="Version";e={'{0:N0}' -f $_.Version};a="left"}

if ($B738InstallFound -eq $false)
{
[console]::ForegroundColor = 'red'
Write-Host "B738 Install not found"
}
}
[console]::ForegroundColor = 'yellow'
$wait = Read-Host -prompt 'Press any key to continue'
[console]::ForegroundColor = 'white'

Gilles

checkB738version_PSscript_PS1.zip
(2.21 KiB) Downloaded 191 times

Post Reply