usbloadergx/source/usbloader/wbfs.cpp

262 lines
5.4 KiB
C++
Raw Normal View History

#include <vector>
#include <ogcsys.h>
#include <unistd.h>
#include <time.h>
#include "Controls/DeviceHandler.hpp"
#include "usbloader/usbstorage2.h"
#include "wbfs.h"
#include "usbloader/wbfs/wbfs_base.h"
#include "usbloader/wbfs/wbfs_wbfs.h"
#include "usbloader/wbfs/wbfs_fat.h"
#include "usbloader/wbfs/wbfs_ntfs.h"
#include "usbloader/wbfs/wbfs_ext.h"
#include "usbloader/GameList.h"
#include "menu/menus.h"
#include "gecko.h"
#define VALID(x) (x >= 0 && x < (int) WbfsList.size() && WbfsList[x] != NULL)
static std::vector<Wbfs *> WbfsList;
2010-09-24 02:48:03 +02:00
wbfs_disc_t* WBFS_OpenDisc(u8 *discid)
{
if(!discid) return NULL;
int part = gameList.GetPartitionNumber(discid);
if(!VALID(part))
return NULL;
return WbfsList[part]->OpenDisc(discid);
}
2010-09-24 02:48:03 +02:00
void WBFS_CloseDisc(wbfs_disc_t *disc)
{
if(!disc) return;
struct discHdr * header = (struct discHdr *) disc->header;
int part_num = gameList.GetPartitionNumber(header->id);
if(!VALID(part_num))
return;
WbfsList[part_num]->CloseDisc(disc);
}
2010-09-24 02:48:03 +02:00
s32 WBFS_Init(u32 device)
{
return Wbfs::Init(device);
}
s32 WBFS_OpenAll()
{
int ret = -1;
int partCount = DeviceHandler::GetUSBPartitionCount();
for(int i = 0; i < partCount; ++i)
{
if(WBFS_OpenPart(i) == 0)
ret = 0;
}
return ret;
}
s32 WBFS_OpenPart(int part_num)
{
PartitionHandle * usbHandle = DeviceHandler::Instance()->GetUSBHandleFromPartition(part_num);
if(!usbHandle || part_num < 0 || part_num >= DeviceHandler::GetUSBPartitionCount())
return -1;
// close
WBFS_Close(part_num);
if(part_num >= (int) WbfsList.size())
WbfsList.resize(part_num+1);
int portPart = DeviceHandler::PartitionToPortPartition(part_num);
int usbPort = DeviceHandler::PartitionToUSBPort(part_num);
gprintf("\tWBFS_OpenPart: filesystem: %s, start sector %u, sector count: %u\n", usbHandle->GetFSName(portPart), usbHandle->GetLBAStart(portPart), usbHandle->GetSecCount(portPart));
if (strncmp(usbHandle->GetFSName(portPart), "FAT", 3) == 0)
{
WbfsList[part_num] = new Wbfs_Fat(usbHandle->GetLBAStart(portPart), usbHandle->GetSecCount(portPart), part_num, usbPort);
}
else if (strncmp(usbHandle->GetFSName(portPart), "NTFS", 4) == 0)
{
WbfsList[part_num] = new Wbfs_Ntfs(usbHandle->GetLBAStart(portPart), usbHandle->GetSecCount(portPart), part_num, usbPort);
}
else if (strncmp(usbHandle->GetFSName(portPart), "LINUX", 5) == 0)
{
WbfsList[part_num] = new Wbfs_Ext(usbHandle->GetLBAStart(portPart), usbHandle->GetSecCount(portPart), part_num, usbPort);
}
else if (strncmp(usbHandle->GetFSName(portPart), "WBFS", 4) == 0)
{
WbfsList[part_num] = new Wbfs_Wbfs(usbHandle->GetLBAStart(portPart), usbHandle->GetSecCount(portPart), part_num, usbPort);
}
else
{
return -1;
}
if (WbfsList[part_num]->Open() != 0)
{
delete WbfsList[part_num];
WbfsList[part_num] = NULL;
return -1;
}
return 0;
}
bool WBFS_Close(int part_num)
{
if(!VALID(part_num))
return false;
delete WbfsList[part_num];
WbfsList[part_num] = NULL;
gameList.RemovePartition(part_num);
return true;
}
void WBFS_CloseAll()
{
gameList.clear();
for(u32 i = 0; i < WbfsList.size(); ++i)
WBFS_Close(i);
}
s32 WBFS_Format(u32 lba, u32 size, u32 port)
{
Wbfs_Wbfs Part(WBFS_MIN_DEVICE, lba, size, port);
return Part.Format();
}
s32 WBFS_GetCount(int part_num, u32 *count)
{
if(!VALID(part_num))
return -1;
int ret = WbfsList[part_num]->GetCount(count);
return ret;
}
s32 WBFS_GetHeaders(int part_num, struct discHdr *outbuf, u32 cnt, u32 len)
{
if(!VALID(part_num))
return -1;
return WbfsList[part_num]->GetHeaders(outbuf, cnt, len);
}
2010-09-24 02:48:03 +02:00
s32 WBFS_CheckGame(u8 *discid)
{
int part_num = gameList.GetPartitionNumber(discid);
if(!VALID(part_num))
return 0;
return WbfsList[part_num]->CheckGame(discid);
}
2010-09-24 02:48:03 +02:00
s32 WBFS_AddGame(void)
{
if(!VALID(Settings.partition))
return -1;
return WbfsList[Settings.partition]->AddGame();
}
2010-09-24 02:48:03 +02:00
s32 WBFS_RemoveGame(u8 *discid)
{
int part_num = gameList.GetPartitionNumber(discid);
if(!VALID(part_num))
return -1;
return WbfsList[part_num]->RemoveGame(discid);
}
2010-09-24 02:48:03 +02:00
s32 WBFS_GameSize(u8 *discid, f32 *size)
{
int part_num = gameList.GetPartitionNumber(discid);
if(!VALID(part_num))
return -1;
return WbfsList[part_num]->GameSize(discid, size);
}
2010-09-24 02:48:03 +02:00
s32 WBFS_DiskSpace(f32 *used, f32 *free)
{
if(!VALID(Settings.partition))
return -1;
return WbfsList[Settings.partition]->DiskSpace(used, free);
}
2010-09-24 02:48:03 +02:00
s32 WBFS_RenameGame(u8 *discid, const void *newname)
{
int part_num = gameList.GetPartitionNumber(discid);
if(!VALID(part_num))
return -1;
return WbfsList[part_num]->RenameGame(discid, newname);
}
2010-09-24 02:48:03 +02:00
s32 WBFS_ReIDGame(u8 *discid, const void *newID)
{
int part_num = gameList.GetPartitionNumber(discid);
if(!VALID(part_num))
return -1;
return WbfsList[part_num]->ReIDGame(discid, newID);
}
*Fixed display of partition size on WBFS partitions with a different wbfs sector size than 512bytes. *Made the ProgressWindow for game installation more accurate *Added displaying newly installed games (marked as new) on favorite list, so you don't have to change to full list when installing new games. (Thanks Cyan for the patch) *Lot's a small fixes *Added WDM Menu on game start. You can set it in the alternative DOL option (one new option there). The menu lists all DOLs on the disc and if a wdm file is provided in the WDM path (configurable in the settings) than the dol parameter and dol replacement name will be taken from the wdm. The DOLs that are not listed in the WDM but exist on the DISC will be listed at the end of the list. *Added avoid of multiple app cleanup when game fails to boot *Changed libfat to use FS info sector on FAT32 partitions. This speeds up the free space information getting to instant. For that the FS info sector has to have correct values. The values of all partitions where homebrews were writing to are currently incorrect because the official libfat does not support FS info sector (i submited a patch) (Windows does write it correct though). That is why there needs to be a synchronization of the FS info sector for partitions used with homebrews. For this purpose a new setting was added in the Loader Settings. You can synchronize all your FAT32 partitions on the USB with it once and you are done (if you don't write to that partition with current homebrews). After that you can enable free space display and it will be instant like on WBFS/NTFS/EXT partitions.
2011-01-16 14:12:07 +01:00
u64 WBFS_EstimeGameSize(void)
{
if(!VALID(Settings.partition))
return 0;
return WbfsList[Settings.partition]->EstimateGameSize();
}
2010-09-24 02:48:03 +02:00
int WBFS_GetFragList(u8 *id)
{
int part_num = gameList.GetPartitionNumber(id);
if(!VALID(part_num))
return -1;
return WbfsList[part_num]->GetFragList(id);
}
int MountWBFS(bool ShowGUI)
{
if(ShowGUI)
return WBFS_Init(WBFS_DEVICE_USB);
int ret = -1;
time_t currTime = time(0);
while (time(0) - currTime < 30)
{
ret = WBFS_Init(WBFS_DEVICE_USB);
printf("%i...", int(time(0) - currTime));
if (ret < 0)
sleep(1);
else
break;
DeviceHandler::Instance()->UnMountAllUSB();
DeviceHandler::Instance()->MountAllUSB();
}
printf("\n");
return ret;
}