Skip to content

Commit 80bdee3

Browse files
feat: use null instead of C:\ for nonexitent path
1 parent bee78ec commit 80bdee3

5 files changed

Lines changed: 47 additions & 42 deletions

File tree

src/renderer/actions/install-path.utils.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@ const possibleBasePaths: Record<TypeOfSimulator, { store: string; steam: string
1818
},
1919
};
2020

21-
export const msfsBasePath = (sim: TypeOfSimulator): string => {
21+
export const msfsBasePath = (sim: TypeOfSimulator): string | null => {
2222
if (os.platform().toString() === 'linux') {
23-
return 'linux';
23+
return null;
2424
}
2525

2626
// Ensure proper functionality in main- and renderer-process
2727
let msfsConfigPath = null;
2828

2929
const steamPath = path.join(possibleBasePaths[sim].steam, 'UserCfg.opt');
3030
const storePath = path.join(possibleBasePaths[sim].store, 'UserCfg.opt');
31-
if (fs.existsSync(steamPath) && fs.existsSync(storePath)) return 'C:\\';
31+
if (fs.existsSync(steamPath) && fs.existsSync(storePath)) return null;
3232
if (fs.existsSync(steamPath)) {
3333
msfsConfigPath = steamPath;
3434
} else if (fs.existsSync(storePath)) {
@@ -42,19 +42,19 @@ export const msfsBasePath = (sim: TypeOfSimulator): string => {
4242
}
4343

4444
if (!msfsConfigPath) {
45-
return 'C:\\';
45+
return null;
4646
}
4747

4848
return path.dirname(msfsConfigPath);
4949
};
5050

51-
export const defaultCommunityDir = (msfsBase: string): string => {
51+
export const defaultCommunityDir = (msfsBase: string | null): string | null => {
52+
if (!msfsBase) {
53+
return null;
54+
}
5255
const msfsConfigPath = path.join(msfsBase, 'UserCfg.opt');
5356
if (!fs.existsSync(msfsConfigPath)) {
54-
if (os.platform().toString() === 'linux') {
55-
return 'linux';
56-
}
57-
return 'C:\\';
57+
return null;
5858
}
5959

6060
try {
@@ -64,11 +64,11 @@ export const defaultCommunityDir = (msfsBase: string): string => {
6464
const packagesPathLine = msfsConfigLines.find((line) => line.includes('InstalledPackagesPath '));
6565
const communityDir = path.join(packagesPathLine.split(' ').slice(1).join(' ').replaceAll('"', ''), '\\Community');
6666

67-
return fs.existsSync(communityDir) ? communityDir : 'C:\\';
67+
return fs.existsSync(communityDir) ? communityDir : null;
6868
} catch (e) {
6969
console.warn('Could not parse community dir from file', msfsConfigPath);
7070
console.error(e);
71-
return 'C:\\';
71+
return null;
7272
}
7373
};
7474

src/renderer/components/ErrorModal/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,24 @@ export const ErrorModal = (): JSX.Element => {
2323
settings.get(`mainSettings.simulator.${Simulators.Msfs2020}.enabled`) &&
2424
((!fs.existsSync(Directories.simulatorBasePath(Simulators.Msfs2020)) &&
2525
Directories.simulatorBasePath(Simulators.Msfs2020) !== 'notInstalled') ||
26-
Directories.simulatorBasePath(Simulators.Msfs2020) === 'C:\\'),
26+
Directories.simulatorBasePath(Simulators.Msfs2020) === null),
2727
);
2828
const [msfs2024BasePathError] = useState<boolean>(
2929
settings.get(`mainSettings.simulator.${Simulators.Msfs2024}.enabled`) &&
3030
((!fs.existsSync(Directories.simulatorBasePath(Simulators.Msfs2024)) &&
3131
Directories.simulatorBasePath(Simulators.Msfs2024) !== 'notInstalled') ||
32-
Directories.simulatorBasePath(Simulators.Msfs2024) === 'C:\\'),
32+
Directories.simulatorBasePath(Simulators.Msfs2024) === null),
3333
);
3434
const [msfs2020installLocationError] = useState<boolean>(
3535
settings.get(`mainSettings.simulator.${Simulators.Msfs2020}.enabled`) &&
3636
(!fs.existsSync(Directories.installLocation(Simulators.Msfs2020)) ||
37-
Directories.installLocation(Simulators.Msfs2020) === 'C:\\' ||
37+
Directories.installLocation(Simulators.Msfs2020) === null ||
3838
!fs.existsSync(Directories.communityLocation(Simulators.Msfs2020))),
3939
);
4040
const [msfs2024installLocationError] = useState<boolean>(
4141
settings.get(`mainSettings.simulator.${Simulators.Msfs2024}.enabled`) &&
4242
(!fs.existsSync(Directories.installLocation(Simulators.Msfs2024)) ||
43-
Directories.installLocation(Simulators.Msfs2024) === 'C:\\' ||
43+
Directories.installLocation(Simulators.Msfs2024) === null ||
4444
!fs.existsSync(Directories.communityLocation(Simulators.Msfs2024))),
4545
);
4646
const [tempLocationError] = useState<boolean>(!fs.existsSync(settings.get('mainSettings.tempLocation')));

src/renderer/rendererSettings.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -139,21 +139,18 @@ const schema: Schema<RendererSettings> = {
139139
properties: {
140140
enabled: {
141141
type: 'boolean',
142-
default:
143-
msfsBasePath(Simulators.Msfs2020) !== 'C:\\' && msfsBasePath(Simulators.Msfs2020) !== 'linux'
144-
? true
145-
: false,
142+
default: msfsBasePath(Simulators.Msfs2020) !== null,
146143
},
147144
basePath: {
148-
type: 'string',
145+
type: ['string', 'null'],
149146
default: msfsBasePath(Simulators.Msfs2020),
150147
},
151148
communityPath: {
152-
type: 'string',
149+
type: ['string', 'null'],
153150
default: defaultCommunityDir(msfsBasePath(Simulators.Msfs2020)),
154151
},
155152
installPath: {
156-
type: 'string',
153+
type: ['string', 'null'],
157154
default: defaultCommunityDir(msfsBasePath(Simulators.Msfs2020)),
158155
},
159156
},
@@ -164,21 +161,18 @@ const schema: Schema<RendererSettings> = {
164161
properties: {
165162
enabled: {
166163
type: 'boolean',
167-
default:
168-
msfsBasePath(Simulators.Msfs2024) !== 'C:\\' && msfsBasePath(Simulators.Msfs2024) !== 'linux'
169-
? true
170-
: false,
164+
default: msfsBasePath(Simulators.Msfs2024) !== null,
171165
},
172166
basePath: {
173-
type: 'string',
167+
type: ['string', 'null'],
174168
default: msfsBasePath(Simulators.Msfs2024),
175169
},
176170
communityPath: {
177-
type: 'string',
171+
type: ['string', 'null'],
178172
default: defaultCommunityDir(msfsBasePath(Simulators.Msfs2024)),
179173
},
180174
installPath: {
181-
type: 'string',
175+
type: ['string', 'null'],
182176
default: defaultCommunityDir(msfsBasePath(Simulators.Msfs2024)),
183177
},
184178
},

src/renderer/utils/Directories.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,44 @@ export class Directories {
2525
return app.getPath('temp');
2626
}
2727

28-
static simulatorBasePath(sim: TypeOfSimulator): string {
29-
return settings.get(`mainSettings.simulator.${sim}.basePath`) as string;
28+
static simulatorBasePath(sim: TypeOfSimulator): string | null {
29+
return settings.get(`mainSettings.simulator.${sim}.basePath`);
3030
}
3131

32-
static communityLocation(sim: TypeOfSimulator): string {
33-
return settings.get(`mainSettings.simulator.${sim}.communityPath`) as string;
32+
static communityLocation(sim: TypeOfSimulator): string | null {
33+
return settings.get(`mainSettings.simulator.${sim}.communityPath`);
3434
}
3535

36-
static inCommunityLocation(sim: TypeOfSimulator, targetDir: string): string {
37-
return path.join(Directories.communityLocation(sim), this.sanitize(targetDir));
36+
static inCommunityLocation(sim: TypeOfSimulator, targetDir: string): string | null {
37+
const communityPath = Directories.communityLocation(sim);
38+
if (!communityPath) return null;
39+
return path.join(communityPath, this.sanitize(targetDir));
3840
}
3941

40-
static inCommunityPackage(addon: Addon, targetDir: string): string {
42+
static inCommunityPackage(addon: Addon, targetDir: string): string | null {
4143
const baseDir = this.inCommunityLocation(addon.simulator, this.sanitize(addon.targetDirectory));
4244
return path.join(baseDir, this.sanitize(targetDir));
4345
}
4446

45-
static installLocation(sim: TypeOfSimulator): string {
46-
return settings.get(`mainSettings.simulator.${sim}.installPath`) as string;
47+
static installLocation(sim: TypeOfSimulator): string | null {
48+
return settings.get(`mainSettings.simulator.${sim}.installPath`);
4749
}
4850

49-
static inInstallLocation(sim: TypeOfSimulator, targetDir: string): string {
50-
return path.join(Directories.installLocation(sim), this.sanitize(targetDir));
51+
static inInstallLocation(sim: TypeOfSimulator, targetDir: string): string | null {
52+
const installPath = this.installLocation(sim);
53+
if (!installPath) return null;
54+
return path.join(installPath, this.sanitize(targetDir));
5155
}
5256

53-
static inInstallPackage(addon: Addon, targetDir: string): string {
57+
static inInstallPackage(addon: Addon, targetDir: string): string | null {
5458
const baseDir = this.inInstallLocation(addon.simulator, this.sanitize(addon.targetDirectory));
59+
if (!baseDir) return null;
5560
return path.join(baseDir, this.sanitize(targetDir));
5661
}
5762

5863
static tempLocation(sim: TypeOfSimulator): string {
5964
return settings.get('mainSettings.separateTempLocation')
60-
? (settings.get('mainSettings.tempLocation') as string)
65+
? settings.get('mainSettings.tempLocation')
6166
: this.installLocation(sim);
6267
}
6368

src/renderer/utils/InstallManager.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { IncompatibleAddOnsCheck } from 'renderer/utils/IncompatibleAddOnsCheck'
4545
import { FreeDiskSpace, FreeDiskSpaceStatus } from 'renderer/utils/FreeDiskSpace';
4646
import { setAddonAndTrackLatestReleaseInfo } from 'renderer/redux/features/latestVersionNames';
4747
import { AddonData, ReleaseInfo } from 'renderer/utils/AddonData';
48+
import install from 'electron-devtools-installer/dist';
4849

4950
type FragmenterEventArguments<K extends keyof FragmenterInstallerEvents | keyof FragmenterContextEvents> = Parameters<
5051
(FragmenterInstallerEvents & FragmenterContextEvents)[K]
@@ -755,6 +756,11 @@ export class InstallManager {
755756
const fragmenterUpdateChecker = new FragmenterUpdateChecker();
756757

757758
for (const track of addon.tracks) {
759+
if (!installDir) {
760+
console.warn(`[InstallManager](checkForUpdates) No install directory for addon ${addon.key}`);
761+
store.dispatch(setInstallStatus({ addonKey: addon.key, installState: { status: InstallStatus.Unknown } }));
762+
continue;
763+
}
758764
const updateInfo = await fragmenterUpdateChecker.needsUpdate(track.url, installDir, { forceCacheBust: true });
759765

760766
let info: ReleaseInfo;

0 commit comments

Comments
 (0)