From abd3cdf553189d3a74235653681fa6eb91f582f5 Mon Sep 17 00:00:00 2001 From: Denis Freund Date: Wed, 11 Oct 2023 19:46:05 +0200 Subject: [PATCH] fix missing store check fix --- package.json | 2 +- src/renderer/utils/Directories.ts | 53 +++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 570e365..40f9a3c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "headwind-installer", "productName": "Headwind Installer", - "version": "1.4.0", + "version": "1.4.1", "description": "Desktop application to install and customize Headwind addons", "configUrls": { "production": "https://cdn.headwindsim.net/installer/config/production.json", diff --git a/src/renderer/utils/Directories.ts b/src/renderer/utils/Directories.ts index 58883ab..9e9310d 100644 --- a/src/renderer/utils/Directories.ts +++ b/src/renderer/utils/Directories.ts @@ -1,4 +1,5 @@ import path from "path"; +import walk from "walkdir"; import { Addon } from "renderer/utils/InstallerConfiguration"; import fs from "fs-extra"; import settings from "common/settings"; @@ -24,10 +25,30 @@ export class Directories { static getInstalledPackagesSteamPath(): Promise { return new Promise((resolve, reject) => { - // Resolve the path to the file using the APPDATA environment variable - const filePath = path.join(process.env.APPDATA, 'Microsoft Flight Simulator', 'UserCfg.opt'); + // Ensure proper functionality in main- and renderer-process + let msfsConfigPath = null; + + const steamPath = path.join(process.env.APPDATA, "\\Microsoft Flight Simulator\\UserCfg.opt"); + const storePath = path.join(process.env.LOCALAPPDATA, "\\Packages\\Microsoft.FlightSimulator_8wekyb3d8bbwe\\LocalCache\\UserCfg.opt"); + + if (fs.existsSync(steamPath)) { + msfsConfigPath = steamPath; + } else if (fs.existsSync(storePath)) { + msfsConfigPath = storePath; + } else { + walk(process.env.LOCALAPPDATA, (path) => { + if (path.includes("Flight") && path.includes("UserCfg.opt")) { + msfsConfigPath = path; + } + }); + } + + if (!msfsConfigPath) { + reject('MSFSConfigPath not found.'); + return; + } - fs.readFile(filePath, 'utf8', (err, data) => { + fs.readFile(msfsConfigPath, 'utf8', (err, data) => { if (err) { reject("Error reading the file: " + err); return; @@ -49,10 +70,30 @@ export class Directories { static getInstalledPackagesOneStorePath(): Promise { return new Promise((resolve, reject) => { - // Resolve the path to the file using the APPDATA environment variable - const filePath = path.join(process.env.APPDATA, 'Microsoft Flight Simulator', 'UserCfg.opt'); + // Ensure proper functionality in main- and renderer-process + let msfsConfigPath = null; + + const steamPath = path.join(process.env.APPDATA, "\\Microsoft Flight Simulator\\UserCfg.opt"); + const storePath = path.join(process.env.LOCALAPPDATA, "\\Packages\\Microsoft.FlightSimulator_8wekyb3d8bbwe\\LocalCache\\UserCfg.opt"); + + if (fs.existsSync(steamPath)) { + msfsConfigPath = steamPath; + } else if (fs.existsSync(storePath)) { + msfsConfigPath = storePath; + } else { + walk(process.env.LOCALAPPDATA, (path) => { + if (path.includes("Flight") && path.includes("UserCfg.opt")) { + msfsConfigPath = path; + } + }); + } + + if (!msfsConfigPath) { + reject('MSFSConfigPath not found.'); + return; + } - fs.readFile(filePath, 'utf8', (err, data) => { + fs.readFile(msfsConfigPath, 'utf8', (err, data) => { if (err) { reject("Error reading the file: " + err); return;