mirror of
https://github.com/nzp-team/quakespasm.git
synced 2024-11-10 06:32:03 +00:00
Merge pull request #43 from tyleryoung88/main
VITA: Add option to check for updates.
This commit is contained in:
commit
e3624a44c7
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) {
|
||||
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DEFAULT);
|
||||
|
||||
ImGui_ImplVitaGL_NewFrame();
|
||||
|
||||
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::End();
|
||||
|
||||
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);
|
||||
sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DEFAULT);
|
||||
}
|
||||
|
||||
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());
|
||||
vglSwapBuffers(GL_FALSE);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,11 +9,15 @@
|
|||
#include <string>
|
||||
#include <cstring>
|
||||
#include <taihen.h>
|
||||
#include <psp2/ctrl.h>
|
||||
#include "unzip.h"
|
||||
#include "utils.h"
|
||||
#include "dialogs.h"
|
||||
#include "network.h"
|
||||
|
||||
#define SCR_WIDTH 960
|
||||
#define SCR_HEIGHT 544
|
||||
|
||||
int _newlib_heap_size_user = 256 * 1024 * 1024;
|
||||
|
||||
int file_exists(const char *path) {
|
||||
|
@ -71,7 +75,23 @@ void extract_file(char *file, char *dir) {
|
|||
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[]) {
|
||||
bool optionsmenu = true;
|
||||
|
||||
scePowerSetArmClockFrequency(444);
|
||||
scePowerSetBusClockFrequency(222);
|
||||
sceIoRemove(TEMP_DOWNLOAD_NAME);
|
||||
|
@ -95,7 +115,8 @@ int main(int argc, char *argv[]) {
|
|||
sceNetCtlInit();
|
||||
sceNetCtlInetGetState(&ret);
|
||||
if (ret != SCE_NETCTL_STATE_CONNECTED) {
|
||||
goto launch_nzp;
|
||||
sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check for libshacccg.suprx existence
|
||||
|
@ -103,13 +124,52 @@ int main(int argc, char *argv[]) {
|
|||
early_fatal_error("Error: libshacccg.suprx is not installed.");
|
||||
|
||||
// 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();
|
||||
|
||||
SceKernelThreadInfo info;
|
||||
info.size = sizeof(SceKernelThreadInfo);
|
||||
ImGui_ImplVitaGL_Init_Extended();
|
||||
ImGuiIO& io = ImGui::GetIO(); (void)io;
|
||||
ImGui_ImplVitaGL_Init();
|
||||
ImGui::GetIO().MouseDrawCursor = false;
|
||||
|
||||
bool done = false;
|
||||
while(!done)
|
||||
{
|
||||
ImGui_ImplVitaGL_NewFrame();
|
||||
|
||||
sceCtrlSetSamplingMode(SCE_CTRL_MODE_ANALOG);
|
||||
SceCtrlData ctrl;
|
||||
sceCtrlPeekBufferPositive(0, &ctrl, 1);
|
||||
|
||||
if(optionsmenu)
|
||||
{
|
||||
char msg1[256], msg2[256];
|
||||
sprintf(msg1, "Press X to check for updates");
|
||||
sprintf(msg2, "Or press START to slay zombies!");
|
||||
ImVec2 pos1 = ImGui::CalcTextSize(msg1);
|
||||
ImVec2 pos2 = ImGui::CalcTextSize(msg2);
|
||||
|
||||
ImGui::SetNextWindowPos(ImVec2((SCR_WIDTH / 2) - 200, (SCR_HEIGHT / 2) - 50), ImGuiSetCond_Always);
|
||||
ImGui::SetNextWindowSize(ImVec2(400, 100), ImGuiSetCond_Always);
|
||||
ImGui::Begin("", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNav);
|
||||
ImGui::SetCursorPos(ImVec2((400 - pos1.x) / 2, 35));
|
||||
ImGui::Text(msg1);
|
||||
ImGui::SetCursorPos(ImVec2((400 - pos2.x) / 2, 53));
|
||||
ImGui::Text(msg2);
|
||||
ImGui::End();
|
||||
|
||||
// Rendering
|
||||
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) {
|
||||
|
@ -118,7 +178,7 @@ int main(int argc, char *argv[]) {
|
|||
if (cur_version[strlen(cur_version) - 1] == '\n')
|
||||
cur_version[strlen(cur_version) - 1] = 0;
|
||||
} else {
|
||||
goto download_update;
|
||||
download_update();
|
||||
}
|
||||
printf("Current version: %s\n", cur_version);
|
||||
|
||||
|
@ -132,24 +192,24 @@ int main(int argc, char *argv[]) {
|
|||
start[strlen(cur_version)] = 0;
|
||||
printf("Last version: %s\n", start);
|
||||
if (!strcmp(cur_version, start)) {
|
||||
printf("Up to date\n");
|
||||
goto launch_nzp;
|
||||
sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL);
|
||||
return 0;
|
||||
} else {
|
||||
download_update:
|
||||
sceAppMgrUmount("app0:");
|
||||
printf("Downloading update\n");
|
||||
download_file("https://github.com/nzp-team/nzportable/releases/download/nightly/nzportable-vita.zip", "Downloading update");
|
||||
printf("Extracting data files\n");
|
||||
extract_file(TEMP_DOWNLOAD_NAME, "ux0:/");
|
||||
sceIoRemove(TEMP_DOWNLOAD_NAME);
|
||||
printf("Extracting vpk\n");
|
||||
extract_file("ux0:data/nzp.vpk", "ux0:app/NZZMBSPTB/");
|
||||
sceIoRemove("ux0:data/nzp.vpk");
|
||||
download_update();
|
||||
}
|
||||
}
|
||||
printf("%s\n", generic_mem_buffer);
|
||||
|
||||
launch_nzp:
|
||||
}
|
||||
if(ctrl.buttons & SCE_CTRL_START)
|
||||
{
|
||||
sceAppMgrLoadExec("app0:nzp.bin", NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
ImGui_ImplVitaGL_Shutdown();
|
||||
ImGui::DestroyContext();
|
||||
vglEnd();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue