enchancements to install from url

This commit is contained in:
Chee Yee
2024-10-08 20:50:42 -07:00
parent 0a1420dd96
commit a71bd1eb28
15 changed files with 467 additions and 73 deletions
+69 -7
View File
@@ -1,6 +1,7 @@
#include <string.h>
#include <stdlib.h>
#include <pthread.h>
#include <json-c/json.h>
#include <lexbor/html/parser.h>
#include <lexbor/dom/interfaces/element.h>
#include <minizip/unzip.h>
@@ -19,6 +20,7 @@
#include "clients/rclone.h"
#include "clients/sftpclient.h"
#include "filehost/filehost.h"
#include "server/http_server.h"
#include "common.h"
#include "fs.h"
#include "config.h"
@@ -1108,7 +1110,7 @@ namespace Actions
}
}
void *InstallUrlPkgThread(void *argp)
void *InstallLocalUrlPkgThread(void *argp)
{
bytes_transfered = 0;
sceRtcGetCurrentTick(&prev_tick);
@@ -1119,10 +1121,10 @@ namespace Actions
OrbisTick tick;
sceRtcGetCurrentClockLocalTime(&now);
sceRtcGetTick(&now, &tick);
sprintf(filename, "%s/%lu.pkg", DATA_PATH, tick.mytick);
sprintf(filename, "%s/%lu.pkg", TMP_FOLDER_PATH, tick.mytick);
std::string full_url = std::string(install_pkg_url.url);
FileHost *filehost = FileHost::getFileHost(full_url);
FileHost *filehost = FileHost::getFileHost(full_url, install_pkg_url.enable_alldebrid, install_pkg_url.enable_realdebrid);
if (!filehost->IsValidUrl())
{
sprintf(status_message, "%s", lang_strings[STR_FAIL_TO_OBTAIN_GG_DL_MSG]);
@@ -1145,7 +1147,7 @@ namespace Actions
std::string host = full_url.substr(0, path_pos);
std::string path = full_url.substr(path_pos);
WebDAVClient tmp_client;
BaseClient tmp_client;
tmp_client.Connect(host.c_str(), install_pkg_url.username, install_pkg_url.password);
sprintf(activity_message, "%s URL to %s", lang_strings[STR_DOWNLOADING], filename);
@@ -1153,7 +1155,7 @@ namespace Actions
memset(&header, 0, s);
int ret = tmp_client.Size(path, &bytes_to_download);
if (!ret)
if (ret == 0)
{
sprintf(status_message, "%s - %s", lang_strings[STR_FAILED], lang_strings[STR_CANNOT_READ_PKG_HDR_MSG]);
tmp_client.Quit();
@@ -1163,7 +1165,7 @@ namespace Actions
}
file_transfering = 1;
int is_performed = tmp_client.Get(path, filename);
int is_performed = tmp_client.Get(filename, path);
if (is_performed == 0)
{
@@ -1216,10 +1218,70 @@ namespace Actions
return NULL;
}
void *InstallRpiUrlPkgThread(void *argp)
{
json_object *params = json_object_new_object();
json_object_object_add(params, "url", json_object_new_string(install_pkg_url.url));
json_object_object_add(params, "use_alldebrid", json_object_new_boolean(install_pkg_url.enable_alldebrid));
json_object_object_add(params, "use_realdebrid", json_object_new_boolean(install_pkg_url.enable_realdebrid));
json_object_object_add(params, "use_disk_cache", json_object_new_boolean(install_pkg_url.enable_disk_cache));
const char *params_str = json_object_to_json_string(params);
char host[128];
sprintf(host, "http://127.0.0.1:%d", http_server_port);
httplib::Client tmp_client(host);
tmp_client.set_keep_alive(true);
tmp_client.set_follow_location(true);
tmp_client.set_connection_timeout(30);
tmp_client.set_read_timeout(30);
tmp_client.enable_server_certificate_verification(false);
auto res = tmp_client.Post("/__local__/install_url", params_str, strlen(params_str), "application/json");
if (res != nullptr && HTTP_SUCCESS(res->status))
{
json_object *jobj = json_tokener_parse(res->body.c_str());
if (jobj != nullptr)
{
json_object *result = json_object_object_get(jobj, "result");
if (result != nullptr)
{
bool success = json_object_get_boolean(json_object_object_get(result, "success"));
if (!success)
{
const char* error_message = json_object_get_string(json_object_object_get(result, "error"));
sprintf(status_message, "%s", error_message);
activity_inprogess = false;
Windows::SetModalMode(false);
}
}
}
else
{
activity_inprogess = false;
Windows::SetModalMode(false);
}
}
else
{
activity_inprogess = false;
Windows::SetModalMode(false);
}
return NULL;
}
void InstallUrlPkg()
{
int res;
sprintf(status_message, "%s", "");
int res = pthread_create(&bk_activity_thid, NULL, InstallUrlPkgThread, NULL);
if (!install_pkg_url.enable_rpi)
res = pthread_create(&bk_activity_thid, NULL, InstallLocalUrlPkgThread, NULL);
else
res = pthread_create(&bk_activity_thid, NULL, InstallRpiUrlPkgThread, NULL);
if (res != 0)
{
activity_inprogess = false;
+2 -1
View File
@@ -99,7 +99,8 @@ namespace Actions
void InstallRemotePkgs();
void *InstallLocalPkgsThread(void *argp);
void InstallLocalPkgs();
void *InstallUrlPkgThread(void *argp);
void *InstallLocalUrlPkgThread(void *argp);
void *InstallRpiUrlPkgThread(void *argp);
void InstallUrlPkg();
void *KeepAliveThread(void *argp);
void *ExtractZipThread(void *argp);
+4 -1
View File
@@ -152,12 +152,15 @@ namespace CONFIG
FS::MkDirs(DATA_PATH);
}
memset(&install_pkg_url, 0, sizeof(install_pkg_url));
install_pkg_url.enable_rpi = true;
sites = {"Site 1", "Site 2", "Site 3", "Site 4", "Site 5", "Site 6", "Site 7", "Site 8", "Site 9", "Site 10",
"Site 11", "Site 12", "Site 13", "Site 14", "Site 15", "Site 16", "Site 17", "Site 18", "Site 19", "Site 20"};
langs = { "Default", "Arabic", "Catalan", "Croatian", "Dutch", "English", "Euskera", "French", "Galego", "German", "Greek",
"Hungarian", "Indonesian", "Italiano", "Japanese", "Korean", "Polish", "Portuguese_BR", "Russian", "Romanian", "Ryukyuan", "Spanish", "Turkish",
"Simplified Chinese", "Traditional Chinese", "Thai", "Ukrainian"};
"Simplified Chinese", "Traditional Chinese", "Thai", "Ukrainian", "Vietnamese"};
http_servers = {HTTP_SERVER_APACHE, HTTP_SERVER_MS_IIS, HTTP_SERVER_NGINX, HTTP_SERVER_NPX_SERVE, HTTP_SERVER_RCLONE, HTTP_SERVER_ARCHIVEORG, HTTP_SERVER_MYRIENT};
text_file_extensions = { ".txt", ".ini", ".log", ".json", ".xml", ".html", ".xhtml", ".conf", ".config" };
+4
View File
@@ -121,6 +121,10 @@ struct PackageUrlInfo
char url[512];
char username[33];
char password[25];
bool enable_alldebrid;
bool enable_realdebrid;
bool enable_disk_cache;
bool enable_rpi;
};
extern std::vector<std::string> sites;
+4 -1
View File
@@ -172,8 +172,11 @@ 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
"Enable disk caching. Can improve package install speed in cases where connection to remote is slow, but breaks resuming of install", // STR_ENABLE_DISC_CACHE_MSG
"DC", // STR_ENABLE_DISK_CACHE
"Install Via AllDebrid", // STR_ENABLE_ALLDEBRID_MSG
"Install Via RealDebrid", // STR_ENABLE_REALDEBRID_MSG
"Enable Disk Cache", // STR_ENABLE_DISKCACHE_DESC
};
bool needs_extended_font = false;
+5 -2
View File
@@ -167,7 +167,10 @@
FUNC(STR_REALDEBRID) \
FUNC(STR_BACKGROUND_INSTALL_INPROGRESS) \
FUNC(STR_ENABLE_DISC_CACHE_MSG) \
FUNC(STR_ENABLE_DISK_CACHE)
FUNC(STR_ENABLE_DISK_CACHE) \
FUNC(STR_ENABLE_ALLDEBRID_MSG) \
FUNC(STR_ENABLE_REALDEBRID_MSG) \
FUNC(STR_ENABLE_DISKCACHE_DESC)
#define GET_VALUE(x) x,
#define GET_STRING(x) #x,
@@ -177,7 +180,7 @@ enum
FOREACH_STR(GET_VALUE)
};
#define LANG_STRINGS_NUM 164
#define LANG_STRINGS_NUM 167
#define LANG_ID_SIZE 64
#define LANG_STR_SIZE 384
extern char lang_identifiers[LANG_STRINGS_NUM][LANG_ID_SIZE];
+10 -8
View File
@@ -139,41 +139,43 @@ void InitImgui()
sceSystemServiceParamGetInt( ORBIS_SYSTEM_SERVICE_PARAM_ID_LANG, &lang_idx );
lang = Util::Trim(lang, " ");
if (lang.compare("Korean") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_KOREAN))
bool use_system_lang = lang.empty() || lang.compare("Default") == 0;
if (lang.compare("Korean") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_KOREAN))
{
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, NULL, io.Fonts->GetGlyphRangesKorean());
}
else if (lang.compare("Simplified Chinese") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_CHINESE_S))
else if (lang.compare("Simplified Chinese") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_CHINESE_S))
{
ImFontConfig config;
config.OversampleH = 1;
config.OversampleV = 1;
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, &config, io.Fonts->GetGlyphRangesChineseFull());
}
else if (lang.compare("Traditional Chinese") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_CHINESE_T))
else if (lang.compare("Traditional Chinese") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_CHINESE_T))
{
ImFontConfig config;
config.OversampleH = 1;
config.OversampleV = 1;
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, &config, io.Fonts->GetGlyphRangesChineseFull());
}
else if (lang.compare("Japanese") == 0 || lang.compare("Ryukyuan") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_JAPANESE))
else if (lang.compare("Japanese") == 0 || lang.compare("Ryukyuan") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_JAPANESE))
{
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
}
else if (lang.compare("Thai") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_THAI))
else if (lang.compare("Thai") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_THAI))
{
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, NULL, io.Fonts->GetGlyphRangesThai());
}
else if (lang.compare("Vietnamese") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_VIETNAMESE))
else if (lang.compare("Vietnamese") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_VIETNAMESE))
{
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, NULL, io.Fonts->GetGlyphRangesVietnamese());
}
else if (lang.compare("Greek") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_GREEK))
else if (lang.compare("Greek") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_GREEK))
{
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, NULL, io.Fonts->GetGlyphRangesGreek());
}
else if (lang.compare("Arabic") == 0 || (lang.empty() && lang_idx == ORBIS_SYSTEM_PARAM_LANG_ARABIC))
else if (lang.compare("Arabic") == 0 || (use_system_lang && lang_idx == ORBIS_SYSTEM_PARAM_LANG_ARABIC))
{
io.Fonts->AddFontFromFileTTF("/app0/assets/fonts/Roboto_ext.ttf", 26.0f, NULL, arabic);
}
+6
View File
@@ -1177,6 +1177,12 @@ namespace HttpServer
SplitPkgInstallData *pkg_data = INSTALLER::GetSplitPkgInstallData(hash);
if (pkg_data == nullptr)
{
failed(res, 500, "Cannot resume split_inst");
return;
}
if (req.method == "HEAD")
{
res.status = 204;
+55 -11
View File
@@ -450,7 +450,7 @@ namespace Windows
}
if (ImGui::IsItemHovered())
{
ImGui::SetNextWindowSize(ImVec2(450, 70));
ImGui::SetNextWindowSize(ImVec2(450, 110));
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + 440);
ImGui::Text("%s", lang_strings[STR_ENABLE_RPI_FTP_SMB_MSG]);
@@ -469,7 +469,7 @@ namespace Windows
}
if (ImGui::IsItemHovered())
{
ImGui::SetNextWindowSize(ImVec2(550, 85));
ImGui::SetNextWindowSize(ImVec2(550, 110));
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + 540);
ImGui::Text("%s", lang_strings[STR_ENABLE_DISC_CACHE_MSG]);
@@ -1498,7 +1498,52 @@ namespace Windows
{
ImVec2 cur_pos = ImGui::GetCursorPos();
char id[128];
if (ImGui::Button(lang_strings[STR_ONETIME_URL], ImVec2(535, 0)))
ImGui::Checkbox("##enable_alldebrid_install_uril", &install_pkg_url.enable_alldebrid);
ImGui::SameLine();
ImGui::Text("%s", lang_strings[STR_ENABLE_ALLDEBRID_MSG]);
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetCursorPosX()+40);
ImGui::Checkbox("##enable_realdebrid_install_uril", &install_pkg_url.enable_realdebrid);
ImGui::SameLine();
ImGui::Text("%s", lang_strings[STR_ENABLE_REALDEBRID_MSG]);
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetCursorPosX()+40);
ImGui::Checkbox("##enable_rpi_install_url", &install_pkg_url.enable_rpi);
if (ImGui::IsItemHovered())
{
ImGui::SetNextWindowSize(ImVec2(550, 110));
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + 540);
ImGui::Text("%s", lang_strings[STR_ENABLE_RPI_WEBDAV_MSG]);
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
ImGui::SameLine();
ImGui::Text("%s", lang_strings[STR_ENABLE_RPI]);
if (install_pkg_url.enable_rpi)
{
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetCursorPosX()+40);
ImGui::Checkbox("##enable_diskcache_install_uril", &install_pkg_url.enable_disk_cache);
if (ImGui::IsItemHovered())
{
ImGui::SetNextWindowSize(ImVec2(550, 110));
ImGui::BeginTooltip();
ImGui::PushTextWrapPos(ImGui::GetCursorPos().x + 540);
ImGui::Text("%s", lang_strings[STR_ENABLE_DISC_CACHE_MSG]);
ImGui::PopTextWrapPos();
ImGui::EndTooltip();
}
ImGui::SameLine();
ImGui::Text("%s", lang_strings[STR_ENABLE_DISKCACHE_DESC]);
}
ImGui::Separator();
if (ImGui::Button(lang_strings[STR_ONETIME_URL], ImVec2(1070, 0)))
{
ResetImeCallbacks();
sprintf(install_pkg_url.url, "%s", "");
@@ -1512,14 +1557,6 @@ namespace Windows
SetModalMode(false);
ImGui::CloseCurrentPopup();
}
ImGui::SameLine();
sprintf(id, "%s##favoriteurl", lang_strings[STR_CANCEL]);
if (ImGui::Button(id, ImVec2(535, 0)))
{
select_url_inprogress = false;
SetModalMode(false);
ImGui::CloseCurrentPopup();
}
ImGui::Separator();
for (int j = 0; j < MAX_FAVORITE_URLS; j++)
@@ -1567,6 +1604,13 @@ namespace Windows
}
}
if (ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false))
{
select_url_inprogress = false;
SetModalMode(false);
ImGui::CloseCurrentPopup();
}
ImGui::EndPopup();
}
}