Skip to content

Commit

Permalink
fix: add folder fallback to prevent app crash (#135)
Browse files Browse the repository at this point in the history
If Windows Controlled Folder access is enabled, it will prevent
simbridge from accessing the documents folder and the app will crash.
Added a fallback to use the appdata directory, which is not protected by
default.

Note: the old workaround via powershell was removed, as the reason for
platform-folders to fail was Windows blocking it as well. So it's not
needed anymore IMO.

Fixes #134 
Fixes #133
Fixes #130

---------

Co-authored-by: Saschl <[email protected]>
  • Loading branch information
Saschl and Saschl authored Nov 13, 2024
1 parent 2789e15 commit 08f0195
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 15 deletions.
18 changes: 6 additions & 12 deletions apps/server/src/utilities/pathUtil.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
import getPath from 'platform-folders';
import * as path from 'path';
import { Logger } from '@nestjs/common';
import { homedir } from 'os';
import { execFileSync } from 'child_process';

export const getSimbridgeDir = () => {
try {
return path.join(getPath('documents'), 'FlyByWireSim', 'Simbridge');
} catch (e) {
Logger.warn('Could not get documents path via WinAPI, trying alternate method', e);
Logger.warn(
'Could not get documents path via WinAPI, Windows Controlled Folder Access is likely blocking the app. Using AppData as fallback',
e,
);
}
try {
const output = execFileSync('Powershell.exe', ['-Command', `[System.Environment]::GetFolderPath('MyDocuments')`]);
const documents = output.toString().trim();
if (!documents) {
throw new Error('Path is empty');
}
return path.join(documents, 'FlyByWireSim', 'Simbridge');
return path.join(getPath('appdata'), 'FlyByWireSim', 'Simbridge');
} catch (e) {
Logger.warn('Could not get documents path via Powershell, trying to use %USERPROFILE% method', e);
Logger.error('Could not get AppData path via WinAPI. Giving up.', e);
}

return path.join(homedir(), 'Documents', 'FlyByWireSim', 'Simbridge');
};

//@ts-expect-error pkg only defined when running as exe
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fbw-simbridge",
"version": "0.6.1",
"version": "0.6.2",
"description": "The simbridge server for FBW addons for various tasks the addons themselves can't achieve",
"author": "",
"private": false,
Expand Down

0 comments on commit 08f0195

Please sign in to comment.