MCPcopy Create free account
hub / github.com/FlashpointProject/launcher / readFile

Function readFile

src/shared/preferences/PreferencesFile.ts:73–87  ·  view source on GitHub ↗
(filePath: string, fpPath: string, onError?: (error: string) => void)

Source from the content-addressed store, hash-verified

71 }
72
73 export async function readFile(filePath: string, fpPath: string, onError?: (error: string) => void): Promise<AppPreferencesData> {
74 let defaultPrefs = deepCopy(defaultPreferencesData);
75 try {
76 const overridePath = path.join(fpPath, '.preferences.defaults.json');
77 console.log('Checking for prefs override at ' + overridePath);
78 const overrideJson = JSON.parse(fs.readFileSync(overridePath, { encoding: 'utf-8' }));
79 defaultPrefs = overwritePreferenceData(defaultPrefs, overrideJson, (e) => {
80 throw 'Bad parse: ' + e;
81 });
82 } catch (err) {
83 log.debug('Launcher', 'Failed to load default prefs override, ignoring: ' + err);
84 }
85 const json = await readJsonFile(filePath, fileEncoding);
86 return overwritePreferenceData(defaultPrefs, json, onError);
87 }
88
89 export async function saveFile(filePath: string, data: AppPreferencesData, state: BackState): Promise<void> {
90 const json = stringifyJsonDataFile(data);

Callers 3

readOrCreateFileFunction · 0.70
nextMethod · 0.50
loadPlatformsFunction · 0.50

Calls 4

deepCopyFunction · 0.90
overwritePreferenceDataFunction · 0.90
readJsonFileFunction · 0.90
parseMethod · 0.80

Tested by

no test coverage detected