-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve MSFS base path detection (#423)
* feat: rewrite MSFS base path detection * fix: openPath() does not focus Explorer window * chore: update changelog * refactor: dismiss promise (cherry picked from commit 0a3895c)
- Loading branch information
1 parent
9630008
commit 5f340bd
Showing
10 changed files
with
201 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,74 @@ | ||
import settings from 'renderer/rendererSettings'; | ||
import settings, { msStoreBasePath, steamBasePath } from 'renderer/rendererSettings'; | ||
import { Directories } from 'renderer/utils/Directories'; | ||
import { dialog } from '@electron/remote'; | ||
import fs from 'fs'; | ||
|
||
export const setupMsfsCommunityPath = async (): Promise<string> => { | ||
const currentPath = Directories.installLocation(); | ||
|
||
const selectPath = async (currentPath: string, dialogTitle: string, setting: string): Promise<string> => { | ||
const path = await dialog.showOpenDialog({ | ||
title: 'Select your MSFS community directory', | ||
title: dialogTitle, | ||
defaultPath: typeof currentPath === 'string' ? currentPath : '', | ||
properties: ['openDirectory'], | ||
}); | ||
|
||
if (path.filePaths[0]) { | ||
settings.set('mainSettings.msfsCommunityPath', path.filePaths[0]); | ||
settings.set(setting, path.filePaths[0]); | ||
return path.filePaths[0]; | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
export const setupInstallPath = async (): Promise<string> => { | ||
const currentPath = Directories.installLocation(); | ||
export const setupMsfsBasePath = async (): Promise<string> => { | ||
const currentPath = Directories.msfsBasePath(); | ||
|
||
const path = await dialog.showOpenDialog({ | ||
title: 'Select your install directory', | ||
defaultPath: typeof currentPath === 'string' ? currentPath : '', | ||
properties: ['openDirectory'], | ||
}); | ||
const availablePaths: string[] = []; | ||
if (fs.existsSync(msStoreBasePath)) { | ||
availablePaths.push('Microsoft Store Edition'); | ||
} | ||
if (fs.existsSync(steamBasePath)) { | ||
availablePaths.push('Steam Edition'); | ||
} | ||
|
||
if (path.filePaths[0]) { | ||
settings.set('mainSettings.installPath', path.filePaths[0]); | ||
if (!settings.get('mainSettings.separateLiveriesPath')) { | ||
settings.set('mainSettings.liveriesPath', path.filePaths[0]); | ||
if (availablePaths.length > 0) { | ||
availablePaths.push('Custom Directory'); | ||
|
||
const { response } = await dialog.showMessageBox({ | ||
title: 'FlyByWire Installer', | ||
message: 'We found a possible MSFS installation.', | ||
type: 'warning', | ||
buttons: availablePaths, | ||
}); | ||
|
||
const selection = availablePaths[response]; | ||
switch (selection) { | ||
case 'Microsoft Store Edition': | ||
settings.set('mainSettings.msfsBasePath', msStoreBasePath); | ||
return msStoreBasePath; | ||
case 'Steam Edition': | ||
settings.set('mainSettings.msfsBasePath', steamBasePath); | ||
return steamBasePath; | ||
case 'Custom Directory': | ||
break; | ||
} | ||
return path.filePaths[0]; | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
|
||
export const setupTempLocation = async (): Promise<string> => { | ||
const currentPath = Directories.tempLocation(); | ||
return await selectPath(currentPath, 'Select your MSFS base directory', 'mainSettings.msfsBasePath'); | ||
}; | ||
|
||
const path = await dialog.showOpenDialog({ | ||
title: 'Select a location for temporary folders', | ||
defaultPath: typeof currentPath === 'string' ? currentPath : '', | ||
properties: ['openDirectory'], | ||
}); | ||
export const setupMsfsCommunityPath = async (): Promise<string> => { | ||
const currentPath = Directories.installLocation(); | ||
|
||
if (path.filePaths[0]) { | ||
settings.set('mainSettings.tempLocation', path.filePaths[0]); | ||
return path.filePaths[0]; | ||
} else { | ||
return ''; | ||
} | ||
return await selectPath(currentPath, 'Select your MSFS community directory', 'mainSettings.msfsCommunityPath'); | ||
}; | ||
|
||
export const setupLiveriesPath = async (): Promise<string> => { | ||
const currentPath = Directories.liveries(); | ||
export const setupInstallPath = async (): Promise<string> => { | ||
const currentPath = Directories.installLocation(); | ||
|
||
const path = await dialog.showOpenDialog({ | ||
title: 'Select your liveries directory', | ||
defaultPath: typeof currentPath === 'string' ? currentPath : '', | ||
properties: ['openDirectory'], | ||
}); | ||
return await selectPath(currentPath, 'Select your install directory', 'mainSettings.installPath'); | ||
}; | ||
|
||
if (path.filePaths[0]) { | ||
settings.set('mainSettings.liveriesPath', path.filePaths[0]); | ||
return path.filePaths[0]; | ||
} else { | ||
return ''; | ||
} | ||
export const setupTempLocation = async (): Promise<string> => { | ||
const currentPath = Directories.tempLocation(); | ||
|
||
return await selectPath(currentPath, 'Select a location for temporary folders', 'mainSettings.tempLocation'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.