diff --git a/src/main/events/torrenting/resume-game-download.ts b/src/main/events/torrenting/resume-game-download.ts index 51a81996..fa555199 100644 --- a/src/main/events/torrenting/resume-game-download.ts +++ b/src/main/events/torrenting/resume-game-download.ts @@ -20,7 +20,7 @@ const resumeGameDownload = async ( if (game.status === "paused") { await DownloadManager.pauseDownload(); - await gameRepository.update({ status: "active" }, { status: "paused" }); + await gameRepository.update({ id: gameId }, { status: "active" }); await DownloadManager.resumeDownload(gameId); } diff --git a/src/main/events/torrenting/start-game-download.ts b/src/main/events/torrenting/start-game-download.ts index 62bce369..5a987327 100644 --- a/src/main/events/torrenting/start-game-download.ts +++ b/src/main/events/torrenting/start-game-download.ts @@ -11,6 +11,7 @@ import { getFileBase64, getSteamAppAsset } from "@main/helpers"; import { DownloadManager } from "@main/services"; import { Downloader } from "@shared"; import { stateManager } from "@main/state-manager"; +import { Not } from "typeorm"; const startGameDownload = async ( _event: Electron.IpcMainInvokeEvent, @@ -43,7 +44,10 @@ const startGameDownload = async ( if (!repack || game?.status === "active") return; - await gameRepository.update({ status: "active" }, { status: "paused" }); + await gameRepository.update( + { status: "active", progress: Not(1) }, + { status: "paused" } + ); if (game) { await gameRepository.update( diff --git a/src/main/services/download-manager.ts b/src/main/services/download-manager.ts index 94e19835..25f99543 100644 --- a/src/main/services/download-manager.ts +++ b/src/main/services/download-manager.ts @@ -10,6 +10,8 @@ import { Notification } from "electron"; import { t } from "i18next"; import { Downloader } from "@shared"; import { DownloadProgress } from "@types"; +import { QueryDeepPartialEntity } from "typeorm/query-builder/QueryPartialEntity"; +import { Game } from "@main/entity"; export class DownloadManager { private static downloads = new Map(); @@ -94,17 +96,24 @@ export class DownloadManager { const progress = Number(status.completedLength) / Number(status.totalLength); - await gameRepository.update( - { id: this.gameId }, - { - progress: - isNaN(progress) || downloadingMetadata ? undefined : progress, + if (!downloadingMetadata) { + const update: QueryDeepPartialEntity = { bytesDownloaded: Number(status.completedLength), fileSize: Number(status.totalLength), status: status.status, - folderName: this.getFolderName(status), - } - ); + }; + + if (!isNaN(progress)) update.progress = progress; + + await gameRepository.update( + { id: this.gameId }, + { + ...update, + status: status.status, + folderName: this.getFolderName(status), + } + ); + } const game = await gameRepository.findOne({ where: { id: this.gameId, isDeleted: false }, diff --git a/src/renderer/src/pages/downloads/downloads.tsx b/src/renderer/src/pages/downloads/downloads.tsx index c1c2b811..e18f5bb1 100644 --- a/src/renderer/src/pages/downloads/downloads.tsx +++ b/src/renderer/src/pages/downloads/downloads.tsx @@ -10,7 +10,7 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { BinaryNotFoundModal } from "../shared-modals/binary-not-found-modal"; import * as styles from "./downloads.css"; import { DeleteModal } from "./delete-modal"; -import { Downloader, GameStatus, GameStatusHelper, formatBytes } from "@shared"; +import { Downloader, formatBytes } from "@shared"; export function Downloads() { const { library, updateLibrary } = useLibrary(); @@ -26,6 +26,7 @@ export function Downloads() { const [showDeleteModal, setShowDeleteModal] = useState(false); const { + lastPacket, progress, pauseDownload, resumeDownload, @@ -50,13 +51,13 @@ export function Downloads() { }); const getFinalDownloadSize = (game: Game) => { - const isGameDownloading = gameDownloading?.id === game?.id; + const isGameDownloading = lastPacket?.game.id === game?.id; if (!game) return "N/A"; if (game.fileSize) return formatBytes(game.fileSize); - if (gameDownloading?.fileSize && isGameDownloading) - return formatBytes(gameDownloading.fileSize); + if (lastPacket?.game.fileSize && isGameDownloading) + return formatBytes(lastPacket?.game.fileSize); return game.repack?.fileSize ?? "N/A"; }; @@ -67,7 +68,7 @@ export function Downloads() { }; const getGameInfo = (game: Game) => { - const isGameDownloading = gameDownloading?.id === game?.id; + const isGameDownloading = lastPacket?.game.id === game?.id; const finalDownloadSize = getFinalDownloadSize(game); if (isGameDeleting(game?.id)) { @@ -79,27 +80,21 @@ export function Downloads() { <>

{progress}

- {gameDownloading?.status && - gameDownloading?.status !== GameStatus.Downloading ? ( -

{t(gameDownloading?.status)}

- ) : ( - <> -

- {formatBytes(gameDownloading?.bytesDownloaded)} /{" "} - {finalDownloadSize} -

- {game.downloader === Downloader.Torrent && ( -

- {numPeers} peers / {numSeeds} seeds -

- )} - +

+ {formatBytes(lastPacket?.game.bytesDownloaded)} /{" "} + {finalDownloadSize} +

+ + {game.downloader === Downloader.Torrent && ( +

+ {lastPacket?.numPeers} peers / {lastPacket?.numSeeds} seeds +

)} ); } - if (GameStatusHelper.isReady(game?.status)) { + if (game?.progress === 1) { return ( <>

{game?.repack?.title}

@@ -107,11 +102,9 @@ export function Downloads() { ); } - if (game?.status === GameStatus.Cancelled) return

{t("cancelled")}

; - if (game?.status === GameStatus.DownloadingMetadata) - return

{t("starting_download")}

; + if (game?.status === "removed") return

{t("cancelled")}

; - if (game?.status === GameStatus.Paused) { + if (game?.status === "paused") { return ( <>

{formatDownloadProgress(game.progress)}

@@ -129,7 +122,7 @@ export function Downloads() { }; const getGameActions = (game: Game) => { - const isGameDownloading = gameDownloading?.id === game?.id; + const isGameDownloading = lastPacket?.game.id === game?.id; const deleting = isGameDeleting(game.id); @@ -146,7 +139,7 @@ export function Downloads() { ); } - if (game?.status === GameStatus.Paused) { + if (game?.status === "paused") { return ( <> - ); - } - return ( <>