ZockerParadise
Posts: 2
Joined: Thu Apr 25, 2024 11:12 am

NEED HELP Installation path from Script !? HOW

Hello guy iam working on setup , no i have a problem , how to do to add the Instal Path from my script ..

Here is my script
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
And i added -installerDir "$(wix.InstallDir)" to Parameter Values.

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
Catalin
Posts: 6623
Joined: Wed Jun 13, 2018 7:49 am

Re: NEED HELP Installation path from Script !? HOW

Hello and welcome to our forums,

If you have added your files in the "Application Folder" in the "Files and Folders" page and want to modify that, please note that you need to set its' property - APPDIR.

To do so, please have a look over the following article: Get and set a property in Windows PowerShell Script custom action

Hope this helps!

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
ZockerParadise
Posts: 2
Joined: Thu Apr 25, 2024 11:12 am

Re: NEED HELP Installation path from Script !? HOW

Hi Thanks for answer ,

Solved :-)
Catalin
Posts: 6623
Joined: Wed Jun 13, 2018 7:49 am

Re: NEED HELP Installation path from Script !? HOW

Hello,

You are always welcome! :)

Best regards,
Catalin
Catalin Gheorghe - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”