Skip to content

Commit

Permalink
fix missing store check
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
Revyn112 committed Oct 11, 2023
1 parent 874e3cb commit abd3cdf
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
53 changes: 47 additions & 6 deletions src/renderer/utils/Directories.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -24,10 +25,30 @@ export class Directories {

static getInstalledPackagesSteamPath(): Promise<string> {
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;
Expand All @@ -49,10 +70,30 @@ export class Directories {

static getInstalledPackagesOneStorePath(): Promise<string> {
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;
Expand Down

0 comments on commit abd3cdf

Please sign in to comment.