Dynamically calculate the totalProgress
This commit is contained in:
parent
fc36c5f436
commit
5c154181dc
|
@ -31,17 +31,16 @@ link_directories(
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(${PROJECT_NAME}
|
add_executable(${PROJECT_NAME}
|
||||||
src/main.c
|
|
||||||
src/ui.c
|
src/ui.c
|
||||||
src/install.c
|
src/install.c
|
||||||
src/io.c
|
src/io.c
|
||||||
src/promote.c
|
src/promote.c
|
||||||
src/pbp.c
|
src/pbp.c
|
||||||
src/sha256
|
src/sha256
|
||||||
|
src/main.c
|
||||||
)
|
)
|
||||||
|
|
||||||
target_link_libraries(${PROJECT_NAME}
|
target_link_libraries(${PROJECT_NAME}
|
||||||
|
|
||||||
vita2d
|
vita2d
|
||||||
z
|
z
|
||||||
c
|
c
|
||||||
|
|
|
@ -9,18 +9,26 @@
|
||||||
#include "install.h"
|
#include "install.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
|
static char* NeededDirectories[] = {
|
||||||
|
"ux0:pspemu",
|
||||||
|
"ux0:pspemu/PSP",
|
||||||
|
"ux0:pspemu/PSP/SAVEDATA",
|
||||||
|
"ux0:pspemu/temp",
|
||||||
|
"ux0:pspemu/temp/game",
|
||||||
|
"ux0:pspemu/temp/game/PSP",
|
||||||
|
"ux0:pspemu/temp/game/PSP/GAME",
|
||||||
|
"ux0:pspemu/temp/game/PSP/GAME/" TITLE_ID,
|
||||||
|
"ux0:pspemu/temp/game/PSP/LICENSE"
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t GetTotalNeededDirectories() {
|
||||||
|
return (sizeof(NeededDirectories) / sizeof(char*));
|
||||||
|
}
|
||||||
|
|
||||||
void createPspEmuDirectories() {
|
void createPspEmuDirectories() {
|
||||||
|
for(size_t i = 0; i < GetTotalNeededDirectories(); i++){
|
||||||
CreateDirAndUpdateUi("ux0:pspemu");
|
CreateDirAndUpdateUi(NeededDirectories[i]);
|
||||||
CreateDirAndUpdateUi("ux0:pspemu/PSP");
|
}
|
||||||
CreateDirAndUpdateUi("ux0:pspemu/PSP/SAVEDATA");
|
|
||||||
|
|
||||||
CreateDirAndUpdateUi("ux0:pspemu/temp");
|
|
||||||
CreateDirAndUpdateUi("ux0:pspemu/temp/game");
|
|
||||||
CreateDirAndUpdateUi("ux0:pspemu/temp/game/PSP");
|
|
||||||
CreateDirAndUpdateUi("ux0:pspemu/temp/game/PSP/GAME");
|
|
||||||
CreateDirAndUpdateUi("ux0:pspemu/temp/game/PSP/LICENSE");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -34,9 +42,9 @@ void genEbootSignature(char* ebootPath) {
|
||||||
memset(ebootSig, 0x00, sizeof(ebootSig));
|
memset(ebootSig, 0x00, sizeof(ebootSig));
|
||||||
memset(pbpHash, 0x00, sizeof(pbpHash));
|
memset(pbpHash, 0x00, sizeof(pbpHash));
|
||||||
|
|
||||||
snprintf(ebootSigFilePath, MAX_PATH, "ux0:/pspemu/temp/game/PSP/GAME/%s/__sce_ebootpbp", TITLE_ID);
|
snprintf(ebootSigFilePath, MAX_PATH, "ux0:pspemu/temp/game/PSP/GAME/%s/__sce_ebootpbp", TITLE_ID);
|
||||||
|
|
||||||
updateUi("Calculating EBOOT.PBP hash ...");
|
updateUi("Calculating EBOOT.PBP Sha256 ...");
|
||||||
HashPbp(ebootPath, pbpHash);
|
HashPbp(ebootPath, pbpHash);
|
||||||
|
|
||||||
updateUi("Generating EBOOT.PBP Signature ...");
|
updateUi("Generating EBOOT.PBP Signature ...");
|
||||||
|
@ -47,33 +55,28 @@ void genEbootSignature(char* ebootPath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void placePspGameData() {
|
void placePspGameData() {
|
||||||
char gameFolder[MAX_PATH];
|
|
||||||
char ebootFile[MAX_PATH];
|
char ebootFile[MAX_PATH];
|
||||||
char pbootFile[MAX_PATH];
|
char pbootFile[MAX_PATH];
|
||||||
char rifFile[MAX_PATH];
|
char rifFile[MAX_PATH];
|
||||||
|
|
||||||
// create game folder .
|
|
||||||
snprintf(gameFolder, MAX_PATH, "ux0:/pspemu/temp/game/PSP/GAME/%s", TITLE_ID);
|
|
||||||
CreateDirAndUpdateUi(gameFolder);
|
|
||||||
|
|
||||||
// get path to EBOOT.PBP and PBOOT.PBP
|
// get path to EBOOT.PBP and PBOOT.PBP
|
||||||
snprintf(ebootFile, MAX_PATH, "ux0:/pspemu/temp/game/PSP/GAME/%s/EBOOT.PBP", TITLE_ID);
|
snprintf(ebootFile, MAX_PATH, "ux0:pspemu/temp/game/PSP/GAME/%s/EBOOT.PBP", TITLE_ID);
|
||||||
snprintf(pbootFile, MAX_PATH, "ux0:/pspemu/temp/game/PSP/GAME/%s/PBOOT.PBP", TITLE_ID);
|
snprintf(pbootFile, MAX_PATH, "ux0:pspemu/temp/game/PSP/GAME/%s/PBOOT.PBP", TITLE_ID);
|
||||||
snprintf(rifFile, MAX_PATH, "ux0:/pspemu/temp/game/PSP/LICENSE/%s.rif", CONTENT_ID);
|
snprintf(rifFile, MAX_PATH, "ux0:pspemu/temp/game/PSP/LICENSE/%s.rif", CONTENT_ID);
|
||||||
|
|
||||||
CopyFileAndUpdateUi("app0:/psp/EBOOT.PBP", ebootFile);
|
CopyFileAndUpdateUi("app0:psp/EBOOT.PBP", ebootFile);
|
||||||
CopyFileAndUpdateUi("app0:/psp/PBOOT.PBP", pbootFile);
|
CopyFileAndUpdateUi("app0:psp/PBOOT.PBP", pbootFile);
|
||||||
CopyFileAndUpdateUi("app0:/rif/game.rif", rifFile);
|
CopyFileAndUpdateUi("app0:rif/game.rif", rifFile);
|
||||||
|
|
||||||
genEbootSignature(ebootFile);
|
genEbootSignature(ebootFile);
|
||||||
}
|
}
|
||||||
void createBubble() {
|
void createBubble() {
|
||||||
updateUi("Promoting ...");
|
updateUi("Promoting ...");
|
||||||
promoteCma("ux0:/pspemu/temp/game", TITLE_ID, SCE_PKG_TYPE_PSP);
|
promoteCma("ux0:pspemu/temp/game", TITLE_ID, SCE_PKG_TYPE_PSP);
|
||||||
}
|
}
|
||||||
|
|
||||||
void copySaveFiles() {
|
void copySaveFiles() {
|
||||||
CopyTree("app0:/save", "ux0:/pspemu/PSP/SAVEDATA");
|
CopyTree("app0:save", "ux0:/pspemu/PSP/SAVEDATA");
|
||||||
}
|
}
|
||||||
|
|
||||||
void doInstall() {
|
void doInstall() {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#define TITLE_ID "NPUZ01234"
|
#define TITLE_ID "NPUZ01234"
|
||||||
#define CONTENT_ID "IP9100-PCSI00011_00-PSMRUNTIME000000"
|
#define CONTENT_ID "IP9100-PCSI00011_00-PSMRUNTIME000000"
|
||||||
|
|
||||||
|
size_t GetTotalNeededDirectories();
|
||||||
void createPspEmuDirectories();
|
void createPspEmuDirectories();
|
||||||
void placePspGameData();
|
void placePspGameData();
|
||||||
void createBubble();
|
void createBubble();
|
||||||
|
|
37
src/io.c
37
src/io.c
|
@ -100,4 +100,41 @@ void CopyTree(const char* src, const char* dst) {
|
||||||
|
|
||||||
free(srcEnt);
|
free(srcEnt);
|
||||||
free(dstEnt);
|
free(dstEnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t CountTree(const char* src) {
|
||||||
|
size_t count = 0;
|
||||||
|
SceUID dfd = sceIoDopen(src);
|
||||||
|
|
||||||
|
char* srcEnt = malloc(MAX_PATH);
|
||||||
|
memset(srcEnt, 0x00, MAX_PATH);
|
||||||
|
|
||||||
|
|
||||||
|
int dir_read_ret = 0;
|
||||||
|
SceIoDirent* dir = malloc(sizeof(SceIoDirent));
|
||||||
|
do{
|
||||||
|
memset(dir, 0x00, sizeof(SceIoDirent));
|
||||||
|
|
||||||
|
dir_read_ret = sceIoDread(dfd, dir);
|
||||||
|
|
||||||
|
snprintf(srcEnt, MAX_PATH, "%s/%s", src, dir->d_name);
|
||||||
|
|
||||||
|
if(SCE_S_ISDIR(dir->d_stat.st_mode)) {
|
||||||
|
count++;
|
||||||
|
count += CountTree(srcEnt);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} while(dir_read_ret > 0);
|
||||||
|
|
||||||
|
|
||||||
|
free(dir);
|
||||||
|
sceIoDclose(dfd);
|
||||||
|
|
||||||
|
free(srcEnt);
|
||||||
|
|
||||||
|
return count;
|
||||||
}
|
}
|
1
src/io.h
1
src/io.h
|
@ -8,3 +8,4 @@ int WriteFile(const char *file, void *buf, int size);
|
||||||
|
|
||||||
void CopyFileAndUpdateUi(char* src, char* dst);
|
void CopyFileAndUpdateUi(char* src, char* dst);
|
||||||
void CreateDirAndUpdateUi(char* dir);
|
void CreateDirAndUpdateUi(char* dir);
|
||||||
|
size_t CountTree(const char* src);
|
|
@ -31,37 +31,31 @@ int promoteCma(const char *path, const char *titleid, int type) {
|
||||||
|
|
||||||
res = loadScePaf();
|
res = loadScePaf();
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sceClibPrintf("loadScePaf: %x\n", res);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_PROMOTER_UTIL);
|
res = sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_PROMOTER_UTIL);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sceClibPrintf("sceSysmoduleLoadModuleInternal: %x\n", res);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = scePromoterUtilityInit();
|
res = scePromoterUtilityInit();
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sceClibPrintf("scePromoterUtilityInit: %x\n", res);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = scePromoterUtilityPromoteImport(&promoteArgs);
|
res = scePromoterUtilityPromoteImport(&promoteArgs);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sceClibPrintf("scePromoterUtilityPromoteImport: %x\n", res);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = scePromoterUtilityExit();
|
res = scePromoterUtilityExit();
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sceClibPrintf("scePromoterUtilityExit: %x\n", res);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = sceSysmoduleUnloadModuleInternal(SCE_SYSMODULE_INTERNAL_PROMOTER_UTIL);
|
res = sceSysmoduleUnloadModuleInternal(SCE_SYSMODULE_INTERNAL_PROMOTER_UTIL);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sceClibPrintf("sceSysmoduleUnloadModuleInternal: %x\n", res);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +63,6 @@ int promoteCma(const char *path, const char *titleid, int type) {
|
||||||
res = unloadScePaf();
|
res = unloadScePaf();
|
||||||
if (res < 0)
|
if (res < 0)
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sceClibPrintf("unloadScePaf: %x\n", res);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
src/ui.c
25
src/ui.c
|
@ -4,14 +4,26 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include "install.h"
|
||||||
|
#include "io.h"
|
||||||
|
|
||||||
int progress = 0;
|
static int progress = 0;
|
||||||
const int totalProgress = 42; // this is like how many times updateUi is called ..
|
static int totalProgress = 0;
|
||||||
|
|
||||||
vita2d_pgf *pgf;
|
vita2d_pgf *pgf;
|
||||||
vita2d_pvf *pvf;
|
vita2d_pvf *pvf;
|
||||||
|
|
||||||
|
// calculate the total progress
|
||||||
|
void countProgress() {
|
||||||
|
totalProgress = 6; // Copy EBOOT.PBP, PBOOT.PBP, GAME.RIF
|
||||||
|
// PROMOTE, HASH EBOOT, GEN EBOOT SIGNATURE steps
|
||||||
|
|
||||||
|
totalProgress += GetTotalNeededDirectories(); // Directories required to be created.
|
||||||
|
totalProgress += CountTree("app0:save"); // Total number of files / dirs in ARK4 savedata.
|
||||||
|
}
|
||||||
|
|
||||||
void uiInit() {
|
void uiInit() {
|
||||||
|
countProgress();
|
||||||
vita2d_init();
|
vita2d_init();
|
||||||
vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
|
vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
|
||||||
pgf = vita2d_load_default_pgf();
|
pgf = vita2d_load_default_pgf();
|
||||||
|
@ -32,14 +44,15 @@ void drawProgress() {
|
||||||
int end = 900;
|
int end = 900;
|
||||||
int start = 60;
|
int start = 60;
|
||||||
int y = 300;
|
int y = 300;
|
||||||
int percent = (int)floor(((float)progress / (float)totalProgress) * 840.0);
|
int barPx = (int)floor(((float)progress / (float)totalProgress) * (float)(end - start));
|
||||||
|
int percent = (int)floor(((float)progress / (float)totalProgress) * 100.0);
|
||||||
char percentText[0x100];
|
char percentText[0x100];
|
||||||
|
|
||||||
vita2d_draw_line(start, y, end, y, RGBA8(128,128,128,255));
|
vita2d_draw_line(start, y, end, y, RGBA8(128,128,128,255));
|
||||||
vita2d_draw_line(start, y, start + percent, y, RGBA8(0,255,0,255));
|
vita2d_draw_line(start, y, start + barPx, y, RGBA8(0,255,0,255));
|
||||||
|
|
||||||
snprintf(percentText, sizeof(percentText), "%i%%", progress);
|
snprintf(percentText, sizeof(percentText), "%i%% (%i/%i)", percent, progress, totalProgress);
|
||||||
drawTextCenter(320, percentText);
|
drawTextCenter(330, percentText);
|
||||||
}
|
}
|
||||||
|
|
||||||
void endDraw() {
|
void endDraw() {
|
||||||
|
|
Loading…
Reference in New Issue