2012-05-06 12:59:58 +02:00
# include <unistd.h>
2009-11-22 15:09:08 +01:00
# include "menus.h"
2012-05-06 12:59:58 +02:00
# include "GameCube/GCGames.h"
# include "GameCube/GCDumper.hpp"
2010-02-22 22:29:47 +01:00
# include "usbloader/usbstorage2.h"
2009-11-22 15:09:08 +01:00
# include "usbloader/wbfs.h"
# include "usbloader/disc.h"
2010-09-18 13:46:25 +02:00
# include "usbloader/GameList.h"
2009-11-22 15:09:08 +01:00
# include "prompts/ProgressWindow.h"
2012-05-06 12:59:58 +02:00
# include "prompts/GCMultiDiscMenu.h"
2010-09-26 10:33:43 +02:00
# include "themes/CTheme.h"
2012-02-09 22:18:16 +01:00
# include "utils/tools.h"
2012-06-27 22:01:37 +02:00
# include "system/IosLoader.h"
2020-12-12 22:33:31 +01:00
# include "cache/cache.hpp"
2009-11-22 15:09:08 +01:00
2012-05-06 12:59:58 +02:00
# define WII_MAGIC 0x5D1C9EA3
2011-12-28 17:27:30 +01:00
extern int install_abort_signal ;
float gamesize = 0.0f ;
2009-11-22 15:09:08 +01:00
/****************************************************************************
2012-05-06 12:59:58 +02:00
* MenuGCInstall
2009-11-22 15:09:08 +01:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2012-05-06 12:59:58 +02:00
int MenuGCInstall ( )
{
GCDumper gcDumper ;
if ( gcDumper . ReadDiscHeader ( ) < 0 )
{
WindowPrompt ( tr ( " Error " ) , tr ( " Error reading disc " ) , tr ( " OK " ) ) ;
return MENU_DISCLIST ;
}
std : : vector < u32 > installGames ;
if ( gcDumper . GetDiscHeaders ( ) . size ( ) = = 0 )
{
WindowPrompt ( tr ( " Error " ) , tr ( " No games found on the disc " ) , tr ( " OK " ) ) ;
return MENU_DISCLIST ;
}
else if ( gcDumper . GetDiscHeaders ( ) . size ( ) > 1 )
{
//! Multi game disc, lets ask the user which games to install
GCMultiDiscMenu gcMenu ( gcDumper . GetDiscHeaders ( ) ) ;
gcMenu . SetAlignment ( ALIGN_CENTER , ALIGN_MIDDLE ) ;
gcMenu . SetEffect ( EFFECT_FADE , 20 ) ;
mainWindow - > SetState ( STATE_DISABLED ) ;
mainWindow - > Append ( & gcMenu ) ;
int choice = gcMenu . ShowSelection ( ) ;
gcMenu . SetEffect ( EFFECT_FADE , - 20 ) ;
while ( gcMenu . GetEffect ( ) > 0 ) usleep ( 1000 ) ;
2009-11-22 15:09:08 +01:00
2012-05-06 12:59:58 +02:00
mainWindow - > Remove ( & gcMenu ) ;
mainWindow - > SetState ( STATE_DEFAULT ) ;
installGames = gcMenu . GetSelectedGames ( ) ;
if ( choice = = 0 | | installGames . size ( ) = = 0 )
return MENU_DISCLIST ;
}
else
{
if ( ! WindowPrompt ( tr ( " Continue to install game? " ) , gcDumper . GetDiscHeaders ( ) . at ( 0 ) . title , tr ( " Yes " ) , tr ( " Cancel " ) ) )
return MENU_DISCLIST ;
installGames . push_back ( 0 ) ;
}
//! setup dumper settings
gcDumper . SetCompressed ( Settings . GCInstallCompressed ) ;
gcDumper . SetCompressed ( Settings . GCInstallAligned ) ;
2012-12-09 21:31:55 +01:00
//! If a different main path than the SD path is selected ask where to install
2012-05-06 12:59:58 +02:00
int destination = 1 ;
if ( strcmp ( Settings . GameCubePath , Settings . GameCubeSDPath ) ! = 0 )
destination = WindowPrompt ( tr ( " Where should the game be installed to? " ) , 0 , tr ( " Main Path " ) , tr ( " SD Path " ) , tr ( " Cancel " ) ) ;
if ( ! destination )
return MENU_DISCLIST ;
2012-06-27 22:01:37 +02:00
//! Alert the user if he is dumping on SD with DIOS MIOS (USB) installed
if ( destination = = 2 & & IosLoader : : GetMIOSInfo ( ) = = DIOS_MIOS )
{
if ( ! WindowPrompt ( tr ( " Are you sure you want to install on SD? " ) , ( " You have DIOS-MIOS installed so the game need to be on a FAT32 USB. You will need to install DIOS-MIOS Lite to run this game from SD. " ) , tr ( " Yes " ) , tr ( " Cancel " ) ) )
return MENU_DISCLIST ;
}
2012-05-06 12:59:58 +02:00
2012-12-09 22:36:32 +01:00
// Load only available games from the selected device
int oldGameCubeSource = Settings . GameCubeSource ;
Settings . GameCubeSource = destination - 1 ;
GCGames : : Instance ( ) - > LoadAllGames ( ) ;
2012-05-06 12:59:58 +02:00
const char * InstallPath = destination = = 1 ? Settings . GameCubePath : Settings . GameCubeSDPath ;
//! Start of install process, enable wii slot light
wiilight ( 1 ) ;
int result = 0 ;
int installed_games = 0 ;
for ( u32 i = 0 ; i < installGames . size ( ) ; + + i )
{
//! check if the game is already installed on SD/USB
2012-12-09 21:31:55 +01:00
if ( GCGames : : Instance ( ) - > IsInstalled ( ( char * ) gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . id , gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . disc_no ) )
2012-05-06 12:59:58 +02:00
{
WindowPrompt ( tr ( " Game is already installed: " ) , gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . title , tr ( " OK " ) ) ;
if ( i + 1 < installGames . size ( ) ) {
continue ;
}
else if ( i = = 0 )
{
result = MENU_DISCLIST ;
break ;
}
}
2012-12-09 21:31:55 +01:00
// Check Disc2 installation format (DML 2.6+ auto-swap feature doesn't work with extracted game format)
if ( Settings . GCInstallCompressed & & gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . disc_no = = 1 )
{
int choice = WindowPrompt ( tr ( gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . title ) , tr ( " Disc2 needs to be installed in uncompressed format to work with DM(L) v2.6+, are you sure you want to install in compressed format? " ) , tr ( " Yes " ) , tr ( " Cancel " ) ) ;
if ( choice = = 0 )
{
if ( i + 1 < installGames . size ( ) ) {
continue ;
}
else if ( i = = 0 )
{
result = MENU_DISCLIST ;
break ;
}
}
}
2012-12-09 22:36:32 +01:00
// Check if another Disc number from the same game is already installed on this device
GCGames : : Instance ( ) - > LoadAllGames ( ) ; // refresh installed game list
char installedGamePath [ 512 ] ;
if ( GCGames : : Instance ( ) - > IsInstalled ( ( char * ) gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . id , gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . disc_no = = 0 ? 1 : 0 ) )
{
snprintf ( installedGamePath , sizeof ( installedGamePath ) , GCGames : : Instance ( ) - > GetPath ( ( char * ) gcDumper . GetDiscHeaders ( ) . at ( installGames [ i ] ) . id ) ) ;
char * pathPtr = strrchr ( installedGamePath , ' / ' ) ;
if ( pathPtr ) * pathPtr = 0 ;
}
else
installedGamePath [ 0 ] = 0 ;
2012-05-06 12:59:58 +02:00
// game is not yet installed so let's install it
2012-12-09 22:36:32 +01:00
int ret = gcDumper . InstallGame ( InstallPath , installGames [ i ] , installedGamePath ) ;
2012-05-06 12:59:58 +02:00
if ( ret > = 0 ) {
//! success
installed_games + + ;
}
else if ( ret = = PROGRESS_CANCELED )
{
result = MENU_DISCLIST ;
break ;
}
else if ( ret < 0 )
{
//! Error occured, ask the user what to do if there are more games to install
if ( i + 1 < installGames . size ( ) )
{
if ( ! WindowPrompt ( tr ( " Install Error! " ) , tr ( " Do you want to continue with next game? " ) , tr ( " Yes " ) , tr ( " Cancel " ) ) )
{
result = MENU_DISCLIST ;
break ;
}
}
else
{
WindowPrompt ( tr ( " Install Error! " ) , 0 , tr ( " Back " ) ) ;
result = MENU_DISCLIST ;
break ;
}
}
}
wiilight ( 0 ) ;
2012-12-09 22:36:32 +01:00
Settings . GameCubeSource = oldGameCubeSource ;
2012-05-06 12:59:58 +02:00
GCGames : : Instance ( ) - > LoadAllGames ( ) ;
//! no game was installed so don't show successfully installed prompt
if ( installed_games = = 0 )
return result ;
2012-05-09 21:27:54 +02:00
gameList . FilterList ( ) ;
2012-05-06 12:59:58 +02:00
bgMusic - > Pause ( ) ;
GuiSound instsuccess ( Resources : : GetFile ( " success.ogg " ) , Resources : : GetFileSize ( " success.ogg " ) , Settings . sfxvolume ) ;
instsuccess . SetVolume ( Settings . sfxvolume ) ;
instsuccess . SetLoop ( 0 ) ;
instsuccess . Play ( ) ;
char gamesTxt [ 20 ] ;
snprintf ( gamesTxt , sizeof ( gamesTxt ) , " %i %s " , installed_games , tr ( " Games " ) ) ;
WindowPrompt ( tr ( " Successfully installed: " ) , installGames . size ( ) > 1 ? gamesTxt : gcDumper . GetDiscHeaders ( ) . at ( installGames [ 0 ] ) . title , tr ( " OK " ) ) ;
instsuccess . Stop ( ) ;
bgMusic - > Resume ( ) ;
return MENU_DISCLIST ;
}
/****************************************************************************
* MenuInstall
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2010-09-19 01:16:05 +02:00
int MenuInstall ( )
{
2012-05-06 12:59:58 +02:00
gprintf ( " \n MenuInstall() \n " ) ;
2011-07-26 00:28:22 +02:00
static struct discHdr headerdisc ATTRIBUTE_ALIGN ( 32 ) ;
Disc_SetUSB ( NULL ) ;
int ret , choice = 0 ;
ret = DiscWait ( tr ( " Insert Disk " ) , tr ( " Waiting... " ) , tr ( " Cancel " ) , 0 , 0 ) ;
if ( ret < 0 )
{
WindowPrompt ( tr ( " Error reading Disc " ) , 0 , tr ( " Back " ) ) ;
return MENU_DISCLIST ;
}
ret = Disc_Open ( ) ;
if ( ret < 0 )
{
WindowPrompt ( tr ( " Could not open Disc " ) , 0 , tr ( " Back " ) ) ;
return MENU_DISCLIST ;
}
2012-05-06 12:59:58 +02:00
memset ( & headerdisc , 0 , sizeof ( struct discHdr ) ) ;
Disc_ReadHeader ( & headerdisc ) ;
2011-07-26 00:28:22 +02:00
2012-05-06 12:59:58 +02:00
if ( ( headerdisc . magic ! = WII_MAGIC ) & & ( headerdisc . gc_magic ! = GCGames : : MAGIC ) )
{
2019-11-11 21:00:00 +01:00
choice = WindowPrompt ( tr ( " Not a Wii or a GameCube Disc " ) , tr ( " Insert a Wii or a GameCube Disc! " ) , tr ( " OK " ) , tr ( " Back " ) ) ;
2011-07-26 00:28:22 +02:00
if ( choice = = 1 )
2011-12-28 17:27:30 +01:00
return MenuInstall ( ) ;
2011-07-26 00:28:22 +02:00
else
return MENU_DISCLIST ;
}
2012-05-06 12:59:58 +02:00
if ( headerdisc . gc_magic = = GCGames : : MAGIC )
{
return MenuGCInstall ( ) ;
}
2011-07-26 00:28:22 +02:00
ret = WBFS_CheckGame ( headerdisc . id ) ;
if ( ret )
{
2012-05-06 12:59:58 +02:00
WindowPrompt ( tr ( " Game is already installed: " ) , headerdisc . title , tr ( " Back " ) ) ;
2011-07-26 00:28:22 +02:00
return MENU_DISCLIST ;
}
f32 freespace , used ;
WBFS_DiskSpace ( & used , & freespace ) ;
2011-12-28 17:27:30 +01:00
gamesize = ( float ) WBFS_EstimeGameSize ( ) ;
2011-07-26 00:28:22 +02:00
2012-05-06 12:59:58 +02:00
char gametxt [ strlen ( headerdisc . title ) + 16 ] ;
snprintf ( gametxt , sizeof ( gametxt ) , " %s : %.2fGB " , headerdisc . title , gamesize / GB_SIZE ) ;
2011-07-26 00:28:22 +02:00
wiilight ( 1 ) ;
choice = WindowPrompt ( tr ( " Continue to install game? " ) , gametxt , tr ( " OK " ) , tr ( " Cancel " ) ) ;
if ( choice = = 1 )
{
sprintf ( gametxt , " %s " , tr ( " Installing game: " ) ) ;
if ( gamesize / GB_SIZE > freespace )
{
char errortxt [ 50 ] ;
sprintf ( errortxt , " %s: %.2fGB, %s: %.2fGB " , tr ( " Game Size " ) , gamesize / GB_SIZE , tr ( " Free Space " ) , freespace ) ;
WindowPrompt ( tr ( " Not enough free space! " ) , errortxt , tr ( " OK " ) ) ;
}
else
{
2012-05-06 12:59:58 +02:00
StartProgress ( gametxt , headerdisc . title , 0 , true , true ) ;
2011-12-28 17:27:30 +01:00
ProgressCancelEnable ( true ) ;
2011-07-26 00:28:22 +02:00
ret = WBFS_AddGame ( ) ;
2011-12-28 17:27:30 +01:00
ProgressCancelEnable ( false ) ;
2011-07-26 00:28:22 +02:00
ProgressStop ( ) ;
wiilight ( 0 ) ;
2011-12-28 17:27:30 +01:00
if ( install_abort_signal )
{
WindowPrompt ( tr ( " Install Canceled " ) , 0 , tr ( " OK " ) ) ;
}
else if ( ret ! = 0 )
2011-07-26 00:28:22 +02:00
{
WindowPrompt ( tr ( " Install Error! " ) , 0 , tr ( " Back " ) ) ;
}
else
{
2012-05-06 12:59:58 +02:00
ShowProgress ( tr ( " Install finished " ) , headerdisc . title , tr ( " Reloading game list now, please wait... " ) , gamesize , gamesize , true , true ) ;
2020-12-12 22:33:31 +01:00
ResetGameHeaderCache ( ) ;
2011-07-26 00:28:22 +02:00
gameList . ReadGameList ( ) ; //get the entries again
gameList . FilterList ( ) ;
bgMusic - > Pause ( ) ;
2012-05-06 12:59:58 +02:00
GuiSound instsuccess ( Resources : : GetFile ( " success.ogg " ) , Resources : : GetFileSize ( " success.ogg " ) , Settings . sfxvolume ) ;
instsuccess . SetVolume ( Settings . sfxvolume ) ;
instsuccess . SetLoop ( 0 ) ;
instsuccess . Play ( ) ;
WindowPrompt ( tr ( " Successfully installed: " ) , headerdisc . title , tr ( " OK " ) ) ;
instsuccess . Stop ( ) ;
2011-07-26 00:28:22 +02:00
bgMusic - > Resume ( ) ;
}
}
}
//Turn off the WiiLight
wiilight ( 0 ) ;
2011-12-28 17:27:30 +01:00
gamesize = 0.0f ;
2011-07-26 00:28:22 +02:00
return MENU_DISCLIST ;
2009-11-22 15:09:08 +01:00
}