VITA: Add option to check for updates.

This commit is contained in:
Tyler Young 2023-11-30 21:28:03 -05:00
parent b77b49e4b8
commit c9d2fde128
2 changed files with 107 additions and 44 deletions

View file

@ -31,6 +31,8 @@ void early_fatal_error(const char *msg) {
} }
void DrawExtractorDialog(int index, float file_extracted_bytes, float extracted_bytes, float file_total_bytes, float total_bytes, char *filename, int num_files) { void DrawExtractorDialog(int index, float file_extracted_bytes, float extracted_bytes, float file_total_bytes, float total_bytes, char *filename, int num_files) {
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DEFAULT);
ImGui_ImplVitaGL_NewFrame(); ImGui_ImplVitaGL_NewFrame();
char msg1[256], msg2[256]; char msg1[256], msg2[256];
@ -51,11 +53,11 @@ void DrawExtractorDialog(int index, float file_extracted_bytes, float extracted_
ImGui::ProgressBar(extracted_bytes / total_bytes, ImVec2(200, 0)); ImGui::ProgressBar(extracted_bytes / total_bytes, ImVec2(200, 0));
ImGui::End(); ImGui::End();
glViewport(0, 0, static_cast<int>(ImGui::GetIO().DisplaySize.x), static_cast<int>(ImGui::GetIO().DisplaySize.y)); glViewport(0, 0, static_cast<int>(ImGui::GetIO().DisplaySize.x), static_cast<int>(ImGui::GetIO().DisplaySize.y));
ImGui::Render(); ImGui::Render();
ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData());
vglSwapBuffers(GL_FALSE); vglSwapBuffers(GL_FALSE);
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DEFAULT);
} }
void DrawDownloaderDialog(int index, float downloaded_bytes, float total_bytes, char *text, int passes, bool self_contained) { void DrawDownloaderDialog(int index, float downloaded_bytes, float total_bytes, char *text, int passes, bool self_contained) {
@ -96,4 +98,5 @@ void DrawDownloaderDialog(int index, float downloaded_bytes, float total_bytes,
ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData());
vglSwapBuffers(GL_FALSE); vglSwapBuffers(GL_FALSE);
} }
} }

View file

@ -9,11 +9,15 @@
#include <string> #include <string>
#include <cstring> #include <cstring>
#include <taihen.h> #include <taihen.h>
#include <psp2/ctrl.h>
#include "unzip.h" #include "unzip.h"
#include "utils.h" #include "utils.h"
#include "dialogs.h" #include "dialogs.h"
#include "network.h" #include "network.h"
#define SCR_WIDTH 960
#define SCR_HEIGHT 544
int _newlib_heap_size_user = 256 * 1024 * 1024; int _newlib_heap_size_user = 256 * 1024 * 1024;
int file_exists(const char *path) { int file_exists(const char *path) {
@ -71,7 +75,23 @@ void extract_file(char *file, char *dir) {
ImGui::GetIO().MouseDrawCursor = false; ImGui::GetIO().MouseDrawCursor = false;
} }
void download_update()
{
sceAppMgrUmount("app0:");
download_file("https://github.com/nzp-team/nzportable/releases/download/nightly/nzportable-vita.zip", "Downloading update");
extract_file(TEMP_DOWNLOAD_NAME, "ux0:/");
sceIoRemove(TEMP_DOWNLOAD_NAME);
extract_file("ux0:data/nzp.vpk", "ux0:app/NZZMBSPTB/");
sceIoRemove("ux0:data/nzp.vpk");
printf("%s\n", generic_mem_buffer);
sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL);
return 0;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
bool optionsmenu = true;
scePowerSetArmClockFrequency(444); scePowerSetArmClockFrequency(444);
scePowerSetBusClockFrequency(222); scePowerSetBusClockFrequency(222);
sceIoRemove(TEMP_DOWNLOAD_NAME); sceIoRemove(TEMP_DOWNLOAD_NAME);
@ -87,7 +107,7 @@ int main(int argc, char *argv[]) {
initparam.flags = 0; initparam.flags = 0;
sceNetInit(&initparam); sceNetInit(&initparam);
} }
// Checking for network connection // Checking for network connection
char cur_version[32] = {0}; char cur_version[32] = {0};
char *start; char *start;
@ -95,61 +115,101 @@ int main(int argc, char *argv[]) {
sceNetCtlInit(); sceNetCtlInit();
sceNetCtlInetGetState(&ret); sceNetCtlInetGetState(&ret);
if (ret != SCE_NETCTL_STATE_CONNECTED) { if (ret != SCE_NETCTL_STATE_CONNECTED) {
goto launch_nzp; sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL);
return 0;
} }
// Check for libshacccg.suprx existence // Check for libshacccg.suprx existence
if (!file_exists("ur0:/data/libshacccg.suprx") && !file_exists("ur0:/data/external/libshacccg.suprx")) if (!file_exists("ur0:/data/libshacccg.suprx") && !file_exists("ur0:/data/external/libshacccg.suprx"))
early_fatal_error("Error: libshacccg.suprx is not installed."); early_fatal_error("Error: libshacccg.suprx is not installed.");
// Starting dear ImGui // Starting dear ImGui
vglInitExtended(0, 960, 544, 0x1800000, SCE_GXM_MULTISAMPLE_NONE); vglInitExtended(0, SCR_WIDTH, SCR_HEIGHT, 0x1800000, SCE_GXM_MULTISAMPLE_NONE);
ImGui::CreateContext(); ImGui::CreateContext();
SceKernelThreadInfo info; SceKernelThreadInfo info;
info.size = sizeof(SceKernelThreadInfo); info.size = sizeof(SceKernelThreadInfo);
ImGui_ImplVitaGL_Init_Extended(); ImGuiIO& io = ImGui::GetIO(); (void)io;
ImGui_ImplVitaGL_Init();
ImGui::GetIO().MouseDrawCursor = false; ImGui::GetIO().MouseDrawCursor = false;
// Getting current version bool done = false;
f = fopen("ux0:data/nzp/nzp/version.txt", "r"); while(!done)
if (f) { {
fread(cur_version, 1, 32, f); ImGui_ImplVitaGL_NewFrame();
fclose(f);
if (cur_version[strlen(cur_version) - 1] == '\n') sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
cur_version[strlen(cur_version) - 1] = 0; SceCtrlData ctrl;
} else { sceCtrlPeekBufferPositive(0, &ctrl, 1);
goto download_update;
} if(optionsmenu)
printf("Current version: %s\n", cur_version); {
char msg1[256], msg2[256];
// Checking for updates sprintf(msg1, "Press X to check for updates");
download_file("https://api.github.com/repos/nzp-team/nzportable/releases/tags/nightly", "Checking for updates"); sprintf(msg2, "Or press START to slay zombies!");
f = fopen(TEMP_DOWNLOAD_NAME, "r"); ImVec2 pos1 = ImGui::CalcTextSize(msg1);
if (f) { ImVec2 pos2 = ImGui::CalcTextSize(msg2);
fread(generic_mem_buffer, 1, 32 * 1024 * 1024, f);
fclose(f); ImGui::SetNextWindowPos(ImVec2((SCR_WIDTH / 2) - 200, (SCR_HEIGHT / 2) - 50), ImGuiSetCond_Always);
start = strstr(generic_mem_buffer, "\"name\": \"") + 9; ImGui::SetNextWindowSize(ImVec2(400, 100), ImGuiSetCond_Always);
start[strlen(cur_version)] = 0; ImGui::Begin("", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNav);
printf("Last version: %s\n", start); ImGui::SetCursorPos(ImVec2((400 - pos1.x) / 2, 35));
if (!strcmp(cur_version, start)) { ImGui::Text(msg1);
printf("Up to date\n"); ImGui::SetCursorPos(ImVec2((400 - pos2.x) / 2, 53));
goto launch_nzp; ImGui::Text(msg2);
} else { ImGui::End();
download_update:
sceAppMgrUmount("app0:"); // Rendering
printf("Downloading update\n"); glViewport(0, 0, static_cast<int>(ImGui::GetIO().DisplaySize.x), static_cast<int>(ImGui::GetIO().DisplaySize.y));
download_file("https://github.com/nzp-team/nzportable/releases/download/nightly/nzportable-vita.zip", "Downloading update"); ImGui::Render();
printf("Extracting data files\n"); ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData());
extract_file(TEMP_DOWNLOAD_NAME, "ux0:/"); vglSwapBuffers(GL_FALSE);
sceIoRemove(TEMP_DOWNLOAD_NAME); }
printf("Extracting vpk\n"); if(ctrl.buttons & SCE_CTRL_CROSS)
extract_file("ux0:data/nzp.vpk", "ux0:app/NZZMBSPTB/"); {
sceIoRemove("ux0:data/nzp.vpk"); optionsmenu = false;
// Getting current version
f = fopen("ux0:data/nzp/nzp/version.txt", "r");
if (f) {
fread(cur_version, 1, 32, f);
fclose(f);
if (cur_version[strlen(cur_version) - 1] == '\n')
cur_version[strlen(cur_version) - 1] = 0;
} else {
download_update();
}
printf("Current version: %s\n", cur_version);
// Checking for updates
download_file("https://api.github.com/repos/nzp-team/nzportable/releases/tags/nightly", "Checking for updates");
f = fopen(TEMP_DOWNLOAD_NAME, "r");
if (f) {
fread(generic_mem_buffer, 1, 32 * 1024 * 1024, f);
fclose(f);
start = strstr(generic_mem_buffer, "\"name\": \"") + 9;
start[strlen(cur_version)] = 0;
printf("Last version: %s\n", start);
if (!strcmp(cur_version, start)) {
sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL);
return 0;
} else {
download_update();
}
}
}
if(ctrl.buttons & SCE_CTRL_START)
{
sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL);
return 0;
} }
} }
printf("%s\n", generic_mem_buffer);
launch_nzp: // Cleanup
sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL); ImGui_ImplVitaGL_Shutdown();
ImGui::DestroyContext();
vglEnd();
return 0; return 0;
} }