mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-04 18:45:05 +01:00
forgot to upload these files with the last stuff.
This commit is contained in:
parent
9b46eb613a
commit
37c620db90
256
source/title.c
Normal file
256
source/title.c
Normal file
@ -0,0 +1,256 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <ogcsys.h>
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
s32 Title_GetList(u64 **outbuf, u32 *outlen)
|
||||
{
|
||||
u64 *titles = NULL;
|
||||
|
||||
u32 len, nb_titles;
|
||||
s32 ret;
|
||||
|
||||
/* Get number of titles */
|
||||
ret = ES_GetNumTitles(&nb_titles);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Calculate buffer lenght */
|
||||
len = round_up(sizeof(u64) * nb_titles, 32);
|
||||
|
||||
/* Allocate memory */
|
||||
titles = memalign(32, len);
|
||||
if (!titles)
|
||||
return -1;
|
||||
|
||||
/* Get titles */
|
||||
ret = ES_GetTitles(titles, nb_titles);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
/* Set values */
|
||||
*outbuf = titles;
|
||||
*outlen = nb_titles;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
/* Free memory */
|
||||
if (titles)
|
||||
free(titles);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 Title_GetTicketViews(u64 tid, tikview **outbuf, u32 *outlen)
|
||||
{
|
||||
tikview *views = NULL;
|
||||
|
||||
u32 nb_views;
|
||||
s32 ret;
|
||||
|
||||
/* Get number of ticket views */
|
||||
ret = ES_GetNumTicketViews(tid, &nb_views);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Allocate memory */
|
||||
views = (tikview *)memalign(32, sizeof(tikview) * nb_views);
|
||||
if (!views)
|
||||
return -1;
|
||||
|
||||
/* Get ticket views */
|
||||
ret = ES_GetTicketViews(tid, views, nb_views);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
/* Set values */
|
||||
*outbuf = views;
|
||||
*outlen = nb_views;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
/* Free memory */
|
||||
if (views)
|
||||
free(views);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 Title_GetTMD(u64 tid, signed_blob **outbuf, u32 *outlen)
|
||||
{
|
||||
void *p_tmd = NULL;
|
||||
|
||||
u32 len;
|
||||
s32 ret;
|
||||
|
||||
/* Get TMD size */
|
||||
ret = ES_GetStoredTMDSize(tid, &len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Allocate memory */
|
||||
p_tmd = memalign(32, round_up(len, 32));
|
||||
if (!p_tmd)
|
||||
return -1;
|
||||
|
||||
/* Read TMD */
|
||||
ret = ES_GetStoredTMD(tid, p_tmd, len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
/* Set values */
|
||||
*outbuf = p_tmd;
|
||||
*outlen = len;
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
/* Free memory */
|
||||
if (p_tmd)
|
||||
free(p_tmd);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 Title_GetVersion(u64 tid, u16 *outbuf)
|
||||
{
|
||||
signed_blob *p_tmd = NULL;
|
||||
tmd *tmd_data = NULL;
|
||||
|
||||
u32 len;
|
||||
s32 ret;
|
||||
|
||||
/* Get title TMD */
|
||||
ret = Title_GetTMD(tid, &p_tmd, &len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Retrieve TMD info */
|
||||
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
|
||||
|
||||
/* Set values */
|
||||
*outbuf = tmd_data->title_version;
|
||||
|
||||
/* Free memory */
|
||||
free(p_tmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 Title_GetSysVersion(u64 tid, u64 *outbuf)
|
||||
{
|
||||
signed_blob *p_tmd = NULL;
|
||||
tmd *tmd_data = NULL;
|
||||
|
||||
u32 len;
|
||||
s32 ret;
|
||||
|
||||
/* Get title TMD */
|
||||
ret = Title_GetTMD(tid, &p_tmd, &len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Retrieve TMD info */
|
||||
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
|
||||
|
||||
/* Set values */
|
||||
*outbuf = tmd_data->sys_version;
|
||||
|
||||
/* Free memory */
|
||||
free(p_tmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 Title_GetSize(u64 tid, u32 *outbuf)
|
||||
{
|
||||
signed_blob *p_tmd = NULL;
|
||||
tmd *tmd_data = NULL;
|
||||
|
||||
u32 cnt, len, size = 0;
|
||||
s32 ret;
|
||||
|
||||
/* Get title TMD */
|
||||
ret = Title_GetTMD(tid, &p_tmd, &len);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Retrieve TMD info */
|
||||
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
|
||||
|
||||
/* Calculate title size */
|
||||
for (cnt = 0; cnt < tmd_data->num_contents; cnt++) {
|
||||
tmd_content *content = &tmd_data->contents[cnt];
|
||||
|
||||
/* Add content size */
|
||||
size += content->size;
|
||||
}
|
||||
|
||||
/* Set values */
|
||||
*outbuf = size;
|
||||
|
||||
/* Free memory */
|
||||
free(p_tmd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 Title_GetIOSVersions(u8 **outbuf, u32 *outlen)
|
||||
{
|
||||
u8 *buffer = NULL;
|
||||
u64 *list = NULL;
|
||||
|
||||
u32 count, cnt, idx;
|
||||
s32 ret;
|
||||
|
||||
/* Get title list */
|
||||
ret = Title_GetList(&list, &count);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
/* Count IOS */
|
||||
for (cnt = idx = 0; idx < count; idx++) {
|
||||
u32 tidh = (list[idx] >> 32);
|
||||
u32 tidl = (list[idx] & 0xFFFFFFFF);
|
||||
|
||||
/* Title is IOS */
|
||||
if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255))
|
||||
cnt++;
|
||||
}
|
||||
|
||||
/* Allocate memory */
|
||||
buffer = (u8 *)memalign(32, cnt);
|
||||
if (!buffer) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Copy IOS */
|
||||
for (cnt = idx = 0; idx < count; idx++) {
|
||||
u32 tidh = (list[idx] >> 32);
|
||||
u32 tidl = (list[idx] & 0xFFFFFFFF);
|
||||
|
||||
/* Title is IOS */
|
||||
if ((tidh == 0x1) && (tidl >= 3) && (tidl <= 255))
|
||||
buffer[cnt++] = (u8)(tidl & 0xFF);
|
||||
}
|
||||
|
||||
/* Set values */
|
||||
*outbuf = buffer;
|
||||
*outlen = cnt;
|
||||
|
||||
goto out;
|
||||
|
||||
out:
|
||||
/* Free memory */
|
||||
if (list)
|
||||
free(list);
|
||||
|
||||
return ret;
|
||||
}
|
24
source/title.h
Normal file
24
source/title.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef _TITLE_H_
|
||||
#define _TITLE_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* Constants */
|
||||
#define BLOCK_SIZE 1024
|
||||
|
||||
/* Prototypes */
|
||||
s32 Title_GetList(u64 **, u32 *);
|
||||
s32 Title_GetTicketViews(u64, tikview **, u32 *);
|
||||
s32 Title_GetTMD(u64, signed_blob **, u32 *);
|
||||
s32 Title_GetVersion(u64, u16 *);
|
||||
s32 Title_GetSysVersion(u64, u64 *);
|
||||
s32 Title_GetSize(u64, u32 *);
|
||||
s32 Title_GetIOSVersions(u8 **, u32 *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
23
source/utils.h
Normal file
23
source/utils.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef _UTILS_H_
|
||||
#define _UTILS_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
/* Constants */
|
||||
#define KB_SIZE 1024.0
|
||||
#define MB_SIZE 1048576.0
|
||||
#define GB_SIZE 1073741824.0
|
||||
|
||||
/* Macros */
|
||||
#define round_up(x,n) (-(-(x) & -(n)))
|
||||
|
||||
/* Prototypes */
|
||||
u32 swap32(u32);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
676
source/wad.cpp
Normal file
676
source/wad.cpp
Normal file
@ -0,0 +1,676 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <malloc.h>
|
||||
#include <ogcsys.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "title.h"
|
||||
#include "utils.h"
|
||||
#include "video.h"
|
||||
#include "wad.h"
|
||||
|
||||
|
||||
|
||||
#include "prompts/PromptWindows.h"
|
||||
#include "libwiigui/gui.h"
|
||||
#include "language/gettext.h"
|
||||
#include "menu.h"
|
||||
#include "filelist.h"
|
||||
/*** Extern functions ***/
|
||||
extern void ResumeGui();
|
||||
extern void HaltGui();
|
||||
/*** Extern variables ***/
|
||||
extern GuiWindow * mainWindow;
|
||||
|
||||
|
||||
|
||||
/* 'WAD Header' structure */
|
||||
typedef struct {
|
||||
/* Header length */
|
||||
u32 header_len;
|
||||
|
||||
/* WAD type */
|
||||
u16 type;
|
||||
|
||||
u16 padding;
|
||||
|
||||
/* Data length */
|
||||
u32 certs_len;
|
||||
u32 crl_len;
|
||||
u32 tik_len;
|
||||
u32 tmd_len;
|
||||
u32 data_len;
|
||||
u32 footer_len;
|
||||
} ATTRIBUTE_PACKED wadHeader;
|
||||
|
||||
/* Variables */
|
||||
static u8 wadBuffer[BLOCK_SIZE] ATTRIBUTE_ALIGN(32);
|
||||
|
||||
|
||||
s32 __Wad_ReadFile(FILE *fp, void *outbuf, u32 offset, u32 len)
|
||||
{
|
||||
s32 ret;
|
||||
|
||||
/* Seek to offset */
|
||||
fseek(fp, offset, SEEK_SET);
|
||||
|
||||
/* Read data */
|
||||
ret = fread(outbuf, len, 1, fp);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __Wad_ReadAlloc(FILE *fp, void **outbuf, u32 offset, u32 len)
|
||||
{
|
||||
void *buffer = NULL;
|
||||
s32 ret;
|
||||
|
||||
/* Allocate memory */
|
||||
buffer = memalign(32, len);
|
||||
if (!buffer)
|
||||
return -1;
|
||||
|
||||
/* Read file */
|
||||
ret = __Wad_ReadFile(fp, buffer, offset, len);
|
||||
if (ret < 0) {
|
||||
free(buffer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Set pointer */
|
||||
*outbuf = buffer;
|
||||
return 0;
|
||||
}
|
||||
|
||||
s32 __Wad_GetTitleID(FILE *fp, wadHeader *header, u64 *tid)
|
||||
{
|
||||
//signed_blob *p_tik = NULL;
|
||||
void *p_tik = NULL;
|
||||
tik *tik_data = NULL;
|
||||
|
||||
u32 offset = 0;
|
||||
s32 ret;
|
||||
|
||||
/* Ticket offset */
|
||||
offset += round_up(header->header_len, 64);
|
||||
offset += round_up(header->certs_len, 64);
|
||||
offset += round_up(header->crl_len, 64);
|
||||
|
||||
/* Read ticket */
|
||||
ret = __Wad_ReadAlloc(fp, &p_tik, offset, header->tik_len);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
|
||||
/* Ticket data */
|
||||
tik_data = (tik *)SIGNATURE_PAYLOAD((signed_blob *)p_tik);
|
||||
|
||||
/* Copy title ID */
|
||||
*tid = tik_data->titleid;
|
||||
|
||||
out:
|
||||
/* Free memory */
|
||||
if (p_tik)
|
||||
free(p_tik);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/*s32 Wad_Install(FILE *fp)
|
||||
{
|
||||
wadHeader *header = NULL;
|
||||
signed_blob *p_certs = NULL, *p_crl = NULL, *p_tik = NULL, *p_tmd = NULL;
|
||||
|
||||
tmd *tmd_data = NULL;
|
||||
|
||||
u32 cnt, offset = 0;
|
||||
s32 ret = 666;
|
||||
|
||||
//WindowPrompt("Here we go...","don't turn off your Wii",0,0,0,0,200);
|
||||
// WAD header
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)header, offset, sizeof(wadHeader));
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&header, offset, sizeof(wadHeader));
|
||||
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->header_len, 64);
|
||||
|
||||
// WAD certificates
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_certs, offset, header->certs_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_certs, offset, header->certs_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->certs_len, 64);
|
||||
|
||||
// WAD crl
|
||||
|
||||
if (header->crl_len) {
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_crl, offset, header->crl_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_crl, offset, header->crl_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->crl_len, 64);
|
||||
}
|
||||
|
||||
// WAD ticket
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_tik, offset, header->tik_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_tik, offset, header->tik_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->tik_len, 64);
|
||||
|
||||
// WAD TMD
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_tmd, offset, header->tmd_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_tmd, offset, header->tmd_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->tmd_len, 64);
|
||||
|
||||
//WindowPrompt("Installing ticket...",0,0,0,0,0,200);
|
||||
|
||||
// Install ticket
|
||||
ret = ES_AddTicket(p_tik, header->tik_len, p_certs, header->certs_len, p_crl, header->crl_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
//WindowPrompt(">> Installing title...",0,0,0,0,0,200);
|
||||
|
||||
// Install title
|
||||
ret = ES_AddTitleStart(p_tmd, header->tmd_len, p_certs, header->certs_len, p_crl, header->crl_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
// Get TMD info
|
||||
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
|
||||
|
||||
// Install contents
|
||||
for (cnt = 0; cnt < tmd_data->num_contents; cnt++) {
|
||||
tmd_content *content = &tmd_data->contents[cnt];
|
||||
|
||||
u32 idx = 0, len;
|
||||
s32 cfd;
|
||||
|
||||
//printf("\r\t\t>> Installing content #%02d...", content->cid);
|
||||
|
||||
// Encrypted content size
|
||||
len = round_up(content->size, 64);
|
||||
|
||||
// Install content
|
||||
cfd = ES_AddContentStart(tmd_data->title_id, content->cid);
|
||||
if (cfd < 0) {
|
||||
ret = cfd;
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Install content data
|
||||
while (idx < len) {
|
||||
u32 size;
|
||||
|
||||
// Data length
|
||||
size = (len - idx);
|
||||
if (size > BLOCK_SIZE)
|
||||
size = BLOCK_SIZE;
|
||||
|
||||
// Read data
|
||||
ret = __Wad_ReadFile(fp, &wadBuffer, offset, size);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
// Install data
|
||||
ret = ES_AddContentData(cfd, wadBuffer, size);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
// Increase variables
|
||||
idx += size;
|
||||
offset += size;
|
||||
}
|
||||
|
||||
// Finish content installation
|
||||
ret = ES_AddContentFinish(cfd);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
//WindowPrompt(">> Finishing installation...",0,0,0,0,0,200);
|
||||
|
||||
// Finish title install
|
||||
ret = ES_AddTitleFinish();
|
||||
if (ret >= 0) {
|
||||
// printf(" OK!\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
err:
|
||||
//char titties[100];
|
||||
//snprintf(titties, sizeof(titties), "%d", ret);
|
||||
//printf(" ERROR! (ret = %d)\n", ret);
|
||||
//WindowPrompt("ERROR!",titties,"Back",0,0);
|
||||
// Cancel install
|
||||
ES_AddTitleCancel();
|
||||
return ret;
|
||||
|
||||
out:
|
||||
// Free memory
|
||||
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);
|
||||
|
||||
//WindowPrompt(tr("Success"),"The wad file was installed","Ok");
|
||||
return ret;
|
||||
}*/
|
||||
|
||||
|
||||
s32 Wad_Install(FILE *fp)
|
||||
{
|
||||
//////start the gui shit
|
||||
GuiWindow promptWindow(472,320);
|
||||
promptWindow.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
promptWindow.SetPosition(0, -10);
|
||||
|
||||
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume);
|
||||
GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume);
|
||||
|
||||
char imgPath[100];
|
||||
snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path);
|
||||
GuiImageData btnOutline(imgPath, button_dialogue_box_png);
|
||||
snprintf(imgPath, sizeof(imgPath), "%sdialogue_box.png", CFG.theme_path);
|
||||
GuiImageData dialogBox(imgPath, dialogue_box_png);
|
||||
GuiTrigger trigA;
|
||||
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
|
||||
|
||||
GuiImage dialogBoxImg(&dialogBox);
|
||||
if (Settings.wsprompt == yes){
|
||||
dialogBoxImg.SetWidescreen(CFG.widescreen);}
|
||||
|
||||
GuiText btn1Txt(tr("Ok"), 22, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
GuiImage btn1Img(&btnOutline);
|
||||
if (Settings.wsprompt == yes){
|
||||
btn1Txt.SetWidescreen(CFG.widescreen);
|
||||
btn1Img.SetWidescreen(CFG.widescreen);}
|
||||
GuiButton btn1(&btn1Img,&btn1Img, 2, 4, 0, -35, &trigA, &btnSoundOver, &btnClick,1);
|
||||
btn1.SetLabel(&btn1Txt);
|
||||
btn1.SetState(STATE_SELECTED);
|
||||
|
||||
snprintf(imgPath, sizeof(imgPath), "%sprogressbar_outline.png", CFG.theme_path);
|
||||
GuiImageData progressbarOutline(imgPath, progressbar_outline_png);
|
||||
GuiImage progressbarOutlineImg(&progressbarOutline);
|
||||
if (Settings.wsprompt == yes){
|
||||
progressbarOutlineImg.SetWidescreen(CFG.widescreen);}
|
||||
progressbarOutlineImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
progressbarOutlineImg.SetPosition(25, 50);
|
||||
|
||||
snprintf(imgPath, sizeof(imgPath), "%sprogressbar_empty.png", CFG.theme_path);
|
||||
GuiImageData progressbarEmpty(imgPath, progressbar_empty_png);
|
||||
GuiImage progressbarEmptyImg(&progressbarEmpty);
|
||||
progressbarEmptyImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
progressbarEmptyImg.SetPosition(25, 50);
|
||||
progressbarEmptyImg.SetTile(100);
|
||||
|
||||
snprintf(imgPath, sizeof(imgPath), "%sprogressbar.png", CFG.theme_path);
|
||||
GuiImageData progressbar(imgPath, progressbar_png);
|
||||
GuiImage progressbarImg(&progressbar);
|
||||
progressbarImg.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
|
||||
progressbarImg.SetPosition(25, 50);
|
||||
|
||||
char title[50];
|
||||
sprintf(title, "%s", tr("Installing wad"));
|
||||
GuiText titleTxt(title, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
titleTxt.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
|
||||
titleTxt.SetPosition(0,40);
|
||||
char msg[50];
|
||||
sprintf(msg, " ");
|
||||
// sprintf(msg, "%s", tr("Initializing Network"));
|
||||
GuiText msg1Txt(NULL, 20, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
msg1Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg1Txt.SetPosition(50,75);
|
||||
// char msg2[50] = " ";
|
||||
GuiText msg2Txt(NULL, 20, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
msg2Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg2Txt.SetPosition(50, 98);
|
||||
|
||||
GuiText msg3Txt(NULL, 20, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
msg3Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg3Txt.SetPosition(50, 121);
|
||||
|
||||
GuiText msg4Txt(NULL, 20, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
msg4Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg4Txt.SetPosition(50, 144);
|
||||
|
||||
GuiText msg5Txt(NULL, 20, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
msg5Txt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
|
||||
msg5Txt.SetPosition(50, 167);
|
||||
|
||||
GuiText prTxt(NULL, 26, (GXColor){THEME.prompttxt_r, THEME.prompttxt_g, THEME.prompttxt_b, 255});
|
||||
prTxt.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
|
||||
prTxt.SetPosition(0, 50);
|
||||
|
||||
|
||||
if ((Settings.wsprompt == yes) && (CFG.widescreen)){/////////////adjust for widescreen
|
||||
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);
|
||||
|
||||
}
|
||||
promptWindow.Append(&dialogBoxImg);
|
||||
promptWindow.Append(&titleTxt);
|
||||
promptWindow.Append(&msg5Txt);
|
||||
promptWindow.Append(&msg4Txt);
|
||||
promptWindow.Append(&msg3Txt);
|
||||
promptWindow.Append(&msg1Txt);
|
||||
promptWindow.Append(&msg2Txt);
|
||||
|
||||
//promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_IN, 50);
|
||||
|
||||
HaltGui();
|
||||
mainWindow->SetState(STATE_DISABLED);
|
||||
mainWindow->Append(&promptWindow);
|
||||
mainWindow->ChangeFocus(&promptWindow);
|
||||
//sleep(1);
|
||||
|
||||
|
||||
///start the wad shit
|
||||
wadHeader *header = NULL;
|
||||
signed_blob *p_certs = NULL, *p_crl = NULL, *p_tik = NULL, *p_tmd = NULL;
|
||||
|
||||
tmd *tmd_data = NULL;
|
||||
|
||||
u32 cnt, offset = 0;
|
||||
s32 ret = 666;
|
||||
|
||||
|
||||
ResumeGui();
|
||||
msg1Txt.SetText(tr(">> Reading WAD data..."));
|
||||
HaltGui();
|
||||
// WAD header
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)header, offset, sizeof(wadHeader));
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&header, offset, sizeof(wadHeader));
|
||||
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->header_len, 64);
|
||||
|
||||
// WAD certificates
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_certs, offset, header->certs_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_certs, offset, header->certs_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->certs_len, 64);
|
||||
|
||||
// WAD crl
|
||||
|
||||
if (header->crl_len) {
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_crl, offset, header->crl_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_crl, offset, header->crl_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->crl_len, 64);
|
||||
}
|
||||
|
||||
// WAD ticket
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_tik, offset, header->tik_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_tik, offset, header->tik_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->tik_len, 64);
|
||||
|
||||
// WAD TMD
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&p_tmd, offset, header->tmd_len);
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&p_tmd, offset, header->tmd_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
else
|
||||
offset += round_up(header->tmd_len, 64);
|
||||
ResumeGui();
|
||||
msg1Txt.SetText(tr("Reading WAD data... Ok!"));
|
||||
msg2Txt.SetText(tr(">> Installing ticket..."));
|
||||
HaltGui();
|
||||
// Install ticket
|
||||
ret = ES_AddTicket(p_tik, header->tik_len, p_certs, header->certs_len, p_crl, header->crl_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
ResumeGui();
|
||||
msg2Txt.SetText(tr("Installing ticket... Ok!"));
|
||||
msg3Txt.SetText(tr(">> Installing title..."));
|
||||
//WindowPrompt(">> Installing title...",0,0,0,0,0,200);
|
||||
HaltGui();
|
||||
// Install title
|
||||
ret = ES_AddTitleStart(p_tmd, header->tmd_len, p_certs, header->certs_len, p_crl, header->crl_len);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
// Get TMD info
|
||||
tmd_data = (tmd *)SIGNATURE_PAYLOAD(p_tmd);
|
||||
|
||||
// Install contents
|
||||
//ResumeGui();
|
||||
//HaltGui();
|
||||
promptWindow.Append(&progressbarEmptyImg);
|
||||
promptWindow.Append(&progressbarImg);
|
||||
promptWindow.Append(&progressbarOutlineImg);
|
||||
promptWindow.Append(&prTxt);
|
||||
ResumeGui();
|
||||
msg3Txt.SetText(tr("Installing title... Ok!"));
|
||||
for (cnt = 0; cnt < tmd_data->num_contents; cnt++) {
|
||||
|
||||
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
|
||||
cfd = ES_AddContentStart(tmd_data->title_id, content->cid);
|
||||
if (cfd < 0) {
|
||||
ret = cfd;
|
||||
goto err;
|
||||
}
|
||||
|
||||
// Install content data
|
||||
while (idx < len) {
|
||||
u32 size;
|
||||
|
||||
// Data length
|
||||
size = (len - idx);
|
||||
if (size > BLOCK_SIZE)
|
||||
size = BLOCK_SIZE;
|
||||
|
||||
// Read data
|
||||
ret = __Wad_ReadFile(fp, &wadBuffer, offset, size);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
// Install data
|
||||
ret = ES_AddContentData(cfd, wadBuffer, size);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
|
||||
// Increase variables
|
||||
idx += size;
|
||||
offset += size;
|
||||
snprintf(imgPath, sizeof(imgPath), "%s%d (%d)...",tr(">> Installing content #"),content->cid,idx);
|
||||
|
||||
msg4Txt.SetText(imgPath);
|
||||
|
||||
prTxt.SetTextf("%i%%", 100*(cnt*len+idx)/(tmd_data->num_contents*len));
|
||||
if ((Settings.wsprompt == yes) && (CFG.widescreen)) {
|
||||
progressbarImg.SetTile(78*(cnt*len+idx)/(tmd_data->num_contents*len));
|
||||
} else {
|
||||
progressbarImg.SetTile(100*(cnt*len+idx)/(tmd_data->num_contents*len));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Finish content installation
|
||||
ret = ES_AddContentFinish(cfd);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
msg4Txt.SetText(tr("Installing content... Ok!"));
|
||||
msg5Txt.SetText(tr(">> Finishing installation..."));
|
||||
|
||||
|
||||
|
||||
// Finish title install
|
||||
ret = ES_AddTitleFinish();
|
||||
if (ret >= 0) {
|
||||
// printf(" OK!\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
err:
|
||||
//char titties[100];
|
||||
prTxt.SetTextf("%s%d", tr("Error..."),ret);
|
||||
//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;
|
||||
|
||||
out:
|
||||
// Free memory
|
||||
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);
|
||||
goto exit;
|
||||
|
||||
//WindowPrompt(tr("Success"),"The wad file was installed","Ok");
|
||||
|
||||
exit:
|
||||
//promptWindow.SetEffect(EFFECT_SLIDE_TOP | EFFECT_SLIDE_OUT, 50);
|
||||
//while(promptWindow.GetEffect() > 0) usleep(50);
|
||||
msg5Txt.SetText(tr("Finishing installation... Ok!"));
|
||||
promptWindow.Append(&btn1);
|
||||
while(btn1.GetState() != STATE_CLICKED){
|
||||
}
|
||||
|
||||
|
||||
HaltGui();
|
||||
mainWindow->Remove(&promptWindow);
|
||||
mainWindow->SetState(STATE_DEFAULT);
|
||||
ResumeGui();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 Wad_Uninstall(FILE *fp)
|
||||
{
|
||||
wadHeader *header = NULL;
|
||||
tikview *viewData = NULL;
|
||||
|
||||
u64 tid;
|
||||
u32 viewCnt;
|
||||
s32 ret;
|
||||
|
||||
//WindowPrompt(">> Reading WAD data...",0,"Back",0,0);
|
||||
|
||||
/* WAD header */
|
||||
//ret = __Wad_ReadAlloc(fp, (void *)&header, 0, sizeof(wadHeader));
|
||||
ret = __Wad_ReadAlloc(fp, (void **)&header, 0, sizeof(wadHeader));
|
||||
if (ret < 0) {
|
||||
//WindowPrompt(">> ERROR! (ret = ...",0,"Back",0,0);
|
||||
//printf(" ERROR! (ret = %d)\n", ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* Get title ID */
|
||||
ret = __Wad_GetTitleID(fp, header, &tid);
|
||||
if (ret < 0) {
|
||||
//printf(" ERROR! (ret = %d)\n", ret);
|
||||
//WindowPrompt(">> ERROR! (ret = ...",0,"Back",0,0);
|
||||
goto out;
|
||||
}
|
||||
|
||||
//WindowPrompt(">> Deleting tickets...",0,"Back",0,0);
|
||||
|
||||
/* Get ticket views */
|
||||
ret = Title_GetTicketViews(tid, &viewData, &viewCnt);
|
||||
if (ret < 0)
|
||||
//WindowPrompt(">> ERROR! (ret = ...",0,"Back",0,0);
|
||||
//printf(" ERROR! (ret = %d)\n", ret);
|
||||
|
||||
/* Delete tickets */
|
||||
if (ret >= 0) {
|
||||
u32 cnt;
|
||||
|
||||
/* Delete all tickets */
|
||||
for (cnt = 0; cnt < viewCnt; cnt++) {
|
||||
ret = ES_DeleteTicket(&viewData[cnt]);
|
||||
if (ret < 0)
|
||||
break;
|
||||
}
|
||||
|
||||
if (ret < 0){}
|
||||
//printf(" ERROR! (ret = %d\n", ret);
|
||||
else{}
|
||||
//printf(" OK!\n");
|
||||
}
|
||||
|
||||
//WindowPrompt(">> Deleting title contents...",0,"Back",0,0);
|
||||
|
||||
/* Delete title contents */
|
||||
ret = ES_DeleteTitleContent(tid);
|
||||
if (ret < 0){}
|
||||
//printf(" ERROR! (ret = %d)\n", ret);
|
||||
else{}
|
||||
//printf(" OK!\n");
|
||||
|
||||
|
||||
//WindowPrompt(">> Deleting title...",0,"Back",0,0);
|
||||
|
||||
/* Delete title */
|
||||
ret = ES_DeleteTitle(tid);
|
||||
if (ret < 0){}
|
||||
//printf(" ERROR! (ret = %d)\n", ret);
|
||||
else{}
|
||||
//printf(" OK!\n");
|
||||
|
||||
out:
|
||||
/* Free memory */
|
||||
if (header)
|
||||
free(header);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
8
source/wad.h
Normal file
8
source/wad.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef _WAD_H_
|
||||
#define _WAD_H_
|
||||
|
||||
/* Prototypes */
|
||||
s32 Wad_Install(FILE *);
|
||||
s32 Wad_Uninstall(FILE *);
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user