2012-08-05 19:07:47 +02:00
/****************************************************************************
* Copyright ( C ) 2011 Dimok
* Copyright ( C ) 2012 Cyan
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation , either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program . If not , see < http : //www.gnu.org/licenses/>.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-02-03 22:46:54 +01:00
# include <gccore.h>
# include <string.h>
# include "ImageDownloader.h"
# include "network/networkops.h"
# include "prompts/PromptWindows.h"
# include "prompts/ProgressWindow.h"
# include "prompts/CheckboxPrompt.hpp"
# include "FileOperations/fileops.h"
# include "settings/CSettings.h"
# include "settings/GameTitles.h"
# include "language/gettext.h"
# include "usbloader/GetMissingGameFiles.hpp"
# include "utils/StringTools.h"
2023-01-01 18:00:15 +01:00
# include "usbloader/GameList.h"
2023-01-01 18:00:16 +01:00
# include "wstring.hpp"
2011-02-03 22:46:54 +01:00
# include "gecko.h"
2019-11-11 18:09:59 +01:00
# define VALID_IMAGE(x) (!(x->size == 36864 || x->size <= 1024 || x->size == 7386 || x->size <= 1174 || x->size == 4446 || x->data == NULL))
2011-02-03 22:46:54 +01:00
void ImageDownloader : : DownloadImages ( )
{
2020-07-09 03:11:59 +02:00
bool showBanner = ( Settings . LoaderMode & MODE_GCGAMES ) ;
2012-08-05 19:07:47 +02:00
2023-01-01 18:00:16 +01:00
int choice = CheckboxWindow ( tr ( " Cover Download " ) , 0 , tr ( " 3D Covers " ) , tr ( " Flat Covers " ) , tr ( " Full Covers " ) , tr ( " Disc Artwork " ) , showBanner ? tr ( " Custom Banners " ) : 0 , 0 , showBanner ? 0x1F : 0xF ) ; // ask for download choice
2011-12-22 23:44:48 +01:00
if ( choice = = 0 | | choice = = CheckedNone )
2011-07-26 00:28:22 +02:00
return ;
2011-02-03 22:46:54 +01:00
2011-07-26 00:28:22 +02:00
ImageDownloader Downloader ;
Downloader . SetChoices ( choice ) ;
Downloader . Start ( ) ;
2011-02-03 22:46:54 +01:00
}
void ImageDownloader : : Start ( )
{
2011-07-26 00:28:22 +02:00
gprintf ( " CoverDownload start - choices: %04X \n " , choices ) ;
2011-02-03 22:46:54 +01:00
2011-07-26 00:28:22 +02:00
MissingImagesCount = 0 ;
FindMissingImages ( ) ;
2011-02-03 22:46:54 +01:00
2011-07-26 00:28:22 +02:00
if ( MissingImagesCount = = 0 )
{
2023-01-01 18:00:16 +01:00
WindowPrompt ( tr ( " No files missing! " ) , 0 , tr ( " OK " ) ) ;
2011-07-26 00:28:22 +02:00
return ;
}
2011-02-03 22:46:54 +01:00
2011-07-26 00:28:22 +02:00
u32 TotalDownloadCount = MissingImagesCount ;
2011-02-03 22:46:54 +01:00
2023-01-01 18:00:16 +01:00
if ( WindowPrompt ( tr ( " Found missing images " ) , fmt ( tr ( " %i missing files " ) , TotalDownloadCount ) , tr ( " Yes " ) , tr ( " No " ) ) = = 0 )
2011-07-26 00:28:22 +02:00
return ;
2011-02-03 22:46:54 +01:00
2011-07-26 00:28:22 +02:00
if ( ! IsNetworkInit ( ) & & ! NetworkInitPrompt ( ) )
{
gprintf ( " No network \n " ) ;
return ;
}
2011-02-03 22:46:54 +01:00
2011-10-01 12:41:00 +02:00
ProgressCancelEnable ( true ) ;
2011-02-03 22:46:54 +01:00
2011-07-26 00:28:22 +02:00
DownloadProcess ( TotalDownloadCount ) ;
2011-02-03 22:46:54 +01:00
2011-10-01 12:41:00 +02:00
ProgressCancelEnable ( false ) ;
2011-07-26 00:28:22 +02:00
ProgressStop ( ) ;
2011-02-03 22:46:54 +01:00
2011-07-26 00:28:22 +02:00
if ( MissingImagesCount = = 0 )
WindowPrompt ( tr ( " Download finished " ) , tr ( " All images downloaded successfully. " ) , tr ( " OK " ) ) ;
else
{
int res = WindowPrompt ( tr ( " Download finished " ) , fmt ( tr ( " %i files not found on the server! " ) , MissingImagesCount ) , tr ( " Save List " ) , tr ( " OK " ) ) ;
if ( res )
CreateCSVLog ( ) ;
}
2011-02-03 22:46:54 +01:00
}
void ImageDownloader : : FindMissingImages ( )
{
2023-01-01 18:00:15 +01:00
wString oldFilter ( gameList . GetCurrentFilter ( ) ) ;
// Make sure that all games are added to the gamelist
gameList . LoadUnfiltered ( ) ;
2011-07-26 00:28:22 +02:00
if ( choices & CheckedBox1 )
2020-07-09 03:11:59 +02:00
FindMissing ( Settings . covers_path , Settings . URL_Covers3D , NULL , tr ( " Downloading 3D Covers " ) , NULL , " .png " ) ;
2011-07-26 00:28:22 +02:00
if ( choices & CheckedBox2 )
2020-07-09 03:11:59 +02:00
FindMissing ( Settings . covers2d_path , Settings . URL_Covers2D , NULL , tr ( " Downloading Flat Covers " ) , NULL , " .png " ) ;
2011-07-26 00:28:22 +02:00
if ( choices & CheckedBox3 )
2012-08-05 19:07:47 +02:00
{
2020-07-09 03:11:59 +02:00
const char * downloadURL = ( Settings . coversfull = = COVERSFULL_HQ | | Settings . coversfull = = COVERSFULL_HQ_LQ ) ? Settings . URL_CoversFullHQ : Settings . URL_CoversFull ;
2012-08-05 19:07:47 +02:00
const char * progressTitle = ( Settings . coversfull = = COVERSFULL_HQ | | Settings . coversfull = = COVERSFULL_HQ_LQ ) ? tr ( " Downloading Full HQ Covers " ) : tr ( " Downloading Full LQ Covers " ) ;
2020-07-09 03:11:59 +02:00
const char * backupURL = ( Settings . coversfull = = COVERSFULL_HQ_LQ | | Settings . coversfull = = COVERSFULL_LQ_HQ ) ? ( ( Settings . coversfull = = COVERSFULL_HQ_LQ ) ? Settings . URL_CoversFull : Settings . URL_CoversFullHQ ) : NULL ;
2012-08-05 19:07:47 +02:00
const char * backupProgressTitle = ( Settings . coversfull = = COVERSFULL_HQ_LQ | | Settings . coversfull = = COVERSFULL_LQ_HQ ) ? ( ( Settings . coversfull = = COVERSFULL_HQ_LQ ) ? tr ( " Downloading Full LQ Covers " ) : tr ( " Downloading Full HQ Covers " ) ) : NULL ;
FindMissing ( Settings . coversFull_path , downloadURL , backupURL , progressTitle , backupProgressTitle , " .png " ) ;
}
2011-07-26 00:28:22 +02:00
if ( choices & CheckedBox4 )
{
2020-07-09 03:11:59 +02:00
const char * downloadURL = ( Settings . discart = = DISCARTS_ORIGINALS | | Settings . discart = = DISCARTS_ORIGINALS_CUSTOMS ) ? Settings . URL_Discs : Settings . URL_DiscsCustom ;
2023-01-01 18:00:16 +01:00
const char * progressTitle = ( Settings . discart = = DISCARTS_ORIGINALS | | Settings . discart = = DISCARTS_ORIGINALS_CUSTOMS ) ? tr ( " Downloading Original Disc Artwork " ) : tr ( " Downloading Custom Disc Artwork " ) ;
2020-07-09 03:11:59 +02:00
const char * backupURL = ( Settings . discart = = DISCARTS_ORIGINALS_CUSTOMS | | Settings . discart = = DISCARTS_CUSTOMS_ORIGINALS ) ? ( ( Settings . discart = = DISCARTS_ORIGINALS_CUSTOMS ) ? Settings . URL_DiscsCustom : Settings . URL_Discs ) : NULL ;
2023-01-01 18:00:16 +01:00
const char * backupProgressTitle = ( Settings . discart = = DISCARTS_ORIGINALS_CUSTOMS | | Settings . discart = = DISCARTS_CUSTOMS_ORIGINALS ) ? ( ( Settings . discart = = DISCARTS_ORIGINALS_CUSTOMS ) ? tr ( " Downloading Custom Disc Artwork " ) : tr ( " Downloading Original Disc Artwork " ) ) : NULL ;
2012-08-05 19:07:47 +02:00
FindMissing ( Settings . disc_path , downloadURL , backupURL , progressTitle , backupProgressTitle , " .png " ) ;
2011-07-26 00:28:22 +02:00
}
2012-08-05 19:07:47 +02:00
if ( choices & CheckedBox5 )
2011-07-26 00:28:22 +02:00
{
2020-07-09 03:11:59 +02:00
FindMissing ( Settings . BNRCachePath , Settings . URL_Banners , NULL , tr ( " Downloading Custom Banners " ) , NULL , " .bnr " ) ;
2011-07-26 00:28:22 +02:00
}
2023-01-01 18:00:15 +01:00
// Bring the game list back to it's old state
gameList . FilterList ( oldFilter . c_str ( ) ) ;
2011-02-03 22:46:54 +01:00
}
2012-08-05 19:07:47 +02:00
void ImageDownloader : : FindMissing ( const char * writepath , const char * downloadURL , const char * backupURL , const char * progressTitle , const char * backupProgressTitle , const char * fileExt )
2011-02-03 22:46:54 +01:00
{
2011-07-26 00:28:22 +02:00
if ( ! CreateSubfolder ( writepath ) )
{
WindowPrompt ( tr ( " Error ! " ) , fmt ( " %s %s " , tr ( " Can't create directory " ) , writepath ) , tr ( " OK " ) ) ;
return ;
}
std : : vector < std : : string > MissingFilesList ;
2023-01-01 18:00:15 +01:00
GetMissingGameFiles ( writepath , fileExt , MissingFilesList ) ;
2011-07-26 00:28:22 +02:00
int size = MissingImages . size ( ) ;
MissingImages . resize ( size + MissingFilesList . size ( ) ) ;
for ( u32 i = 0 , n = size ; i < MissingFilesList . size ( ) ; + + i , + + n )
{
MissingImages [ n ] . gameID = MissingFilesList [ i ] ;
MissingImages [ n ] . downloadURL = downloadURL ;
MissingImages [ n ] . backupURL = backupURL ;
MissingImages [ n ] . writepath = writepath ;
MissingImages [ n ] . progressTitle = progressTitle ;
2012-08-05 19:07:47 +02:00
MissingImages [ n ] . backupProgressTitle = backupProgressTitle ;
MissingImages [ n ] . fileExt = fileExt ;
2011-07-26 00:28:22 +02:00
}
MissingImagesCount + = MissingFilesList . size ( ) ;
2011-02-03 22:46:54 +01:00
}
int ImageDownloader : : DownloadProcess ( int TotalDownloadCount )
{
2020-07-09 03:11:59 +02:00
char progressMsg [ 270 ] ;
2012-08-05 19:07:47 +02:00
2011-07-26 00:28:22 +02:00
for ( u32 i = 0 , pos = 0 ; i < MissingImages . size ( ) ; + + i , + + pos )
{
2011-10-01 12:41:00 +02:00
if ( ProgressCanceled ( ) )
2011-07-26 00:28:22 +02:00
break ;
2012-08-05 19:07:47 +02:00
if ( strcmp ( MissingImages [ i ] . fileExt , " .bnr " ) = = 0 )
2020-07-09 03:11:59 +02:00
{
char * path = strchr ( MissingImages [ i ] . downloadURL + ( ( strncmp ( Settings . URL_Banners , " https:// " , 8 ) = = 0 ) ? 8 : 7 ) , ' / ' ) ;
int domainlength = path - Settings . URL_Banners ;
char domain [ domainlength + 1 ] ;
strlcpy ( domain , Settings . URL_Banners , domainlength + 1 ) ;
2012-08-05 19:07:47 +02:00
snprintf ( progressMsg , sizeof ( progressMsg ) , " %s : %s.bnr " , domain , MissingImages [ i ] . gameID . c_str ( ) ) ;
2020-07-09 03:11:59 +02:00
}
2012-08-05 19:07:47 +02:00
else
2020-07-09 03:11:59 +02:00
{
char * path = strchr ( MissingImages [ i ] . downloadURL + ( ( strncmp ( MissingImages [ i ] . downloadURL , " https:// " , 8 ) = = 0 ) ? 8 : 7 ) , ' / ' ) ;
int domainlength = path - MissingImages [ i ] . downloadURL ;
char domain [ domainlength + 1 ] ;
strlcpy ( domain , MissingImages [ i ] . downloadURL , domainlength + 1 ) ;
snprintf ( progressMsg , sizeof ( progressMsg ) , " %s : %s.png " , domain , MissingImages [ i ] . gameID . c_str ( ) ) ;
}
2011-07-26 00:28:22 +02:00
ShowProgress ( MissingImages [ i ] . progressTitle , fmt ( " %i %s " , TotalDownloadCount - pos , tr ( " files left " ) ) , progressMsg , pos , TotalDownloadCount ) ;
2012-08-05 19:07:47 +02:00
if ( MissingImages [ i ] . gameID . size ( ) < 3 )
2011-07-26 00:28:22 +02:00
continue ;
2023-01-01 18:00:16 +01:00
gprintf ( " Searching for %s%s \n " , MissingImages [ i ] . gameID . c_str ( ) , MissingImages [ i ] . fileExt ) ;
2019-11-11 18:09:59 +01:00
struct download file = { } ;
DownloadImage ( MissingImages [ i ] . downloadURL , MissingImages [ i ] . gameID . c_str ( ) , MissingImages [ i ] . fileExt , & file ) ;
if ( file . size < = 0 )
2011-07-26 00:28:22 +02:00
{
if ( MissingImages [ i ] . backupURL )
{
2023-01-01 18:00:16 +01:00
gprintf ( " Trying backup URL \n " ) ;
2012-08-05 19:07:47 +02:00
MissingImages [ i ] . downloadURL = MissingImages [ i ] . backupURL ;
MissingImages [ i ] . backupURL = NULL ;
MissingImages [ i ] . progressTitle = MissingImages [ i ] . backupProgressTitle ;
2011-07-26 00:28:22 +02:00
- - i ;
- - pos ;
}
continue ;
}
char imgPath [ 200 ] ;
2012-08-05 19:07:47 +02:00
snprintf ( imgPath , sizeof ( imgPath ) , " %s/%s%s " , MissingImages [ i ] . writepath , MissingImages [ i ] . gameID . c_str ( ) , MissingImages [ i ] . fileExt ) ;
2011-07-26 00:28:22 +02:00
FILE * pfile = fopen ( imgPath , " wb " ) ;
if ( pfile ! = NULL )
{
fwrite ( file . data , 1 , file . size , pfile ) ;
fclose ( pfile ) ;
MissingImagesCount - - ;
}
2020-11-08 22:29:44 +01:00
MEM2_free ( file . data ) ;
2023-01-01 18:00:16 +01:00
gprintf ( " - Saved %s%s \n " , MissingImages [ i ] . gameID . c_str ( ) , MissingImages [ i ] . fileExt ) ;
2011-07-26 00:28:22 +02:00
//! Remove the image from the vector since it's done
MissingImages . erase ( MissingImages . begin ( ) + i ) ;
- - i ;
}
return MissingImages . size ( ) ;
2011-02-03 22:46:54 +01:00
}
2019-11-11 18:09:59 +01:00
void ImageDownloader : : DownloadImage ( const char * url , const char * gameID , const char * fileExt , struct download * file )
2011-02-03 22:46:54 +01:00
{
2023-01-01 18:00:16 +01:00
char region [ 3 ] ;
2011-07-26 00:28:22 +02:00
char downloadURL [ 512 ] ;
2012-08-05 19:07:47 +02:00
if ( strcmp ( fileExt , " .bnr " ) = = 0 )
{
snprintf ( downloadURL , sizeof ( downloadURL ) , " %s%s.bnr " , url , gameID ) ;
2023-01-01 18:00:16 +01:00
gprintf ( " - Trying: %s \n " , downloadURL ) ;
2019-11-11 18:09:59 +01:00
downloadfile ( downloadURL , file ) ;
if ( file - > size > 132 & & IsValidBanner ( file - > data ) ) // 132 = IMET magic location in the banner with u8 header
return ;
2012-08-05 19:07:47 +02:00
snprintf ( downloadURL , sizeof ( downloadURL ) , " %s%.3s.bnr " , url , gameID ) ;
2023-01-01 18:00:16 +01:00
gprintf ( " - Trying ID3: %s \n " , downloadURL ) ;
2019-11-11 18:09:59 +01:00
downloadfile ( downloadURL , file ) ;
if ( file - > size > 132 & & IsValidBanner ( file - > data ) )
return ;
2012-08-05 19:07:47 +02:00
2023-01-01 18:00:16 +01:00
gprintf ( " - Not found \n " ) ;
2019-11-11 18:09:59 +01:00
return ;
2012-08-05 19:07:47 +02:00
}
2023-01-01 18:00:16 +01:00
// Try to find PAL covers matching the loaders language
2011-07-26 00:28:22 +02:00
switch ( gameID [ 3 ] )
{
2023-01-01 18:00:16 +01:00
case ' P ' : // Europe
case ' D ' : // Germany
case ' F ' : // France
case ' H ' : // Netherlands
case ' I ' : // Italy
case ' L ' : // Japanese import to Europe
case ' M ' : // American import to Europe
case ' R ' : // Russia
case ' S ' : // Spain
case ' U ' : // Australia
case ' V ' : // Scandinavia
case ' X ' : // Europe / USA special releases
case ' Y ' : // Europe / USA special releases
case ' Z ' : // Europe / USA special releases
sprintf ( region , " %.2s " , Settings . db_language ) ;
2011-07-26 00:28:22 +02:00
break ;
2023-01-01 18:00:16 +01:00
case ' E ' : // US
case ' N ' : // Japanese import to US
sprintf ( region , " US " ) ;
2011-07-26 00:28:22 +02:00
break ;
2023-01-01 18:00:16 +01:00
case ' J ' : // Japan
sprintf ( region , " JA " ) ;
2011-07-26 00:28:22 +02:00
break ;
2023-01-01 18:00:16 +01:00
case ' K ' : // Korea
case ' Q ' : // Japanese import to Korea
case ' T ' : // American import to Korea
sprintf ( region , " KO " ) ;
break ;
case ' W ' : // Taiwan / Hong Kong / Macau
sprintf ( region , " ZH " ) ;
2011-07-26 00:28:22 +02:00
break ;
2023-01-01 18:00:16 +01:00
default : // Custom games?
sprintf ( region , " EN " ) ;
2011-07-26 00:28:22 +02:00
}
2023-01-01 18:00:16 +01:00
sprintf ( downloadURL , " %s%s/%s.png " , url , region , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
2019-11-11 18:09:59 +01:00
downloadfile ( downloadURL , file ) ;
2023-01-01 18:00:16 +01:00
if ( VALID_IMAGE ( file ) )
2019-11-11 18:09:59 +01:00
return ;
2011-07-26 00:28:22 +02:00
2023-01-01 18:00:16 +01:00
// Try to find covers matching our systems language
std : : vector < std : : string > v ;
char syslang [ 3 ] = { 0 } ;
switch ( CONF_GetLanguage ( ) )
2011-07-26 00:28:22 +02:00
{
2023-01-01 18:00:16 +01:00
case CONF_LANG_GERMAN :
sprintf ( syslang , " DE " ) ;
break ;
case CONF_LANG_FRENCH :
sprintf ( syslang , " FR " ) ;
break ;
case CONF_LANG_SPANISH :
sprintf ( syslang , " SE " ) ;
break ;
case CONF_LANG_ITALIAN :
sprintf ( syslang , " IT " ) ;
break ;
case CONF_LANG_DUTCH :
sprintf ( syslang , " NL " ) ;
break ;
2011-07-26 00:28:22 +02:00
}
2023-01-01 18:00:16 +01:00
if ( syslang [ 0 ] ! = ' \0 ' & & strncmp ( syslang , region , 2 ) ! = 0 )
2011-07-26 00:28:22 +02:00
{
2023-01-01 18:00:16 +01:00
sprintf ( downloadURL , " %s%s/%s.png " , url , syslang , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
2019-11-11 18:09:59 +01:00
downloadfile ( downloadURL , file ) ;
2023-01-01 18:00:16 +01:00
if ( VALID_IMAGE ( file ) )
2019-11-11 18:09:59 +01:00
return ;
2023-01-01 18:00:16 +01:00
}
2011-07-26 00:28:22 +02:00
2023-01-01 18:00:16 +01:00
// Try to find covers matching the games region e.g. SGWD7K
char gameregion [ 3 ] = { 0 } ;
switch ( gameID [ 3 ] )
{
case ' D ' : // Germany
sprintf ( gameregion , " DE " ) ;
break ;
case ' F ' : // France
sprintf ( gameregion , " FR " ) ;
break ;
case ' H ' : // Netherlands
sprintf ( gameregion , " NL " ) ;
break ;
case ' I ' : // Italy
sprintf ( gameregion , " IT " ) ;
break ;
case ' R ' : // Russia
sprintf ( gameregion , " RU " ) ;
break ;
case ' S ' : // Spain
sprintf ( gameregion , " ES " ) ;
break ;
case ' U ' : // Australia
sprintf ( gameregion , " AU " ) ;
break ;
case ' V ' : // Scandinavia
sprintf ( gameregion , " DK " ) ;
break ;
}
if ( gameregion [ 0 ] ! = ' \0 ' & & strncmp ( gameregion , region , 2 ) ! = 0 & & strncmp ( gameregion , syslang , 2 ) ! = 0 )
{
sprintf ( downloadURL , " %s%s/%s.png " , url , gameregion , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
2019-11-11 18:09:59 +01:00
downloadfile ( downloadURL , file ) ;
2023-01-01 18:00:16 +01:00
if ( VALID_IMAGE ( file ) )
2019-11-11 18:09:59 +01:00
return ;
2023-01-01 18:00:16 +01:00
}
// Might be a special US release
if ( gameID [ 3 ] = = ' X ' | | gameID [ 3 ] = = ' Y ' | | gameID [ 3 ] = = ' Z ' )
{
if ( strncmp ( region , " US " , 2 ) ! = 0 )
2015-11-17 15:41:27 +01:00
{
2023-01-01 18:00:16 +01:00
sprintf ( downloadURL , " %sUS/%s.png " , url , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
2019-11-11 18:09:59 +01:00
downloadfile ( downloadURL , file ) ;
2023-01-01 18:00:16 +01:00
if ( VALID_IMAGE ( file ) )
2019-11-11 18:09:59 +01:00
return ;
2015-11-17 15:41:27 +01:00
}
2011-07-26 00:28:22 +02:00
}
2023-01-01 18:00:16 +01:00
// The game might only have an English cover available
if ( strncmp ( region , " EN " , 2 ) ! = 0 )
{
sprintf ( downloadURL , " %sEN/%s.png " , url , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
downloadfile ( downloadURL , file ) ;
if ( VALID_IMAGE ( file ) )
return ;
}
// Try Finnish and Swedish
if ( gameID [ 3 ] = = ' V ' )
{
snprintf ( downloadURL , sizeof ( downloadURL ) , " %sFI/%s.png " , url , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
downloadfile ( downloadURL , file ) ;
if ( VALID_IMAGE ( file ) )
return ;
snprintf ( downloadURL , sizeof ( downloadURL ) , " %sSE/%s.png " , url , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
downloadfile ( downloadURL , file ) ;
if ( VALID_IMAGE ( file ) )
return ;
}
// Final attempt
snprintf ( downloadURL , sizeof ( downloadURL ) , " %sother/%s.png " , url , gameID ) ;
gprintf ( " - Trying: %s \n " , downloadURL ) ;
downloadfile ( downloadURL , file ) ;
if ( VALID_IMAGE ( file ) )
return ;
gprintf ( " - Not found \n " ) ;
2011-02-03 22:46:54 +01:00
}
void ImageDownloader : : CreateCSVLog ( )
{
2011-07-26 00:28:22 +02:00
char path [ 200 ] ;
snprintf ( path , sizeof ( path ) , " %s/MissingImages.csv " , Settings . update_path ) ;
FILE * f = fopen ( path , " wb " ) ;
if ( ! f ) return ;
const char * ImageType = " 3D Cover " ;
fprintf ( f , " \" ID \" , \" Name \" , \" ImageType \" \n " ) ;
for ( u32 i = 0 ; i < MissingImages . size ( ) ; + + i )
{
2020-07-09 03:11:59 +02:00
if ( MissingImages [ i ] . downloadURL = = Settings . URL_Covers3D )
2011-07-26 00:28:22 +02:00
{
ImageType = " 3D Cover " ;
}
2020-07-09 03:11:59 +02:00
else if ( MissingImages [ i ] . downloadURL = = Settings . URL_Covers2D )
2011-07-26 00:28:22 +02:00
{
ImageType = " 2D Cover " ;
}
2020-07-09 03:11:59 +02:00
else if ( MissingImages [ i ] . downloadURL = = Settings . URL_CoversFullHQ )
2011-07-26 00:28:22 +02:00
{
ImageType = " Full HQ Cover " ;
}
2020-07-09 03:11:59 +02:00
else if ( MissingImages [ i ] . downloadURL = = Settings . URL_CoversFull )
2011-07-26 00:28:22 +02:00
{
ImageType = " Full LQ Cover " ;
}
2020-07-09 03:11:59 +02:00
else if ( MissingImages [ i ] . downloadURL = = Settings . URL_Discs )
2011-07-26 00:28:22 +02:00
{
ImageType = " Original Discart " ;
}
2020-07-09 03:11:59 +02:00
else if ( MissingImages [ i ] . downloadURL = = Settings . URL_DiscsCustom )
2011-07-26 00:28:22 +02:00
{
ImageType = " Custom Discart " ;
}
2020-07-09 03:11:59 +02:00
else if ( MissingImages [ i ] . downloadURL = = Settings . URL_Banners )
2012-08-05 19:07:47 +02:00
{
ImageType = " Custom Banner " ;
}
2011-07-26 00:28:22 +02:00
fprintf ( f , " \" %s \" , \" %s \" , \" %s \" \n " , MissingImages [ i ] . gameID . c_str ( ) , GameTitles . GetTitle ( MissingImages [ i ] . gameID . c_str ( ) ) , ImageType ) ;
2012-08-05 19:07:47 +02:00
gprintf ( " \" %s \" , \" %s \" , \" %s \" \n " , MissingImages [ i ] . gameID . c_str ( ) , GameTitles . GetTitle ( MissingImages [ i ] . gameID . c_str ( ) ) , ImageType ) ;
2011-07-26 00:28:22 +02:00
}
fclose ( f ) ;
2011-02-03 22:46:54 +01:00
}
2012-08-05 19:07:47 +02:00
2019-11-11 18:09:59 +01:00
bool ImageDownloader : : IsValidBanner ( char * banner )
2012-08-05 19:07:47 +02:00
{
if ( ! ( ( * ( u32 * ) ( banner + 64 ) ) = = ' IMET ' ) )
{
if ( ! ( ( * ( u32 * ) ( banner + 128 ) ) = = ' IMET ' ) ) // with U8Archive header
return false ;
}
return true ;
}