Skip to content

Commit

Permalink
fix: use appdata as fallback if windows blocks documents folder access
Browse files Browse the repository at this point in the history
  • Loading branch information
Saschl committed Nov 13, 2024
1 parent 2789e15 commit 676a005
Showing 1 changed file with 6 additions and 12 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.warn('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

0 comments on commit 676a005

Please sign in to comment.