2010-12-31 00:49:22 +01:00
# include <dirent.h>
# include <unistd.h>
# include "FileOperations/fileops.h"
# include "Controls/DeviceHandler.hpp"
# include "wad/nandtitle.h"
# include "system/IosLoader.h"
# include "menu/menus.h"
# include "wpad.h"
# include "usbloader/wbfs.h"
# include "usbloader/GameList.h"
# include "settings/GameTitles.h"
2011-10-21 20:48:10 +02:00
# include "xml/GameTDB.hpp"
2011-11-20 11:46:07 +01:00
# include "utils/ShowError.h"
2010-12-31 00:49:22 +01:00
static int FindGamePartition ( )
{
2011-06-22 19:57:37 +02:00
int partCount = DeviceHandler : : GetUSBPartitionCount ( ) ;
2011-07-26 00:28:22 +02:00
// Loop through all WBFS partitions first to check them in case IOS249 Rev < 18
for ( int i = 0 ; i < partCount ; + + i )
{
2011-07-26 10:57:12 +02:00
if ( DeviceHandler : : GetFilesystemType ( USB1 + i ) ! = PART_FS_WBFS )
2011-07-26 00:28:22 +02:00
continue ;
if ( WBFS_OpenPart ( i ) = = 0 )
{
Settings . partition = i ;
return 0 ;
}
}
2011-12-23 16:48:20 +01:00
int firstValidPartition = - 1 ;
2011-07-26 00:28:22 +02:00
if ( IosLoader : : IsWaninkokoIOS ( ) & & NandTitles . VersionOf ( TITLE_ID ( 1 , IOS_GetVersion ( ) ) ) < 18 )
return - 1 ;
// Loop through FAT/NTFS/EXT partitions, and find the first partition with games on it (if there is one)
for ( int i = 0 ; i < partCount ; + + i )
{
2011-07-26 10:57:12 +02:00
if ( DeviceHandler : : GetFilesystemType ( USB1 + i ) ! = PART_FS_NTFS & &
DeviceHandler : : GetFilesystemType ( USB1 + i ) ! = PART_FS_FAT & &
DeviceHandler : : GetFilesystemType ( USB1 + i ) ! = PART_FS_EXT )
2011-07-26 00:28:22 +02:00
{
continue ;
}
if ( WBFS_OpenPart ( i ) ! = 0 )
continue ;
u32 count ;
// Get the game count...
WBFS_GetCount ( i , & count ) ;
if ( count > 0 )
{
Settings . partition = i ;
return 0 ;
}
2011-12-23 16:48:20 +01:00
if ( firstValidPartition < 0 )
firstValidPartition = i ;
2011-07-26 00:28:22 +02:00
WBFS_Close ( i ) ;
}
2011-12-23 16:48:20 +01:00
if ( firstValidPartition > = 0 )
{
Settings . partition = firstValidPartition ;
return 0 ;
}
2011-07-26 00:28:22 +02:00
return - 1 ;
2010-12-31 00:49:22 +01:00
}
static int PartitionChoice ( )
{
2011-07-26 00:28:22 +02:00
int ret = - 1 ;
2011-11-20 11:46:07 +01:00
int choice = WindowPrompt ( tr ( " No WBFS or FAT/NTFS/EXT partition found " ) , tr ( " You can select or format a partition or use the channel loader mode. " ) , tr ( " Select " ) , tr ( " Format " ) , tr ( " Channels " ) ) ;
2011-07-26 00:28:22 +02:00
if ( choice = = 0 )
{
2011-12-22 23:44:48 +01:00
Settings . LoaderMode = MODE_ALL ;
2011-11-20 11:46:07 +01:00
return 0 ;
2011-07-26 00:28:22 +02:00
}
else if ( choice = = 1 )
{
int part_num = SelectPartitionMenu ( ) ;
if ( part_num > = 0 )
{
if ( IosLoader : : IsWaninkokoIOS ( ) & & NandTitles . VersionOf ( TITLE_ID ( 1 , IOS_GetVersion ( ) ) ) < 18 & &
2011-07-26 10:57:12 +02:00
( DeviceHandler : : GetFilesystemType ( USB1 + part_num ) = = PART_FS_NTFS | |
DeviceHandler : : GetFilesystemType ( USB1 + part_num ) = = PART_FS_FAT | |
DeviceHandler : : GetFilesystemType ( USB1 + part_num ) = = PART_FS_EXT ) )
2011-07-26 00:28:22 +02:00
{
WindowPrompt ( tr ( " Warning: " ) , tr ( " You are trying to select a FAT32/NTFS/EXT partition with cIOS 249 Rev < 18. This is not supported. Continue on your own risk. " ) , tr ( " OK " ) ) ;
}
ret = WBFS_OpenPart ( part_num ) ;
Settings . partition = part_num ;
Settings . Save ( ) ;
}
}
else if ( choice = = 2 )
{
while ( ret < 0 | | ret = = - 666 )
{
int part_num = SelectPartitionMenu ( ) ;
if ( part_num > = 0 )
ret = FormatingPartition ( tr ( " Formatting, please wait... " ) , part_num ) ;
}
}
return ret ;
2010-12-31 00:49:22 +01:00
}
/****************************************************************************
* MountGamePartition
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int MountGamePartition ( bool ShowGUI )
{
2011-11-20 11:46:07 +01:00
s32 ret = - 1 ;
2011-07-26 00:28:22 +02:00
gprintf ( " MountGamePartition() \n " ) ;
2011-11-20 11:46:07 +01:00
s32 wbfsinit = WBFS_Init ( WBFS_DEVICE_USB ) ;
2011-07-26 00:28:22 +02:00
2011-12-22 23:44:48 +01:00
if ( Settings . LoaderMode & MODE_WIIGAMES )
2011-11-20 11:46:07 +01:00
{
2011-12-22 23:44:48 +01:00
if ( wbfsinit < 0 )
{
if ( ShowGUI )
ShowError ( " %s %s " , tr ( " USB Device not found. " ) , tr ( " Switching to channel list mode. " ) ) ;
Settings . LoaderMode = MODE_ALL ;
}
2011-11-20 11:46:07 +01:00
else
2011-12-22 23:44:48 +01:00
{
if ( Settings . MultiplePartitions )
ret = WBFS_OpenAll ( ) ;
2011-12-23 16:48:20 +01:00
else if ( ! Settings . FirstTimeRun )
2011-12-22 23:44:48 +01:00
ret = WBFS_OpenPart ( Settings . partition ) ;
2011-07-26 00:28:22 +02:00
2011-12-22 23:44:48 +01:00
if ( ret < 0 )
ret = FindGamePartition ( ) ;
2011-07-26 00:28:22 +02:00
2011-12-22 23:44:48 +01:00
if ( ret < 0 )
{
if ( ShowGUI )
PartitionChoice ( ) ;
else
Settings . LoaderMode = MODE_ALL ;
}
2011-11-20 11:46:07 +01:00
}
}
2011-07-26 00:28:22 +02:00
gprintf ( " \t Disc_Init \n " ) ;
ret = Disc_Init ( ) ;
if ( ret < 0 )
{
if ( ShowGUI )
WindowPrompt ( tr ( " Error ! " ) , tr ( " Could not initialize DIP module! " ) , tr ( " OK " ) ) ;
Sys_LoadMenu ( ) ;
}
2011-10-21 20:48:10 +02:00
gprintf ( " LoadTitlesFromGameTDB \n " ) ;
//! gameList is loaded in GameTitles.LoadTitlesFromGameTDB after cache file load
2011-07-26 00:28:22 +02:00
//! for speed up purpose. If titles override active, load game list here.
if ( Settings . titlesOverride )
2011-10-21 20:48:10 +02:00
GameTitles . LoadTitlesFromGameTDB ( Settings . titlestxt_path ) ;
2011-07-26 00:28:22 +02:00
else
gameList . LoadUnfiltered ( ) ;
return ret ;
2010-12-31 00:49:22 +01:00
}