mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-22 03:09:15 +01:00
df76e45150
- This allows you to play your Wii games from an SD card - It currently only supports 1 partition - I've tested it with a 256GB Amazon Basics microSDXC card
271 lines
5.6 KiB
C++
271 lines
5.6 KiB
C++
#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 "settings/CSettings.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;
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
s32 WBFS_Init(u32 device)
|
|
{
|
|
return Wbfs::Init(device);
|
|
}
|
|
|
|
s32 WBFS_ReInit(u32 device)
|
|
{
|
|
WBFS_CloseAll();
|
|
if (device == WBFS_DEVICE_SDHC)
|
|
{
|
|
DeviceHandler::Instance()->UnMountSD();
|
|
DeviceHandler::Instance()->MountSD();
|
|
}
|
|
else
|
|
{
|
|
DeviceHandler::Instance()->UnMountAllUSB();
|
|
DeviceHandler::Instance()->MountAllUSB();
|
|
}
|
|
s32 ret = -1;
|
|
|
|
if (device == WBFS_DEVICE_SDHC || !Settings.MultiplePartitions)
|
|
ret = WBFS_OpenPart(Settings.partition);
|
|
else
|
|
ret = WBFS_OpenAll();
|
|
|
|
return ret;
|
|
}
|
|
|
|
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 *handle;
|
|
|
|
if (Settings.SDMode)
|
|
{
|
|
handle = DeviceHandler::Instance()->GetSDHandle();
|
|
if(!handle || part_num < 0)
|
|
return -1;
|
|
}
|
|
else
|
|
{
|
|
handle = DeviceHandler::Instance()->GetUSBHandleFromPartition(part_num);
|
|
if(!handle || 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 = Settings.SDMode ? 0 : DeviceHandler::PartitionToPortPartition(part_num);
|
|
int usbPort = Settings.SDMode ? 0 : DeviceHandler::PartitionToUSBPort(part_num);
|
|
|
|
gprintf("\tWBFS_OpenPart: filesystem: %s, start sector %u, sector count: %u\n", handle->GetFSName(portPart), handle->GetLBAStart(portPart), handle->GetSecCount(portPart));
|
|
|
|
if (strncmp(handle->GetFSName(portPart), "FAT", 3) == 0)
|
|
{
|
|
WbfsList[part_num] = new Wbfs_Fat(handle->GetLBAStart(portPart), handle->GetSecCount(portPart), part_num, usbPort);
|
|
}
|
|
else if (strncmp(handle->GetFSName(portPart), "NTFS", 4) == 0)
|
|
{
|
|
WbfsList[part_num] = new Wbfs_Ntfs(handle->GetLBAStart(portPart), handle->GetSecCount(portPart), part_num, usbPort);
|
|
}
|
|
else if (strncmp(handle->GetFSName(portPart), "LINUX", 5) == 0)
|
|
{
|
|
WbfsList[part_num] = new Wbfs_Ext(handle->GetLBAStart(portPart), handle->GetSecCount(portPart), part_num, usbPort);
|
|
}
|
|
else if (strncmp(handle->GetFSName(portPart), "WBFS", 4) == 0)
|
|
{
|
|
WbfsList[part_num] = new Wbfs_Wbfs(handle->GetLBAStart(portPart), handle->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);
|
|
}
|
|
|
|
s32 WBFS_CheckGame(u8 *discid)
|
|
{
|
|
int part_num = gameList.GetPartitionNumber(discid);
|
|
if(!VALID(part_num))
|
|
return 0;
|
|
|
|
return WbfsList[part_num]->CheckGame(discid);
|
|
}
|
|
|
|
s32 WBFS_AddGame(void)
|
|
{
|
|
if(!VALID(Settings.partition))
|
|
return -1;
|
|
|
|
return WbfsList[Settings.partition]->AddGame();
|
|
}
|
|
|
|
s32 WBFS_RemoveGame(u8 *discid)
|
|
{
|
|
int part_num = gameList.GetPartitionNumber(discid);
|
|
if(!VALID(part_num))
|
|
return -1;
|
|
|
|
return WbfsList[part_num]->RemoveGame(discid);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
s32 WBFS_DiskSpace(f32 *used, f32 *free)
|
|
{
|
|
if(!VALID(Settings.partition))
|
|
return -1;
|
|
|
|
return WbfsList[Settings.partition]->DiskSpace(used, free);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
u64 WBFS_EstimeGameSize(void)
|
|
{
|
|
if(!VALID(Settings.partition))
|
|
return 0;
|
|
|
|
return WbfsList[Settings.partition]->EstimateGameSize();
|
|
}
|
|
|
|
s32 WBFS_GetFragList(u8 *id)
|
|
{
|
|
int part_num = gameList.GetPartitionNumber(id);
|
|
if(!VALID(part_num))
|
|
return -1;
|
|
|
|
return WbfsList[part_num]->GetFragList(id);
|
|
}
|