From 114c1974e16d6f7cc0cdc3f4aa1e81eefb52b447 Mon Sep 17 00:00:00 2001 From: Chee Yee Date: Fri, 28 Jun 2024 02:26:03 -0700 Subject: [PATCH] enable disk caching for all remote types --- CMakeLists.txt | 1 - data/assets/langs/English.ini | 1 + source/actions.cpp | 36 ++++++++++++++++++++++++++++++----- source/config.cpp | 4 ++++ source/config.h | 2 ++ source/installer.cpp | 6 ++++-- source/installer.h | 1 + source/lang.cpp | 2 ++ source/lang.h | 6 ++++-- source/main.cpp | 6 +++--- source/server/http_server.cpp | 6 ++++-- source/windows.cpp | 20 +++++++++++++++++++ 12 files changed, 76 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d652b41..8aa2362 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,7 +70,6 @@ add_self(ezremote_client) add_pkg(ezremote_client ${CMAKE_SOURCE_DIR}/data "RMTC00001" "ezRemote Client" "01.27" 32 0) target_link_libraries(ezremote_client - dbglogger c c++ png diff --git a/data/assets/langs/English.ini b/data/assets/langs/English.ini index bbb51f8..0d57bed 100644 --- a/data/assets/langs/English.ini +++ b/data/assets/langs/English.ini @@ -160,3 +160,4 @@ STR_LANGUAGE=Language STR_TEMP_DIRECTORY=Temp Directory STR_REALDEBRID=Real-Debrid STR_BACKGROUND_INSTALL_INPROGRESS=Package install is running in the background. Don't close the app while install is in progress +STR_ENABLE_DISC_CACHE_MSG=Enable disk caching. Can improve package install speed in cases where connection to remote is slow diff --git a/source/actions.cpp b/source/actions.cpp index 581fb7b..7b15672 100644 --- a/source/actions.cpp +++ b/source/actions.cpp @@ -712,13 +712,39 @@ namespace Actions } else { - std::string url = INSTALLER::getRemoteUrl(it->path, true); - std::string title = INSTALLER::GetRemotePkgTitle(remoteclient, it->path, &header); + if (remote_settings->enable_disk_cache) + { + SplitPkgInstallData *install_data = (SplitPkgInstallData*) malloc(sizeof(SplitPkgInstallData)); + memset(install_data, 0, sizeof(SplitPkgInstallData)); - if (INSTALLER::InstallRemotePkg(url, &header, title, true) == 0) - failed++; + OrbisTick tick; + sceRtcGetCurrentTick(&tick); + std::string install_pkg_path = std::string(temp_folder) + "/" + std::to_string(tick.mytick) + ".pkg"; + SplitFile *sp = new SplitFile(install_pkg_path, INSTALL_ARCHIVE_PKG_SPLIT_SIZE/2); + + install_data->split_file = sp; + install_data->remote_client = remoteclient; + install_data->path = it->path; + remoteclient->Size(it->path, &install_data->size); + install_data->stop_write_thread = false; + install_data->delete_client = false; + + int ret = pthread_create(&install_data->thread, NULL, DownloadSplitPkg, install_data); + + if (INSTALLER::InstallSplitPkg(it->path, install_data, false) == 0) + failed++; + else + success++; + } else - success++; + { + std::string url = INSTALLER::getRemoteUrl(it->path, true); + std::string title = INSTALLER::GetRemotePkgTitle(remoteclient, it->path, &header); + if (INSTALLER::InstallRemotePkg(url, &header, title, true) == 0) + failed++; + else + success++; + } } } else diff --git a/source/config.cpp b/source/config.cpp index 043de38..8d359a7 100644 --- a/source/config.cpp +++ b/source/config.cpp @@ -298,6 +298,9 @@ namespace CONFIG setting.enable_rpi = ReadBool(sites[i].c_str(), CONFIG_ENABLE_RPI, true); WriteBool(sites[i].c_str(), CONFIG_ENABLE_RPI, setting.enable_rpi); + setting.enable_disk_cache = ReadBool(sites[i].c_str(), CONFIG_REMOTE_ENABLE_DISK_CACHE, false); + WriteBool(sites[i].c_str(), CONFIG_REMOTE_ENABLE_DISK_CACHE, setting.enable_disk_cache); + sprintf(setting.http_server_type, "%s", ReadString(sites[i].c_str(), CONFIG_REMOTE_HTTP_SERVER_TYPE, HTTP_SERVER_APACHE)); WriteString(sites[i].c_str(), CONFIG_REMOTE_HTTP_SERVER_TYPE, setting.http_server_type); @@ -371,6 +374,7 @@ namespace CONFIG WriteString(last_site, CONFIG_REMOTE_SERVER_USER, remote_settings->username); WriteString(last_site, CONFIG_REMOTE_SERVER_PASSWORD, encrypted_text.c_str()); WriteBool(last_site, CONFIG_ENABLE_RPI, remote_settings->enable_rpi); + WriteBool(last_site, CONFIG_REMOTE_ENABLE_DISK_CACHE, remote_settings->enable_disk_cache); WriteString(last_site, CONFIG_REMOTE_HTTP_SERVER_TYPE, remote_settings->http_server_type); WriteString(last_site, CONFIG_REMOTE_DEFAULT_DIRECTORY, remote_settings->default_directory); WriteString(CONFIG_GLOBAL, CONFIG_LAST_SITE, last_site); diff --git a/source/config.h b/source/config.h index a4d7f3b..a2179b8 100644 --- a/source/config.h +++ b/source/config.h @@ -57,6 +57,7 @@ #define CONFIG_ENABLE_RPI "remote_server_enable_rpi" #define CONFIG_REMOTE_HTTP_SERVER_TYPE "remote_server_http_server_type" #define CONFIG_REMOTE_DEFAULT_DIRECTORY "remote_server_default_directory" +#define CONFIG_REMOTE_ENABLE_DISK_CACHE "remote_server_enable_disk_cache" #define CONFIG_ALLDEBRID_API_KEY "alldebrid_api_key" #define CONFIG_REALDEBRID_API_KEY "realdebrid_api_key" @@ -110,6 +111,7 @@ struct RemoteSettings char http_server_type[24]; GoogleAccountInfo gg_account; char default_directory[256]; + bool enable_disk_cache; }; struct PackageUrlInfo diff --git a/source/installer.cpp b/source/installer.cpp index beb887d..5857545 100644 --- a/source/installer.cpp +++ b/source/installer.cpp @@ -270,7 +270,8 @@ namespace INSTALLER bg_check_data->split_pkg_data->split_file->Close(); pthread_join(bg_check_data->split_pkg_data->thread, NULL); delete (bg_check_data->split_pkg_data->split_file); - delete (bg_check_data->split_pkg_data->remote_client); + if (bg_check_data->split_pkg_data->delete_client) + delete (bg_check_data->split_pkg_data->remote_client); free(bg_check_data->split_pkg_data); RemoveSplitPkgInstallData(bg_check_data->hash); free(bg_check_data); @@ -1160,7 +1161,8 @@ namespace INSTALLER pkg_data->split_file->Close(); pthread_join(pkg_data->thread, NULL); delete (pkg_data->split_file); - delete (pkg_data->remote_client); + if (pkg_data->delete_client) + delete (pkg_data->remote_client); free(pkg_data); RemoveSplitPkgInstallData(hash); activity_inprogess = false; diff --git a/source/installer.h b/source/installer.h index 77c9de6..9040869 100644 --- a/source/installer.h +++ b/source/installer.h @@ -137,6 +137,7 @@ struct SplitPkgInstallData int64_t size; pthread_t thread; bool stop_write_thread; + bool delete_client; }; static pthread_t bk_install_thid; diff --git a/source/lang.cpp b/source/lang.cpp index 6957c83..face292 100644 --- a/source/lang.cpp +++ b/source/lang.cpp @@ -172,6 +172,8 @@ char lang_strings[LANG_STRINGS_NUM][LANG_STR_SIZE] = { "Temp Directory", // STR_TEMP_DIRECTORY "Real-Debrid", // STR_REALDEBRID "Package install is running in the background. Don't close the app while install is in progress", // STR_BACKGROUND_INSTALL_INPROGRESS + "Enable disk caching. Can improve package install speed in cases where connection to remote is slow", // STR_ENABLE_DISC_CACHE_MSG + "DC", // STR_ENABLE_DISK_CACHE }; bool needs_extended_font = false; diff --git a/source/lang.h b/source/lang.h index 70eafc3..1216aba 100644 --- a/source/lang.h +++ b/source/lang.h @@ -165,7 +165,9 @@ FUNC(STR_LANGUAGE) \ FUNC(STR_TEMP_DIRECTORY) \ FUNC(STR_REALDEBRID) \ - FUNC(STR_BACKGROUND_INSTALL_INPROGRESS) + FUNC(STR_BACKGROUND_INSTALL_INPROGRESS) \ + FUNC(STR_ENABLE_DISC_CACHE_MSG) \ + FUNC(STR_ENABLE_DISK_CACHE) #define GET_VALUE(x) x, #define GET_STRING(x) #x, @@ -175,7 +177,7 @@ enum FOREACH_STR(GET_VALUE) }; -#define LANG_STRINGS_NUM 162 +#define LANG_STRINGS_NUM 164 #define LANG_ID_SIZE 64 #define LANG_STR_SIZE 384 extern char lang_identifiers[LANG_STRINGS_NUM][LANG_ID_SIZE]; diff --git a/source/main.cpp b/source/main.cpp index 477f0ae..de60173 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +// #include #include "imgui.h" #include "SDL2/SDL.h" @@ -271,8 +271,8 @@ static void terminate() int main() { - dbglogger_init(); - dbglogger_log("If you see this you've set up dbglogger correctly."); + // dbglogger_init(); + // dbglogger_log("If you see this you've set up dbglogger correctly."); int rc; // No buffering setvbuf(stdout, NULL, _IONBF, 0); diff --git a/source/server/http_server.cpp b/source/server/http_server.cpp index 790d7ab..d459417 100644 --- a/source/server/http_server.cpp +++ b/source/server/http_server.cpp @@ -1322,8 +1322,9 @@ namespace HttpServer SplitPkgInstallData *install_data = (SplitPkgInstallData*) malloc(sizeof(SplitPkgInstallData)); memset(install_data, 0, sizeof(SplitPkgInstallData)); - Util::ReplaceAll(hash, "/", ""); - std::string install_pkg_path = std::string(temp_folder) + "/" + hash; + OrbisTick tick; + sceRtcGetCurrentTick(&tick); + std::string install_pkg_path = std::string(temp_folder) + "/" + std::to_string(tick.mytick) + ".pkg"; SplitFile *sp = new SplitFile(install_pkg_path, INSTALL_ARCHIVE_PKG_SPLIT_SIZE/2); install_data->split_file = sp; @@ -1331,6 +1332,7 @@ namespace HttpServer install_data->path = path; baseclient->Size(path, &install_data->size); install_data->stop_write_thread = false; + install_data->delete_client = true; int ret = pthread_create(&install_data->thread, NULL, Actions::DownloadSplitPkg, install_data); diff --git a/source/windows.cpp b/source/windows.cpp index 6a5cb3b..43676a7 100644 --- a/source/windows.cpp +++ b/source/windows.cpp @@ -455,6 +455,26 @@ namespace Windows ImGui::PopTextWrapPos(); ImGui::EndTooltip(); } + + ImGui::SameLine(); + ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 5); + ImGui::TextColored(colors[ImGuiCol_ButtonHovered], "%s:", lang_strings[STR_ENABLE_DISK_CACHE]); + ImGui::SameLine(); + + if (ImGui::Checkbox("###enable_disk_cache", &remote_settings->enable_disk_cache)) + { + CONFIG::SaveConfig(); + } + if (ImGui::IsItemHovered()) + { + ImGui::SetNextWindowSize(ImVec2(450, 70)); + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + 440); + ImGui::Text("%s", lang_strings[STR_ENABLE_DISC_CACHE_MSG]); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } + ImGui::PopStyleVar(); ImGui::SameLine();