@@ -209,6 +209,9 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
209209 state : state . downloader . status ,
210210 tasks : state . downloader . getTasks ( ) ,
211211 workers : state . downloader . getWorkerStates ( ) ,
212+ total : state . downloader . getTotal ( ) ,
213+ done : state . downloader . getDone ( ) ,
214+ failures : state . downloader . getFailures ( )
212215 } ;
213216 } ) ;
214217
@@ -2060,6 +2063,62 @@ export function registerRequestCallbacks(state: BackState, init: () => Promise<v
20602063 }
20612064 } ) ;
20622065
2066+ state . socketServer . register ( BackIn . DOWNLOAD_SEARCH_RESULTS , async ( event , query ) => {
2067+ const openDialog = state . socketServer . showMessageBoxBack ( state , event . client ) ;
2068+ const dialogId = openDialog ( {
2069+ largeMessage : true ,
2070+ message : 'Calculating download size of search results...' ,
2071+ buttons : [ ]
2072+ } ) ;
2073+
2074+ const search = fpDatabase . parseUserSearchInput ( '' ) . search ;
2075+ search . limit = 9999999999 ;
2076+ search . filter = query . filter ;
2077+ search . slim = true ;
2078+ search . loadRelations . gameData = true ;
2079+ const games = await fpDatabase . searchGames ( search ) ;
2080+ console . log ( 'Found ' + games . length + ' games' ) ;
2081+
2082+ let totalSize = 0 ;
2083+ for ( const game of games ) {
2084+ if ( game . gameData ) {
2085+ for ( const gd of game . gameData ) {
2086+ if ( ! gd . presentOnDisk ) {
2087+ totalSize += gd . size ;
2088+ }
2089+ }
2090+ }
2091+ }
2092+
2093+ state . socketServer . broadcast ( BackOut . CANCEL_DIALOG , dialogId ) ;
2094+ console . log ( 'size ' + totalSize ) ;
2095+
2096+ if ( totalSize > 0 ) {
2097+ // Estimated size larger than 0B, ask the user before downloading
2098+ const humanReadableSize = sizeToString ( totalSize ) ;
2099+
2100+ const dialogId = state . socketServer . showMessageBoxBack ( state , event . client ) ( {
2101+ message : `Downloading these search results requires approximately ${ humanReadableSize } of additional space. Continue?` ,
2102+ buttons : [ state . languageContainer . misc . yes , state . languageContainer . misc . no ] ,
2103+ cancelId : 1 ,
2104+ largeMessage : true ,
2105+ } ) ;
2106+ const result = ( await awaitDialog ( state , dialogId ) ) . buttonIdx ;
2107+
2108+ if ( result === 1 ) {
2109+ log . debug ( 'Downloads' , 'User aborted search results download at size prompt' ) ;
2110+ return ;
2111+ }
2112+ } else {
2113+ return ;
2114+ }
2115+
2116+ state . downloader . addTasks ( games ) ;
2117+ if ( state . downloader . status !== 'running' ) {
2118+ state . downloader . start ( ) ;
2119+ }
2120+ } ) ;
2121+
20632122 state . socketServer . register ( BackIn . EXPORT_META_EDIT , async ( event , id , properties ) => {
20642123 const game = await fpDatabase . findGame ( id ) ;
20652124 if ( game ) {
0 commit comments