2010-02-25 13:08:03 +01:00
|
|
|
#include "wbfs_wbfs.h"
|
|
|
|
#include "prompts/ProgressWindow.h"
|
|
|
|
#include "settings/cfg.h"
|
|
|
|
#include "wbfs_rw.h"
|
|
|
|
|
|
|
|
extern u32 sector_size;
|
|
|
|
|
|
|
|
s32 Wbfs_Wbfs::Open()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
wbfs_t *part = NULL;
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Open partition */
|
|
|
|
part = wbfs_open_partition( readCallback, writeCallback, NULL, sector_size, size, lba, 0 );
|
|
|
|
if ( !part ) return -1;
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Close current hard disk */
|
|
|
|
Close();
|
|
|
|
hdd = part;
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Save the new sector size, so it will be used in read and write calls
|
|
|
|
sector_size = 1 << hdd->head->hd_sec_sz_s;
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return 0;
|
2010-02-25 13:08:03 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
wbfs_disc_t* Wbfs_Wbfs::OpenDisc( u8 *discid )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
/* No device open */
|
|
|
|
if ( !hdd )
|
|
|
|
return NULL;
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Open disc */
|
|
|
|
return wbfs_open_disc( hdd, discid );
|
2010-02-25 13:08:03 +01:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void Wbfs_Wbfs::CloseDisc( wbfs_disc_t *disc )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
/* No device open */
|
|
|
|
if ( !hdd || !disc )
|
|
|
|
return;
|
2010-02-25 13:08:03 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Close disc */
|
|
|
|
wbfs_close_disc( disc );
|
2010-02-25 13:08:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
s32 Wbfs_Wbfs::Format()
|
|
|
|
{
|
|
|
|
wbfs_t *partition = NULL;
|
|
|
|
|
|
|
|
/* Reset partition */
|
2010-09-19 01:16:05 +02:00
|
|
|
partition = wbfs_open_partition( readCallback, writeCallback, NULL, sector_size, size, lba, 1 );
|
|
|
|
if ( !partition )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Free memory */
|
2010-09-19 01:16:05 +02:00
|
|
|
wbfs_close( partition );
|
2010-02-25 13:08:03 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 Wbfs_Wbfs::GetCount( u32 *count )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
|
|
|
/* No device open */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !hdd )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Get list length */
|
2010-09-19 01:16:05 +02:00
|
|
|
*count = wbfs_count_discs( hdd );
|
2010-02-25 13:08:03 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 Wbfs_Wbfs::GetHeaders( struct discHdr *outbuf, u32 cnt, u32 len )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
|
|
|
u32 idx, size;
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* No device open */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !hdd )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
for ( idx = 0; idx < cnt; idx++ )
|
|
|
|
{
|
|
|
|
u8 *ptr = ( ( u8 * )outbuf ) + ( idx * len );
|
2010-02-25 13:08:03 +01:00
|
|
|
|
|
|
|
/* Get header */
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = wbfs_get_disc_info( hdd, idx, ptr, len, &size );
|
|
|
|
if ( ret < 0 )
|
2010-02-25 13:08:03 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
s32 Wbfs_Wbfs::AddGame()
|
|
|
|
{
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* No device open */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !hdd )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Add game to device */
|
2010-09-19 01:16:05 +02:00
|
|
|
partition_selector_t part_sel;
|
|
|
|
int copy_1_1 = 0;
|
|
|
|
|
|
|
|
if ( Settings.fullcopy )
|
|
|
|
{
|
|
|
|
part_sel = ALL_PARTITIONS;
|
|
|
|
copy_1_1 = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
part_sel = Settings.partitions_to_install == install_game_only ? ONLY_GAME_PARTITION : ALL_PARTITIONS;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = wbfs_add_disc( hdd, __ReadDVD, NULL, ProgressCallback, part_sel, copy_1_1 );
|
|
|
|
if ( ret < 0 )
|
2010-02-25 13:08:03 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 Wbfs_Wbfs::RemoveGame( u8 *discid )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* No device open */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !hdd )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Remove game from USB device */
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = wbfs_rm_disc( hdd, discid );
|
|
|
|
if ( ret < 0 )
|
2010-02-25 13:08:03 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 Wbfs_Wbfs::DiskSpace( f32 *used, f32 *free )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
|
|
|
f32 ssize;
|
|
|
|
u32 cnt;
|
|
|
|
|
|
|
|
/* No device open */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !hdd )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Count used blocks */
|
2010-09-19 01:16:05 +02:00
|
|
|
cnt = wbfs_count_usedblocks( hdd );
|
2010-02-25 13:08:03 +01:00
|
|
|
|
|
|
|
/* Sector size in GB */
|
|
|
|
ssize = hdd->wbfs_sec_sz / GB_SIZE;
|
|
|
|
|
|
|
|
/* Copy values */
|
|
|
|
*free = ssize * cnt;
|
2010-09-19 01:16:05 +02:00
|
|
|
*used = ssize * ( hdd->n_wbfs_sec - cnt );
|
2010-02-25 13:08:03 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 Wbfs_Wbfs::RenameGame( u8 *discid, const void *newname )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* No USB device open */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !hdd )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = wbfs_ren_disc( hdd, discid, ( u8* )newname );
|
|
|
|
if ( ret < 0 )
|
2010-02-25 13:08:03 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 Wbfs_Wbfs::ReIDGame( u8 *discid, const void *newID )
|
2010-02-25 13:08:03 +01:00
|
|
|
{
|
|
|
|
s32 ret;
|
|
|
|
|
|
|
|
/* No USB device open */
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !hdd )
|
2010-02-25 13:08:03 +01:00
|
|
|
return -1;
|
2010-09-19 01:16:05 +02:00
|
|
|
ret = wbfs_rID_disc( hdd, discid, ( u8* )newID );
|
|
|
|
if ( ret < 0 )
|
2010-02-25 13:08:03 +01:00
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
f32 Wbfs_Wbfs::EstimateGameSize()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
partition_selector_t part_sel = ONLY_GAME_PARTITION;
|
|
|
|
if ( Settings.fullcopy )
|
|
|
|
{
|
|
|
|
part_sel = ALL_PARTITIONS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
switch ( Settings.partitions_to_install )
|
|
|
|
{
|
|
|
|
case install_game_only:
|
|
|
|
part_sel = ONLY_GAME_PARTITION;
|
|
|
|
break;
|
|
|
|
case install_all:
|
|
|
|
part_sel = ALL_PARTITIONS;
|
|
|
|
break;
|
|
|
|
case install_all_but_update:
|
|
|
|
part_sel = REMOVE_UPDATE_PARTITION;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return wbfs_estimate_disc( hdd, __ReadDVD, NULL, part_sel );
|
2010-02-25 13:08:03 +01:00
|
|
|
}
|