usbloadergx/source/usbloader/wbfs/wbfs_wbfs.cpp

226 lines
4.7 KiB
C++
Raw Normal View History

#include "wbfs_wbfs.h"
#include "prompts/ProgressWindow.h"
#include "settings/CSettings.h"
#include "usbloader/wbfs.h"
#include "wbfs_rw.h"
#define MAX_WBFS_SECTORSIZE 4096
extern u32 hdd_sector_size;
s32 Wbfs_Wbfs::Open()
{
wbfs_t *part = NULL;
PartInfo.wbfs_sector_size = MAX_WBFS_SECTORSIZE;
PartInfo.hdd_sector_size = hdd_sector_size;
PartInfo.partition_lba = lba;
PartInfo.partition_num_sec = size;
*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
u8 * buffer = (u8 *) malloc(MAX_WBFS_SECTORSIZE);
memset(buffer, 0, MAX_WBFS_SECTORSIZE);
*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
if(readCallback(&PartInfo, lba, 1, buffer) < 0)
{
free(buffer);
*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
return -1;
}
wbfs_head_t head;
memcpy(&head, buffer, sizeof(wbfs_head_t));
free(buffer);
*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
if (head.magic != wbfs_htonl(WBFS_MAGIC))
*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
return -1;
/* Set correct sector values for wbfs read/write */
PartInfo.wbfs_sector_size = 1 << head.hd_sec_sz_s;
PartInfo.partition_num_sec = head.n_hd_sec;
/* Open partition */
part = wbfs_open_partition(readCallback, writeCallback, &PartInfo,
PartInfo.wbfs_sector_size, PartInfo.partition_num_sec,
lba, 0);
2010-09-24 02:48:03 +02:00
if (!part) return -1;
/* Close current hard disk */
Close();
hdd = part;
return 0;
}
void Wbfs_Wbfs::Close()
{
if (hdd)
{
wbfs_close(hdd);
hdd = NULL;
}
}
2010-09-24 02:48:03 +02:00
wbfs_disc_t* Wbfs_Wbfs::OpenDisc(u8 *discid)
{
/* No device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return NULL;
/* Open disc */
2010-09-24 02:48:03 +02:00
return wbfs_open_disc(hdd, discid);
}
2010-09-24 02:48:03 +02:00
void Wbfs_Wbfs::CloseDisc(wbfs_disc_t *disc)
{
/* No device open */
2010-09-24 02:48:03 +02:00
if (!hdd || !disc) return;
/* Close disc */
2010-09-24 02:48:03 +02:00
wbfs_close_disc(disc);
}
s32 Wbfs_Wbfs::Format()
{
WBFS_PartInfo HDD_Inf;
HDD_Inf.wbfs_sector_size = hdd_sector_size;
HDD_Inf.hdd_sector_size = hdd_sector_size;
HDD_Inf.partition_lba = lba;
HDD_Inf.partition_num_sec = size;
//! If size is over 500GB in sectors and sector size is 512
//! set 2048 as hdd sector size
if(size > 1048576000 && hdd_sector_size == 512)
{
HDD_Inf.wbfs_sector_size = 2048;
HDD_Inf.partition_num_sec = size/(2048/hdd_sector_size);
}
wbfs_t *partition = NULL;
/* Reset partition */
partition = wbfs_open_partition(readCallback, writeCallback, &HDD_Inf, HDD_Inf.wbfs_sector_size, HDD_Inf.partition_num_sec, lba, 1);
2010-09-24 02:48:03 +02:00
if (!partition) return -1;
/* Free memory */
2010-09-24 02:48:03 +02:00
wbfs_close(partition);
return 0;
}
2010-09-24 02:48:03 +02:00
s32 Wbfs_Wbfs::GetCount(u32 *count)
{
/* No device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return -1;
/* Get list length */
2010-09-24 02:48:03 +02:00
*count = wbfs_count_discs(hdd);
return 0;
}
2010-09-24 02:48:03 +02:00
s32 Wbfs_Wbfs::GetHeaders(struct discHdr *outbuf, u32 cnt, u32 len)
{
u32 idx, size;
s32 ret;
/* No device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return -1;
2010-09-24 02:48:03 +02:00
for (idx = 0; idx < cnt; idx++)
{
2010-09-24 02:48:03 +02:00
u8 *ptr = ((u8 *) outbuf) + (idx * len);
/* Get header */
2010-09-24 02:48:03 +02:00
ret = wbfs_get_disc_info(hdd, idx, ptr, len, &size);
if (ret < 0) return ret;
}
return 0;
}
s32 Wbfs_Wbfs::AddGame()
{
s32 ret;
/* No device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return -1;
partition_selector_t part_sel = (partition_selector_t) Settings.InstallPartitions;
/* Add game to device */
ret = wbfs_add_disc(hdd, __ReadDVD, NULL, ShowProgress, part_sel, 0);
2010-09-24 02:48:03 +02:00
if (ret < 0) return ret;
return 0;
}
2010-09-24 02:48:03 +02:00
s32 Wbfs_Wbfs::RemoveGame(u8 *discid)
{
s32 ret;
/* No device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return -1;
/* Remove game from USB device */
2010-09-24 02:48:03 +02:00
ret = wbfs_rm_disc(hdd, discid);
if (ret < 0) return ret;
return 0;
}
2010-09-24 02:48:03 +02:00
s32 Wbfs_Wbfs::DiskSpace(f32 *used, f32 *free)
{
f32 ssize;
u32 cnt;
/* No device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return -1;
/* Count used blocks */
2010-09-24 02:48:03 +02:00
cnt = wbfs_count_usedblocks(hdd);
/* Sector size in GB */
ssize = hdd->wbfs_sec_sz / GB_SIZE;
/* Copy values */
*free = ssize * cnt;
2010-09-24 02:48:03 +02:00
*used = ssize * (hdd->n_wbfs_sec - cnt);
return 0;
}
2010-09-24 02:48:03 +02:00
s32 Wbfs_Wbfs::RenameGame(u8 *discid, const void *newname)
{
s32 ret;
/* No USB device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return -1;
ret = wbfs_ren_disc(hdd, discid, (u8*) newname);
if (ret < 0) return ret;
return 0;
}
2010-09-24 02:48:03 +02:00
s32 Wbfs_Wbfs::ReIDGame(u8 *discid, const void *newID)
{
s32 ret;
/* No USB device open */
2010-09-24 02:48:03 +02:00
if (!hdd) return -1;
ret = wbfs_rID_disc(hdd, discid, (u8*) newID);
if (ret < 0) return ret;
return 0;
}
*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_Wbfs::EstimateGameSize()
{
partition_selector_t part_sel = (partition_selector_t) Settings.InstallPartitions;
2010-09-24 02:48:03 +02:00
return wbfs_estimate_disc(hdd, __ReadDVD, NULL, part_sel);
}
s32 Wbfs_Wbfs::GetFragList(u8 *id)
{
//! Doesn't have to be called ".iso" just something different than .wbfs but with a dot.
//! So that the code doesn't fail.
return get_frag_list_for_file((char *) ".iso", id, GetFSType(), lba);
}