Skip to content

Commit

Permalink
[GOG]: add support for linux native dlcs in modify install dialog (#3895
Browse files Browse the repository at this point in the history
)

improv: add support for linux native dlcs in modify install dialog

also automatically run post install script after completed download
  • Loading branch information
imLinguin authored Aug 9, 2024
1 parent b5c8adf commit 59873b0
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 35 deletions.
31 changes: 27 additions & 4 deletions src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,12 @@ export async function install(
}

const sizeOnDisk = await getPathDiskSize(join(path, gameInfo.folder_name))
const install_path = join(path, gameInfo.folder_name)

const installedData: InstalledInfo = {
platform: installPlatform,
executable: '',
install_path: join(path, gameInfo.folder_name),
install_path,
install_size: getFileSize(sizeOnDisk),
is_dlc: false,
version: additionalInfo ? additionalInfo.version : installInfo.game.version,
Expand Down Expand Up @@ -441,6 +442,17 @@ export async function install(
LogPrefix.Gog
)
}
} else if (isLinuxNative) {
const installer = join(install_path, 'support/postinst.sh')
if (existsSync(installer)) {
logInfo(`Running ${installer}`, LogPrefix.Gog)
await spawnAsync(installer, []).catch((err) =>
logError(
`Failed to run linux installer: ${installer} - ${err}`,
LogPrefix.Gog
)
)
}
}
addShortcuts(appName)
return { status: 'done' }
Expand Down Expand Up @@ -1155,9 +1167,6 @@ export async function update(
gameObject.version = installInfo.game.version
gameObject.branch = updateOverwrites?.branch
gameObject.language = overwrittenLanguage
if (updateOverwrites?.dlcs) {
gameObject.installedDLCs = updateOverwrites?.dlcs
}
gameObject.versionEtag = etag
} else {
const installerInfo = await getLinuxInstallerInfo(appName)
Expand All @@ -1166,6 +1175,9 @@ export async function update(
}
gameObject.version = installerInfo.version
}
if (updateOverwrites?.dlcs) {
gameObject.installedDLCs = updateOverwrites?.dlcs
}
const sizeOnDisk = await getPathDiskSize(join(gameObject.install_path))
gameObject.install_size = getFileSize(sizeOnDisk)
installedGamesStore.set('installed', installedArray)
Expand All @@ -1178,6 +1190,17 @@ export async function update(
(isWindows || existsSync(gameSettings.winePrefix))
) {
await setup(appName, gameObject, false)
} else if (gameObject.platform === 'linux') {
const installer = join(gameObject.install_path, 'support/postinst.sh')
if (existsSync(installer)) {
logInfo(`Running ${installer}`, LogPrefix.Gog)
await spawnAsync(installer, []).catch((err) =>
logError(
`Failed to run linux installer: ${installer} - ${err}`,
LogPrefix.Gog
)
)
}
}
sendGameStatusUpdate({
appName: appName,
Expand Down
3 changes: 1 addition & 2 deletions src/frontend/screens/Game/GamePage/components/DotsMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const DotsMenu = ({ gameInfo, handleUpdate }: Props) => {
const [showChangelog, setShowChangelog] = useState(false)
const [showModifyInstallModal, setShowModifyInstallModal] = useState(false)

const { is_installed, title, install } = gameInfo
const { is_installed, title } = gameInfo

const hasRequirements = (gameExtraInfo?.reqs || []).length > 0

Expand All @@ -50,7 +50,6 @@ const DotsMenu = ({ gameInfo, handleUpdate }: Props) => {
}
changelog={gameExtraInfo?.changelog}
runner={gameInfo.runner}
installPlatform={install.platform}
handleUpdate={handleUpdate}
handleChangeLog={() => setShowChangelog(true)}
disableUpdate={is.installing || is.updating}
Expand Down
5 changes: 1 addition & 4 deletions src/frontend/screens/Game/GameSubMenu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ interface Props {
title: string
storeUrl: string
changelog?: string
installPlatform?: string
runner: Runner
handleUpdate: () => void
handleChangeLog: () => void
Expand All @@ -37,7 +36,6 @@ export default function GamesSubmenu({
storeUrl,
changelog,
runner,
installPlatform,
handleUpdate,
handleChangeLog,
disableUpdate,
Expand Down Expand Up @@ -235,8 +233,7 @@ export default function GamesSubmenu({
onShowModifyInstall &&
['legendary', 'gog'].includes(runner) &&
isInstalled &&
!isThirdPartyManaged &&
installPlatform !== 'linux'
!isThirdPartyManaged

return (
<>
Expand Down
57 changes: 32 additions & 25 deletions src/frontend/screens/Game/ModifyInstallModal/GOG/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default function GOGModifyInstallModal({
}: GOGModifyInstallModal) {
const { t, i18n } = useTranslation('gamepage')
const { t: tr } = useTranslation()
const isLinux = gameInfo.install.platform === 'linux'
const [gameInstallInfo, setGameInstallInfo] = useState<GogInstallInfo>()

const [installLanguages, setInstallLanguages] = useState<string[]>([])
Expand Down Expand Up @@ -65,7 +66,7 @@ export default function GOGModifyInstallModal({
const [currentTab, setCurrentTab] = useState('updates')

const handleConfirm = () => {
const gameBuild = selectedBuild || builds[0].build_id
const gameBuild = selectedBuild || builds[0]?.build_id
const versionPinned = !!selectedBuild
const buildModified = gameBuild !== gameInfo.install.buildId
const languageModified = installLanguage !== gameInfo.install.language
Expand Down Expand Up @@ -100,7 +101,9 @@ export default function GOGModifyInstallModal({
}

const gameModified =
buildModified || branchModified || languageModified || dlcModified
(!isLinux && (buildModified || branchModified)) ||
languageModified ||
dlcModified

if (gameModified) {
// Create update
Expand Down Expand Up @@ -247,35 +250,39 @@ export default function GOGModifyInstallModal({
)}
</Tabs>
<TabPanel value={currentTab} index={'updates'}>
<div className="ModifyInstall__branch">
<BranchSelector
appName={gameInfo.app_name}
branches={branches}
branch={branch}
setBranch={setBranch}
savedBranchPassword={savedBranchPassword}
onPasswordChange={(newPasswd) => setSavedBranchPassword(newPasswd)}
/>
</div>

{installLanguages.length > 1 && (
<div className="ModifyInstall__languages">
<GameLanguageSelector
installLanguages={installLanguages}
setInstallLanguage={setInstallLanguage}
installPlatform={gameInfo.install.platform ?? 'windows'}
installLanguage={installLanguage}
{!!branches.length && (
<div className="ModifyInstall__branch">
<BranchSelector
appName={gameInfo.app_name}
branches={branches}
branch={branch}
setBranch={setBranch}
savedBranchPassword={savedBranchPassword}
onPasswordChange={(newPasswd) =>
setSavedBranchPassword(newPasswd)
}
/>
</div>
)}

<div className="ModifyInstall__version">
<BuildSelector
gameBuilds={builds}
selectedBuild={selectedBuild}
setSelectedBuild={setSelectedBuild}
<div className="ModifyInstall__languages">
<GameLanguageSelector
installLanguages={installLanguages}
setInstallLanguage={setInstallLanguage}
installPlatform={gameInfo.install.platform ?? 'windows'}
installLanguage={installLanguage}
/>
</div>

{!!builds.length && (
<div className="ModifyInstall__version">
<BuildSelector
gameBuilds={builds}
selectedBuild={selectedBuild}
setSelectedBuild={setSelectedBuild}
/>
</div>
)}
</TabPanel>
<TabPanel value={currentTab} index={'dlc'}>
<div className="ModifyInstall__gogDlcs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export default function GameLanguageSelector({
label={`${t('game.language', 'Language')}:`}
htmlId="languagePick"
value={installLanguage}
disabled={installLanguages?.length === 1}
onChange={(e) => setInstallLanguage(e.target.value)}
>
{installLanguages &&
Expand Down

0 comments on commit 59873b0

Please sign in to comment.