2009-07-11 09:21:38 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "utils.h"
|
|
|
|
#include "video.h"
|
|
|
|
#include "wad.h"
|
2010-01-19 11:48:50 +01:00
|
|
|
|
2010-09-19 01:04:39 +02:00
|
|
|
#include "nandtitle.h"
|
|
|
|
|
2009-07-11 09:21:38 +02:00
|
|
|
#include "prompts/PromptWindows.h"
|
|
|
|
#include "libwiigui/gui.h"
|
|
|
|
#include "language/gettext.h"
|
|
|
|
#include "menu.h"
|
2010-09-24 19:58:56 +02:00
|
|
|
#include "themes/CTheme.h"
|
|
|
|
|
2009-07-11 09:21:38 +02:00
|
|
|
/* 'WAD Header' structure */
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
/* Header length */
|
|
|
|
u32 header_len;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
/* WAD type */
|
|
|
|
u16 type;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
u16 padding;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
/* Data length */
|
|
|
|
u32 certs_len;
|
|
|
|
u32 crl_len;
|
|
|
|
u32 tik_len;
|
|
|
|
u32 tmd_len;
|
|
|
|
u32 data_len;
|
|
|
|
u32 footer_len;
|
|
|
|
}ATTRIBUTE_PACKED wadHeader;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
|
|
|
/* Variables */
|
2010-09-19 01:16:05 +02:00
|
|
|
static u8 wadBuffer[BLOCK_SIZE] ATTRIBUTE_ALIGN( 32 );
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 __Wad_ReadFile(FILE *fp, void *outbuf, u32 offset, u32 len)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
s32 ret;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Seek to offset */
|
2010-09-24 02:48:03 +02:00
|
|
|
fseek(fp, offset, SEEK_SET);
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Read data */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = fread(outbuf, len, 1, fp);
|
|
|
|
if (ret < 0) return ret;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return 0;
|
2009-07-11 09:21:38 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 __Wad_ReadAlloc(FILE *fp, void **outbuf, u32 offset, u32 len)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
void *buffer = NULL;
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 ret;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
/* Allocate memory */
|
2010-09-24 02:48:03 +02:00
|
|
|
buffer = memalign(32, len);
|
|
|
|
if (!buffer) return -1;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
/* Read file */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadFile(fp, buffer, offset, len);
|
|
|
|
if (ret < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
free(buffer);
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set pointer */
|
|
|
|
*outbuf = buffer;
|
|
|
|
return 0;
|
2009-07-11 09:21:38 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 __Wad_GetTitleID(FILE *fp, wadHeader *header, u64 *tid)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
//signed_blob *p_tik = NULL;
|
2010-09-24 02:48:03 +02:00
|
|
|
void *p_tik = NULL;
|
|
|
|
tik *tik_data = NULL;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 offset = 0;
|
|
|
|
s32 ret;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Ticket offset */
|
|
|
|
offset += round_up( header->header_len, 64 );
|
2010-09-24 02:48:03 +02:00
|
|
|
offset += round_up( header->certs_len, 64 );
|
|
|
|
offset += round_up( header->crl_len, 64 );
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Read ticket */
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadAlloc(fp, &p_tik, offset, header->tik_len);
|
|
|
|
if (ret < 0) goto out;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Ticket data */
|
2010-09-24 02:48:03 +02:00
|
|
|
tik_data = (tik *) SIGNATURE_PAYLOAD((signed_blob *) p_tik);
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Copy title ID */
|
|
|
|
*tid = tik_data->titleid;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
out:
|
2010-09-19 01:16:05 +02:00
|
|
|
/* Free memory */
|
2010-09-24 02:48:03 +02:00
|
|
|
if (p_tik) free(p_tik);
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2009-07-11 09:21:38 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Wad_Install(FILE *fp)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
//////start the gui shit
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiWindow promptWindow(472, 320);
|
|
|
|
promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
|
|
|
promptWindow.SetPosition(0, -10);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
|
|
|
GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png"));
|
2010-09-19 01:16:05 +02:00
|
|
|
GuiTrigger trigA;
|
2010-09-24 02:48:03 +02:00
|
|
|
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage dialogBoxImg(&dialogBox);
|
2010-10-27 16:45:27 +02:00
|
|
|
if (Settings.wsprompt)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
dialogBoxImg.SetWidescreen(Settings.widescreen);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText btn1Txt(tr( "OK" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage btn1Img(&btnOutline);
|
2010-10-27 16:45:27 +02:00
|
|
|
if (Settings.wsprompt)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
btn1Txt.SetWidescreen(Settings.widescreen);
|
|
|
|
btn1Img.SetWidescreen(Settings.widescreen);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-11-13 23:34:53 +01:00
|
|
|
GuiButton btn1(&btn1Img, &btn1Img, 2, 4, 0, -35, &trigA, btnSoundOver, btnSoundClick2, 1);
|
2010-09-24 02:48:03 +02:00
|
|
|
btn1.SetLabel(&btn1Txt);
|
|
|
|
btn1.SetState(STATE_SELECTED);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData progressbarOutline(Resources::GetFile("progressbar_outline.png"), Resources::GetFileSize("progressbar_outline.png"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage progressbarOutlineImg(&progressbarOutline);
|
2010-10-27 16:45:27 +02:00
|
|
|
if (Settings.wsprompt)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarOutlineImg.SetWidescreen(Settings.widescreen);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarOutlineImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
progressbarOutlineImg.SetPosition(25, 50);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData progressbarEmpty(Resources::GetFile("progressbar_empty.png"), Resources::GetFileSize("progressbar_empty.png"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage progressbarEmptyImg(&progressbarEmpty);
|
|
|
|
progressbarEmptyImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
progressbarEmptyImg.SetPosition(25, 50);
|
|
|
|
progressbarEmptyImg.SetTile(100);
|
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData progressbar(Resources::GetFile("progressbar.png"), Resources::GetFileSize("progressbar.png"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage progressbarImg(&progressbar);
|
|
|
|
progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
|
|
|
progressbarImg.SetPosition(25, 50);
|
2009-07-11 09:21:38 +02:00
|
|
|
|
|
|
|
char title[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(title, "%s", tr( "Installing wad" ));
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
|
|
titleTxt.SetPosition(0, 40);
|
2009-07-11 09:21:38 +02:00
|
|
|
char msg[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(msg, " ");
|
2010-09-19 01:16:05 +02:00
|
|
|
// sprintf(msg, "%s", tr("Initializing Network"));
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg1Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg1Txt.SetPosition(50, 75);
|
|
|
|
// char msg2[50] = " ";
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg2Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg2Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg2Txt.SetPosition(50, 98);
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg3Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg3Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg3Txt.SetPosition(50, 121);
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg4Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg4Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg4Txt.SetPosition(50, 144);
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg5Txt((char*) NULL, 20, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg5Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg5Txt.SetPosition(50, 167);
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText prTxt((char*) NULL, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
|
|
|
prTxt.SetPosition(0, 50);
|
|
|
|
|
2010-10-27 16:45:27 +02:00
|
|
|
if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust for widescreen
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarOutlineImg.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
|
|
|
progressbarOutlineImg.SetPosition(0, 50);
|
|
|
|
progressbarEmptyImg.SetPosition(80, 50);
|
|
|
|
progressbarEmptyImg.SetTile(78);
|
|
|
|
progressbarImg.SetPosition(80, 50);
|
|
|
|
|
|
|
|
msg1Txt.SetPosition(90, 75);
|
|
|
|
msg2Txt.SetPosition(90, 98);
|
|
|
|
msg3Txt.SetPosition(90, 121);
|
|
|
|
msg4Txt.SetPosition(90, 144);
|
|
|
|
msg5Txt.SetPosition(90, 167);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
promptWindow.Append(&dialogBoxImg);
|
|
|
|
promptWindow.Append(&titleTxt);
|
|
|
|
promptWindow.Append(&msg5Txt);
|
|
|
|
promptWindow.Append(&msg4Txt);
|
|
|
|
promptWindow.Append(&msg3Txt);
|
|
|
|
promptWindow.Append(&msg1Txt);
|
|
|
|
promptWindow.Append(&msg2Txt);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
//promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50);
|
|
|
|
|
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
mainWindow->SetState(STATE_DISABLED);
|
|
|
|
mainWindow->Append(&promptWindow);
|
|
|
|
mainWindow->ChangeFocus(&promptWindow);
|
2010-09-19 01:16:05 +02:00
|
|
|
//sleep(1);
|
|
|
|
|
|
|
|
|
|
|
|
///start the wad shit
|
|
|
|
bool fail = false;
|
2010-09-24 02:48:03 +02:00
|
|
|
wadHeader *header = NULL;
|
|
|
|
void *pvoid;
|
2010-09-19 01:16:05 +02:00
|
|
|
signed_blob *p_certs = NULL, *p_crl = NULL, *p_tik = NULL, *p_tmd = NULL;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
tmd *tmd_data = NULL;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
u32 cnt, offset = 0;
|
|
|
|
s32 ret = 666;
|
|
|
|
|
|
|
|
ResumeGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetText(tr( ">> Reading WAD data..." ));
|
2010-09-19 01:16:05 +02:00
|
|
|
HaltGui();
|
2009-09-27 20:19:53 +02:00
|
|
|
#define SetPointer(a, p) a=(typeof(a))p
|
2010-09-19 01:16:05 +02:00
|
|
|
// WAD header
|
|
|
|
//ret = __Wad_ReadAlloc(fp, (void *)header, offset, sizeof(wadHeader));
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadAlloc(fp, &pvoid, offset, sizeof(wadHeader));
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
SetPointer( header, pvoid );
|
|
|
|
offset += round_up( header->header_len, 64 );
|
|
|
|
|
|
|
|
// WAD certificates
|
|
|
|
//ret = __Wad_ReadAlloc(fp, (void *)&p_certs, offset, header->certs_len);
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->certs_len);
|
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
SetPointer( p_certs, pvoid );
|
|
|
|
offset += round_up( header->certs_len, 64 );
|
|
|
|
|
|
|
|
// WAD crl
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (header->crl_len)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
//ret = __Wad_ReadAlloc(fp, (void *)&p_crl, offset, header->crl_len);
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->crl_len);
|
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
SetPointer( p_crl, pvoid );
|
|
|
|
offset += round_up( header->crl_len, 64 );
|
|
|
|
}
|
|
|
|
|
|
|
|
// WAD ticket
|
|
|
|
//ret = __Wad_ReadAlloc(fp, (void *)&p_tik, offset, header->tik_len);
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->tik_len);
|
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
SetPointer( p_tik, pvoid );
|
|
|
|
offset += round_up( header->tik_len, 64 );
|
|
|
|
|
|
|
|
// WAD TMD
|
|
|
|
//ret = __Wad_ReadAlloc(fp, (void *)&p_tmd, offset, header->tmd_len);
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadAlloc(fp, &pvoid, offset, header->tmd_len);
|
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
SetPointer( p_tmd, pvoid );
|
|
|
|
offset += round_up( header->tmd_len, 64 );
|
|
|
|
|
|
|
|
ResumeGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetText(tr( "Reading WAD data... Ok!" ));
|
|
|
|
msg2Txt.SetText(tr( ">> Installing ticket..." ));
|
2010-09-19 01:16:05 +02:00
|
|
|
HaltGui();
|
|
|
|
// Install ticket
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = ES_AddTicket(p_tik, header->tik_len, p_certs, header->certs_len, p_crl, header->crl_len);
|
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
ResumeGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
msg2Txt.SetText(tr( "Installing ticket... Ok!" ));
|
|
|
|
msg3Txt.SetText(tr( ">> Installing title..." ));
|
2010-09-19 01:16:05 +02:00
|
|
|
//WindowPrompt(">> Installing title...",0,0,0,0,0,200);
|
|
|
|
HaltGui();
|
|
|
|
// Install title
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = ES_AddTitleStart(p_tmd, header->tmd_len, p_certs, header->certs_len, p_crl, header->crl_len);
|
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
// Get TMD info
|
2010-09-24 02:48:03 +02:00
|
|
|
tmd_data = (tmd *) SIGNATURE_PAYLOAD(p_tmd);
|
2010-11-13 23:34:53 +01:00
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
char imgPath[150];
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
// Install contents
|
|
|
|
//ResumeGui();
|
|
|
|
//HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
promptWindow.Append(&progressbarEmptyImg);
|
|
|
|
promptWindow.Append(&progressbarImg);
|
|
|
|
promptWindow.Append(&progressbarOutlineImg);
|
|
|
|
promptWindow.Append(&prTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
ResumeGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
msg3Txt.SetText(tr( "Installing title... Ok!" ));
|
|
|
|
for (cnt = 0; cnt < tmd_data->num_contents; cnt++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
tmd_content *content = &tmd_data->contents[cnt];
|
|
|
|
|
|
|
|
u32 idx = 0, len;
|
|
|
|
s32 cfd;
|
|
|
|
ResumeGui();
|
|
|
|
|
|
|
|
//printf("\r\t\t>> Installing content #%02d...", content->cid);
|
|
|
|
// Encrypted content size
|
|
|
|
len = round_up( content->size, 64 );
|
|
|
|
|
|
|
|
// Install content
|
2010-09-24 02:48:03 +02:00
|
|
|
cfd = ES_AddContentStart(tmd_data->title_id, content->cid);
|
|
|
|
if (cfd < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
ret = cfd;
|
|
|
|
goto err;
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
snprintf(imgPath, sizeof(imgPath), "%s%d...", tr( ">> Installing content #" ), content->cid);
|
|
|
|
msg4Txt.SetText(imgPath);
|
2010-09-19 01:16:05 +02:00
|
|
|
// Install content data
|
2010-09-24 02:48:03 +02:00
|
|
|
while (idx < len)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
//VIDEO_WaitVSync ();
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
u32 size;
|
|
|
|
|
|
|
|
// Data length
|
2010-09-24 02:48:03 +02:00
|
|
|
size = (len - idx);
|
|
|
|
if (size > BLOCK_SIZE) size = BLOCK_SIZE;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Read data
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadFile(fp, &wadBuffer, offset, size);
|
|
|
|
if (ret < 0) goto err;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Install data
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = ES_AddContentData(cfd, wadBuffer, size);
|
|
|
|
if (ret < 0) goto err;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Increase variables
|
2010-09-24 02:48:03 +02:00
|
|
|
idx += size;
|
2010-09-19 01:16:05 +02:00
|
|
|
offset += size;
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
//snprintf(imgPath, sizeof(imgPath), "%s%d (%d)...",tr(">> Installing content #"),content->cid,idx);
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
//msg4Txt.SetText(imgPath);
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
prTxt.SetTextf("%i%%", 100 * (cnt * len + idx) / (tmd_data->num_contents * len));
|
2010-10-27 16:45:27 +02:00
|
|
|
if ((Settings.wsprompt) && (Settings.widescreen))
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarImg.SetTile(78 * (cnt * len + idx) / (tmd_data->num_contents * len));
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
progressbarImg.SetTile(100 * (cnt * len + idx) / (tmd_data->num_contents * len));
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Finish content installation
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = ES_AddContentFinish(cfd);
|
|
|
|
if (ret < 0) goto err;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
msg4Txt.SetText(tr( "Installing content... Ok!" ));
|
|
|
|
msg5Txt.SetText(tr( ">> Finishing installation..." ));
|
2010-02-09 11:59:55 +01:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
// Finish title install
|
|
|
|
ret = ES_AddTitleFinish();
|
2010-09-24 02:48:03 +02:00
|
|
|
if (ret >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
// printf(" OK!\n");
|
2010-09-19 01:16:05 +02:00
|
|
|
goto out;
|
|
|
|
}
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
err:
|
2010-09-19 01:16:05 +02:00
|
|
|
//char titties[100];
|
|
|
|
ResumeGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
prTxt.SetTextf("%s%d", tr( "Error..." ), ret);
|
|
|
|
promptWindow.Append(&prTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
fail = true;
|
|
|
|
//snprintf(titties, sizeof(titties), "%d", ret);
|
|
|
|
//printf(" ERROR! (ret = %d)\n", ret);
|
|
|
|
//WindowPrompt("ERROR!",titties,"Back",0,0);
|
|
|
|
// Cancel install
|
|
|
|
ES_AddTitleCancel();
|
|
|
|
goto exit;
|
|
|
|
//return ret;
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
out:
|
2010-09-19 01:16:05 +02:00
|
|
|
// Free memory
|
2010-09-24 02:48:03 +02:00
|
|
|
if (header) free(header);
|
|
|
|
if (p_certs) free(p_certs);
|
|
|
|
if (p_crl) free(p_crl);
|
|
|
|
if (p_tik) free(p_tik);
|
|
|
|
if (p_tmd) free(p_tmd);
|
2010-09-19 01:16:05 +02:00
|
|
|
goto exit;
|
2009-07-31 22:15:55 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
exit: if (!fail) msg5Txt.SetText(tr( "Finishing installation... Ok!" ));
|
|
|
|
promptWindow.Append(&btn1);
|
|
|
|
while (btn1.GetState() != STATE_CLICKED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
}
|
2009-07-31 22:15:55 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
mainWindow->Remove(&promptWindow);
|
|
|
|
mainWindow->SetState(STATE_DEFAULT);
|
2010-09-19 01:16:05 +02:00
|
|
|
ResumeGui();
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2009-07-11 09:21:38 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s32 Wad_Uninstall(FILE *fp)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
//////start the gui shit
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiWindow promptWindow(472, 320);
|
|
|
|
promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
|
|
|
promptWindow.SetPosition(0, -10);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-26 10:33:43 +02:00
|
|
|
GuiImageData btnOutline(Resources::GetFile("button_dialogue_box.png"), Resources::GetFileSize("button_dialogue_box.png"));
|
|
|
|
GuiImageData dialogBox(Resources::GetFile("dialogue_box.png"), Resources::GetFileSize("dialogue_box.png"));
|
2010-09-19 01:16:05 +02:00
|
|
|
GuiTrigger trigA;
|
2010-09-24 02:48:03 +02:00
|
|
|
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage dialogBoxImg(&dialogBox);
|
2010-10-27 16:45:27 +02:00
|
|
|
if (Settings.wsprompt)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
dialogBoxImg.SetWidescreen(Settings.widescreen);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText btn1Txt(tr( "OK" ), 22, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
GuiImage btn1Img(&btnOutline);
|
2010-10-27 16:45:27 +02:00
|
|
|
if (Settings.wsprompt)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
btn1Txt.SetWidescreen(Settings.widescreen);
|
|
|
|
btn1Img.SetWidescreen(Settings.widescreen);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
2010-11-13 23:34:53 +01:00
|
|
|
GuiButton btn1(&btn1Img, &btn1Img, 2, 4, 0, -55, &trigA, btnSoundOver, btnSoundClick2, 1);
|
2010-09-24 02:48:03 +02:00
|
|
|
btn1.SetLabel(&btn1Txt);
|
|
|
|
btn1.SetState(STATE_SELECTED);
|
2009-07-28 13:04:15 +02:00
|
|
|
|
|
|
|
char title[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(title, "%s", tr( "Uninstalling wad" ));
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText titleTxt(title, 26, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
|
|
|
titleTxt.SetPosition(0, 40);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg1Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg1Txt.SetPosition(50, 75);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg2Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg2Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg2Txt.SetPosition(50, 98);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg3Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg3Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg3Txt.SetPosition(50, 121);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg4Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg4Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg4Txt.SetPosition(50, 144);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-12-26 18:02:14 +01:00
|
|
|
GuiText msg5Txt((char*) NULL, 18, thColor("r=0 g=0 b=0 a=255 - prompt windows text color"));
|
2010-09-24 02:48:03 +02:00
|
|
|
msg5Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
|
|
|
msg5Txt.SetPosition(50, 167);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-10-27 16:45:27 +02:00
|
|
|
if ((Settings.wsprompt) && (Settings.widescreen)) /////////////adjust for widescreen
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetPosition(70, 95);
|
|
|
|
msg2Txt.SetPosition(70, 118);
|
|
|
|
msg3Txt.SetPosition(70, 141);
|
|
|
|
msg4Txt.SetPosition(70, 164);
|
|
|
|
msg5Txt.SetPosition(70, 187);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
}
|
2010-09-24 02:48:03 +02:00
|
|
|
promptWindow.Append(&dialogBoxImg);
|
|
|
|
promptWindow.Append(&titleTxt);
|
|
|
|
promptWindow.Append(&msg5Txt);
|
|
|
|
promptWindow.Append(&msg4Txt);
|
|
|
|
promptWindow.Append(&msg3Txt);
|
|
|
|
promptWindow.Append(&msg1Txt);
|
|
|
|
promptWindow.Append(&msg2Txt);
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
mainWindow->SetState(STATE_DISABLED);
|
|
|
|
mainWindow->Append(&promptWindow);
|
|
|
|
mainWindow->ChangeFocus(&promptWindow);
|
2010-09-19 01:16:05 +02:00
|
|
|
ResumeGui();
|
|
|
|
//sleep(3);
|
|
|
|
|
|
|
|
///start the wad shit
|
2010-09-24 02:48:03 +02:00
|
|
|
wadHeader *header = NULL;
|
|
|
|
void *pvoid = NULL;
|
|
|
|
tikview *viewData = NULL;
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
u64 tid;
|
|
|
|
u32 viewCnt;
|
|
|
|
s32 ret;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetText(tr( ">> Reading WAD data..." ));
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
// WAD header
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_ReadAlloc(fp, &pvoid, 0, sizeof(wadHeader));
|
|
|
|
if (ret < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
char errTxt[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(errTxt, "%sret = %d", tr( ">> Reading WAD data...ERROR! " ), ret);
|
|
|
|
msg1Txt.SetText(errTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
//printf(" ERROR! (ret = %d)\n", ret);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
SetPointer( header, pvoid );
|
|
|
|
|
|
|
|
// Get title ID
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = __Wad_GetTitleID(fp, header, &tid);
|
|
|
|
if (ret < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
//printf(" ERROR! (ret = %d)\n", ret);
|
|
|
|
char errTxt[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(errTxt, "%sret = %d", tr( ">> Reading WAD data...ERROR! " ), ret);
|
|
|
|
msg1Txt.SetText(errTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
msg1Txt.SetText(tr( ">> Reading WAD data...Ok!" ));
|
|
|
|
msg2Txt.SetText(tr( ">> Deleting tickets..." ));
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
// Get ticket views
|
2010-09-24 15:46:32 +02:00
|
|
|
ret = NandTitles.GetTicketViews(tid, &viewData, &viewCnt);
|
2010-09-24 02:48:03 +02:00
|
|
|
if (ret < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
char errTxt[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(errTxt, "%sret = %d", tr( ">> Deleting tickets...ERROR! " ), ret);
|
|
|
|
msg2Txt.SetText(errTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
//printf(" ERROR! (ret = %d)\n", ret);
|
|
|
|
}
|
|
|
|
// Delete tickets
|
2010-09-24 02:48:03 +02:00
|
|
|
if (ret >= 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
u32 cnt;
|
|
|
|
|
|
|
|
// Delete all tickets
|
2010-09-24 02:48:03 +02:00
|
|
|
for (cnt = 0; cnt < viewCnt; cnt++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = ES_DeleteTicket(&viewData[cnt]);
|
|
|
|
if (ret < 0) break;
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (ret < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
char errTxt[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(errTxt, "%sret = %d", tr( ">> Deleting tickets...ERROR! " ), ret);
|
|
|
|
msg2Txt.SetText(errTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
//printf(" ERROR! (ret = %d\n", ret);
|
|
|
|
else
|
2010-09-24 02:48:03 +02:00
|
|
|
//printf(" OK!\n");
|
|
|
|
msg2Txt.SetText(tr( ">> Deleting tickets...Ok! " ));
|
2010-09-19 01:16:05 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
msg3Txt.SetText(tr( ">> Deleting title contents..." ));
|
2010-09-19 01:16:05 +02:00
|
|
|
//WindowPrompt(">> Deleting title contents...",0,"Back",0,0);
|
|
|
|
|
|
|
|
// Delete title contents
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = ES_DeleteTitleContent(tid);
|
|
|
|
if (ret < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
char errTxt[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(errTxt, "%sret = %d", tr( ">> Deleting title contents...ERROR! " ), ret);
|
|
|
|
msg3Txt.SetText(errTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
//printf(" ERROR! (ret = %d)\n", ret);
|
|
|
|
else
|
2010-09-24 02:48:03 +02:00
|
|
|
//printf(" OK!\n");
|
|
|
|
msg3Txt.SetText(tr( ">> Deleting title contents...Ok!" ));
|
2010-09-19 01:16:05 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
msg4Txt.SetText(tr( ">> Deleting title..." ));
|
2010-09-19 01:16:05 +02:00
|
|
|
// Delete title
|
2010-09-24 02:48:03 +02:00
|
|
|
ret = ES_DeleteTitle(tid);
|
|
|
|
if (ret < 0)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
char errTxt[50];
|
2010-09-24 02:48:03 +02:00
|
|
|
sprintf(errTxt, "%sret = %d", tr( ">> Deleting title ...ERROR! " ), ret);
|
|
|
|
msg4Txt.SetText(errTxt);
|
2010-09-19 01:16:05 +02:00
|
|
|
}
|
|
|
|
//printf(" ERROR! (ret = %d)\n", ret);
|
|
|
|
else
|
2010-09-24 02:48:03 +02:00
|
|
|
//printf(" OK!\n");
|
|
|
|
msg4Txt.SetText(tr( ">> Deleting title ...Ok!" ));
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
out:
|
2010-09-19 01:16:05 +02:00
|
|
|
// Free memory
|
2010-09-24 02:48:03 +02:00
|
|
|
if (header) free(header);
|
2009-07-11 09:21:38 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
goto exit;
|
2009-07-31 22:15:55 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
exit: msg5Txt.SetText(tr( "Done!" ));
|
|
|
|
promptWindow.Append(&btn1);
|
|
|
|
while (btn1.GetState() != STATE_CLICKED)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
|
|
|
}
|
2009-07-31 22:15:55 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
HaltGui();
|
2010-09-24 02:48:03 +02:00
|
|
|
mainWindow->Remove(&promptWindow);
|
|
|
|
mainWindow->SetState(STATE_DEFAULT);
|
2010-09-19 01:16:05 +02:00
|
|
|
ResumeGui();
|
2009-07-28 13:04:15 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
return ret;
|
2009-07-11 09:21:38 +02:00
|
|
|
}
|
|
|
|
|