usbloadergx/source/menu/menu_install.cpp

171 lines
4.8 KiB
C++
Raw Normal View History

#include "menus.h"
#include "usbloader/usbstorage2.h"
#include "usbloader/wbfs.h"
#include "usbloader/disc.h"
#include "usbloader/utils.h"
#include "usbloader/GameList.h"
#include "prompts/ProgressWindow.h"
#include "themes/CTheme.h"
float gamesize;
/****************************************************************************
* MenuInstall
***************************************************************************/
int MenuInstall()
{
2010-09-24 02:48:03 +02:00
gprintf("\nMenuInstall()");
int menu = MENU_NONE;
static struct discHdr headerdisc ATTRIBUTE_ALIGN( 32 );
2010-09-24 02:48:03 +02:00
Disc_SetUSB(NULL);
int ret, choice = 0;
char name[200];
2010-09-24 02:48:03 +02:00
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, Settings.sfxvolume);
GuiImageData battery(Resources::GetFile("battery.png"), Resources::GetFileSize("battery.png"));
GuiImageData batteryBar(Resources::GetFile("battery_bar.png"), Resources::GetFileSize("battery_bar.png"));
GuiImageData batteryRed(Resources::GetFile("battery_red.png"), Resources::GetFileSize("battery_red.png"));
GuiImageData batteryBarRed(Resources::GetFile("battery_bar_red.png"), Resources::GetFileSize("battery_bar_red.png"));
HaltGui();
2010-09-24 02:48:03 +02:00
GuiWindow w(screenwidth, screenheight);
2010-09-24 02:48:03 +02:00
mainWindow->Append(&w);
ResumeGui();
2010-09-24 02:48:03 +02:00
while (menu == MENU_NONE)
{
2010-09-24 02:48:03 +02:00
VIDEO_WaitVSync();
2010-09-24 02:48:03 +02:00
ret = DiscWait(tr( "Insert Disk" ), tr( "Waiting..." ), tr( "Cancel" ), 0, 0);
if (ret < 0)
{
2010-09-24 02:48:03 +02:00
WindowPrompt(tr( "Error reading Disc" ), 0, tr( "Back" ));
menu = MENU_DISCLIST;
break;
}
ret = Disc_Open();
2010-09-24 02:48:03 +02:00
if (ret < 0)
{
2010-09-24 02:48:03 +02:00
WindowPrompt(tr( "Could not open Disc" ), 0, tr( "Back" ));
menu = MENU_DISCLIST;
break;
}
ret = Disc_IsWii();
2010-09-24 02:48:03 +02:00
if (ret < 0)
{
2010-09-24 02:48:03 +02:00
choice = WindowPrompt(tr( "Not a Wii Disc" ), tr( "Insert a Wii Disc!" ), tr( "OK" ), tr( "Back" ));
2010-09-24 02:48:03 +02:00
if (choice == 1)
{
menu = MENU_INSTALL;
break;
}
2010-09-24 02:48:03 +02:00
else menu = MENU_DISCLIST;
break;
}
2010-09-24 02:48:03 +02:00
Disc_ReadHeader(&headerdisc);
snprintf(name, sizeof(name), "%s", headerdisc.title);
2010-09-24 02:48:03 +02:00
ret = WBFS_CheckGame(headerdisc.id);
if (ret)
{
2010-09-24 02:48:03 +02:00
WindowPrompt(tr( "Game is already installed:" ), name, tr( "Back" ));
menu = MENU_DISCLIST;
break;
}
f32 freespace, used;
2010-09-24 02:48:03 +02:00
WBFS_DiskSpace(&used, &freespace);
gamesize = WBFS_EstimeGameSize() / GB_SIZE;
char gametxt[50];
2010-09-24 02:48:03 +02:00
sprintf(gametxt, "%s : %.2fGB", name, gamesize);
2010-09-24 02:48:03 +02:00
wiilight(1);
choice = WindowPrompt(tr( "Continue to install game?" ), gametxt, tr( "OK" ), tr( "Cancel" ));
2010-09-24 02:48:03 +02:00
if (choice == 1)
{
2010-09-24 02:48:03 +02:00
sprintf(gametxt, "%s", tr( "Installing game:" ));
2010-09-24 02:48:03 +02:00
if (gamesize > freespace)
{
char errortxt[50];
2010-09-24 02:48:03 +02:00
sprintf(errortxt, "%s: %.2fGB, %s: %.2fGB", tr( "Game Size" ), gamesize, tr( "Free Space" ), freespace);
WindowPrompt(tr( "Not enough free space!" ), errortxt, tr( "OK" ));
menu = MENU_DISCLIST;
break;
}
else
{
2010-09-24 02:48:03 +02:00
USBStorage2_Watchdog(0);
SetupGameInstallProgress(gametxt, name);
ret = WBFS_AddGame();
ProgressStop();
2010-09-24 02:48:03 +02:00
USBStorage2_Watchdog(1);
wiilight(0);
if (ret != 0)
{
2010-09-24 02:48:03 +02:00
WindowPrompt(tr( "Install Error!" ), 0, tr( "Back" ));
menu = MENU_DISCLIST;
break;
}
else
{
gameList.ReadGameList(); //get the entries again
gameList.FilterList();
GuiSound * instsuccess = NULL;
bgMusic->Pause();
2010-09-24 02:48:03 +02:00
instsuccess = new GuiSound(success_ogg, success_ogg_size, Settings.sfxvolume);
instsuccess->SetVolume(Settings.sfxvolume);
instsuccess->SetLoop(0);
instsuccess->Play();
2010-09-24 02:48:03 +02:00
WindowPrompt(tr( "Successfully installed:" ), name, tr( "OK" ));
instsuccess->Stop();
delete instsuccess;
bgMusic->Resume();
menu = MENU_DISCLIST;
break;
}
}
}
else
{
menu = MENU_DISCLIST;
break;
}
2010-09-24 02:48:03 +02:00
if (shutdown == 1)
{
2010-09-24 02:48:03 +02:00
wiilight(0);
Sys_Shutdown();
}
2010-09-24 02:48:03 +02:00
if (reset == 1)
{
2010-09-24 02:48:03 +02:00
wiilight(0);
Sys_Reboot();
}
}
//Turn off the WiiLight
2010-09-24 02:48:03 +02:00
wiilight(0);
HaltGui();
2010-09-24 02:48:03 +02:00
mainWindow->Remove(&w);
ResumeGui();
return menu;
}