Skip to content

Commit

Permalink
add base path, change support text
Browse files Browse the repository at this point in the history
  • Loading branch information
Revyn112 committed Nov 15, 2023
1 parent 9f8c79d commit b174744
Show file tree
Hide file tree
Showing 14 changed files with 255 additions and 127 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 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.3",
"version": "1.4.4",
"description": "Desktop application to install and customize Headwind addons",
"configUrls": {
"production": "https://cdn.headwindsim.net/installer/config/production.json",
Expand Down Expand Up @@ -110,7 +110,7 @@
"@ant-design/icons": "^4.4.0",
"@flybywiresim/fragmenter": "^0.7.4",
"@flybywiresim/react-components": "^0.2.5",
"@headwindsimulations/api-client": "^1.0.0",
"@headwindsimulations/api-client": "^1.1.2",
"@reduxjs/toolkit": "^1.7.1",
"@sentry/cli": "^2.5.0",
"@sentry/electron": "^3.0.7",
Expand Down
2 changes: 2 additions & 0 deletions src/common/channels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ export default {
requestSessionID: 'sentry/requestSessionID',
provideSessionID: 'sentry/provideSessionID',
},
openPath: 'openPath',
msfsBasePathSelectionDialog: 'msfsBasePathSelectionDialog',
};
36 changes: 30 additions & 6 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@ import * as os from 'os';
import { Dispatch, SetStateAction, useEffect, useState } from "react";
import * as packageInfo from '../../package.json';

const defaultCommunityDir = (): string => {
export const msStoreBasePath = path.join(process.env.LOCALAPPDATA, "\\Packages\\Microsoft.FlightSimulator_8wekyb3d8bbwe\\LocalCache\\");
export const steamBasePath = path.join(process.env.APPDATA, "\\Microsoft Flight Simulator\\");

const msfsBasePath = (): string => {
if (os.platform().toString() === 'linux') {
return 'linux';
}

// 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");
const steamPath = path.join(steamBasePath, "UserCfg.opt");
const storePath = path.join(msStoreBasePath, "UserCfg.opt");

if (fs.existsSync(steamPath)) {
if (fs.existsSync(storePath)) {
return 'C:\\';
}
msfsConfigPath = steamPath;
} else if (fs.existsSync(storePath)) {
if (fs.existsSync(steamPath)) {
return 'C:\\';
}
msfsConfigPath = storePath;
} else {
walk(process.env.LOCALAPPDATA, (path) => {
Expand All @@ -33,6 +42,16 @@ const defaultCommunityDir = (): string => {
return 'C:\\';
}

return path.dirname(msfsConfigPath);

};

export const defaultCommunityDir = (msfsBase: string): string => {
const msfsConfigPath = path.join(msfsBase, 'UserCfg.opt');
if (!fs.existsSync(msfsConfigPath)) {
return 'C:\\';
}

try {
const msfsConfig = fs.readFileSync(msfsConfigPath).toString();
const msfsConfigLines = msfsConfig.split(/\r?\n/);
Expand Down Expand Up @@ -92,6 +111,7 @@ interface Settings {
useLongDateFormat: boolean,
useDarkTheme: boolean,
allowSeasonalEffects: boolean,
msfsBasePath: string,
msfsPackagePath: string,
configDownloadUrl: string,
},
Expand Down Expand Up @@ -184,21 +204,25 @@ const schema: Schema<Settings> = {
type: "boolean",
default: true,
},
msfsBasePath: {
type: "string",
default: msfsBasePath(),
},
msfsCommunityPath: {
type: "string",
default: defaultCommunityDir(),
default: defaultCommunityDir(msfsBasePath()),
},
installPath: {
type: "string",
default: defaultCommunityDir(),
default: defaultCommunityDir(msfsBasePath()),
},
separateTempLocation: {
type: "boolean",
default: false,
},
tempLocation: {
type: "string",
default: defaultCommunityDir(),
default: defaultCommunityDir(msfsBasePath()),
},
configDownloadUrl: {
type: "string",
Expand Down
60 changes: 58 additions & 2 deletions src/main/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { app, BrowserWindow, Menu, globalShortcut, shell, ipcMain } from 'electron';
import { app, BrowserWindow, Menu, globalShortcut, shell, ipcMain, dialog } from 'electron';
import { NsisUpdater } from "electron-updater";
import * as path from 'path';
import installExtension, { REDUX_DEVTOOLS, REACT_DEVELOPER_TOOLS } from 'electron-devtools-installer';
import * as packageInfo from '../../package.json';
import settings, { persistWindowSettings } from "common/settings";
import settings, { defaultCommunityDir, msStoreBasePath, persistWindowSettings, steamBasePath } from "common/settings";
import channels from "common/channels";
import * as remote from "@electron/remote/main";
import { InstallManager } from "main/InstallManager";
import { SentryClient } from "main/SentryClient";
import fs from 'fs-extra';

function initializeApp() {
function createWindow() {
Expand Down Expand Up @@ -88,6 +89,61 @@ function initializeApp() {
});
});

ipcMain.on(channels.openPath, (_, value: string) => {
shell.openPath(value).then();
});

ipcMain.on(channels.msfsBasePathSelectionDialog, () => {
const availablePaths: string[] = [];
const availablePathIndex: string[] = [];
if (fs.existsSync(msStoreBasePath)) {
availablePaths.push('Microsoft Store Edition');
availablePathIndex.push('MS Store');
}
if (fs.existsSync(steamBasePath)) {
availablePaths.push('Steam Edition');
availablePathIndex.push('Steam');
}
availablePaths.push('Custom Directory');
availablePathIndex.push('Custom');
dialog.showMessageBox({
title: "Headwind Installer",
message: 'We couldn\'t determine the correct MSFS base path. Would you please help us? \n \n It is usually located somewhere here: \n "%LOCALAPPDATA%\\Packages\\Microsoft.FlightSimulator_8wekyb3d8bbwe\\LocalCache" \n \n or here: \n "%APPDATA%\\Microsoft Flight Simulator\\" \n\n and contains the UserOpt.cfg',
type: 'warning',
buttons: availablePaths,
}).then((promise) => {
const selection = availablePathIndex[promise.response];
const setNewPath = (path: string) => {
settings.set('mainSettings.msfsBasePath', path);
settings.set('mainSettings.msfsCommunityPath', defaultCommunityDir(path));
settings.set('mainSettings.installPath', defaultCommunityDir(path));
dialog.showMessageBox({
title: "Headwind Installer",
message: 'We had to reset your community directory. If you are using a custom directory, you might want to change it again.',
type: 'warning',
});
mainWindow.reload();
};
switch (selection) {
case 'MS Store':
setNewPath(msStoreBasePath);
break;
case 'Steam':
setNewPath(steamBasePath);
break;
case 'Custom':
dialog.showOpenDialog({
title: 'Select your MSFS Base directory',
properties: ['openDirectory'],
}).then((path) => {
if (path.filePaths[0]) {
setNewPath(path.filePaths[0]);
}
});
}
});
});

/*
* Setting the value of the program's taskbar progress bar.
* value: The value to set the progress bar to. ( [0 - 1.0], -1 to hide the progress bar )
Expand Down
58 changes: 57 additions & 1 deletion src/renderer/actions/install-path.utils.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,62 @@
import settings from "common/settings";
import settings, {defaultCommunityDir, msStoreBasePath, steamBasePath} from "common/settings";
import { Directories } from "renderer/utils/Directories";
import { dialog } from "@electron/remote";
import fs from "fs-extra";

export const setupMsfsBasePath = async (): Promise<string> => {
let basePath: string = "";
const availablePaths: string[] = [];
const availablePathIndex: string[] = [];
if (fs.existsSync(msStoreBasePath)) {
availablePaths.push('Microsoft Store Edition');
availablePathIndex.push('MS Store');
}
if (fs.existsSync(steamBasePath)) {
availablePaths.push('Steam Edition');
availablePathIndex.push('Steam');
}
availablePaths.push('Custom Directory');
availablePathIndex.push('Custom');
dialog.showMessageBox({
title: "Headwind Installer",
message: 'We need to set the correct MSFS base path. Would you please help us? \n \n It is usually located somewhere here: \n "%LOCALAPPDATA%\\Packages\\Microsoft.FlightSimulator_8wekyb3d8bbwe\\LocalCache" \n \n or here: \n "%APPDATA%\\Microsoft Flight Simulator\\" \n\n and contains the UserOpt.cfg',
type: 'warning',
buttons: availablePaths,
}).then((promise) => {
const selection = availablePathIndex[promise.response];
const setNewPath = (path: string) => {
settings.set('mainSettings.msfsBasePath', path);
settings.set('mainSettings.msfsCommunityPath', defaultCommunityDir(path));
settings.set('mainSettings.installPath', defaultCommunityDir(path));
dialog.showMessageBox({
title: "Headwind Installer",
message: 'We had to reset your community directory. If you are using a custom directory, you might want to change it again.',
type: 'warning',
});

return path;
};
switch (selection) {
case 'MS Store':
basePath = setNewPath(msStoreBasePath);
break;
case 'Steam':
basePath = setNewPath(steamBasePath);
break;
case 'Custom':
dialog.showOpenDialog({
title: 'Select your MSFS Base directory',
properties: ['openDirectory'],
}).then((path) => {
if (path.filePaths[0]) {
basePath = setNewPath(path.filePaths[0]);
}
});
}
});

return basePath;
};

export const setupMsfsCommunityPath = async (): Promise<string> => {
const currentPath = Directories.installLocation();
Expand Down
5 changes: 3 additions & 2 deletions src/renderer/components/AddonSection/MyInstall/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import {
NamedDirectoryDefinition,
} from "renderer/utils/InstallerConfiguration";
import { BoxArrowRight, Folder } from "react-bootstrap-icons";
import { shell } from "electron";
import { ipcRenderer, shell } from "electron";
import { Directories } from "renderer/utils/Directories";
import { useAppSelector } from "renderer/redux/store";
import { InstallStatusCategories } from "renderer/components/AddonSection/Enums";
import channels from "common/channels";

export interface MyInstallProps {
addon: Addon,
Expand Down Expand Up @@ -55,7 +56,7 @@ export const MyInstall: FC<MyInstallProps> = ({ addon }) => {
break;
}

shell.openPath(fullPath).then();
ipcRenderer.send(channels.openPath, fullPath);
};

const directoriesDisabled = !InstallStatusCategories.installed.includes(installStates[addon.key]?.status);
Expand Down
22 changes: 21 additions & 1 deletion src/renderer/components/ErrorModal/index.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import React, { useState } from 'react';
import { setupInstallPath } from 'renderer/actions/install-path.utils';
import { setupInstallPath, setupMsfsBasePath } from 'renderer/actions/install-path.utils';
import settings from "common/settings";
import { Directories } from "renderer/utils/Directories";
import * as fs from "fs";
import * as path from "path";

export const ErrorModal = (): JSX.Element => {
const [baseError, setBaseError] = useState<boolean>(!fs.existsSync(path.join(Directories.baseLocation(), 'UserCfg.opt')));
const [communityError, setCommunityError] = useState<boolean>(!fs.existsSync(Directories.installLocation()) || Directories.installLocation() === 'C:\\');
const [linuxError, setLinuxError] = useState<boolean>(Directories.installLocation() === 'linux');

const handleClose = () => {
setBaseError(false);
setCommunityError(false);
setLinuxError(false);
};
Expand All @@ -22,6 +25,13 @@ export const ErrorModal = (): JSX.Element => {
}
};

const handleSelectBasePath = async () => {
const path = await setupMsfsBasePath();
if (path) {
handleClose();
}
};

const content = (): JSX.Element => {
// Linux's error goes first because it may interfere with the other dir checkers
if (linuxError) {
Expand All @@ -33,6 +43,16 @@ export const ErrorModal = (): JSX.Element => {
</>
);
}
if (baseError && (Directories.installLocation() !== 'linux')) {
return (
<>
<span className="w-3/5 text-center text-2xl">Your Microsoft Flight Base Folder folder is set to</span>
<pre className="w-3/5 bg-gray-700 text-2xl text-center font-mono px-6 py-2.5 mb-0 rounded-lg">{Directories.baseLocation()}</pre>
<span className="w-3/5 text-center text-2xl">but we couldn't find the UserOpt.cfg there. Please set the correct location before we can continue.</span>
<button className="bg-navy-lightest hover:bg-navy-lighter px-5 py-2 text-lg font-semibold rounded-lg" onClick={handleSelectBasePath}>Select</button>
</>
);
}
if (communityError && (Directories.installLocation() !== 'linux')) {
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/Modal/ErrorDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const ErrorDialog: FC<ErrorDialogProps> = ({ error, onAcknowledge }) => {
</div>

<div className="flex flex-col">
<p>Use this error code to obtain support on <a onClick={handleOpenDiscordSupport}>Headwind Simulations Discord</a>:</p>
<p>Obtain support with a screenshot of this dialog on <a onClick={handleOpenDiscordSupport}>Headwind Simulations Discord</a>:</p>

<SentrySessionCard />
</div>
Expand Down
Loading

0 comments on commit b174744

Please sign in to comment.