From 5c154181dc79276ca27de76870e3c7dd94f606eb Mon Sep 17 00:00:00 2001
From: Li
Date: Sun, 10 Sep 2023 20:21:29 +1200
Subject: [PATCH] Dynamically calculate the totalProgress
---
CMakeLists.txt | 3 +--
src/install.c | 53 ++++++++++++++++++++++++++------------------------
src/install.h | 1 +
src/io.c | 37 +++++++++++++++++++++++++++++++++++
src/io.h | 1 +
src/promote.c | 7 -------
src/ui.c | 25 ++++++++++++++++++------
7 files changed, 87 insertions(+), 40 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a4fd09..bb4cb7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -31,17 +31,16 @@ link_directories(
)
add_executable(${PROJECT_NAME}
- src/main.c
src/ui.c
src/install.c
src/io.c
src/promote.c
src/pbp.c
src/sha256
+ src/main.c
)
target_link_libraries(${PROJECT_NAME}
-
vita2d
z
c
diff --git a/src/install.c b/src/install.c
index 23d9069..c2b72d9 100644
--- a/src/install.c
+++ b/src/install.c
@@ -9,18 +9,26 @@
#include "install.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() {
-
- CreateDirAndUpdateUi("ux0:pspemu");
- 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");
+ for(size_t i = 0; i < GetTotalNeededDirectories(); i++){
+ CreateDirAndUpdateUi(NeededDirectories[i]);
+ }
}
@@ -34,9 +42,9 @@ void genEbootSignature(char* ebootPath) {
memset(ebootSig, 0x00, sizeof(ebootSig));
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);
updateUi("Generating EBOOT.PBP Signature ...");
@@ -47,33 +55,28 @@ void genEbootSignature(char* ebootPath) {
}
void placePspGameData() {
- char gameFolder[MAX_PATH];
char ebootFile[MAX_PATH];
char pbootFile[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
- 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(rifFile, MAX_PATH, "ux0:/pspemu/temp/game/PSP/LICENSE/%s.rif", CONTENT_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(rifFile, MAX_PATH, "ux0:pspemu/temp/game/PSP/LICENSE/%s.rif", CONTENT_ID);
- CopyFileAndUpdateUi("app0:/psp/EBOOT.PBP", ebootFile);
- CopyFileAndUpdateUi("app0:/psp/PBOOT.PBP", pbootFile);
- CopyFileAndUpdateUi("app0:/rif/game.rif", rifFile);
+ CopyFileAndUpdateUi("app0:psp/EBOOT.PBP", ebootFile);
+ CopyFileAndUpdateUi("app0:psp/PBOOT.PBP", pbootFile);
+ CopyFileAndUpdateUi("app0:rif/game.rif", rifFile);
genEbootSignature(ebootFile);
}
void createBubble() {
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() {
- CopyTree("app0:/save", "ux0:/pspemu/PSP/SAVEDATA");
+ CopyTree("app0:save", "ux0:/pspemu/PSP/SAVEDATA");
}
void doInstall() {
diff --git a/src/install.h b/src/install.h
index c7ae0e8..1329480 100644
--- a/src/install.h
+++ b/src/install.h
@@ -1,6 +1,7 @@
#define TITLE_ID "NPUZ01234"
#define CONTENT_ID "IP9100-PCSI00011_00-PSMRUNTIME000000"
+size_t GetTotalNeededDirectories();
void createPspEmuDirectories();
void placePspGameData();
void createBubble();
diff --git a/src/io.c b/src/io.c
index 283bf54..ad00548 100644
--- a/src/io.c
+++ b/src/io.c
@@ -100,4 +100,41 @@ void CopyTree(const char* src, const char* dst) {
free(srcEnt);
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;
}
\ No newline at end of file
diff --git a/src/io.h b/src/io.h
index e96cdc9..471165d 100644
--- a/src/io.h
+++ b/src/io.h
@@ -8,3 +8,4 @@ int WriteFile(const char *file, void *buf, int size);
void CopyFileAndUpdateUi(char* src, char* dst);
void CreateDirAndUpdateUi(char* dir);
+size_t CountTree(const char* src);
\ No newline at end of file
diff --git a/src/promote.c b/src/promote.c
index a308600..1f14946 100644
--- a/src/promote.c
+++ b/src/promote.c
@@ -31,37 +31,31 @@ int promoteCma(const char *path, const char *titleid, int type) {
res = loadScePaf();
if (res < 0) {
- sceClibPrintf("loadScePaf: %x\n", res);
return res;
}
res = sceSysmoduleLoadModuleInternal(SCE_SYSMODULE_INTERNAL_PROMOTER_UTIL);
if (res < 0) {
- sceClibPrintf("sceSysmoduleLoadModuleInternal: %x\n", res);
return res;
}
res = scePromoterUtilityInit();
if (res < 0) {
- sceClibPrintf("scePromoterUtilityInit: %x\n", res);
return res;
}
res = scePromoterUtilityPromoteImport(&promoteArgs);
if (res < 0) {
- sceClibPrintf("scePromoterUtilityPromoteImport: %x\n", res);
return res;
}
res = scePromoterUtilityExit();
if (res < 0) {
- sceClibPrintf("scePromoterUtilityExit: %x\n", res);
return res;
}
res = sceSysmoduleUnloadModuleInternal(SCE_SYSMODULE_INTERNAL_PROMOTER_UTIL);
if (res < 0) {
- sceClibPrintf("sceSysmoduleUnloadModuleInternal: %x\n", res);
return res;
}
@@ -69,7 +63,6 @@ int promoteCma(const char *path, const char *titleid, int type) {
res = unloadScePaf();
if (res < 0)
if (res < 0) {
- sceClibPrintf("unloadScePaf: %x\n", res);
return res;
}
diff --git a/src/ui.c b/src/ui.c
index 430c059..edd8a6f 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -4,14 +4,26 @@
#include
#include
#include
+#include "install.h"
+#include "io.h"
-int progress = 0;
-const int totalProgress = 42; // this is like how many times updateUi is called ..
+static int progress = 0;
+static int totalProgress = 0;
vita2d_pgf *pgf;
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() {
+ countProgress();
vita2d_init();
vita2d_set_clear_color(RGBA8(0x00, 0x00, 0x00, 0xFF));
pgf = vita2d_load_default_pgf();
@@ -32,14 +44,15 @@ void drawProgress() {
int end = 900;
int start = 60;
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];
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);
- drawTextCenter(320, percentText);
+ snprintf(percentText, sizeof(percentText), "%i%% (%i/%i)", percent, progress, totalProgress);
+ drawTextCenter(330, percentText);
}
void endDraw() {