make install work

This commit is contained in:
Chee Yee
2023-07-17 02:14:01 -07:00
parent daa15c9fa9
commit caad7dcbd7
3 changed files with 118 additions and 0 deletions
+79
View File
@@ -281,6 +281,85 @@ namespace INSTALLER
return 0;
}
int InstallLocalPkg(const std::string &filename)
{
int ret;
pkg_header header;
memset(&header, 0, sizeof(header));
if (FS::Head(filename.c_str(), (void *)&header, sizeof(header)) == 0)
return 0;
if (BE32(header.pkg_magic) != PKG_MAGIC)
return 0;
char filepath[1024];
snprintf(filepath, 1023, "%s", filename.c_str());
if (strncmp(filename.c_str(), "/data/", 6) == 0)
snprintf(filepath, 1023, "/user%s", filename.c_str());
char titleId[18];
memset(titleId, 0, sizeof(titleId));
int is_app = -1;
ret = sceAppInstUtilGetTitleIdFromPkg(filename.c_str(), titleId, &is_app);
if (ret)
{
return 0;
}
OrbisBgftTaskProgress progress_info;
int prog = 0;
OrbisBgftDownloadParamEx download_params;
memset(&download_params, 0, sizeof(download_params));
{
download_params.params.entitlementType = 5;
download_params.params.id = (char *)header.pkg_content_id;
download_params.params.contentUrl = filepath;
download_params.params.contentName = (char *)header.pkg_content_id;
;
download_params.params.iconPath = "";
download_params.params.playgoScenarioId = "0";
download_params.params.option = ORBIS_BGFT_TASK_OPT_FORCE_UPDATE;
download_params.slot = 0;
}
retry:
int task_id = -1;
ret = sceBgftServiceIntDownloadRegisterTaskByStorageEx(&download_params, &task_id);
if (ret == 0x80990088 || ret == 0x80990015)
{
ret = sceAppInstUtilAppUnInstall(titleId);
if (ret != 0)
return 0;
goto retry;
}
else if (ret > 0)
return 0;
ret = sceBgftServiceDownloadStartTask(task_id);
if (ret)
return 0;
Util::Notify("%s queued", titleId);
sprintf(activity_message, "%s", lang_strings[STR_WAIT_FOR_INSTALL_MSG]);
bytes_to_download = 1;
bytes_transfered = 0;
while (prog < 99)
{
memset(&progress_info, 0, sizeof(progress_info));
ret = sceBgftServiceDownloadGetProgress(task_id, &progress_info);
if (ret || (progress_info.transferred > 0 && progress_info.errorResult != 0))
return -3;
prog = (uint32_t)(((float)progress_info.transferred / progress_info.length) * 100.f);
bytes_to_download = progress_info.length;
bytes_transfered = progress_info.transferred;
}
return 1;
err:
return 0;
}
int InstallLocalPkg(const std::string &filename, pkg_header *header, bool remove_after_install)
{
int ret;
+1
View File
@@ -122,6 +122,7 @@ namespace INSTALLER
bool canInstallRemotePkg(const std::string &url);
std::string getRemoteUrl(const std::string filename, bool encodeUrl = false);
int InstallRemotePkg(const std::string &filename, pkg_header *header);
int InstallLocalPkg(const std::string &filename);
int InstallLocalPkg(const std::string &filename, pkg_header *header, bool remove_after_install = false);
bool ExtractLocalPkg(const std::string &filename, const std::string sfo_path, const std::string icon_path);
bool ExtractRemotePkg(const std::string &filename, const std::string sfo_path, const std::string icon_path);
+38
View File
@@ -9,6 +9,7 @@
#include "lang.h"
#include "system.h"
#include "zip_util.h"
#include "installer.h"
#include "dbglogger.h"
#define SERVER_CERT_FILE "/app0/assets/certs/domain.crt"
@@ -436,6 +437,43 @@ namespace HttpServer
success(res);
});
svr->Post("/__local__/install", [&](const Request & req, Response & res)
{
json_object *items;
json_object *jobj = json_tokener_parse(req.body.c_str());
if (jobj != nullptr)
{
items = json_object_object_get(jobj, "items");
if (items == nullptr)
{
bad_request(res, "Required items parameter missing");
return;
}
}
else
{
bad_request(res, "Invalid payload");
return;
}
std::string failed_items;
size_t len = json_object_array_length(items);
for (size_t i=0; i < len; i++)
{
const char *item = json_object_get_string(json_object_array_get_idx(items, i));
if (!INSTALLER::InstallLocalPkg(item))
failed_items += (std::string(item) + ",");
}
if (failed_items.length() > 0)
{
std::string error_msg = std::string("One or more file(s) failed to install. ") + failed_items;
failed(res, 200, error_msg);
}
else
success(res);
});
svr->Post("/__local__/edit", [&](const Request & req, Response & res)
{
const char *item;