2011-06-18 09:00:42 +02:00
/****************************************************************************
* Copyright ( C ) 2011
* 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 .
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# include <unistd.h>
# include "FeatureSettingsMenu.hpp"
# include "settings/CGameCategories.hpp"
# include "settings/GameTitles.h"
# include "settings/CSettings.h"
# include "settings/SettingsPrompts.h"
# include "network/Wiinnertag.h"
# include "network/networkops.h"
# include "FileOperations/fileops.h"
# include "prompts/PromptWindows.h"
2011-09-24 01:49:18 +02:00
# include "prompts/ProgressWindow.h"
# include "wad/nandtitle.h"
2011-06-26 23:38:05 +02:00
# include "usbloader/GameList.h"
2011-06-18 09:00:42 +02:00
# include "language/gettext.h"
static const char * OnOffText [ ] =
{
2011-07-26 00:28:22 +02:00
trNOOP ( " OFF " ) ,
trNOOP ( " ON " )
2011-06-18 09:00:42 +02:00
} ;
2011-06-22 19:57:37 +02:00
static const char * WiilightText [ WIILIGHT_MAX ] =
{
2011-07-26 00:28:22 +02:00
trNOOP ( " OFF " ) ,
trNOOP ( " ON " ) ,
trNOOP ( " Only for Install " )
2011-06-22 19:57:37 +02:00
} ;
2011-06-18 09:00:42 +02:00
FeatureSettingsMenu : : FeatureSettingsMenu ( )
2011-07-26 00:28:22 +02:00
: SettingsMenu ( tr ( " Features Settings " ) , & GuiOptions , MENU_NONE )
2011-06-18 09:00:42 +02:00
{
2011-07-26 00:28:22 +02:00
int Idx = 0 ;
Options - > SetName ( Idx + + , " %s " , tr ( " Titles from WiiTDB " ) ) ;
Options - > SetName ( Idx + + , " %s " , tr ( " Cache Titles " ) ) ;
Options - > SetName ( Idx + + , " %s " , tr ( " Wiilight " ) ) ;
Options - > SetName ( Idx + + , " %s " , tr ( " Rumble " ) ) ;
Options - > SetName ( Idx + + , " %s " , tr ( " AutoInit Network " ) ) ;
Options - > SetName ( Idx + + , " %s " , tr ( " Messageboard Update " ) ) ;
Options - > SetName ( Idx + + , " %s " , tr ( " Wiinnertag " ) ) ;
Options - > SetName ( Idx + + , " %s " , tr ( " Import Categories " ) ) ;
2011-09-24 01:49:18 +02:00
Options - > SetName ( Idx + + , " %s " , tr ( " Export All Saves to EmuNand " ) ) ;
2011-10-01 12:41:00 +02:00
Options - > SetName ( Idx + + , " %s " , tr ( " Dump NAND to EmuNand " ) ) ;
2011-07-26 00:28:22 +02:00
OldTitlesOverride = Settings . titlesOverride ;
SetOptionValues ( ) ;
2011-06-18 09:00:42 +02:00
}
2011-06-26 23:38:05 +02:00
FeatureSettingsMenu : : ~ FeatureSettingsMenu ( )
{
2011-07-26 00:28:22 +02:00
if ( Settings . titlesOverride ! = OldTitlesOverride )
{
GameTitles . LoadTitlesFromWiiTDB ( Settings . titlestxt_path , true ) ;
if ( ! Settings . titlesOverride )
gameList . ReadGameList ( ) ;
}
2011-06-26 23:38:05 +02:00
}
2011-06-18 09:00:42 +02:00
void FeatureSettingsMenu : : SetOptionValues ( )
{
2011-07-26 00:28:22 +02:00
int Idx = 0 ;
2011-06-18 09:00:42 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: Titles from WiiTDB
Options - > SetValue ( Idx + + , " %s " , tr ( OnOffText [ Settings . titlesOverride ] ) ) ;
2011-06-18 09:00:42 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: Cache Titles
Options - > SetValue ( Idx + + , " %s " , tr ( OnOffText [ Settings . CacheTitles ] ) ) ;
2011-06-18 09:00:42 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: Wiilight
Options - > SetValue ( Idx + + , " %s " , tr ( WiilightText [ Settings . wiilight ] ) ) ;
2011-06-22 19:57:37 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: Rumble
Options - > SetValue ( Idx + + , " %s " , tr ( OnOffText [ Settings . rumble ] ) ) ;
2011-06-22 19:57:37 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: AutoInit Network
Options - > SetValue ( Idx + + , " %s " , tr ( OnOffText [ Settings . autonetwork ] ) ) ;
2011-06-22 19:57:37 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: Messageboard Update
Options - > SetValue ( Idx + + , " %s " , tr ( OnOffText [ Settings . PlaylogUpdate ] ) ) ;
2011-06-22 19:57:37 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: Wiinnertag
Options - > SetValue ( Idx + + , " %s " , tr ( OnOffText [ Settings . Wiinnertag ] ) ) ;
2011-06-18 09:00:42 +02:00
2011-07-26 00:28:22 +02:00
//! Settings: Import categories from WiiTDB
Options - > SetValue ( Idx + + , " " ) ;
2011-09-24 01:49:18 +02:00
//! Settings: Export Savegames to EmuNand
Options - > SetValue ( Idx + + , " " ) ;
2011-10-01 12:41:00 +02:00
//! Settings: Dump NAND to EmuNand
Options - > SetValue ( Idx + + , " " ) ;
2011-06-18 09:00:42 +02:00
}
int FeatureSettingsMenu : : GetMenuInternal ( )
{
2011-07-26 00:28:22 +02:00
int ret = optionBrowser - > GetClickedOption ( ) ;
if ( ret < 0 )
return MENU_NONE ;
int Idx = - 1 ;
//! Settings: Titles from WiiTDB
if ( ret = = + + Idx )
{
if ( + + Settings . titlesOverride > = MAX_ON_OFF ) Settings . titlesOverride = 0 ;
}
//! Settings: Cache Titles
else if ( ret = = + + Idx )
{
if ( + + Settings . CacheTitles > = MAX_ON_OFF ) Settings . CacheTitles = 0 ;
if ( Settings . CacheTitles ) //! create new cache file
GameTitles . LoadTitlesFromWiiTDB ( Settings . titlestxt_path ) ;
}
//! Settings: Wiilight
else if ( ret = = + + Idx )
{
if ( + + Settings . wiilight > = WIILIGHT_MAX ) Settings . wiilight = 0 ;
}
//! Settings: Rumble
else if ( ret = = + + Idx )
{
if ( + + Settings . rumble > = MAX_ON_OFF ) Settings . rumble = 0 ; //RUMBLE
}
//! Settings: AutoInit Network
else if ( ret = = + + Idx )
{
if ( + + Settings . autonetwork > = MAX_ON_OFF ) Settings . autonetwork = 0 ;
}
//! Settings: Messageboard Update
else if ( ret = = + + Idx )
{
if ( + + Settings . PlaylogUpdate > = MAX_ON_OFF ) Settings . PlaylogUpdate = 0 ;
}
//! Settings: Winnertag
else if ( ret = = + + Idx )
{
if ( + + Settings . Wiinnertag > = MAX_ON_OFF ) Settings . Wiinnertag = 0 ;
if ( Settings . Wiinnertag = = ON & & ! Settings . autonetwork )
{
int choice = WindowPrompt ( tr ( " Warning " ) , tr ( " Wiinnertag requires you to enable automatic network connect on application start. Do you want to enable it now? " ) , tr ( " Yes " ) , tr ( " Cancel " ) ) ;
if ( choice )
{
Settings . autonetwork = ON ;
if ( ! IsNetworkInit ( ) )
Initialize_Network ( ) ;
}
}
char filepath [ 200 ] ;
snprintf ( filepath , sizeof ( filepath ) , " %sWiinnertag.xml " , Settings . WiinnertagPath ) ;
if ( Settings . Wiinnertag = = ON & & ! CheckFile ( filepath ) )
{
int choice = WindowPrompt ( tr ( " Warning " ) , tr ( " No Wiinnertag.xml found in the config path. Do you want an example file created? " ) , tr ( " Yes " ) , tr ( " No " ) ) ;
if ( choice )
{
if ( Wiinnertag : : CreateExample ( Settings . WiinnertagPath ) )
{
char text [ 200 ] ;
snprintf ( text , sizeof ( text ) , " %s %s " , tr ( " An example file was created here: " ) , filepath ) ;
WindowPrompt ( tr ( " Success " ) , text , tr ( " OK " ) ) ;
}
else
{
char text [ 200 ] ;
snprintf ( text , sizeof ( text ) , " %s %s " , tr ( " Could not write to: " ) , filepath ) ;
WindowPrompt ( tr ( " Failed " ) , text , tr ( " OK " ) ) ;
}
}
}
}
//! Settings: Import categories from WiiTDB
else if ( ret = = + + Idx )
{
int choice = WindowPrompt ( tr ( " Import Categories " ) , tr ( " Are you sure you want to import game categories from WiiTDB? " ) , tr ( " Yes " ) , tr ( " Cancel " ) ) ;
if ( choice )
{
char xmlpath [ 300 ] ;
snprintf ( xmlpath , sizeof ( xmlpath ) , " %swiitdb.xml " , Settings . titlestxt_path ) ;
if ( ! GameCategories . ImportFromWiiTDB ( xmlpath ) )
{
WindowPrompt ( tr ( " Error " ) , tr ( " Could not open the WiiTDB.xml file. " ) , tr ( " OK " ) ) ;
}
else
{
GameCategories . Save ( ) ;
GameCategories . CategoryList . goToFirst ( ) ;
WindowPrompt ( tr ( " Import Categories " ) , tr ( " Import operation successfully completed. " ) , tr ( " OK " ) ) ;
}
}
}
2011-09-24 01:49:18 +02:00
//! Settings: Export Savegames to EmuNand
else if ( ret = = + + Idx )
{
2011-09-24 15:42:32 +02:00
int choice = WindowPrompt ( tr ( " Do you want to extract all the save games? " ) , tr ( " The save games will be extracted to your emu nand path. Attention: All existing saves will be overwritten. " ) , tr ( " Yes " ) , tr ( " Cancel " ) ) ;
if ( choice = = 1 )
2011-09-24 01:49:18 +02:00
{
2011-10-01 12:41:00 +02:00
ProgressCancelEnable ( true ) ;
2011-09-24 15:42:32 +02:00
StartProgress ( tr ( " Extracting files: " ) , 0 , 0 , true , false ) ;
char filePath [ 512 ] ;
char nandPath [ ISFS_MAXPATH ] ;
bool noErrors = true ;
bool skipErrors = false ;
wString filter ( gameList . GetCurrentFilter ( ) ) ;
gameList . LoadUnfiltered ( ) ;
for ( int i = 0 ; i < gameList . size ( ) ; + + i )
{
snprintf ( nandPath , sizeof ( nandPath ) , " /title/00010000/%02x%02x%02x%02x " , gameList [ i ] - > id [ 0 ] , gameList [ i ] - > id [ 1 ] , gameList [ i ] - > id [ 2 ] , gameList [ i ] - > id [ 3 ] ) ;
snprintf ( filePath , sizeof ( filePath ) , " %s%s " , Settings . NandEmuPath , nandPath ) ;
2011-09-24 01:49:18 +02:00
2011-09-24 15:42:32 +02:00
ShowProgress ( tr ( " Extracting files: " ) , GameTitles . GetTitle ( gameList [ i ] ) , 0 , 0 , - 1 , true , false ) ;
2011-09-24 01:49:18 +02:00
2011-09-24 15:42:32 +02:00
int ret = NandTitle : : ExtractDir ( nandPath , filePath ) ;
2011-10-01 12:41:00 +02:00
if ( ret = = PROGRESS_CANCELED )
{
break ;
}
else if ( ret < 0 ) //! Games with installable channels: Mario Kart, Wii Fit, etc.
2011-09-24 15:42:32 +02:00
{
snprintf ( nandPath , sizeof ( nandPath ) , " /title/00010004/%02x%02x%02x%02x " , gameList [ i ] - > id [ 0 ] , gameList [ i ] - > id [ 1 ] , gameList [ i ] - > id [ 2 ] , gameList [ i ] - > 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 ) ;
}
if ( ret < 0 & & ! skipErrors )
{
noErrors = false ;
char text [ 200 ] ;
snprintf ( text , sizeof ( text ) , " %s %s. %s. %s " , tr ( " Could not extract files for: " ) , GameTitles . GetTitle ( gameList [ i ] ) , tr ( " Savegame might not exist for this game. " ) , tr ( " Continue? " ) ) ;
ProgressStop ( ) ;
int ret = WindowPrompt ( tr ( " Error " ) , text , tr ( " Yes " ) , tr ( " No " ) , tr ( " Skip Errors " ) ) ;
if ( ret = = 0 )
skipErrors = true ;
else if ( ret = = 2 )
break ;
}
2011-09-24 01:49:18 +02:00
}
2011-09-24 15:42:32 +02:00
ProgressStop ( ) ;
2011-10-01 12:41:00 +02:00
ProgressCancelEnable ( false ) ;
2011-09-24 01:49:18 +02:00
2011-10-01 12:41:00 +02:00
if ( ret ! = PROGRESS_CANCELED )
{
if ( noErrors )
WindowPrompt ( tr ( " Success. " ) , tr ( " All files extracted. " ) , tr ( " OK " ) ) ;
else
WindowPrompt ( tr ( " Process finished. " ) , tr ( " Errors occured. " ) , tr ( " OK " ) ) ;
}
2011-09-24 15:42:32 +02:00
gameList . FilterList ( filter . c_str ( ) ) ;
}
2011-09-24 01:49:18 +02:00
}
2011-10-01 12:41:00 +02:00
//! Settings: Dump NAND to EmuNand
else if ( ret = = + + Idx )
{
int choice = WindowPrompt ( tr ( " What to extract from NAND? " ) , tr ( " The files will be extracted to your emu nand path. Attention: All existing files will be overwritten. " ) , tr ( " Everything " ) , tr ( " Enter Path " ) , tr ( " Cancel " ) ) ;
if ( choice )
{
char filePath [ 255 ] ;
char * nandPath = ( char * ) memalign ( 32 , ISFS_MAXPATH ) ;
if ( ! nandPath )
{
WindowPrompt ( tr ( " Error " ) , tr ( " Not enough memory. " ) , tr ( " OK " ) ) ;
return MENU_NONE ;
}
snprintf ( nandPath , sizeof ( nandPath ) , " / " ) ;
if ( choice = = 2 )
{
choice = OnScreenKeyboard ( nandPath , ISFS_MAXPATH , 1 ) ;
if ( strlen ( nandPath ) > 1 & & nandPath [ strlen ( nandPath ) - 1 ] = = ' / ' )
nandPath [ strlen ( nandPath ) - 1 ] = 0 ;
}
snprintf ( filePath , sizeof ( filePath ) , " %s%s " , Settings . NandEmuPath , nandPath ) ;
if ( choice )
{
u32 dummy ;
int ret = - 1 ;
ProgressCancelEnable ( true ) ;
StartProgress ( tr ( " Extracting nand files: " ) , 0 , 0 , true , false ) ;
ShowProgress ( tr ( " Extracting nand files: " ) , 0 , 0 , - 1 , true , false ) ;
ISFS_Initialize ( ) ;
if ( ISFS_ReadDir ( nandPath , NULL , & dummy ) < 0 )
ret = NandTitle : : ExtractFile ( nandPath , filePath , false ) ;
else
ret = NandTitle : : ExtractDir ( nandPath , filePath , false ) ;
ISFS_Deinitialize ( ) ;
ProgressStop ( ) ;
ProgressCancelEnable ( false ) ;
if ( ret ! = PROGRESS_CANCELED )
{
if ( ret < 0 )
WindowPrompt ( tr ( " Process finished. " ) , tr ( " Errors occured. " ) , tr ( " OK " ) ) ;
else
WindowPrompt ( tr ( " Success. " ) , tr ( " All files extracted. " ) , tr ( " OK " ) ) ;
}
}
free ( nandPath ) ;
}
}
2011-07-26 00:28:22 +02:00
SetOptionValues ( ) ;
return MENU_NONE ;
2011-06-18 09:00:42 +02:00
}