Skip to content

Commit

Permalink
fix: Fix the problem of mistakenly deleting paths and launcher config…
Browse files Browse the repository at this point in the history
…urations when downloading game materials
  • Loading branch information
ximu3 committed Dec 15, 2024
1 parent 4ec55ae commit d507c30
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
19 changes: 9 additions & 10 deletions src/main/adder/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ import { rebuildRecords } from '~/database/record'
export async function addGameToDB({
dataSource,
id,
dbId,
preExistingDbId,
screenshotUrl,
playingTime
}: {
dataSource: string
id: string
dbId?: string
preExistingDbId?: string
screenshotUrl?: string
playingTime?: number
}): Promise<void> {
const metadata = await getGameMetadata(dataSource, id)
const coverUrl = await getGameCover(dataSource, id)
const iconUrl = await getGameIcon(dataSource, id)
if (!dbId) {
dbId = generateUUID()
}
const dbId = preExistingDbId || generateUUID()

await getDataPath(`games/${dbId}/`, true)

Expand Down Expand Up @@ -66,11 +64,12 @@ export async function addGameToDB({
...metadata
})

await setDBValue(`games/${dbId}/record.json`, ['addDate'], new Date().toISOString())

await setDBValue(`games/${dbId}/launcher.json`, ['#all'], {})
await setDBValue(`games/${dbId}/path.json`, ['#all'], {})
await setDBValue(`games/${dbId}/save.json`, ['#all'], {})
if (!preExistingDbId) {
await setDBValue(`games/${dbId}/record.json`, ['addDate'], new Date().toISOString())
await setDBValue(`games/${dbId}/launcher.json`, ['#all'], {})
await setDBValue(`games/${dbId}/path.json`, ['#all'], {})
await setDBValue(`games/${dbId}/save.json`, ['#all'], {})
}

const mainWindow = BrowserWindow.getAllWindows()[0]

Expand Down
6 changes: 3 additions & 3 deletions src/main/adder/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import log from 'electron-log/main.js'
export async function addGameToDatabase({
dataSource,
id,
dbId,
preExistingDbId,
screenshotUrl,
playingTime
}: {
dataSource: string
id: string
dbId?: string
preExistingDbId?: string
screenshotUrl?: string
playingTime?: number
}): Promise<void> {
try {
await addGameToDB({ dataSource, id, dbId, screenshotUrl, playingTime })
await addGameToDB({ dataSource, id, preExistingDbId, screenshotUrl, playingTime })
} catch (error) {
log.error('Error adding game to database:', error)
throw error
Expand Down
6 changes: 3 additions & 3 deletions src/main/ipc/adder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ export function setupAdderIPC(mainWindow: BrowserWindow): void {
{
dataSource,
id,
dbId,
preExistingDbId,
screenshotUrl
}: {
dataSource: string
id: string
dbId?: string
preExistingDbId?: string
screenshotUrl?: string
}
) => {
await addGameToDatabase({ dataSource, id, dbId, screenshotUrl })
await addGameToDatabase({ dataSource, id, preExistingDbId, screenshotUrl })
}
)

Expand Down
2 changes: 1 addition & 1 deletion src/renderer/src/pages/GameAdder/ScreenshotList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function ScreenshotList(): JSX.Element {
setIsAdding(true)
toast.promise(
(async (): Promise<void> => {
await ipcInvoke('add-game-to-db', { dataSource, id, dbId, screenshotUrl })
await ipcInvoke('add-game-to-db', { dataSource, id, preExistingDbId: dbId, screenshotUrl })
setIsAdding(false)
setIsOpen(false)
setDbId('')
Expand Down

0 comments on commit d507c30

Please sign in to comment.