diff --git a/Source/CMakeLists.txt b/Source/CMakeLists.txt index 0295c78a..28a5c030 100644 --- a/Source/CMakeLists.txt +++ b/Source/CMakeLists.txt @@ -264,7 +264,6 @@ if (VITA_RELEASE) SceAudio_stub ScePower_stub SceNet_stub - SceNetCtl_stub SceAppMgr_stub SceAppUtil_stub c diff --git a/Source/SysVita/UI/DownloaderScreen.cpp b/Source/SysVita/UI/DownloaderScreen.cpp index 0ad52e4c..807ccc6b 100644 --- a/Source/SysVita/UI/DownloaderScreen.cpp +++ b/Source/SysVita/UI/DownloaderScreen.cpp @@ -30,8 +30,6 @@ #include "Utility/Timer.h" #include "SysVita/UI/Menu.h" -#define MAX(a, b) a > b ? a : b - static char *sizes[] = { "B", "KB", @@ -60,26 +58,25 @@ void DrawDownloaderScreen(int index, float downloaded_bytes, float total_bytes, char msg[512]; sprintf(msg, "%s (%ld / %ld)", text, index, passes); ImVec2 pos = ImGui::CalcTextSize(msg); - float win_size = pos.x > 400.0f ? pos.x + 10.0f : 400.0f; ImGui::GetIO().MouseDrawCursor = false; ImGui::SetNextWindowPos(ImVec2((SCR_WIDTH / 2) - 200 * UI_SCALE, (SCR_HEIGHT / 2) - 50 * UI_SCALE), ImGuiSetCond_Always); - ImGui::SetNextWindowSize(ImVec2(win_size * UI_SCALE, 100 * UI_SCALE), ImGuiSetCond_Always); + ImGui::SetNextWindowSize(ImVec2(400 * UI_SCALE, 100 * UI_SCALE), ImGuiSetCond_Always); ImGui::Begin("", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus); - ImGui::SetCursorPos(ImVec2((win_size * UI_SCALE - pos.x) / 2, 20 * UI_SCALE)); + ImGui::SetCursorPos(ImVec2((400 * UI_SCALE - pos.x) / 2, 20 * UI_SCALE)); ImGui::Text(msg); if (total_bytes < 4000000000.0f) { sprintf(msg, "%.2f %s / %.2f %s", format(downloaded_bytes), sizes[quota(downloaded_bytes)], format(total_bytes), sizes[quota(total_bytes)]); pos = ImGui::CalcTextSize(msg); - ImGui::SetCursorPos(ImVec2((win_size * UI_SCALE - pos.x) / 2, 40 * UI_SCALE)); + ImGui::SetCursorPos(ImVec2((400 * UI_SCALE - pos.x) / 2, 40 * UI_SCALE)); ImGui::Text(msg); - ImGui::SetCursorPos(ImVec2((win_size / 4) * UI_SCALE, 60 * UI_SCALE)); + ImGui::SetCursorPos(ImVec2(100 * UI_SCALE, 60 * UI_SCALE)); ImGui::ProgressBar(downloaded_bytes / total_bytes, ImVec2(200 * UI_SCALE, 0)); } else { sprintf(msg, "%.2f %s", format(downloaded_bytes), sizes[quota(downloaded_bytes)]); pos = ImGui::CalcTextSize(msg); - ImGui::SetCursorPos(ImVec2((win_size * UI_SCALE - pos.x) / 2, 50 * UI_SCALE)); + ImGui::SetCursorPos(ImVec2((400 * UI_SCALE - pos.x) / 2, 50 * UI_SCALE)); ImGui::Text(msg); } @@ -90,6 +87,36 @@ void DrawDownloaderScreen(int index, float downloaded_bytes, float total_bytes, vglStopRendering(); } +void DrawDownloaderScreenCompat(float downloaded_bytes, float total_bytes, char *text) { + vglStartRendering(); + ImGui_ImplVitaGL_NewFrame(); + + ImVec2 pos = ImGui::CalcTextSize(text); + + ImGui::GetIO().MouseDrawCursor = false; + ImGui::SetNextWindowPos(ImVec2((SCR_WIDTH / 2) - 200 * UI_SCALE, (SCR_HEIGHT / 2) - 50 * UI_SCALE), ImGuiSetCond_Always); + ImGui::SetNextWindowSize(ImVec2(400 * UI_SCALE, 100 * UI_SCALE), ImGuiSetCond_Always); + ImGui::Begin("", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus); + + ImGui::SetCursorPos(ImVec2((400 * UI_SCALE - pos.x) / 2, 20 * UI_SCALE)); + ImGui::Text(text); + + char msg[512]; + sprintf(msg, "%.2f %s / %.2f %s", format(downloaded_bytes), sizes[quota(downloaded_bytes)], format(total_bytes), sizes[quota(total_bytes)]); + pos = ImGui::CalcTextSize(msg); + ImGui::SetCursorPos(ImVec2((400 * UI_SCALE - pos.x) / 2, 40 * UI_SCALE)); + ImGui::Text(msg); + ImGui::SetCursorPos(ImVec2(100 * UI_SCALE, 60 * UI_SCALE)); + ImGui::ProgressBar(downloaded_bytes / total_bytes, ImVec2(200 * UI_SCALE, 0)); + + ImGui::End(); + glViewport(0, 0, static_cast(ImGui::GetIO().DisplaySize.x), static_cast(ImGui::GetIO().DisplaySize.y)); + ImGui::Render(); + ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData()); + vglStopRendering(); + sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DEFAULT); +} + void DrawExtractorScreen(int index, float file_extracted_bytes, float extracted_bytes, float file_total_bytes, float total_bytes, char *filename, int num_files) { vglStartRendering(); ImGui_ImplVitaGL_NewFrame(); @@ -99,18 +126,16 @@ void DrawExtractorScreen(int index, float file_extracted_bytes, float extracted_ sprintf(msg2, "%s (%.2f %s / %.2f %s)", filename, format(file_extracted_bytes), sizes[quota(file_extracted_bytes)], format(file_total_bytes), sizes[quota(file_total_bytes)]); ImVec2 pos1 = ImGui::CalcTextSize(msg1); ImVec2 pos2 = ImGui::CalcTextSize(msg2); - float win_size = MAX(pos1.x, pos2.x); - win_size = win_size > 400.0f ? win_size + 10.0f : 400.0f; ImGui::GetIO().MouseDrawCursor = false; ImGui::SetNextWindowPos(ImVec2((SCR_WIDTH / 2) - 200 * UI_SCALE, (SCR_HEIGHT / 2) - 50 * UI_SCALE), ImGuiSetCond_Always); - ImGui::SetNextWindowSize(ImVec2(win_size * UI_SCALE, 100 * UI_SCALE), ImGuiSetCond_Always); + ImGui::SetNextWindowSize(ImVec2(400 * UI_SCALE, 100 * UI_SCALE), ImGuiSetCond_Always); ImGui::Begin("", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoBringToFrontOnFocus); - ImGui::SetCursorPos(ImVec2((win_size * UI_SCALE - pos1.x) / 2, 20 * UI_SCALE)); + ImGui::SetCursorPos(ImVec2((400 * UI_SCALE - pos1.x) / 2, 20 * UI_SCALE)); ImGui::Text(msg1); - ImGui::SetCursorPos(ImVec2((win_size * UI_SCALE - pos2.x) / 2, 40 * UI_SCALE)); + ImGui::SetCursorPos(ImVec2((400 * UI_SCALE - pos2.x) / 2, 40 * UI_SCALE)); ImGui::Text(msg2); - ImGui::SetCursorPos(ImVec2((win_size / 4) * UI_SCALE, 60 * UI_SCALE)); + ImGui::SetCursorPos(ImVec2(100 * UI_SCALE, 60 * UI_SCALE)); ImGui::ProgressBar(extracted_bytes / total_bytes, ImVec2(200 * UI_SCALE, 0)); ImGui::End(); @@ -118,4 +143,5 @@ void DrawExtractorScreen(int index, float file_extracted_bytes, float extracted_ ImGui::Render(); ImGui_ImplVitaGL_RenderDrawData(ImGui::GetDrawData()); vglStopRendering(); + sceKernelPowerTick(SCE_KERNEL_POWER_TICK_DEFAULT); } diff --git a/Source/SysVita/UI/MainMenuScreen.cpp b/Source/SysVita/UI/MainMenuScreen.cpp index 2f9bf99a..9e765529 100644 --- a/Source/SysVita/UI/MainMenuScreen.cpp +++ b/Source/SysVita/UI/MainMenuScreen.cpp @@ -443,6 +443,15 @@ char *DrawRomSelector() { DrawPendingDialog(); vglStopRendering(); + if (pendingDownload) { + if (download_file("https://github.com/Rinnegatamante/DaedalusX64-vitaGL/releases/download/Nightly/DaedalusX64.zip", "ux0:data/temp.zip", lang_strings[STR_DLG_DOWNLOAD_DATA], 26 * 1024 * 1024) >= 0) { + extract_file("ux0:data/temp.zip", "ux0:data/"); + sceIoRemove("ux0:data/temp.zip"); + resetRomList(); + } + pendingDownload = false; + } + if (selected) { CheatCodes_Read( hovered->settings.GameName.c_str(), "Daedalus.cht", hovered->id.CountryID ); return selectedRom; diff --git a/Source/SysVita/UI/Menu.h b/Source/SysVita/UI/Menu.h index f41eb0b3..31b76543 100644 --- a/Source/SysVita/UI/Menu.h +++ b/Source/SysVita/UI/Menu.h @@ -53,7 +53,7 @@ enum { }; // Translation strings -#define LANG_STRINGS_NUM 145 +#define LANG_STRINGS_NUM 147 #define FOREACH_STR(FUNC) \ FUNC(STR_DOWNLOADER_COMPAT_LIST) \ @@ -200,7 +200,9 @@ enum { FUNC(STR_DLG_CUSTOM_PATH) \ FUNC(STR_SEARCH) \ FUNC(STR_DLG_SEARCH_ROM) \ - FUNC(STR_EXTRACTING) + FUNC(STR_EXTRACTING) \ + FUNC(STR_DOWNLOAD_DATA) \ + FUNC(STR_DLG_DOWNLOAD_DATA) #define GET_VALUE(x) x, #define GET_STRING(x) #x, @@ -268,6 +270,7 @@ extern char gCustomRomPath[256]; extern bool pendingDialog; extern bool pendingAlert; +extern bool pendingDownload; extern bool custom_path_str_dirty; char *DrawRomSelector(); @@ -275,6 +278,7 @@ void DrawInGameMenu(); void DrawMenuBar(); void DrawInGameMenuBar(); void DrawDownloaderScreen(int index, float downloaded_bytes, float total_bytes, char *text, int passes); +void DrawDownloaderScreenCompat(float downloaded_bytes, float total_bytes, char *text); void DrawExtractorScreen(int index, float file_extracted_bytes, float extracted_bytes, float file_total_bytes, float total_bytes, char *filename, int num_files); void DrawPendingDialog(); void DrawPendingAlert(); @@ -293,5 +297,6 @@ void reloadFont(); void resetRomList(); void extract_file(char *file, char *dir); +int download_file(char *url, char *file, char *msg, float int_total_bytes); void dummy_func(); diff --git a/Source/SysVita/UI/MenuBarScreen.cpp b/Source/SysVita/UI/MenuBarScreen.cpp index 7f74c39d..00402a21 100644 --- a/Source/SysVita/UI/MenuBarScreen.cpp +++ b/Source/SysVita/UI/MenuBarScreen.cpp @@ -32,6 +32,8 @@ #define MAX_SAVESLOT 9 +bool pendingDownload = false; + bool oldBigText = false; int gLanguageIndex = SCE_SYSTEM_PARAM_LANG_ENGLISH_US; int gUiTheme = DARK_THEME; @@ -671,6 +673,10 @@ void DrawMenuBar() { ImGui_ImplVitaGL_NewFrame(); if (ImGui::BeginMainMenuBar()){ if (ImGui::BeginMenu(lang_strings[STR_MENU_OPTIONS])) { + if (ImGui::MenuItem(lang_strings[STR_DOWNLOAD_DATA])) { + pendingDownload = true; + } + ImGui::Separator(); if (ImGui::MenuItem(custom_path_str)) { showDialog(lang_strings[STR_DLG_CUSTOM_PATH], change_custom_rom_path, dummy_func, DIALOG_KEYBOARD); } diff --git a/Source/SysVita/UI/TranslationStrings.cpp b/Source/SysVita/UI/TranslationStrings.cpp index 367d3de5..9eb00c66 100644 --- a/Source/SysVita/UI/TranslationStrings.cpp +++ b/Source/SysVita/UI/TranslationStrings.cpp @@ -151,4 +151,6 @@ char lang_strings[][256] = { "Search: ", // STR_SEARCH "Insert a Rom name filter", // STR_DLG_SEARCH_ROM "Extracting archive", // STR_EXTRACTING + "Download Data Files", // STR_DOWNLOAD_DATA + "Downloading Data Files", // STR_DLG_DOWNLOAD_DATA }; diff --git a/Source/SysVita/main.cpp b/Source/SysVita/main.cpp index 1cd91495..f1f01c27 100644 --- a/Source/SysVita/main.cpp +++ b/Source/SysVita/main.cpp @@ -50,6 +50,8 @@ char gCustomRomPath[256] = {0}; static char fname[512], ext_fname[512], read_buffer[8192]; +static char *net_url = nullptr; + int console_language; Dialog cur_dialog; @@ -79,6 +81,8 @@ int gUseVSync = GL_TRUE; bool pendingDialog = false; bool pendingAlert = false; +void *net_memory = nullptr; + char boot_params[1024]; void recursive_mkdir(char *dir) { @@ -100,7 +104,7 @@ void extract_file(char *file, char *dir) { unzFile zipfile = unzOpen(file); unzGetGlobalInfo(zipfile, &global_info); unzGoToFirstFile(zipfile); - uint64_t total_extracted_bytes; + uint64_t total_extracted_bytes = 0; uint64_t curr_extracted_bytes = 0; uint64_t curr_file_bytes = 0; int num_files = global_info.number_entry; @@ -134,6 +138,7 @@ void extract_file(char *file, char *dir) { if ((zip_idx + 1) < num_files) unzGoToNextFile(zipfile); } unzClose(zipfile); + ImGui::GetIO().MouseDrawCursor = true; } void log2file(const char *format, ...) { @@ -212,7 +217,6 @@ static int compatListThread(unsigned int args, void* arg){ curl_handle = curl_easy_init(); for (int i = 1; i <= NUM_DB_CHUNKS; i++) { downloader_pass = i; - sceKernelWaitSema(net_mutex, 1, NULL); sprintf(dbname, "%sdb%ld.json", DAEDALUS_VITA_MAIN_PATH, i); sprintf(url, "https://api.github.com/repos/Rinnegatamante/DaedalusX64-vitaGL-Compatibility/issues?state=open&page=%ld&per_page=100", i); fh = fopen(TEMP_DOWNLOAD_NAME, "wb"); @@ -237,13 +241,27 @@ static int compatListThread(unsigned int args, void* arg){ return 0; } +static int downloaderThread(unsigned int args, void* arg){ + char url[512]; + curl_handle = curl_easy_init(); + sprintf(url, net_url); + fh = fopen(TEMP_DOWNLOAD_NAME, "wb"); + downloaded_bytes = 0; + startDownload(url); + fclose(fh); + if (downloaded_bytes <= 12 * 1024) + sceIoRemove(TEMP_DOWNLOAD_NAME); + curl_easy_cleanup(curl_handle); + sceKernelExitDeleteThread(0); + return 0; +} + static int updaterThread(unsigned int args, void* arg){ uint8_t update_detected = 0; char url[512]; curl_handle = curl_easy_init(); for (int i = UPDATER_CHECK_UPDATES; i < NUM_UPDATE_PASSES; i++) { downloader_pass = i; - sceKernelWaitSema(net_mutex, 1, NULL); if (i == UPDATER_CHECK_UPDATES) sprintf(url, "https://api.github.com/repos/Rinnegatamante/DaedalusX64-vitaGL/releases/latest"); else if (!update_detected) { downloaded_bytes = total_bytes; @@ -296,6 +314,48 @@ void reloadFont() { ImGui::GetIO().Fonts->AddFontFromFileTTF("app0:/Roboto.ttf", 16.0f * UI_SCALE, NULL, ranges); } +void start_net() { + sceSysmoduleLoadModule(SCE_SYSMODULE_NET); + int ret = sceNetShowNetstat(); + SceNetInitParam initparam; + if (ret == SCE_NET_ERROR_ENOTINIT) { + net_memory = malloc(NET_INIT_SIZE); + initparam.memory = net_memory; + initparam.size = NET_INIT_SIZE; + initparam.flags = 0; + sceNetInit(&initparam); + } +} + +int download_file(char *url, char *file, char *msg, float int_total_bytes) { + start_net(); + + SceKernelThreadInfo info; + info.size = sizeof(SceKernelThreadInfo); + int res = 0; + total_bytes = 0xFFFFFFFF; + downloaded_bytes = 0; + net_url = url; + + SceUID thd = sceKernelCreateThread("Net Downloader", &downloaderThread, 0x10000100, 0x100000, 0, 0, NULL); + sceKernelStartThread(thd, 0, NULL); + do { + DrawDownloaderScreenCompat(downloaded_bytes, downloaded_bytes > int_total_bytes ? downloaded_bytes : int_total_bytes, msg); + res = sceKernelGetThreadInfo(thd, &info); + } while (info.status <= SCE_THREAD_STOPPED && res >= 0); + + FILE *f = fopen(TEMP_DOWNLOAD_NAME, "r"); + if (f) { + fclose(f); + sceIoRemove(file); + sceIoRename(TEMP_DOWNLOAD_NAME, file); + }else return -1; + + ImGui::GetIO().MouseDrawCursor = true; + + return 0; +} + static void Initialize() { sys_initialized = true; @@ -327,21 +387,8 @@ static void Initialize() uint8_t gSkipAutoUpdate = strstr(stringify(GIT_VERSION), "dirty") != nullptr; // Initializing net - void *net_memory = nullptr; - if ((gAutoUpdate && !gSkipAutoUpdate) || !gSkipCompatListUpdate) { - net_mutex = sceKernelCreateSema("Net Mutex", 0, 0, 1, NULL); - sceSysmoduleLoadModule(SCE_SYSMODULE_NET); - int ret = sceNetShowNetstat(); - SceNetInitParam initparam; - if (ret == SCE_NET_ERROR_ENOTINIT) { - net_memory = malloc(NET_INIT_SIZE); - initparam.memory = net_memory; - initparam.size = NET_INIT_SIZE; - initparam.flags = 0; - sceNetInit(&initparam); - } - sceNetCtlInit(); - } + if ((gAutoUpdate && !gSkipAutoUpdate) || !gSkipCompatListUpdate) + start_net(); // Initializing vitaGL vglInitExtended(0x100000, SCR_WIDTH, SCR_HEIGHT, 0x1800000, (SceGxmMultisampleMode)gAntiAliasing); @@ -368,7 +415,6 @@ static void Initialize() SceUID thd = sceKernelCreateThread("Auto Updater", &updaterThread, 0x10000100, 0x100000, 0, 0, NULL); sceKernelStartThread(thd, 0, NULL); do { - sceKernelSignalSema(net_mutex, 1); if (downloader_pass == UPDATER_CHECK_UPDATES) DrawDownloaderScreen(downloader_pass + 1, downloaded_bytes, total_bytes, lang_strings[STR_DOWNLOADER_CHECK_UPDATE], NUM_UPDATE_PASSES); else DrawDownloaderScreen(downloader_pass + 1, downloaded_bytes, total_bytes, lang_strings[STR_DOWNLOADER_UPDATE], NUM_UPDATE_PASSES); res = sceKernelGetThreadInfo(thd, &info); @@ -393,22 +439,12 @@ static void Initialize() SceUID thd = sceKernelCreateThread("Compat List Updater", &compatListThread, 0x10000100, 0x100000, 0, 0, NULL); sceKernelStartThread(thd, 0, NULL); do { - sceKernelSignalSema(net_mutex, 1); DrawDownloaderScreen(downloader_pass, downloaded_bytes, total_bytes, lang_strings[STR_DOWNLOADER_COMPAT_LIST], NUM_DB_CHUNKS); res = sceKernelGetThreadInfo(thd, &info); } while (info.status <= SCE_THREAD_STOPPED && res >= 0); } - - if ((gAutoUpdate && !gSkipAutoUpdate) || !gSkipCompatListUpdate) { - ImGui::GetIO().MouseDrawCursor = true; - - // Closing net - sceNetCtlTerm(); - sceNetTerm(); - sceSysmoduleUnloadModule(SCE_SYSMODULE_NET); - free(net_memory); - sceKernelDeleteSema(net_mutex); - } + + ImGui::GetIO().MouseDrawCursor = true; } void setCpuMode(int cpu_mode)