Here is my script
And i added -installerDir "$(wix.InstallDir)" to Parameter Values.param($installerDir)
# Function to extract Community folder path from UserCfg.opt file
Function Get-CommunityPath {
Param(
[string]$CfgFilePath
)
$instPathMarker = "InstalledPackagesPath"
$communityPath = ""
# Read each line of the file
foreach ($line in Get-Content -Path $CfgFilePath) {
# Check if the line contains the marker for the Community folder path
if ($line -match $instPathMarker) {
# Extract the Community folder path
$communityPath = ($line -replace "^.*$instPathMarker\s*""?([^""]+)""?.*", '$1').Trim()
break
}
}
return $communityPath
}
# Main script
# Set path to UserCfg.opt file for MSFS Store version
$strCfgPath = "$env:LOCALAPPDATA\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\UserCfg.opt"
# Check if UserCfg.opt file exists for MSFS Store version
if (Test-Path $strCfgPath -PathType Leaf) {
# Get Community folder path from UserCfg.opt file
$strCommunityPath = Get-CommunityPath -CfgFilePath $strCfgPath
# Set installation path to Community folder path
$installerDir = $strCommunityPath
} else {
# Set default installation path if UserCfg.opt file doesn't exist
$installerDir = "$env:ProgramFiles\YourCompany\YourApplication"
}
# Set path to UserCfg.opt file for Steam version
$strCfgPath = "$env:APPDATA\Microsoft Flight Simulator\UserCfg.opt"
# Check if UserCfg.opt file exists for Steam version
if (Test-Path $strCfgPath -PathType Leaf) {
# Get Community folder path from UserCfg.opt file
$strCommunityPath = Get-CommunityPath -CfgFilePath $strCfgPath
# Set installation path to Community folder path
$installerDir = $strCommunityPath
}
# Output installation directory to Advanced Installer
$installerDir
But when i compile it doeant work , it shows me the directory that is set on - Install Parameters Page
In my test case the script Reads this out
Return code: 0
Script output: "F:\MSFS 2020 Game"
Now i want this Path in the Installation Path on the installer