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] Mark wineprefixes starting with XDG_RUNTIME_DIR as invalid #3271

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions src/backend/api/misc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export const getFonts = async (reload: boolean) =>
ipcRenderer.invoke('getFonts', reload)
export const checkDiskSpace = async (installPath: string) =>
ipcRenderer.invoke('checkDiskSpace', installPath)
export const checkWinePrefix = async (prefix: string) =>
ipcRenderer.invoke('checkWinePrefix', prefix)
export const getGOGLinuxInstallersLangs = async (appName: string) =>
ipcRenderer.invoke('getGOGLinuxInstallersLangs', appName)
export const getAlternativeWine = async () =>
Expand Down
10 changes: 10 additions & 0 deletions src/backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,16 @@ ipcMain.handle('checkDiskSpace', async (event, folder) => {
})
})

ipcMain.handle('checkWinePrefix', async (event, prefix) => {
const isValidFlatpakPath = !(
isFlatpak && prefix.startsWith(process.env.XDG_RUNTIME_DIR || '/run/user/')
)

logDebug(`Checking wine prefix ${prefix}`, LogPrefix.Backend)

return isValidFlatpakPath
})

ipcMain.handle('isFrameless', () => isFrameless())
ipcMain.handle('isMinimized', () => !!getMainWindow()?.isMinimized())
ipcMain.handle('isMaximized', () => !!getMainWindow()?.isMaximized())
Expand Down
1 change: 1 addition & 0 deletions src/common/typedefs/ipcBridge.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ interface AsyncIPCFunctions {
addToDMQueue: (element: DMQueueElement) => Promise<void>
kill: (appName: string, runner: Runner) => Promise<void>
checkDiskSpace: (folder: string) => Promise<DiskSpaceData>
checkWinePrefix: (prefix: string) => Promise<boolean>
callTool: (args: Tools) => Promise<void>
runWineCommand: (
args: WineCommandArgs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ interface Props {
wineVersion: WineInstallation | undefined
children: React.ReactNode
gameInfo: GameInfo
validWinePrefix: boolean
}

type DiskSpaceInfo = {
Expand Down Expand Up @@ -116,7 +117,8 @@ export default function DownloadDialog({
wineVersion,
children,
gameInfo,
crossoverBottle
crossoverBottle,
validWinePrefix
}: Props) {
const previousProgress = JSON.parse(
storage.getItem(appName) || '{}'
Expand Down Expand Up @@ -422,7 +424,8 @@ export default function DownloadDialog({
installPath &&
gameInstallInfo?.manifest?.download_size &&
!gettingInstallInfo &&
validFlatpakPath
validFlatpakPath &&
validWinePrefix

const showDlcSelector =
runner === 'legendary' && DLCList && DLCList?.length > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type Props = {
platformToInstall: InstallPlatform
backdropClick: () => void
appName?: string
validWinePrefix: boolean
}

export default function SideloadDialog({
Expand All @@ -45,7 +46,8 @@ export default function SideloadDialog({
platformToInstall,
setWinePrefix,
children,
appName
appName,
validWinePrefix
}: Props) {
const { t } = useTranslation('gamepage')
const [title, setTitle] = useState<string | never>(
Expand Down Expand Up @@ -389,7 +391,12 @@ export default function SideloadDialog({
<button
onClick={async () => handleInstall()}
className={`button is-success`}
disabled={(!selectedExe.length && !gameUrl) || addingApp || searching}
disabled={
(!selectedExe.length && !gameUrl) ||
addingApp ||
searching ||
!validWinePrefix
}
>
{addingApp && <FontAwesomeIcon icon={faSpinner} spin />}
{!addingApp && t('button.finish', 'Finish')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ type Props = {
>
setWinePrefix: React.Dispatch<React.SetStateAction<string>>
setCrossoverBottle: React.Dispatch<React.SetStateAction<string>>
setValidWinePrefix: React.Dispatch<React.SetStateAction<boolean>>
winePrefix: string
crossoverBottle: string
wineVersionList: WineInstallation[]
wineVersion: WineInstallation | undefined
title?: string
validWinePrefix: boolean
}

export default function WineSelector({
Expand All @@ -30,7 +32,9 @@ export default function WineSelector({
wineVersion,
title = 'sideload',
crossoverBottle,
setCrossoverBottle
setCrossoverBottle,
setValidWinePrefix,
validWinePrefix
}: Props) {
const { t } = useTranslation('gamepage')

Expand Down Expand Up @@ -90,14 +94,25 @@ export default function WineSelector({
{showPrefix && (
<PathSelectionBox
type="directory"
onPathChange={setWinePrefix}
onPathChange={async (path) => {
setWinePrefix(path)
setValidWinePrefix(await window.api.checkWinePrefix(path))
}}
path={winePrefix}
pathDialogTitle={t('box.wineprefix', 'Select WinePrefix Folder')}
label={t('install.wineprefix', 'WinePrefix')}
htmlId="setinstallpath"
noDeleteButton
/>
)}
{!validWinePrefix && (
<span className="error">
{`${t(
'install.flatpak-path-not-writtable',
'Error: Sandbox access not granted to this path, data loss will occur.'
)}`}
</span>
)}
{showBottle && (
<TextInputField
label={t('setting.winecrossoverbottle', 'CrossOver Bottle')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default React.memo(function InstallModal({
const [wineVersion, setWineVersion] = useState<WineInstallation>()
const [wineVersionList, setWineVersionList] = useState<WineInstallation[]>([])
const [crossoverBottle, setCrossoverBottle] = useState('')
const [validWinePrefix, setValidWinePrefix] = useState(true)

const isLinuxNative = Boolean(gameInfo?.is_linux_native)
const isMacNative = Boolean(gameInfo?.is_mac_native)
Expand Down Expand Up @@ -171,6 +172,7 @@ export default React.memo(function InstallModal({
platformToInstall={platformToInstall}
gameInfo={gameInfo}
crossoverBottle={crossoverBottle}
validWinePrefix={validWinePrefix}
>
{platformSelection()}
{hasWine ? (
Expand All @@ -183,6 +185,8 @@ export default React.memo(function InstallModal({
setWineVersion={setWineVersion}
crossoverBottle={crossoverBottle}
setCrossoverBottle={setCrossoverBottle}
setValidWinePrefix={setValidWinePrefix}
validWinePrefix={validWinePrefix}
/>
) : null}
</DownloadDialog>
Expand All @@ -196,6 +200,7 @@ export default React.memo(function InstallModal({
platformToInstall={platformToInstall}
appName={appName}
crossoverBottle={crossoverBottle}
validWinePrefix={validWinePrefix}
>
{platformSelection()}
{hasWine ? (
Expand All @@ -207,6 +212,8 @@ export default React.memo(function InstallModal({
setWineVersion={setWineVersion}
crossoverBottle={crossoverBottle}
setCrossoverBottle={setCrossoverBottle}
setValidWinePrefix={setValidWinePrefix}
validWinePrefix={validWinePrefix}
/>
) : null}
</SideloadDialog>
Expand Down