diff --git a/sphaira/include/ui/sidebar.hpp b/sphaira/include/ui/sidebar.hpp index bfadc70..c846cec 100644 --- a/sphaira/include/ui/sidebar.hpp +++ b/sphaira/include/ui/sidebar.hpp @@ -180,6 +180,13 @@ public: // uses numpad. explicit SidebarEntryTextInput(const std::string& title, s64 value, const std::string& guide = {}, s64 len_min = -1, s64 len_max = PATH_MAX, const std::string& info = ""); + auto GetNumValue() const -> s64 { + return std::stoul(GetValue()); + } + + void SetNumValue(s64 value) { + SetValue(std::to_string(value)); + } private: const std::string m_guide; const s64 m_len_min; @@ -245,8 +252,8 @@ private: class FormSidebar : public Sidebar { public: - // explicit FormSidebar(const std::string& title) : Sidebar{title, Side::RIGHT, 540.f} { - explicit FormSidebar(const std::string& title) : Sidebar{title, Side::RIGHT} { + explicit FormSidebar(const std::string& title) : Sidebar{title, Side::LEFT, 540.f} { + // explicit FormSidebar(const std::string& title) : Sidebar{title, Side::LEFT} { } }; diff --git a/sphaira/source/utils/devoptab.cpp b/sphaira/source/utils/devoptab.cpp index 2adffa0..7f7c8d8 100644 --- a/sphaira/source/utils/devoptab.cpp +++ b/sphaira/source/utils/devoptab.cpp @@ -34,16 +34,18 @@ enum class DevoptabType { struct TypeEntry { const char* name; + const char* scheme; + long port; DevoptabType type; }; const TypeEntry TYPE_ENTRIES[] = { - {"HTTP", DevoptabType::HTTP}, - {"FTP", DevoptabType::FTP}, - {"SFTP", DevoptabType::SFTP}, - {"NFS", DevoptabType::NFS}, - {"SMB", DevoptabType::SMB}, - {"WEBDAV", DevoptabType::WEBDAV}, + {"HTTP", "http://", 80, DevoptabType::HTTP}, + {"FTP", "ftp://", 21, DevoptabType::FTP}, + {"SFTP", "sftp://", 22, DevoptabType::SFTP}, + {"NFS", "nfs://", 2049, DevoptabType::NFS}, + {"SMB", "smb://", 445, DevoptabType::SMB}, + {"WEBDAV", "webdav://", 80, DevoptabType::WEBDAV}, }; struct TypeConfig { @@ -94,6 +96,7 @@ struct DevoptabForm final : public FormSidebar { private: void SetupButtons(bool type_change); + void UpdateSchemeURL(); private: DevoptabType m_type{}; @@ -119,6 +122,24 @@ DevoptabForm::DevoptabForm() : FormSidebar{"Mount Creator"} { SetupButtons(true); } +void DevoptabForm::UpdateSchemeURL() { + for (const auto& e : TYPE_ENTRIES) { + if (e.type == m_type) { + const auto scheme_start = m_url->GetValue().find("://"); + if (scheme_start != std::string::npos) { + m_url->SetValue(e.scheme + m_url->GetValue().substr(scheme_start + 3)); + } else if (m_url->GetValue().starts_with("://")) { + m_url->SetValue(e.scheme + m_url->GetValue().substr(3)); + } else if (m_url->GetValue().empty()) { + m_url->SetValue(e.scheme); + } + + m_port->SetNumValue(e.port); + break; + } + } +} + void DevoptabForm::SetupButtons(bool type_change) { if (type_change) { SidebarEntryArray::Items items; @@ -129,6 +150,7 @@ void DevoptabForm::SetupButtons(bool type_change) { this->Add( "Type", items, [this](s64& index) { m_type = TYPE_ENTRIES[index].type; + UpdateSchemeURL(); }, (s64)m_type, "Select the type of the forwarder."_i18n @@ -200,6 +222,9 @@ void DevoptabForm::SetupButtons(bool type_change) { "Hide the mount from being visible as a export option for games and saves."_i18n ); + // set default scheme if needed. + UpdateSchemeURL(); + const auto callback = this->Add("Save", [this](){ m_config.name = m_name->GetValue(); m_config.url = m_url->GetValue(); @@ -234,14 +259,15 @@ void DevoptabForm::SetupButtons(bool type_change) { callback->Depends([this](){ return !m_name->GetValue().empty() && - !m_url->GetValue().empty(); + !m_url->GetValue().empty() && + !m_url->GetValue().ends_with("://"); }, "Name and URL must be set!"_i18n); } } // namespace void DisplayDevoptabSideBar() { - auto options = std::make_unique("Devoptab Options"_i18n, Sidebar::Side::RIGHT); + auto options = std::make_unique("Devoptab Options"_i18n, Sidebar::Side::LEFT); ON_SCOPE_EXIT(App::Push(std::move(options))); options->Add("Create New Entry"_i18n, [](){ diff --git a/sphaira/source/utils/devoptab_common.cpp b/sphaira/source/utils/devoptab_common.cpp index 231a0b1..fbc6561 100644 --- a/sphaira/source/utils/devoptab_common.cpp +++ b/sphaira/source/utils/devoptab_common.cpp @@ -1188,6 +1188,12 @@ bool MountCurlDevice::Mount() { log_write("[CURL] updated host: %s\n", url.c_str()); } + // if (url.starts_with("sftp://")) { + // log_write("[CURL] updating host: %s\n", url.c_str()); + // url.replace(0, std::strlen("sftp"), ""); // what should this be? + // log_write("[CURL] updated host: %s\n", url.c_str()); + // } + const auto flags = CURLU_GUESS_SCHEME|CURLU_URLENCODE; CURLUcode rc = curl_url_set(curlu, CURLUPART_URL, url.c_str(), flags); if (rc != CURLUE_OK) {