add bg download function

This commit is contained in:
cy33hc
2026-05-30 13:49:31 -07:00
parent 81a5143f2f
commit 7395056a75
5 changed files with 48 additions and 17 deletions
-1
View File
@@ -107,7 +107,6 @@ target_link_libraries(ezremote_client
SceUserService
ScePad
SceAudioOut
SceSysUtil
SceImeDialog
SceNet
SceBgft
+41
View File
@@ -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);
}
-15
View File
@@ -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;
-1
View File
@@ -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);
+7
View File
@@ -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;