2010-11-13 23:34:53 +01:00
/****************************************************************************
* Copyright ( C ) 2010
* by Dimok
*
* This software is provided ' as - is ' , without any express or implied
* warranty . In no event will the authors be held liable for any
* damages arising from the use of this software .
*
* Permission is granted to anyone to use this software for any
* purpose , including commercial applications , and to alter it and
* redistribute it freely , subject to the following restrictions :
*
* 1. The origin of this software must not be misrepresented ; you
* must not claim that you wrote the original software . If you use
* this software in a product , an acknowledgment in the product
* documentation would be appreciated but is not required .
*
* 2. Altered source versions must be plainly marked as such , and
* must not be misrepresented as being the original software .
*
* 3. This notice may not be removed or altered from any source
* distribution .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2011-06-03 22:31:09 +02:00
# include <unistd.h>
2010-11-13 23:34:53 +01:00
# include "GameSettingsMenu.hpp"
# include "themes/CTheme.h"
2012-05-06 12:59:58 +02:00
# include "FileOperations/fileops.h"
2010-11-13 23:34:53 +01:00
# include "prompts/PromptWindows.h"
2011-09-24 01:49:18 +02:00
# include "prompts/ProgressWindow.h"
2011-06-03 22:31:09 +02:00
# include "prompts/CategorySelectPrompt.hpp"
2010-11-13 23:34:53 +01:00
# include "settings/GameTitles.h"
2011-06-03 22:31:09 +02:00
# include "usbloader/GameList.h"
2010-11-13 23:34:53 +01:00
# include "language/gettext.h"
# include "wad/nandtitle.h"
# include "cheats/cheatmenu.h"
2011-01-09 11:45:29 +01:00
# include "GameLoadSM.hpp"
2012-05-06 12:59:58 +02:00
# include "GCGameLoadSM.hpp"
2010-11-13 23:34:53 +01:00
# include "UninstallSM.hpp"
2011-06-03 22:31:09 +02:00
GameSettingsMenu : : GameSettingsMenu ( GameBrowseMenu * parent , struct discHdr * header )
2011-07-26 00:28:22 +02:00
: FlyingButtonsMenu ( GameTitles . GetTitle ( header ) ) , browserMenu ( parent )
2010-11-13 23:34:53 +01:00
{
2011-07-26 00:28:22 +02:00
DiscHeader = header ;
//! Don't switch menu's by default but return to disc window.
2010-12-05 20:09:32 +01:00
ParentMenu = - 2 ;
2010-11-13 23:34:53 +01:00
}
GameSettingsMenu : : ~ GameSettingsMenu ( )
{
}
2011-11-12 19:14:09 +01:00
int GameSettingsMenu : : Execute ( GameBrowseMenu * parent , struct discHdr * header )
2011-06-03 22:31:09 +02:00
{
2011-07-26 00:28:22 +02:00
GameSettingsMenu * Menu = new GameSettingsMenu ( parent , header ) ;
mainWindow - > Append ( Menu ) ;
2011-06-03 22:31:09 +02:00
2011-07-26 00:28:22 +02:00
Menu - > ShowMenu ( ) ;
2011-06-03 22:31:09 +02:00
2011-07-26 00:28:22 +02:00
int returnMenu = MENU_NONE ;
2011-06-03 22:31:09 +02:00
2011-07-26 00:28:22 +02:00
while ( ( returnMenu = Menu - > MainLoop ( ) ) = = MENU_NONE ) ;
2011-06-03 22:31:09 +02:00
2011-07-26 00:28:22 +02:00
delete Menu ;
2011-06-03 22:31:09 +02:00
2011-07-26 00:28:22 +02:00
return returnMenu ;
2011-06-03 22:31:09 +02:00
}
2010-11-13 23:34:53 +01:00
void GameSettingsMenu : : SetupMainButtons ( )
{
2011-07-26 00:28:22 +02:00
int pos = 0 ;
2010-11-13 23:34:53 +01:00
2011-07-26 00:28:22 +02:00
SetMainButton ( pos + + , tr ( " Game Load " ) , MainButtonImgData , MainButtonImgOverData ) ;
SetMainButton ( pos + + , tr ( " Ocarina " ) , MainButtonImgData , MainButtonImgOverData ) ;
SetMainButton ( pos + + , tr ( " Categories " ) , MainButtonImgData , MainButtonImgOverData ) ;
2012-02-09 22:18:16 +01:00
if ( DiscHeader - > type = = TYPE_GAME_WII_IMG
| | DiscHeader - > type = = TYPE_GAME_WII_DISC
| | DiscHeader - > type = = TYPE_GAME_NANDCHAN )
2011-12-22 23:44:48 +01:00
{
SetMainButton ( pos + + , tr ( " Extract Save to EmuNand " ) , MainButtonImgData , MainButtonImgOverData ) ;
}
2011-07-26 00:28:22 +02:00
SetMainButton ( pos + + , tr ( " Default Gamesettings " ) , MainButtonImgData , MainButtonImgOverData ) ;
SetMainButton ( pos + + , tr ( " Uninstall Menu " ) , MainButtonImgData , MainButtonImgOverData ) ;
2010-11-13 23:34:53 +01:00
}
void GameSettingsMenu : : CreateSettingsMenu ( int menuNr )
{
2011-07-26 00:28:22 +02:00
if ( CurrentMenu )
return ;
int Idx = 0 ;
//! Game Load
if ( menuNr = = Idx + + )
{
HideMenu ( ) ;
ResumeGui ( ) ;
2012-05-06 12:59:58 +02:00
if ( DiscHeader - > type = = TYPE_GAME_GC_IMG
| | DiscHeader - > type = = TYPE_GAME_GC_DISC
| | DiscHeader - > type = = TYPE_GAME_GC_EXTRACTED )
{
CurrentMenu = new GCGameLoadSM ( DiscHeader ) ;
}
else
{
CurrentMenu = new GameLoadSM ( DiscHeader ) ;
}
2011-07-26 00:28:22 +02:00
Append ( CurrentMenu ) ;
}
//! Ocarina
else if ( menuNr = = Idx + + )
{
char ID [ 7 ] ;
snprintf ( ID , sizeof ( ID ) , " %s " , ( char * ) DiscHeader - > id ) ;
CheatMenu ( ID ) ;
}
//! Categories
else if ( menuNr = = Idx + + )
{
if ( ! Settings . godmode & & ( Settings . ParentalBlocks & BLOCK_CATEGORIES_MENU ) )
{
WindowPrompt ( tr ( " Permission denied. " ) , tr ( " Console must be unlocked for this option. " ) , tr ( " OK " ) ) ;
return ;
}
HideMenu ( ) ;
Remove ( backBtn ) ;
ResumeGui ( ) ;
mainWindow - > SetState ( STATE_DISABLED ) ;
CategorySelectPrompt promptMenu ( DiscHeader ) ;
promptMenu . SetAlignment ( thAlign ( " center - category game prompt align hor " ) , thAlign ( " middle - category game prompt align ver " ) ) ;
promptMenu . SetPosition ( thInt ( " 0 - category game prompt pos x " ) , thInt ( " 0 - category game prompt pos y " ) ) ;
promptMenu . SetEffect ( EFFECT_FADE , 20 ) ;
mainWindow - > Append ( & promptMenu ) ;
promptMenu . Show ( ) ;
promptMenu . SetEffect ( EFFECT_FADE , - 20 ) ;
while ( promptMenu . GetEffect ( ) > 0 ) usleep ( 100 ) ;
mainWindow - > Remove ( & promptMenu ) ;
if ( promptMenu . categoriesChanged ( ) )
{
2011-11-12 19:14:09 +01:00
gameList . FilterList ( ) ;
2011-07-26 00:28:22 +02:00
browserMenu - > ReloadBrowser ( ) ;
}
mainWindow - > SetState ( STATE_DEFAULT ) ;
Append ( backBtn ) ;
ShowMenu ( ) ;
}
2011-09-24 01:49:18 +02:00
//! Extract Save to EmuNand
2012-02-09 22:18:16 +01:00
else if ( ( DiscHeader - > type = = TYPE_GAME_WII_IMG
| | DiscHeader - > type = = TYPE_GAME_WII_DISC
| | DiscHeader - > type = = TYPE_GAME_NANDCHAN )
& & menuNr = = Idx + + )
2011-09-24 01:49:18 +02:00
{
int choice = WindowPrompt ( tr ( " Do you want to extract the save game? " ) , tr ( " The save game will be extracted to your emu nand path. " ) , tr ( " Yes " ) , tr ( " Cancel " ) ) ;
if ( choice = = 1 )
{
char filePath [ 512 ] ;
char nandPath [ 512 ] ;
2012-01-04 21:10:38 +01:00
if ( DiscHeader - > tid ! = 0 ) //! Channels
{
2017-12-14 15:26:57 +01:00
snprintf ( nandPath , sizeof ( nandPath ) , " /title/%08x/%08x/data " , ( unsigned int ) ( DiscHeader - > tid > > 32 ) , ( unsigned int ) DiscHeader - > tid ) ;
2012-01-04 21:10:38 +01:00
snprintf ( filePath , sizeof ( filePath ) , " %s%s " , Settings . NandEmuChanPath , nandPath ) ;
}
else //! Wii games
{
snprintf ( nandPath , sizeof ( nandPath ) , " /title/00010000/%02x%02x%02x%02x " , DiscHeader - > id [ 0 ] , DiscHeader - > id [ 1 ] , DiscHeader - > id [ 2 ] , DiscHeader - > id [ 3 ] ) ;
snprintf ( filePath , sizeof ( filePath ) , " %s%s " , Settings . NandEmuPath , nandPath ) ;
}
2011-09-24 01:49:18 +02:00
2011-12-28 17:27:30 +01:00
ProgressCancelEnable ( true ) ;
2011-09-24 01:49:18 +02:00
StartProgress ( tr ( " Extracting file: " ) , 0 , 0 , true , false ) ;
int ret = NandTitle : : ExtractDir ( nandPath , filePath ) ;
2011-09-24 15:42:32 +02:00
if ( ret < 0 ) //! Games with installable channels: Mario Kart, Wii Fit, etc.
{
snprintf ( nandPath , sizeof ( nandPath ) , " /title/00010004/%02x%02x%02x%02x " , DiscHeader - > id [ 0 ] , DiscHeader - > id [ 1 ] , DiscHeader - > id [ 2 ] , DiscHeader - > id [ 3 ] ) ;
2011-09-25 11:49:04 +02:00
snprintf ( filePath , sizeof ( filePath ) , " %s%s " , Settings . NandEmuPath , nandPath ) ;
2011-09-24 15:42:32 +02:00
ret = NandTitle : : ExtractDir ( nandPath , filePath ) ;
}
2012-05-06 12:59:58 +02:00
//! extract the Mii file if not yet done
snprintf ( nandPath , sizeof ( nandPath ) , " /shared2/menu/FaceLib/RFL_DB.dat " ) ;
snprintf ( filePath , sizeof ( filePath ) , " %s%s " , ( DiscHeader - > tid ! = 0 ) ? Settings . NandEmuChanPath : Settings . NandEmuPath , nandPath ) ;
if ( ! CheckFile ( filePath ) )
NandTitle : : ExtractDir ( nandPath , filePath ) ;
2011-09-24 01:49:18 +02:00
ProgressStop ( ) ;
2011-12-28 17:27:30 +01:00
ProgressCancelEnable ( false ) ;
2011-09-24 01:49:18 +02:00
if ( ret < 0 )
WindowPrompt ( tr ( " Error: " ) , tr ( " Failed to extract all files. Savegame might not exist. " ) , tr ( " OK " ) ) ;
else
WindowPrompt ( tr ( " Files extracted successfully. " ) , 0 , tr ( " OK " ) ) ;
}
}
2011-07-26 00:28:22 +02:00
//! Default Gamesettings
else if ( menuNr = = Idx + + )
{
int choice = WindowPrompt ( tr ( " Are you sure? " ) , 0 , tr ( " Yes " ) , tr ( " Cancel " ) ) ;
if ( choice = = 1 )
{
GameSettings . Remove ( DiscHeader - > id ) ;
GameSettings . Save ( ) ;
}
}
//! Uninstall Menu
else if ( menuNr = = Idx + + )
{
HideMenu ( ) ;
ResumeGui ( ) ;
CurrentMenu = new UninstallSM ( DiscHeader ) ;
Append ( CurrentMenu ) ;
}
2010-11-13 23:34:53 +01:00
}
void GameSettingsMenu : : DeleteSettingsMenu ( )
{
2011-07-26 00:28:22 +02:00
delete CurrentMenu ;
CurrentMenu = NULL ;
2010-11-13 23:34:53 +01:00
}