add back ability for remote package install for smb/ftp

This commit is contained in:
Chee Yee
2023-02-13 00:07:05 -08:00
parent 2be520d9cf
commit 83070356d4
16 changed files with 130 additions and 59 deletions
+1
View File
@@ -105,3 +105,4 @@ STR_FAIL_COPY_MSG=Failed to copy file
STR_CANT_MOVE_TO_SUBDIR_MSG=Cannot move parent directory to sub subdirectory
STR_CANT_COPY_TO_SUBDIR_MSG=Cannot copy parent directory to sub subdirectory
STR_UNSUPPORTED_OPERATION_MSG=Operation not supported
STR_HTTP_PORT=Http Port
+1 -2
View File
@@ -624,7 +624,6 @@ namespace Actions
int success = 0;
int skipped = 0;
WebDAV::WebDavClient *client = (WebDAV::WebDavClient *)remoteclient;
std::vector<DirEntry> files;
if (multi_selected_remote_files.size()>0)
std::copy(multi_selected_remote_files.begin(), multi_selected_remote_files.end(), std::back_inserter(files));
@@ -646,7 +645,7 @@ namespace Actions
pkg_header header;
memset(&header, 0, sizeof(header));
if (client->Head(it->path, (void *)&header, sizeof(header)) == 0)
if (remoteclient->Head(it->path, (void *)&header, sizeof(header)) == 0)
failed++;
else
{
+6
View File
@@ -62,6 +62,8 @@ namespace CONFIG
sprintf(setting.server, "%s", ReadString(sites[i].c_str(), CONFIG_REMOTE_SERVER_URL, ""));
WriteString(sites[i].c_str(), CONFIG_REMOTE_SERVER_URL, setting.server);
setting.is_smb = strncmp(setting.server, "smb://", 6) == 0;
setting.is_ftp = strncmp(setting.server, "ftp://", 6) == 0;
sprintf(setting.username, "%s", ReadString(sites[i].c_str(), CONFIG_REMOTE_SERVER_USER, ""));
WriteString(sites[i].c_str(), CONFIG_REMOTE_SERVER_USER, setting.username);
@@ -69,6 +71,9 @@ namespace CONFIG
sprintf(setting.password, "%s", ReadString(sites[i].c_str(), CONFIG_REMOTE_SERVER_PASSWORD, ""));
WriteString(sites[i].c_str(), CONFIG_REMOTE_SERVER_PASSWORD, setting.password);
setting.http_port = ReadInt(sites[i].c_str(), CONFIG_REMOTE_SERVER_HTTP_PORT, 80);
WriteInt(sites[i].c_str(), CONFIG_REMOTE_SERVER_HTTP_PORT, setting.http_port);
site_settings.insert(std::make_pair(sites[i], setting));
}
@@ -95,6 +100,7 @@ namespace CONFIG
WriteString(last_site, CONFIG_REMOTE_SERVER_URL, remote_settings->server);
WriteString(last_site, CONFIG_REMOTE_SERVER_USER, remote_settings->username);
WriteString(last_site, CONFIG_REMOTE_SERVER_PASSWORD, remote_settings->password);
WriteInt(last_site, CONFIG_REMOTE_SERVER_HTTP_PORT, remote_settings->http_port);
WriteString(CONFIG_GLOBAL, CONFIG_LAST_SITE, last_site);
WriteBool(CONFIG_GLOBAL, CONFIG_AUTO_DELETE_TMP_PKG, auto_delete_tmp_pkg);
WriteIniFile(CONFIG_INI_FILE);
+4
View File
@@ -19,6 +19,7 @@
#define CONFIG_REMOTE_SERVER_URL "remote_server_url"
#define CONFIG_REMOTE_SERVER_USER "remote_server_user"
#define CONFIG_REMOTE_SERVER_PASSWORD "remote_server_password"
#define CONFIG_REMOTE_SERVER_HTTP_PORT "remote_server_http_port"
#define CONFIG_FAVORITE_URLS "favorite_urls"
#define MAX_FAVORITE_URLS 30
@@ -37,6 +38,9 @@ struct RemoteSettings
char server[256];
char username[33];
char password[25];
int http_port;
bool is_smb;
bool is_ftp;
};
extern std::vector<std::string> sites;
+16
View File
@@ -1704,3 +1704,19 @@ int FtpClient::Move(const std::string &from, const std::string &to)
sprintf(mp_ftphandle->response, lang_strings[STR_UNSUPPORTED_OPERATION_MSG]);
return 0;
}
int FtpClient::Head(const std::string &path, void *buffer, uint64_t len)
{
ftphandle *nData;
if (!FtpAccess(path, FtpClient::fileread, FtpClient::transfermode::image, mp_ftphandle, &nData))
{
return 0;
}
int l = FtpRead(buffer, len, nData);
FtpClose(nData);
if (l != len)
return 0;
return 1;
}
+1
View File
@@ -83,6 +83,7 @@ public:
int Delete(const std::string &path);
int Copy(const std::string &from, const std::string &to);
int Move(const std::string &from, const std::string &to);
int Head(const std::string &path, void *buffer, uint64_t len);
std::vector<DirEntry> ListDir(const std::string &path);
void SetCallbackXferFunction(FtpCallbackXfer pointer);
void SetCallbackArg(void *arg);
+43 -13
View File
@@ -96,20 +96,50 @@ namespace INSTALLER
s_bgft_initialized = false;
}
std::string getRemoteUrl(const std::string filename)
{
if (remoteclient->clientType() == CLIENT_TYPE_WEBDAV)
{
std::string full_url = remote_settings->server + filename;
size_t scheme_pos = full_url.find("://");
if (scheme_pos == std::string::npos) return "";
size_t root_pos = full_url.find("/", scheme_pos+3);
std::string host = full_url.substr(0, root_pos);
std::string path = full_url.substr(root_pos);
WebDAV::Urn::Path uri(path);
CURL *curl = curl_easy_init();
path = uri.quote(curl);
curl_easy_cleanup(curl);
return host + path;
}
else
{
std::string full_url = std::string(remote_settings->server);
size_t scheme_pos = full_url.find("://");
if (scheme_pos == std::string::npos) return "";
size_t root_pos = full_url.find("/", scheme_pos+3);
std::string host = full_url.substr(scheme_pos+3, (root_pos-(scheme_pos+3)));
size_t port_pos = host.find(":");
if (port_pos != std::string::npos)
host = host.substr(0, port_pos);
std::string path = std::string(filename);
WebDAV::Urn::Path uri(path);
CURL *curl = curl_easy_init();
path = uri.quote(curl);
return "http://" + host + ":" + std::to_string(remote_settings->http_port) + path;
}
return "";
}
int InstallRemotePkg(const std::string &filename, pkg_header *header)
{
std::string full_url = remote_settings->server + filename;
size_t scheme_pos = full_url.find("://");
size_t root_pos = full_url.find("/", scheme_pos+3);
std::string host = full_url.substr(0, root_pos);
std::string path = full_url.substr(root_pos);
WebDAV::Urn::Path uri(path);
CURL *curl = curl_easy_init();
path = uri.quote(curl);
curl_easy_cleanup(curl);
char url[2000];
sprintf(url, "%s%s", host.c_str(), path.c_str());
std::string url = getRemoteUrl(filename);
if (url.empty())
return 0;
int ret;
std::string cid = std::string((char *)header->pkg_content_id);
@@ -155,7 +185,7 @@ namespace INSTALLER
params.userId = user_id;
params.entitlementType = 5;
params.id = (char *)header->pkg_content_id;
params.contentUrl = url;
params.contentUrl = url.c_str();
params.contentName = cid.c_str();
params.iconPath = "";
params.playgoScenarioId = "0";
+2 -1
View File
@@ -116,7 +116,8 @@ char lang_strings[LANG_STRINGS_NUM][LANG_STR_SIZE] = {
"Failed to copy file", // STR_FAIL_COPY_MSG
"Cannot move parent directory to sub subdirectory", // STR_CANT_MOVE_TO_SUBDIR_MSG
"Cannot copy parent directory to sub subdirectory", // STR_CANT_COPY_TO_SUBDIR_MSG
"Operation not supported" // STR_UNSUPPORTED_OPERATION_MSG
"Operation not supported", // STR_UNSUPPORTED_OPERATION_MSG
"Http Port" // STR_HTTP_PORT
};
bool needs_extended_font = false;
+3 -2
View File
@@ -110,7 +110,8 @@
FUNC(STR_FAIL_COPY_MSG) \
FUNC(STR_CANT_MOVE_TO_SUBDIR_MSG) \
FUNC(STR_CANT_COPY_TO_SUBDIR_MSG) \
FUNC(STR_UNSUPPORTED_OPERATION_MSG)
FUNC(STR_UNSUPPORTED_OPERATION_MSG) \
FUNC(STR_HTTP_PORT)
#define GET_VALUE(x) x,
#define GET_STRING(x) #x,
@@ -120,7 +121,7 @@ enum
FOREACH_STR(GET_VALUE)
};
#define LANG_STRINGS_NUM 107
#define LANG_STRINGS_NUM 108
#define LANG_ID_SIZE 64
#define LANG_STR_SIZE 256
extern char lang_identifiers[LANG_STRINGS_NUM][LANG_ID_SIZE];
+1
View File
@@ -25,6 +25,7 @@ public:
virtual int Delete(const std::string &path) = 0;
virtual int Copy(const std::string &from, const std::string &to) = 0;
virtual int Move(const std::string &from, const std::string &to) = 0;
virtual int Head(const std::string &path, void *buffer, uint64_t len) = 0;
virtual bool FileExists(const std::string &path) = 0;
virtual std::vector<DirEntry> ListDir(const std::string &path) = 0;
virtual std::string GetPath(std::string path1, std::string path2) = 0;
+3 -3
View File
@@ -230,13 +230,13 @@ int SmbClient::Get(const std::string &outputfile, const std::string &ppath, uint
int SmbClient::Copy(const std::string &ffrom, const std::string &tto)
{
sprintf(response, lang_strings[STR_UNSUPPORTED_OPERATION_MSG]);
sprintf(response, "%s", lang_strings[STR_UNSUPPORTED_OPERATION_MSG]);
return 0;
}
int SmbClient::Move(const std::string &ffrom, const std::string &tto)
{
sprintf(response, lang_strings[STR_UNSUPPORTED_OPERATION_MSG]);
sprintf(response, "%s", lang_strings[STR_UNSUPPORTED_OPERATION_MSG]);
return 0;
}
@@ -500,7 +500,7 @@ std::string SmbClient::GetPath(std::string ppath1, std::string ppath2)
return Util::Ltrim(path1, "/");
}
int SmbClient::Head(const std::string &ppath, void* buffer, uint16_t len)
int SmbClient::Head(const std::string &ppath, void *buffer, uint64_t len)
{
std::string path = std::string(ppath);
path = Util::Trim(path, "/");
+1 -1
View File
@@ -36,7 +36,7 @@ public:
const char *LastResponse();
int Quit();
std::string GetPath(std::string ppath1, std::string ppath2);
int Head(const std::string &path, void* buffer, uint16_t len);
int Head(const std::string &path, void *buffer, uint64_t len);
ClientType clientType();
private:
+1 -1
View File
@@ -361,7 +361,7 @@ namespace WebDAV
return path1;
}
int WebDavClient::Head(const std::string &path, void *buffer, int64_t len)
int WebDavClient::Head(const std::string &path, void *buffer, uint64_t len)
{
char *buffer_ptr = nullptr;
unsigned long long buffer_size = 0;
+1 -1
View File
@@ -32,7 +32,7 @@ namespace WebDAV
const char *LastResponse();
int Quit();
std::string GetPath(std::string path1, std::string path2);
int Head(const std::string &path, void *buffer, int64_t len);
int Head(const std::string &path, void *buffer, uint64_t len);
bool GetHeaders(const std::string &path, dict_t *headers);
WebDAV::Client *GetClient();
ClientType clientType();
+44 -35
View File
@@ -91,6 +91,7 @@ namespace Windows
sprintf(status_message, "");
sprintf(local_filter, "");
sprintf(remote_filter, "");
sprintf(txt_http_port, "%d", remote_settings->http_port);
dont_prompt_overwrite = false;
confirm_transfer_state = -1;
dont_prompt_overwrite_cb = false;
@@ -259,46 +260,15 @@ namespace Windows
{
ImGui::SetItemDefaultFocus();
}
if (is_connected)
sprintf(id, "%s###connectbutton", is_connected ? lang_strings[STR_DISCONNECT] : lang_strings[STR_CONNECT]);
if (ImGui::Button(id, ImVec2(200, 0)))
{
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.3f);
}
if (ImGui::Button(lang_strings[STR_CONNECT], ImVec2(180, 0)))
{
selected_action = ACTION_CONNECT;
}
if (is_connected)
{
ImGui::PopItemFlag();
ImGui::PopStyleVar();
selected_action = is_connected ? ACTION_DISCONNECT : ACTION_CONNECT;
}
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%s", lang_strings[STR_CONNECT]);
ImGui::EndTooltip();
}
ImGui::SameLine();
if (!is_connected)
{
ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true);
ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.3f);
}
if (ImGui::Button(lang_strings[STR_DISCONNECT], ImVec2(200, 0)))
{
selected_action = ACTION_DISCONNECT;
}
if (!is_connected)
{
ImGui::PopItemFlag();
ImGui::PopStyleVar();
}
if (ImGui::IsItemHovered())
{
ImGui::BeginTooltip();
ImGui::Text("%s", lang_strings[STR_DISCONNECT]);
ImGui::Text("%s", is_connected ? lang_strings[STR_DISCONNECT] : lang_strings[STR_CONNECT]);
ImGui::EndTooltip();
}
ImGui::SameLine();
@@ -316,6 +286,7 @@ namespace Windows
sprintf(last_site, "%s", sites[n].c_str());
sprintf(display_site, "%s", site_id);
remote_settings = &site_settings[sites[n]];
sprintf(txt_http_port, "%d", remote_settings->http_port);
}
// Set the initial focus when opening the combo (scrolling + keyboard navigation focus)
@@ -373,6 +344,27 @@ namespace Windows
gui_mode = GUI_MODE_IME;
}
if (remote_settings->is_smb || remote_settings->is_ftp)
{
ImGui::SameLine();
ImGui::SetCursorPosX(ImGui::GetCursorPosX() + 5);
ImGui::TextColored(colors[ImGuiCol_ButtonHovered], "%s:", lang_strings[STR_HTTP_PORT]);
ImGui::SameLine();
sprintf(id, "%s##http_port", txt_http_port);
pos = ImGui::GetCursorPos();
if (ImGui::Button(id, ImVec2(65, 0)))
{
ime_single_field = txt_http_port;
ResetImeCallbacks();
ime_field_size = 24;
ime_callback = SingleValueImeCallback;
ime_after_update = AfterHttpPortChangeCallback;
Dialog::initImeDialog(lang_strings[STR_PASSWORD], txt_http_port, 24, ORBIS_TYPE_NUMBER, pos.x, pos.y);
gui_mode = GUI_MODE_IME;
}
}
ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0, 10));
EndGroupPanel();
@@ -1679,4 +1671,21 @@ namespace Windows
{
selected_action = ACTION_CREATE_LOCAL_ZIP;
}
void AferServerChangeCallback(int ime_result)
{
if (ime_result == IME_DIALOG_RESULT_FINISHED)
{
remote_settings->is_smb = strncmp(remote_settings->server, "smb://", 6) == 0;
remote_settings->is_ftp = strncmp(remote_settings->server, "ftp://", 6) == 0;
}
}
void AfterHttpPortChangeCallback(int ime_result)
{
if (ime_result == IME_DIALOG_RESULT_FINISHED)
{
remote_settings->http_port = atoi(txt_http_port);
}
}
}
+2
View File
@@ -206,6 +206,8 @@ namespace Windows
void AfterFavoriteUrlCallback(int ime_result);
void AfterExtractFolderCallback(int ime_result);
void AfterZipFileCallback(int ime_result);
void AferServerChangeCallback(int ime_result);
void AfterHttpPortChangeCallback(int ime_result);
}
#endif