mirror of
https://github.com/nzp-team/quakespasm.git
synced 2024-11-21 19:31:21 +00:00
VITA: Add option to check for updates.
This commit is contained in:
parent
b77b49e4b8
commit
c9d2fde128
2 changed files with 107 additions and 44 deletions
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
@ -95,7 +115,8 @@ 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
|
||||||
|
@ -103,53 +124,92 @@ int main(int argc, char *argv[]) {
|
||||||
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')
|
|
||||||
cur_version[strlen(cur_version) - 1] = 0;
|
|
||||||
} else {
|
|
||||||
goto download_update;
|
|
||||||
}
|
|
||||||
printf("Current version: %s\n", cur_version);
|
|
||||||
|
|
||||||
// Checking for updates
|
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
|
||||||
download_file("https://api.github.com/repos/nzp-team/nzportable/releases/tags/nightly", "Checking for updates");
|
SceCtrlData ctrl;
|
||||||
f = fopen(TEMP_DOWNLOAD_NAME, "r");
|
sceCtrlPeekBufferPositive(0, &ctrl, 1);
|
||||||
if (f) {
|
|
||||||
fread(generic_mem_buffer, 1, 32 * 1024 * 1024, f);
|
if(optionsmenu)
|
||||||
fclose(f);
|
{
|
||||||
start = strstr(generic_mem_buffer, "\"name\": \"") + 9;
|
char msg1[256], msg2[256];
|
||||||
start[strlen(cur_version)] = 0;
|
sprintf(msg1, "Press X to check for updates");
|
||||||
printf("Last version: %s\n", start);
|
sprintf(msg2, "Or press START to slay zombies!");
|
||||||
if (!strcmp(cur_version, start)) {
|
ImVec2 pos1 = ImGui::CalcTextSize(msg1);
|
||||||
printf("Up to date\n");
|
ImVec2 pos2 = ImGui::CalcTextSize(msg2);
|
||||||
goto launch_nzp;
|
|
||||||
} else {
|
ImGui::SetNextWindowPos(ImVec2((SCR_WIDTH / 2) - 200, (SCR_HEIGHT / 2) - 50), ImGuiSetCond_Always);
|
||||||
download_update:
|
ImGui::SetNextWindowSize(ImVec2(400, 100), ImGuiSetCond_Always);
|
||||||
sceAppMgrUmount("app0:");
|
ImGui::Begin("", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNav);
|
||||||
printf("Downloading update\n");
|
ImGui::SetCursorPos(ImVec2((400 - pos1.x) / 2, 35));
|
||||||
download_file("https://github.com/nzp-team/nzportable/releases/download/nightly/nzportable-vita.zip", "Downloading update");
|
ImGui::Text(msg1);
|
||||||
printf("Extracting data files\n");
|
ImGui::SetCursorPos(ImVec2((400 - pos2.x) / 2, 53));
|
||||||
extract_file(TEMP_DOWNLOAD_NAME, "ux0:/");
|
ImGui::Text(msg2);
|
||||||
sceIoRemove(TEMP_DOWNLOAD_NAME);
|
ImGui::End();
|
||||||
printf("Extracting vpk\n");
|
|
||||||
extract_file("ux0:data/nzp.vpk", "ux0:app/NZZMBSPTB/");
|
// Rendering
|
||||||
sceIoRemove("ux0:data/nzp.vpk");
|
glViewport(0, 0, static_cast<int>(ImGui::GetIO().DisplaySize.x), static_cast<int>(ImGui::GetIO().DisplaySize.y));
|
||||||
|
ImGui::Render();
|
||||||
|
ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
vglSwapBuffers(GL_FALSE);
|
||||||
|
}
|
||||||
|
if(ctrl.buttons & SCE_CTRL_CROSS)
|
||||||
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
Loading…
Reference in a new issue