Skip to content

[GOG]: fix obtaning manifest for updates check #2882

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

Merged
merged 3 commits into from
Jul 23, 2023
Merged
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
5 changes: 4 additions & 1 deletion src/backend/storeManagers/gog/games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,6 @@ export async function syncQueuedPlaytimeGOG() {
if (playtimeSyncQueue.has('lock')) {
return
}
playtimeSyncQueue.set('lock', [])
const userData: UserData | undefined = configStore.get_nodefault('userData')
if (!userData) {
logError('Unable to syncQueued playtime, userData not present', {
Expand All @@ -1012,6 +1011,10 @@ export async function syncQueuedPlaytimeGOG() {
return
}
const queue = playtimeSyncQueue.get(userData.galaxyUserId, [])
if (queue.length === 0) {
return
}
playtimeSyncQueue.set('lock', [])
const failed = []

for (const session of queue) {
Expand Down
45 changes: 34 additions & 11 deletions src/backend/storeManagers/gog/library.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ import { basename, join } from 'node:path'
import { existsSync, readFileSync } from 'graceful-fs'
import { app } from 'electron'

import { logError, logInfo, LogPrefix, logWarning } from '../../logger/logger'
import {
logDebug,
logError,
logInfo,
LogPrefix,
logWarning
} from '../../logger/logger'
import { getGOGdlBin, getFileSize } from '../../utils'
import { gogdlLogFile } from '../../constants'
import {
Expand Down Expand Up @@ -587,21 +593,38 @@ export async function getMetaResponse(
etag?: string
) {
const buildData = await axios.get(
`https://content-system.gog.com/products/${appName}/os/${platform}/builds?generation=2`
`https://content-system.gog.com/products/${appName}/os/${platform}/builds?generation=2&_version=2`
)
const headers = etag
? {
'If-None-Match': etag
}
: undefined
const metaUrl =
buildData.data?.items?.find((build: BuildItem) => !build.branch)?.link ||
buildData.data?.items[0]?.link
const metaResponse = await axios.get(metaUrl, {
headers,
validateStatus: (status) => status === 200 || status === 304
})
return { status: metaResponse.status, etag: metaResponse.headers.etag }
const metaUrls =
buildData.data?.items?.find((build: BuildItem) => !build.branch)?.urls ||
buildData.data?.items[0]?.urls ||
[]

for (const metaUrl of metaUrls) {
try {
const metaResponse = await axios.get(metaUrl.url, {
headers,
validateStatus: (status) => status === 200 || status === 304
})

return { status: metaResponse.status, etag: metaResponse.headers.etag }
} catch (e) {
logDebug(
`Failed to obtain manifest from CDN for ${appName}, ignoring ${e}`,
{
prefix: LogPrefix.Gog
}
)
continue
}
}

return { status: 304, etag: etag }
}

export async function checkForGameUpdate(
Expand All @@ -611,7 +634,7 @@ export async function checkForGameUpdate(
) {
const metaResponse = await getMetaResponse(appName, platform, etag)

return metaResponse.status === 200
return metaResponse.status === 200 && metaResponse.etag !== etag
}

/**
Expand Down