From 7395056a75eb32d11b380e94febfbde82da17238 Mon Sep 17 00:00:00 2001 From: cy33hc Date: Sat, 30 May 2026 13:49:31 -0700 Subject: [PATCH] add bg download function --- CMakeLists.txt | 1 - source/actions.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ source/system.cpp | 15 --------------- source/system.h | 1 - source/util.h | 7 +++++++ 5 files changed, 48 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3eef0c2..ff2410e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,7 +107,6 @@ target_link_libraries(ezremote_client SceUserService ScePad SceAudioOut - SceSysUtil SceImeDialog SceNet SceBgft diff --git a/source/actions.cpp b/source/actions.cpp index 87994a5..427b25f 100644 --- a/source/actions.cpp +++ b/source/actions.cpp @@ -490,6 +490,43 @@ namespace Actions } } + int BackgroundDownload(const char *src, const char *dest, uint64_t file_size) + { + uint64_t id = Util::GetTick(); + json_object *params = json_object_new_object(); + json_object_object_add(params, "type", json_object_new_int(remote_settings->type)); + json_object_object_add(params, "url", json_object_new_string(remote_settings->server)); + json_object_object_add(params, "username", json_object_new_string(remote_settings->username)); + json_object_object_add(params, "password", json_object_new_string(remote_settings->password)); + json_object_object_add(params, "src_path", json_object_new_string(src)); + json_object_object_add(params, "dest_path", json_object_new_string(dest)); + json_object_object_add(params, "size", json_object_new_uint64(file_size)); + json_object_object_add(params, "id", json_object_new_uint64(id)); + if (remote_settings->type == CLIENT_TYPE_HTTP_SERVER) + { + json_object_object_add(params, "http_server_type", json_object_new_string(remote_settings->http_server_type)); + } + + const char *params_str = json_object_to_json_string(params); + + httplib::Client tmp_client = httplib::Client("http://127.0.0.1:" + std::to_string(http_int_server_port)); + if (auto res = tmp_client.Post("/download_url", params_str, strlen(params_str), "application/json")) + { + if (HTTP_SUCCESS(res->status)) + { + Util::Notify("%s queued for download", src); + return 1; + } + else + { + Util::Notify("Failed to queue %s for download in background", src); + return 0; + } + } + + return 0; + } + int DownloadFile(const char *src, const char *dest) { bytes_transfered = 0; @@ -526,6 +563,10 @@ namespace Actions if (confirm_state == CONFIRM_YES) { sceRtcGetCurrentTick(&prev_tick); + if (enable_background_download && bytes_to_download > minimum_backgrond_file_size) + { + return BackgroundDownload(src, dest, bytes_to_download); + } return remoteclient->Get(dest, src); } diff --git a/source/system.cpp b/source/system.cpp index 86a2092..6386b29 100644 --- a/source/system.cpp +++ b/source/system.cpp @@ -14,7 +14,6 @@ int (*sceRtcFormatRFC3339LocalTime)(char *pszDateTime, const OrbisTick *tick); unsigned int (*sceRtcGetTickResolution)(); int (*sceShellUIUtilLaunchByUri)(const char *uri, SceShellUIUtilLaunchByUriParam *param); int (*sceShellUIUtilInitialize)(); -// int (*sceLncUtilGetAppId)(const char* tid); void convertUtcToLocalTime(const OrbisDateTime *utc, OrbisDateTime *local_time) { @@ -108,20 +107,6 @@ int load_sys_modules() return -1; } - /* - handle = sceKernelLoadStartModule("/system/common/lib/libSceSystemService.sprx", 0, NULL, 0, 0, 0); - if (handle == 0) - { - return -1; - } - - sceKernelDlsym(handle, "sceLncUtilGetAppId", (void **)&sceLncUtilGetAppId); - if (sceLncUtilGetAppId == NULL) - { - return -1; - } - */ - if (sceShellUIUtilInitialize() < 0) return -1; return 0; diff --git a/source/system.h b/source/system.h index 0586df8..4f1e3e1 100644 --- a/source/system.h +++ b/source/system.h @@ -37,7 +37,6 @@ extern int (*sceRtcFormatRFC3339LocalTime)(char *pszDateTime, const OrbisTick *t extern unsigned int (*sceRtcGetTickResolution)(); extern int (*sceShellUIUtilLaunchByUri)(const char *uri, SceShellUIUtilLaunchByUriParam *param); extern int (*sceShellUIUtilInitialize)(); -// extern int (*sceLncUtilGetAppId)(const char* tid); int load_sys_modules(); void convertUtcToLocalTime(const OrbisDateTime *utc, OrbisDateTime *local_time); diff --git a/source/util.h b/source/util.h index 9bd1e13..946301b 100644 --- a/source/util.h +++ b/source/util.h @@ -88,6 +88,13 @@ namespace Util return out; } + static uint64_t GetTick() + { + static struct timeval tick; + gettimeofday(&tick, NULL); + return tick.tv_sec * 1000000 + tick.tv_usec; + } + static inline void Notify(const char *fmt, ...) { OrbisNotificationRequest request;