Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add folder fallback to prevent app crash #135

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we note here a documentation link to either MS or our docs for how to override WCFA if someone wants to do this? Note as a comment on the code, not the log message FYI.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this ? No user is gonna look in the code and as a dev one should be able to use google :D Especially since that link will likely eventually go stale and will need updating. If anything I would suggest making a bot command for support that links to the relevant MS docs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the console closes by default so only who either disabled the setting or opens it manually will see the error message. Bot command sounds fine to me

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
Loading