-added support for usb port 1, you can find the setting in the

global settings under startup, it will only work with d2x v9 beta,
d2x v10 alt or hermes cIOS 5.0 or later, setting is saved in the
NAND save, so individual for every wii, wiiflow will reboot after
you change it
This commit is contained in:
fix94.1 2013-02-14 21:30:48 +00:00
parent f4b2e16207
commit 0ce4e2c363
9 changed files with 105 additions and 102 deletions

View File

@ -31,6 +31,7 @@ NandSave InternalSave;
#define BANNER_PATH "/title/00010000/57465346/data/banner.bin"
#define IOS_SAVE_PATH "/title/00010000/57465346/data/ios"
#define PORT_SAVE_PATH "/title/00010000/57465346/data/port"
NandSave::NandSave()
{
@ -148,24 +149,34 @@ error:
return loaded;
}
void NandSave::LoadIOS()
void NandSave::LoadSettings()
{
if(loaded == false)
return;
u32 size = 0;
memset(&ISFS_Path, 0, ISFS_MAXPATH);
strcpy(ISFS_Path, IOS_SAVE_PATH);
ios_settings_t *file = (ios_settings_t*)ISFS_GetFile(ISFS_Path, &size, -1);
if(file == NULL)
return;
gprintf("Loading IOS Settings from NAND\n");
if(size == sizeof(ios_settings_t))
if(file != NULL && size == sizeof(ios_settings_t))
{
gprintf("Loading IOS Settings from NAND\n");
if(file->cios > 0)
mainIOS = file->cios;
useMainIOS = file->use_cios;
}
free(file);
if(file != NULL)
free(file);
strcpy(ISFS_Path, PORT_SAVE_PATH);
u8 *port = ISFS_GetFile(ISFS_Path, &size, -1);
if(port != NULL && size == sizeof(u8))
{
gprintf("Using Port Settings from NAND\n");
currentPort = port[0] & 1;
}
if(port != NULL)
free(port);
}
void NandSave::SaveIOS(u8 ios, bool use_ios)
@ -176,13 +187,28 @@ void NandSave::SaveIOS(u8 ios, bool use_ios)
ios_settings.cios = ios;
ios_settings.use_cios = use_ios;
gprintf("Saving IOS Settings to NAND\n");
WriteFile(IOS_SAVE_PATH, (u8*)&ios_settings, sizeof(ios_settings_t));
}
void NandSave::SavePort(u8 port)
{
if(loaded == false)
return;
gprintf("Saving Port Settings to NAND\n");
WriteFile(PORT_SAVE_PATH, &port, sizeof(port));
}
void NandSave::WriteFile(const char *file_name, u8 *content, u32 size)
{
memset(&ISFS_Path, 0, ISFS_MAXPATH);
strcpy(ISFS_Path, IOS_SAVE_PATH);
if(file_name == NULL || content == NULL || size == 0)
return;
strcpy(ISFS_Path, file_name);
ISFS_CreateFile(ISFS_Path, 0, 3, 3, 3);
fd = ISFS_Open(ISFS_Path, ISFS_OPEN_WRITE);
if(fd < 0)
return;
ret = ISFS_Write(fd, &ios_settings, sizeof(ios_settings_t));
ret = ISFS_Write(fd, content, size);
ISFS_Close(fd);
if(ret < 0)
ISFS_Delete(ISFS_Path);

View File

@ -30,9 +30,11 @@ class NandSave
public:
NandSave();
bool CheckSave();
void LoadIOS();
void LoadSettings();
void SaveIOS(u8 ios, bool use_ios);
void SavePort(u8 port);
private:
void WriteFile(const char *file_name, u8 *content, u32 size);
s32 fd;
s32 ret;
bool loaded;

View File

@ -43,7 +43,7 @@ DeviceHandler DeviceHandle;
void DeviceHandler::Init()
{
sd.Init();
usb0.Init();
usb.Init();
OGC_Device.Init();
}
@ -66,7 +66,7 @@ void DeviceHandler::UnMountAll()
SDHC_Close();
sd.Cleanup();
usb0.Cleanup();
usb.Cleanup();
}
bool DeviceHandler::Mount(int dev)
@ -85,10 +85,7 @@ bool DeviceHandler::IsInserted(int dev)
if(dev == SD)
return SD_Inserted() && sd.IsMounted(0);
else if(dev >= USB1 && dev <= USB8)
{
int portPart = dev-1;//PartitionToPortPartition(dev-USB1);
return usb0.IsMounted(portPart);
}
return usb.IsMounted(dev-USB1);
return false;
}
@ -138,13 +135,7 @@ bool DeviceHandler::MountUSB(int pos)
{
if(pos >= GetUSBPartitionCount())
return false;
int portPart = pos;//PartitionToPortPartition(pos);
if(PartitionToUSBPort(pos) == 0)
return usb0.Mount(portPart, DeviceName[USB1+pos]);
return false;
return usb.Mount(pos, DeviceName[USB1+pos]);
}
bool DeviceHandler::MountAllUSB()
@ -152,10 +143,10 @@ bool DeviceHandler::MountAllUSB()
/* Kill possible USB thread */
KillUSBKeepAliveThread();
/* Wait for our slowass HDD */
WaitForDevice(GetUSB0Interface());
WaitForDevice(GetUSBInterface());
/* Get Partitions and Mount them */
if(!usb0.IsInserted() || !usb0.IsMounted(0))
usb0.SetDevice(GetUSB0Interface());
if(!usb.IsInserted() || !usb.IsMounted(0))
usb.SetDevice(GetUSBInterface());
bool result = false;
int partCount = GetUSBPartitionCount();
for(int i = 0; i < partCount; i++)
@ -164,7 +155,7 @@ bool DeviceHandler::MountAllUSB()
result = true;
}
if(!result)
result = usb0.Mount(0, DeviceName[USB1], true); /* Force FAT */
result = usb.Mount(0, DeviceName[USB1], true); /* Force FAT */
if(result && usb_libogc_mode)
CreateUSBKeepAliveThread();
return result;
@ -174,13 +165,7 @@ void DeviceHandler::UnMountUSB(int pos)
{
if(pos >= GetUSBPartitionCount())
return;
int portPart = pos;//PartitionToPortPartition(pos);
if(PartitionToUSBPort(pos) == 0)
return usb0.UnMount(portPart);
//else if(usb1)
// return usb1->UnMount(portPart);
return usb.UnMount(pos);
}
void DeviceHandler::UnMountAllUSB()
@ -211,19 +196,9 @@ const char *DeviceHandler::GetFSName(int dev)
return sd.GetFSName(0);
else if(dev >= USB1 && dev <= USB8)
{
int partCount0 = 0;
//int partCount1 = 0;
//if(usb0)
partCount0 += usb0.GetPartitionCount();
//if(usb1)
// partCount1 += usb1->GetPartitionCount();
if(dev-USB1 < partCount0)
return usb0.GetFSName(dev-USB1);
//else if(usb1)
// return usb1->GetFSName(dev-USB1-partCount0);
if(dev-USB1 < usb.GetPartitionCount())
return usb.GetFSName(dev-USB1);
}
return "";
}
@ -246,13 +221,7 @@ int DeviceHandler::GetFSType(int dev)
u16 DeviceHandler::GetUSBPartitionCount()
{
u16 partCount0 = 0;
u16 partCount1 = 0;
partCount0 = usb0.GetPartitionCount();
//if(usb1)
// partCount1 = usb1->GetPartitionCount();
return partCount0+partCount1;
return usb.GetPartitionCount();
}
wbfs_t * DeviceHandler::GetWbfsHandle(int dev)
@ -260,9 +229,7 @@ wbfs_t * DeviceHandler::GetWbfsHandle(int dev)
if(dev == SD)
return sd.GetWbfsHandle(0);
else if(dev >= USB1 && dev <= USB8)
return usb0.GetWbfsHandle(dev-USB1);
//else if(dev >= USB1 && dev <= USB8 && usb1)
// return usb1->GetWbfsHandle(dev-USB1);
return usb.GetWbfsHandle(dev-USB1);
return NULL;
}
@ -277,7 +244,7 @@ s32 DeviceHandler::OpenWBFS(int dev)
else if(dev >= USB1 && dev <= USB8 && IsInserted(dev))
{
part_idx = dev;
part_lba = usb0.GetLBAStart(dev - USB1);
part_lba = usb.GetLBAStart(dev - USB1);
}
else
return -1;
@ -285,37 +252,6 @@ s32 DeviceHandler::OpenWBFS(int dev)
return WBFS_Init(GetWbfsHandle(dev), part_fs, part_idx, part_lba, partition);
}
int DeviceHandler::PartitionToUSBPort(int part)
{
u16 partCount0 = 0;
//if(usb0)
partCount0 = usb0.GetPartitionCount();
if(part >= partCount0)
return 1;
else
return 0;
}
int DeviceHandler::PartitionToPortPartition(int part)
{
u16 partCount0 = 0;
//if(usb0)
partCount0 = usb0.GetPartitionCount();
if(part >= partCount0)
return part-partCount0;
else
return part;
}
/*
PartitionHandle *DeviceHandler::GetUSBHandleFromPartition(int part)
{
if(PartitionToUSBPort(part) == 0)
return usb0;
else
return usb1;
}
*/
void DeviceHandler::WaitForDevice(const DISC_INTERFACE *Handle)
{
if(Handle == NULL)
@ -364,3 +300,13 @@ bool DeviceHandler::PartitionUsableForNandEmu(int Partition)
return false;
}
const DISC_INTERFACE *DeviceHandler::GetUSBInterface()
{
if(((CurrentIOS.Type == IOS_TYPE_HERMES && CurrentIOS.Version > 4) ||
(CurrentIOS.Type == IOS_TYPE_D2X && CurrentIOS.Version > 8) ||
(CurrentIOS.Type == IOS_TYPE_NORMAL_IOS && CurrentIOS.Revision == 58))
&& currentPort == 1)
return &__io_usbstorage2_port1;
return &__io_usbstorage2_port0;
}

View File

@ -78,7 +78,7 @@ public:
bool MountUSBPort1();
bool SD_Inserted() { return sd.IsInserted(); }
bool USB0_Inserted() { return usb0.IsInserted(); }
bool USB_Inserted() { return usb.IsInserted(); }
bool UsablePartitionMounted();
bool PartitionUsableForNandEmu(int Partition);
void WaitForDevice(const DISC_INTERFACE *Handle);
@ -87,9 +87,8 @@ public:
void UnMountUSB(int pos);
void UnMountAllUSB();
PartitionHandle * GetUSBHandleFromPartition(int part);
const DISC_INTERFACE *GetUSB0Interface() { return &__io_usbstorage2_port0; }
const DISC_INTERFACE *GetUSB1Interface() { return &__io_usbstorage2_port1; }
PartitionHandle *GetUSBHandleFromPartition(int part);
const DISC_INTERFACE *GetUSBInterface();
int PathToDriveType(const char *path);
const char * GetFSName(int dev);
@ -98,8 +97,6 @@ public:
const char *PathToFSName(const char *path) { return GetFSName(PathToDriveType(path)); }
wbfs_t *GetWbfsHandle(int dev);
s32 OpenWBFS(int dev);
int PartitionToUSBPort(int part);
int PartitionToPortPartition(int part);
/* Special Devolution Stuff */
bool MountDevolution();
@ -108,7 +105,7 @@ private:
bool MountUSB(int part);
PartitionHandle sd;
PartitionHandle usb0;
PartitionHandle usb;
/* Special Devolution Stuff */
PartitionHandle OGC_Device;
};

View File

@ -39,6 +39,8 @@
#include "memory/mem2.hpp"
int mainIOS = 0;
u8 currentPort = 0;
IOS_Info CurrentIOS;
signed_blob *GetTMD(u8 ios, u32 *TMD_Length)
{

View File

@ -50,6 +50,7 @@ extern bool useMainIOS;
extern volatile bool NANDemuView;
extern volatile bool networkInit;
extern u8 currentPartition;
extern u8 currentPort;
extern char wii_games_dir[];
#ifdef __cplusplus

View File

@ -68,9 +68,9 @@ int main(int argc, char **argv)
NandHandle.Init_ISFS();
else
NandHandle.LoadDefaultIOS(); /* safe reload to preferred IOS */
/* Maybe new IOS settings */
/* Maybe new IOS and Port settings */
if(InternalSave.CheckSave())
InternalSave.LoadIOS();
InternalSave.LoadSettings();
/* Handle (c)IOS Loading */
if(neek2o() || Sys_DolphinMode()) /* wont reload anythin */
iosOK = loadIOS(IOS_GetVersion(), false);

View File

@ -866,7 +866,7 @@ private:
void _textExitTo(void);
void _textBoot(void);
//
void _refreshBoot(void);
void _refreshBoot(u8 port = 0);
//
void _hideCheatSettings(bool instant = false);
void _hideError(bool instant = false);

View File

@ -28,6 +28,9 @@ s16 m_bootLblCurCIOSrev;
s16 m_bootLblCIOSrevM;
s16 m_bootLblCIOSrevP;
s16 m_bootLblUSBPort;
s16 m_bootBtnUSBPort;
static void showBoot(void)
{
m_btnMgr.show(m_bootLblTitle);
@ -38,6 +41,9 @@ static void showBoot(void)
m_btnMgr.show(m_bootLblCurCIOSrev);
m_btnMgr.show(m_bootLblCIOSrevM);
m_btnMgr.show(m_bootLblCIOSrevP);
m_btnMgr.show(m_bootLblUSBPort);
m_btnMgr.show(m_bootBtnUSBPort);
}
static void hideBoot(bool instant)
@ -50,27 +56,31 @@ static void hideBoot(bool instant)
m_btnMgr.hide(m_bootLblCurCIOSrev, instant);
m_btnMgr.hide(m_bootLblCIOSrevM, instant);
m_btnMgr.hide(m_bootLblCIOSrevP, instant);
m_btnMgr.hide(m_bootLblUSBPort, instant);
m_btnMgr.hide(m_bootBtnUSBPort, instant);
}
void CMenu::_Boot(void)
{
SetupInput();
_refreshBoot();
u8 port = currentPort;
bool prev_load = m_cfg.getBool("GENERAL", "force_cios_load", false);
u8 prev_ios = min(m_cfg.getInt("GENERAL", "force_cios_rev", 0), 254);
_refreshBoot(port);
while(!m_exit)
{
_mainLoopCommon();
if(BTN_HOME_PRESSED || BTN_B_PRESSED)
break;
break;
else if(BTN_A_PRESSED)
{
if(m_btnMgr.selected(m_bootBtnLoadCIOS))
{
bool old = m_cfg.getBool("GENERAL", "force_cios_load", false);
m_cfg.setBool("GENERAL", "force_cios_load", !old);
_refreshBoot();
_refreshBoot(port);
}
else if(m_btnMgr.selected(m_bootLblCIOSrevM) || m_btnMgr.selected(m_bootLblCIOSrevP))
{
@ -89,20 +99,32 @@ void CMenu::_Boot(void)
itr--;
}
m_cfg.setInt("GENERAL", "force_cios_rev", itr->first);
_refreshBoot(port);
}
else if(m_btnMgr.selected(m_bootBtnUSBPort))
{
port = (port == 0 ? 1 : 0);
_refreshBoot(port);
}
_refreshBoot();
}
}
bool cur_load = m_cfg.getBool("GENERAL", "force_cios_load", false);
u8 cur_ios = min(m_cfg.getInt("GENERAL", "force_cios_rev", 0), 254);
if(prev_load != cur_load || prev_ios != cur_ios)
InternalSave.SaveIOS(cur_ios, cur_load);
if(port != currentPort)
{
InternalSave.SavePort(port);
m_reload = true;
}
hideBoot(false);
}
void CMenu::_refreshBoot(void)
void CMenu::_refreshBoot(u8 port)
{
m_btnMgr.setText(m_bootBtnLoadCIOS, _optBoolToString(m_cfg.getBool("GENERAL", "force_cios_load", false)));
m_btnMgr.setText(m_bootBtnUSBPort, wfmt(L"%i", port));
u8 IOS_Revision = min(m_cfg.getInt("GENERAL", "force_cios_rev", 0), 254);
if(IOS_Revision > 0)
m_btnMgr.setText(m_bootLblCurCIOSrev, wfmt(L"%i", IOS_Revision));
@ -116,6 +138,7 @@ void CMenu::_textBoot(void)
m_btnMgr.setText(m_bootLblTitle, _t("cfgbt1", L"Startup Settings"));
m_btnMgr.setText(m_bootLblLoadCIOS, _t("cfgbt2", L"Force Load cIOS"));
m_btnMgr.setText(m_bootLblCIOSrev, _t("cfgbt3", L"Force cIOS Revision"));
m_btnMgr.setText(m_bootLblUSBPort, _t("cfgbt4", L"USB Port"));
}
@ -131,6 +154,9 @@ void CMenu::_initBoot(void)
m_bootLblCIOSrevM = _addPicButton("BOOT/CIOS_REV_MINUS", theme.btnTexMinus, theme.btnTexMinusS, 330, 190, 56, 56);
m_bootLblCIOSrevP = _addPicButton("BOOT/CIOS_REV_PLUS", theme.btnTexPlus, theme.btnTexPlusS, 544, 190, 56, 56);
m_bootLblUSBPort = _addLabel("BOOT/USB_PORT", theme.lblFont, L"", 40, 250, 290, 56, theme.lblFontColor, FTGX_JUSTIFY_LEFT | FTGX_ALIGN_MIDDLE);
m_bootBtnUSBPort = _addButton("BOOT/USB_PORT_BTN", theme.btnFont, L"", 330, 250, 270, 56, theme.btnFontColor);
_setHideAnim(m_bootLblTitle, "BOOT/TITLE", 0, -200, 0.f, 1.f);
_setHideAnim(m_bootLblLoadCIOS, "BOOT/LOAD_CIOS", -200, 0, 1.f, 0.f);
_setHideAnim(m_bootBtnLoadCIOS, "BOOT/LOAD_CIOS_BTN", 200, 0, 1.f, 0.f);
@ -140,6 +166,9 @@ void CMenu::_initBoot(void)
_setHideAnim(m_bootLblCIOSrevM, "BOOT/CIOS_REV_MINUS", 200, 0, 1.f, 0.f);
_setHideAnim(m_bootLblCIOSrevP, "BOOT/CIOS_REV_PLUS", 200, 0, 1.f, 0.f);
_setHideAnim(m_bootLblUSBPort, "BOOT/USB_PORT", -200, 0, 1.f, 0.f);
_setHideAnim(m_bootBtnUSBPort, "BOOT/USB_PORT_BTN", 200, 0, 1.f, 0.f);
hideBoot(true);
_textBoot();
}