impr: Remove dependencies on curl, mbedTLS and GLFW in the SDK
This commit is contained in:
parent
0140e24822
commit
0a6681ccb7
@ -38,11 +38,6 @@ add_subdirectory(lib/external/libwolv EXCLUDE_FROM_ALL)
|
|||||||
set(LIBPL_ENABLE_CLI OFF CACHE BOOL "" FORCE)
|
set(LIBPL_ENABLE_CLI OFF CACHE BOOL "" FORCE)
|
||||||
add_subdirectory(lib/external/pattern_language EXCLUDE_FROM_ALL)
|
add_subdirectory(lib/external/pattern_language EXCLUDE_FROM_ALL)
|
||||||
|
|
||||||
find_package(CURL REQUIRED)
|
|
||||||
find_package(mbedTLS 3.4.0 REQUIRED)
|
|
||||||
set(CURL_LIBRARIES ${CURL_LIBRARIES} PARENT_SCOPE)
|
|
||||||
set(MBEDTLS_LIBRARIES ${MBEDTLS_LIBRARIES} PARENT_SCOPE)
|
|
||||||
|
|
||||||
add_subdirectory(lib/libimhex)
|
add_subdirectory(lib/libimhex)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
@ -39,6 +39,7 @@ set(LIBIMHEX_SOURCES
|
|||||||
source/helpers/default_paths.cpp
|
source/helpers/default_paths.cpp
|
||||||
source/helpers/imgui_hooks.cpp
|
source/helpers/imgui_hooks.cpp
|
||||||
source/helpers/semantic_version.cpp
|
source/helpers/semantic_version.cpp
|
||||||
|
source/helpers/keys.cpp
|
||||||
|
|
||||||
source/test/tests.cpp
|
source/test/tests.cpp
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <hex.hpp>
|
#include <hex.hpp>
|
||||||
#include <hex/api/localization_manager.hpp>
|
#include <hex/api/localization_manager.hpp>
|
||||||
#include <hex/helpers/semantic_version.hpp>
|
#include <hex/helpers/semantic_version.hpp>
|
||||||
|
#include <hex/helpers/fs.hpp>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@ -11,8 +12,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
#include <memory>
|
||||||
#include <wolv/io/fs.hpp>
|
|
||||||
|
|
||||||
using ImGuiID = unsigned int;
|
using ImGuiID = unsigned int;
|
||||||
struct ImVec2;
|
struct ImVec2;
|
||||||
|
@ -12,10 +12,6 @@
|
|||||||
|
|
||||||
#if defined(OS_WEB)
|
#if defined(OS_WEB)
|
||||||
#include <emscripten/fetch.h>
|
#include <emscripten/fetch.h>
|
||||||
|
|
||||||
using curl_off_t = long;
|
|
||||||
#else
|
|
||||||
#include <curl/curl.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef void CURL;
|
typedef void CURL;
|
||||||
@ -121,18 +117,18 @@ namespace hex {
|
|||||||
|
|
||||||
static std::string urlDecode(const std::string &input);
|
static std::string urlDecode(const std::string &input);
|
||||||
|
|
||||||
protected:
|
void setProgress(float progress) { m_progress = progress; }
|
||||||
void setDefaultConfig();
|
bool isCanceled() const { return m_canceled; }
|
||||||
|
|
||||||
|
static size_t writeToVector(void *contents, size_t size, size_t nmemb, void *userdata);
|
||||||
|
static size_t writeToFile(void *contents, size_t size, size_t nmemb, void *userdata);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
Result<T> executeImpl(std::vector<u8> &data);
|
Result<T> executeImpl(std::vector<u8> &data);
|
||||||
|
|
||||||
static size_t writeToVector(void *contents, size_t size, size_t nmemb, void *userdata);
|
|
||||||
static size_t writeToFile(void *contents, size_t size, size_t nmemb, void *userdata);
|
|
||||||
static int progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void checkProxyErrors();
|
static void checkProxyErrors();
|
||||||
|
void setDefaultConfig();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if defined(OS_WEB)
|
#if defined(OS_WEB)
|
||||||
|
@ -5,8 +5,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <future>
|
#include <future>
|
||||||
|
|
||||||
#include <curl/curl.h>
|
|
||||||
|
|
||||||
#include <hex/helpers/logger.hpp>
|
#include <hex/helpers/logger.hpp>
|
||||||
#include <hex/helpers/fmt.hpp>
|
#include <hex/helpers/fmt.hpp>
|
||||||
|
|
||||||
@ -14,14 +12,26 @@
|
|||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
|
namespace impl {
|
||||||
|
|
||||||
|
void setWriteFunctions(CURL *curl, wolv::io::File &file);
|
||||||
|
void setWriteFunctions(CURL *curl, std::vector<u8> &data);
|
||||||
|
void setupFileUpload(CURL *curl, wolv::io::File &file, const std::string &fileName, const std::string &mimeName);
|
||||||
|
void setupFileUpload(CURL *curl, const std::vector<u8> &data, const std::fs::path &fileName, const std::string &mimeName);
|
||||||
|
int executeCurl(CURL *curl, const std::string &url, const std::string &method, const std::string &body, std::map<std::string, std::string> &headers);
|
||||||
|
long getStatusCode(CURL *curl);
|
||||||
|
std::string getStatusText(int result);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
std::future<HttpRequest::Result<T>> HttpRequest::downloadFile(const std::fs::path &path) {
|
std::future<HttpRequest::Result<T>> HttpRequest::downloadFile(const std::fs::path &path) {
|
||||||
return std::async(std::launch::async, [this, path] {
|
return std::async(std::launch::async, [this, path] {
|
||||||
std::vector<u8> response;
|
std::vector<u8> response;
|
||||||
|
|
||||||
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
wolv::io::File file(path, wolv::io::File::Mode::Create);
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, writeToFile);
|
impl::setWriteFunctions(m_curl, file);
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &file);
|
|
||||||
|
|
||||||
return this->executeImpl<T>(response);
|
return this->executeImpl<T>(response);
|
||||||
});
|
});
|
||||||
@ -31,40 +41,12 @@
|
|||||||
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(const std::fs::path &path, const std::string &mimeName) {
|
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(const std::fs::path &path, const std::string &mimeName) {
|
||||||
return std::async(std::launch::async, [this, path, mimeName]{
|
return std::async(std::launch::async, [this, path, mimeName]{
|
||||||
auto fileName = wolv::util::toUTF8String(path.filename());
|
auto fileName = wolv::util::toUTF8String(path.filename());
|
||||||
|
|
||||||
curl_mime *mime = curl_mime_init(m_curl);
|
|
||||||
curl_mimepart *part = curl_mime_addpart(mime);
|
|
||||||
|
|
||||||
wolv::io::File file(path, wolv::io::File::Mode::Read);
|
wolv::io::File file(path, wolv::io::File::Mode::Read);
|
||||||
|
|
||||||
curl_mime_data_cb(part, file.getSize(),
|
impl::setupFileUpload(m_curl, file, fileName, mimeName);
|
||||||
[](char *buffer, size_t size, size_t nitems, void *arg) -> size_t {
|
|
||||||
auto handle = static_cast<FILE*>(arg);
|
|
||||||
|
|
||||||
return fread(buffer, size, nitems, handle);
|
|
||||||
},
|
|
||||||
[](void *arg, curl_off_t offset, int origin) -> int {
|
|
||||||
auto handle = static_cast<FILE*>(arg);
|
|
||||||
|
|
||||||
if (fseek(handle, offset, origin) != 0)
|
|
||||||
return CURL_SEEKFUNC_CANTSEEK;
|
|
||||||
else
|
|
||||||
return CURL_SEEKFUNC_OK;
|
|
||||||
},
|
|
||||||
[](void *arg) {
|
|
||||||
auto handle = static_cast<FILE*>(arg);
|
|
||||||
|
|
||||||
fclose(handle);
|
|
||||||
},
|
|
||||||
file.getHandle());
|
|
||||||
curl_mime_filename(part, fileName.c_str());
|
|
||||||
curl_mime_name(part, mimeName.c_str());
|
|
||||||
|
|
||||||
curl_easy_setopt(m_curl, CURLOPT_MIMEPOST, mime);
|
|
||||||
|
|
||||||
std::vector<u8> responseData;
|
std::vector<u8> responseData;
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, writeToVector);
|
impl::setWriteFunctions(m_curl, responseData);
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &responseData);
|
|
||||||
|
|
||||||
return this->executeImpl<T>(responseData);
|
return this->executeImpl<T>(responseData);
|
||||||
});
|
});
|
||||||
@ -73,19 +55,10 @@
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(std::vector<u8> data, const std::string &mimeName, const std::fs::path &fileName) {
|
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(std::vector<u8> data, const std::string &mimeName, const std::fs::path &fileName) {
|
||||||
return std::async(std::launch::async, [this, data = std::move(data), mimeName, fileName]{
|
return std::async(std::launch::async, [this, data = std::move(data), mimeName, fileName]{
|
||||||
curl_mime *mime = curl_mime_init(m_curl);
|
impl::setupFileUpload(m_curl, data, fileName, mimeName);
|
||||||
curl_mimepart *part = curl_mime_addpart(mime);
|
|
||||||
|
|
||||||
curl_mime_data(part, reinterpret_cast<const char *>(data.data()), data.size());
|
|
||||||
auto fileNameStr = wolv::util::toUTF8String(fileName.filename());
|
|
||||||
curl_mime_filename(part, fileNameStr.c_str());
|
|
||||||
curl_mime_name(part, mimeName.c_str());
|
|
||||||
|
|
||||||
curl_easy_setopt(m_curl, CURLOPT_MIMEPOST, mime);
|
|
||||||
|
|
||||||
std::vector<u8> responseData;
|
std::vector<u8> responseData;
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, writeToVector);
|
impl::setWriteFunctions(m_curl, responseData);
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &responseData);
|
|
||||||
|
|
||||||
return this->executeImpl<T>(responseData);
|
return this->executeImpl<T>(responseData);
|
||||||
});
|
});
|
||||||
@ -96,8 +69,7 @@
|
|||||||
return std::async(std::launch::async, [this] {
|
return std::async(std::launch::async, [this] {
|
||||||
|
|
||||||
std::vector<u8> responseData;
|
std::vector<u8> responseData;
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, writeToVector);
|
impl::setWriteFunctions(m_curl, responseData);
|
||||||
curl_easy_setopt(m_curl, CURLOPT_WRITEDATA, &responseData);
|
|
||||||
|
|
||||||
return this->executeImpl<T>(responseData);
|
return this->executeImpl<T>(responseData);
|
||||||
});
|
});
|
||||||
@ -105,43 +77,16 @@
|
|||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
HttpRequest::Result<T> HttpRequest::executeImpl(std::vector<u8> &data) {
|
HttpRequest::Result<T> HttpRequest::executeImpl(std::vector<u8> &data) {
|
||||||
curl_easy_setopt(m_curl, CURLOPT_URL, m_url.c_str());
|
|
||||||
curl_easy_setopt(m_curl, CURLOPT_CUSTOMREQUEST, m_method.c_str());
|
|
||||||
|
|
||||||
setDefaultConfig();
|
setDefaultConfig();
|
||||||
|
|
||||||
if (!m_body.empty()) {
|
std::scoped_lock lock(m_transmissionMutex);
|
||||||
curl_easy_setopt(m_curl, CURLOPT_POSTFIELDS, m_body.c_str());
|
|
||||||
|
if (auto result = impl::executeCurl(m_curl, m_url, m_method, m_body, m_headers); result != 0) {
|
||||||
|
log::error("Http request '{0} {1}' failed with error {2}: '{3}'", m_method, m_url, u32(result), impl::getStatusText(result));
|
||||||
|
checkProxyErrors();
|
||||||
}
|
}
|
||||||
|
|
||||||
curl_slist *headers = nullptr;
|
return Result<T>(impl::getStatusCode(m_curl), { data.begin(), data.end() });
|
||||||
headers = curl_slist_append(headers, "Cache-Control: no-cache");
|
|
||||||
ON_SCOPE_EXIT { curl_slist_free_all(headers); };
|
|
||||||
|
|
||||||
for (auto &[key, value] : m_headers) {
|
|
||||||
std::string header = hex::format("{}: {}", key, value);
|
|
||||||
headers = curl_slist_append(headers, header.c_str());
|
|
||||||
}
|
|
||||||
curl_easy_setopt(m_curl, CURLOPT_HTTPHEADER, headers);
|
|
||||||
|
|
||||||
{
|
|
||||||
std::scoped_lock lock(m_transmissionMutex);
|
|
||||||
|
|
||||||
auto result = curl_easy_perform(m_curl);
|
|
||||||
if (result != CURLE_OK){
|
|
||||||
char *url = nullptr;
|
|
||||||
curl_easy_getinfo(m_curl, CURLINFO_EFFECTIVE_URL, &url);
|
|
||||||
log::error("Http request '{0} {1}' failed with error {2}: '{3}'", m_method, url, u32(result), curl_easy_strerror(result));
|
|
||||||
checkProxyErrors();
|
|
||||||
|
|
||||||
return { };
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long statusCode = 0;
|
|
||||||
curl_easy_getinfo(m_curl, CURLINFO_RESPONSE_CODE, &statusCode);
|
|
||||||
|
|
||||||
return Result<T>(statusCode, { data.begin(), data.end() });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,122 +1,123 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
|
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
enum class Keys {
|
enum class Keys {
|
||||||
#else
|
#else
|
||||||
enum Keys {
|
enum Keys {
|
||||||
#endif
|
#endif
|
||||||
Space = GLFW_KEY_SPACE,
|
Invalid,
|
||||||
Apostrophe = GLFW_KEY_APOSTROPHE,
|
Space,
|
||||||
Comma = GLFW_KEY_COMMA,
|
Apostrophe,
|
||||||
Minus = GLFW_KEY_MINUS,
|
Comma,
|
||||||
Period = GLFW_KEY_PERIOD,
|
Minus,
|
||||||
Slash = GLFW_KEY_SLASH,
|
Period,
|
||||||
Num0 = GLFW_KEY_0,
|
Slash,
|
||||||
Num1 = GLFW_KEY_1,
|
Num0,
|
||||||
Num2 = GLFW_KEY_2,
|
Num1,
|
||||||
Num3 = GLFW_KEY_3,
|
Num2,
|
||||||
Num4 = GLFW_KEY_4,
|
Num3,
|
||||||
Num5 = GLFW_KEY_5,
|
Num4,
|
||||||
Num6 = GLFW_KEY_6,
|
Num5,
|
||||||
Num7 = GLFW_KEY_7,
|
Num6,
|
||||||
Num8 = GLFW_KEY_8,
|
Num7,
|
||||||
Num9 = GLFW_KEY_9,
|
Num8,
|
||||||
Semicolon = GLFW_KEY_SEMICOLON,
|
Num9,
|
||||||
Equals = GLFW_KEY_EQUAL,
|
Semicolon,
|
||||||
A = GLFW_KEY_A,
|
Equals,
|
||||||
B = GLFW_KEY_B,
|
A,
|
||||||
C = GLFW_KEY_C,
|
B,
|
||||||
D = GLFW_KEY_D,
|
C,
|
||||||
E = GLFW_KEY_E,
|
D,
|
||||||
F = GLFW_KEY_F,
|
E,
|
||||||
G = GLFW_KEY_G,
|
F,
|
||||||
H = GLFW_KEY_H,
|
G,
|
||||||
I = GLFW_KEY_I,
|
H,
|
||||||
J = GLFW_KEY_J,
|
I,
|
||||||
K = GLFW_KEY_K,
|
J,
|
||||||
L = GLFW_KEY_L,
|
K,
|
||||||
M = GLFW_KEY_M,
|
L,
|
||||||
N = GLFW_KEY_N,
|
M,
|
||||||
O = GLFW_KEY_O,
|
N,
|
||||||
P = GLFW_KEY_P,
|
O,
|
||||||
Q = GLFW_KEY_Q,
|
P,
|
||||||
R = GLFW_KEY_R,
|
Q,
|
||||||
S = GLFW_KEY_S,
|
R,
|
||||||
T = GLFW_KEY_T,
|
S,
|
||||||
U = GLFW_KEY_U,
|
T,
|
||||||
V = GLFW_KEY_V,
|
U,
|
||||||
W = GLFW_KEY_W,
|
V,
|
||||||
X = GLFW_KEY_X,
|
W,
|
||||||
Y = GLFW_KEY_Y,
|
X,
|
||||||
Z = GLFW_KEY_Z,
|
Y,
|
||||||
LeftBracket = GLFW_KEY_LEFT_BRACKET,
|
Z,
|
||||||
Backslash = GLFW_KEY_BACKSLASH,
|
LeftBracket,
|
||||||
RightBracket = GLFW_KEY_RIGHT_BRACKET,
|
Backslash,
|
||||||
GraveAccent = GLFW_KEY_GRAVE_ACCENT,
|
RightBracket,
|
||||||
World1 = GLFW_KEY_WORLD_1,
|
GraveAccent,
|
||||||
World2 = GLFW_KEY_WORLD_2,
|
World1,
|
||||||
Escape = GLFW_KEY_ESCAPE,
|
World2,
|
||||||
Enter = GLFW_KEY_ENTER,
|
Escape,
|
||||||
Tab = GLFW_KEY_TAB,
|
Enter,
|
||||||
Backspace = GLFW_KEY_BACKSPACE,
|
Tab,
|
||||||
Insert = GLFW_KEY_INSERT,
|
Backspace,
|
||||||
Delete = GLFW_KEY_DELETE,
|
Insert,
|
||||||
Right = GLFW_KEY_RIGHT,
|
Delete,
|
||||||
Left = GLFW_KEY_LEFT,
|
Right,
|
||||||
Down = GLFW_KEY_DOWN,
|
Left,
|
||||||
Up = GLFW_KEY_UP,
|
Down,
|
||||||
PageUp = GLFW_KEY_PAGE_UP,
|
Up,
|
||||||
PageDown = GLFW_KEY_PAGE_DOWN,
|
PageUp,
|
||||||
Home = GLFW_KEY_HOME,
|
PageDown,
|
||||||
End = GLFW_KEY_END,
|
Home,
|
||||||
CapsLock = GLFW_KEY_CAPS_LOCK,
|
End,
|
||||||
ScrollLock = GLFW_KEY_SCROLL_LOCK,
|
CapsLock,
|
||||||
NumLock = GLFW_KEY_NUM_LOCK,
|
ScrollLock,
|
||||||
PrintScreen = GLFW_KEY_PRINT_SCREEN,
|
NumLock,
|
||||||
Pause = GLFW_KEY_PAUSE,
|
PrintScreen,
|
||||||
F1 = GLFW_KEY_F1,
|
Pause,
|
||||||
F2 = GLFW_KEY_F2,
|
F1,
|
||||||
F3 = GLFW_KEY_F3,
|
F2,
|
||||||
F4 = GLFW_KEY_F4,
|
F3,
|
||||||
F5 = GLFW_KEY_F5,
|
F4,
|
||||||
F6 = GLFW_KEY_F6,
|
F5,
|
||||||
F7 = GLFW_KEY_F7,
|
F6,
|
||||||
F8 = GLFW_KEY_F8,
|
F7,
|
||||||
F9 = GLFW_KEY_F9,
|
F8,
|
||||||
F10 = GLFW_KEY_F10,
|
F9,
|
||||||
F11 = GLFW_KEY_F11,
|
F10,
|
||||||
F12 = GLFW_KEY_F12,
|
F11,
|
||||||
F13 = GLFW_KEY_F13,
|
F12,
|
||||||
F14 = GLFW_KEY_F14,
|
F13,
|
||||||
F15 = GLFW_KEY_F15,
|
F14,
|
||||||
F16 = GLFW_KEY_F16,
|
F15,
|
||||||
F17 = GLFW_KEY_F17,
|
F16,
|
||||||
F18 = GLFW_KEY_F18,
|
F17,
|
||||||
F19 = GLFW_KEY_F19,
|
F18,
|
||||||
F20 = GLFW_KEY_F20,
|
F19,
|
||||||
F21 = GLFW_KEY_F21,
|
F20,
|
||||||
F22 = GLFW_KEY_F22,
|
F21,
|
||||||
F23 = GLFW_KEY_F23,
|
F22,
|
||||||
F24 = GLFW_KEY_F24,
|
F23,
|
||||||
F25 = GLFW_KEY_F25,
|
F24,
|
||||||
KeyPad0 = GLFW_KEY_KP_0,
|
F25,
|
||||||
KeyPad1 = GLFW_KEY_KP_1,
|
KeyPad0,
|
||||||
KeyPad2 = GLFW_KEY_KP_2,
|
KeyPad1,
|
||||||
KeyPad3 = GLFW_KEY_KP_3,
|
KeyPad2,
|
||||||
KeyPad4 = GLFW_KEY_KP_4,
|
KeyPad3,
|
||||||
KeyPad5 = GLFW_KEY_KP_5,
|
KeyPad4,
|
||||||
KeyPad6 = GLFW_KEY_KP_6,
|
KeyPad5,
|
||||||
KeyPad7 = GLFW_KEY_KP_7,
|
KeyPad6,
|
||||||
KeyPad8 = GLFW_KEY_KP_8,
|
KeyPad7,
|
||||||
KeyPad9 = GLFW_KEY_KP_9,
|
KeyPad8,
|
||||||
KeyPadDecimal = GLFW_KEY_KP_DECIMAL,
|
KeyPad9,
|
||||||
KeyPadDivide = GLFW_KEY_KP_DIVIDE,
|
KeyPadDecimal,
|
||||||
KeyPadMultiply = GLFW_KEY_KP_MULTIPLY,
|
KeyPadDivide,
|
||||||
KeyPadSubtract = GLFW_KEY_KP_SUBTRACT,
|
KeyPadMultiply,
|
||||||
KeyPadAdd = GLFW_KEY_KP_ADD,
|
KeyPadSubtract,
|
||||||
KeyPadEnter = GLFW_KEY_KP_ENTER,
|
KeyPadAdd,
|
||||||
KeyPadEqual = GLFW_KEY_KP_EQUAL,
|
KeyPadEnter,
|
||||||
Menu = GLFW_KEY_MENU,
|
KeyPadEqual,
|
||||||
|
Menu
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Keys scanCodeToKey(int scanCode);
|
@ -12,7 +12,6 @@
|
|||||||
#include <numbers>
|
#include <numbers>
|
||||||
|
|
||||||
#include <opengl_support.h>
|
#include <opengl_support.h>
|
||||||
#include <GLFW/glfw3.h>
|
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
namespace hex::gl {
|
namespace hex::gl {
|
||||||
|
@ -310,7 +310,7 @@ namespace hex {
|
|||||||
if (focused)
|
if (focused)
|
||||||
pressedShortcut += CurrentView;
|
pressedShortcut += CurrentView;
|
||||||
|
|
||||||
pressedShortcut += static_cast<Keys>(keyCode);
|
pressedShortcut += scanCodeToKey(keyCode);
|
||||||
|
|
||||||
return pressedShortcut;
|
return pressedShortcut;
|
||||||
}
|
}
|
||||||
|
@ -49,15 +49,6 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void HttpRequest::checkProxyErrors() { }
|
void HttpRequest::checkProxyErrors() { }
|
||||||
|
|
||||||
int HttpRequest::progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow) {
|
|
||||||
std::ignore = contents;
|
|
||||||
std::ignore = dlTotal;
|
|
||||||
std::ignore = dlNow;
|
|
||||||
std::ignore = ulTotal;
|
|
||||||
std::ignore = ulNow;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -1,6 +1,7 @@
|
|||||||
#if !defined(OS_WEB)
|
#if !defined(OS_WEB)
|
||||||
|
|
||||||
#include <hex/helpers/http_requests.hpp>
|
#include <hex/helpers/http_requests.hpp>
|
||||||
|
#include <curl/curl.h>
|
||||||
|
|
||||||
namespace hex {
|
namespace hex {
|
||||||
|
|
||||||
@ -11,6 +12,19 @@ namespace hex {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow) {
|
||||||
|
auto &request = *static_cast<HttpRequest *>(contents);
|
||||||
|
|
||||||
|
if (dlTotal > 0)
|
||||||
|
request.setProgress(float(dlNow) / dlTotal);
|
||||||
|
else if (ulTotal > 0)
|
||||||
|
request.setProgress(float(ulNow) / ulTotal);
|
||||||
|
else
|
||||||
|
request.setProgress(0.0F);
|
||||||
|
|
||||||
|
return request.isCanceled() ? CURLE_ABORTED_BY_CALLBACK : CURLE_OK;
|
||||||
|
}
|
||||||
|
|
||||||
HttpRequest::HttpRequest(std::string method, std::string url) : m_method(std::move(method)), m_url(std::move(url)) {
|
HttpRequest::HttpRequest(std::string method, std::string url) : m_method(std::move(method)), m_url(std::move(url)) {
|
||||||
AT_FIRST_TIME {
|
AT_FIRST_TIME {
|
||||||
curl_global_init(CURL_GLOBAL_ALL);
|
curl_global_init(CURL_GLOBAL_ALL);
|
||||||
@ -95,19 +109,101 @@ namespace hex {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int HttpRequest::progressCallback(void *contents, curl_off_t dlTotal, curl_off_t dlNow, curl_off_t ulTotal, curl_off_t ulNow) {
|
namespace impl {
|
||||||
auto &request = *static_cast<HttpRequest *>(contents);
|
|
||||||
|
|
||||||
if (dlTotal > 0)
|
void setWriteFunctions(CURL *curl, wolv::io::File &file) {
|
||||||
request.m_progress = float(dlNow) / dlTotal;
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HttpRequest::writeToFile);
|
||||||
else if (ulTotal > 0)
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &file);
|
||||||
request.m_progress = float(ulNow) / ulTotal;
|
}
|
||||||
else
|
|
||||||
request.m_progress = 0.0F;
|
void setWriteFunctions(CURL *curl, std::vector<u8> &data) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HttpRequest::writeToVector);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupFileUpload(CURL *curl, wolv::io::File &file, const std::string &fileName, const std::string &mimeName) {
|
||||||
|
curl_mime *mime = curl_mime_init(curl);
|
||||||
|
curl_mimepart *part = curl_mime_addpart(mime);
|
||||||
|
|
||||||
|
|
||||||
|
curl_mime_data_cb(part, file.getSize(),
|
||||||
|
[](char *buffer, size_t size, size_t nitems, void *arg) -> size_t {
|
||||||
|
auto handle = static_cast<FILE*>(arg);
|
||||||
|
|
||||||
|
return fread(buffer, size, nitems, handle);
|
||||||
|
},
|
||||||
|
[](void *arg, curl_off_t offset, int origin) -> int {
|
||||||
|
auto handle = static_cast<FILE*>(arg);
|
||||||
|
|
||||||
|
if (fseek(handle, offset, origin) != 0)
|
||||||
|
return CURL_SEEKFUNC_CANTSEEK;
|
||||||
|
else
|
||||||
|
return CURL_SEEKFUNC_OK;
|
||||||
|
},
|
||||||
|
[](void *arg) {
|
||||||
|
auto handle = static_cast<FILE*>(arg);
|
||||||
|
|
||||||
|
fclose(handle);
|
||||||
|
},
|
||||||
|
file.getHandle());
|
||||||
|
curl_mime_filename(part, fileName.c_str());
|
||||||
|
curl_mime_name(part, mimeName.c_str());
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupFileUpload(CURL *curl, const std::vector<u8> &data, const std::fs::path &fileName, const std::string &mimeName) {
|
||||||
|
curl_mime *mime = curl_mime_init(curl);
|
||||||
|
curl_mimepart *part = curl_mime_addpart(mime);
|
||||||
|
|
||||||
|
curl_mime_data(part, reinterpret_cast<const char *>(data.data()), data.size());
|
||||||
|
auto fileNameStr = wolv::util::toUTF8String(fileName.filename());
|
||||||
|
curl_mime_filename(part, fileNameStr.c_str());
|
||||||
|
curl_mime_name(part, mimeName.c_str());
|
||||||
|
|
||||||
|
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
|
||||||
|
}
|
||||||
|
|
||||||
|
int executeCurl(CURL *curl, const std::string &url, const std::string &method, const std::string &body, std::map<std::string, std::string> &headers) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, method.c_str());
|
||||||
|
|
||||||
|
if (!body.empty()) {
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
curl_slist *headersList = nullptr;
|
||||||
|
headersList = curl_slist_append(headersList, "Cache-Control: no-cache");
|
||||||
|
ON_SCOPE_EXIT { curl_slist_free_all(headersList); };
|
||||||
|
|
||||||
|
for (auto &[key, value] : headers) {
|
||||||
|
std::string header = hex::format("{}: {}", key, value);
|
||||||
|
headersList = curl_slist_append(headersList, header.c_str());
|
||||||
|
}
|
||||||
|
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||||
|
|
||||||
|
auto result = curl_easy_perform(curl);
|
||||||
|
if (result != CURLE_OK){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
long getStatusCode(CURL *curl) {
|
||||||
|
long statusCode = 0;
|
||||||
|
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &statusCode);
|
||||||
|
|
||||||
|
return statusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getStatusText(int result) {
|
||||||
|
return curl_easy_strerror(CURLcode(result));
|
||||||
|
}
|
||||||
|
|
||||||
return request.m_canceled ? CURLE_ABORTED_BY_CALLBACK : CURLE_OK;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
121
lib/libimhex/source/helpers/keys.cpp
Normal file
121
lib/libimhex/source/helpers/keys.cpp
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#include <hex/helpers/keys.hpp>
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
Keys scanCodeToKey(int scanCode) {
|
||||||
|
switch (scanCode) {
|
||||||
|
case GLFW_KEY_SPACE: return Keys::Space;
|
||||||
|
case GLFW_KEY_APOSTROPHE: return Keys::Apostrophe;
|
||||||
|
case GLFW_KEY_COMMA: return Keys::Comma;
|
||||||
|
case GLFW_KEY_MINUS: return Keys::Minus;
|
||||||
|
case GLFW_KEY_PERIOD: return Keys::Period;
|
||||||
|
case GLFW_KEY_SLASH: return Keys::Slash;
|
||||||
|
case GLFW_KEY_0: return Keys::Num0;
|
||||||
|
case GLFW_KEY_1: return Keys::Num1;
|
||||||
|
case GLFW_KEY_2: return Keys::Num2;
|
||||||
|
case GLFW_KEY_3: return Keys::Num3;
|
||||||
|
case GLFW_KEY_4: return Keys::Num4;
|
||||||
|
case GLFW_KEY_5: return Keys::Num5;
|
||||||
|
case GLFW_KEY_6: return Keys::Num6;
|
||||||
|
case GLFW_KEY_7: return Keys::Num7;
|
||||||
|
case GLFW_KEY_8: return Keys::Num8;
|
||||||
|
case GLFW_KEY_9: return Keys::Num9;
|
||||||
|
case GLFW_KEY_SEMICOLON: return Keys::Semicolon;
|
||||||
|
case GLFW_KEY_EQUAL: return Keys::Equals;
|
||||||
|
case GLFW_KEY_A: return Keys::A;
|
||||||
|
case GLFW_KEY_B: return Keys::B;
|
||||||
|
case GLFW_KEY_C: return Keys::C;
|
||||||
|
case GLFW_KEY_D: return Keys::D;
|
||||||
|
case GLFW_KEY_E: return Keys::E;
|
||||||
|
case GLFW_KEY_F: return Keys::F;
|
||||||
|
case GLFW_KEY_G: return Keys::G;
|
||||||
|
case GLFW_KEY_H: return Keys::H;
|
||||||
|
case GLFW_KEY_I: return Keys::I;
|
||||||
|
case GLFW_KEY_J: return Keys::J;
|
||||||
|
case GLFW_KEY_K: return Keys::K;
|
||||||
|
case GLFW_KEY_L: return Keys::L;
|
||||||
|
case GLFW_KEY_M: return Keys::M;
|
||||||
|
case GLFW_KEY_N: return Keys::N;
|
||||||
|
case GLFW_KEY_O: return Keys::O;
|
||||||
|
case GLFW_KEY_P: return Keys::P;
|
||||||
|
case GLFW_KEY_Q: return Keys::Q;
|
||||||
|
case GLFW_KEY_R: return Keys::R;
|
||||||
|
case GLFW_KEY_S: return Keys::S;
|
||||||
|
case GLFW_KEY_T: return Keys::T;
|
||||||
|
case GLFW_KEY_U: return Keys::U;
|
||||||
|
case GLFW_KEY_V: return Keys::V;
|
||||||
|
case GLFW_KEY_W: return Keys::W;
|
||||||
|
case GLFW_KEY_X: return Keys::X;
|
||||||
|
case GLFW_KEY_Y: return Keys::Y;
|
||||||
|
case GLFW_KEY_Z: return Keys::Z;
|
||||||
|
case GLFW_KEY_LEFT_BRACKET: return Keys::LeftBracket;
|
||||||
|
case GLFW_KEY_BACKSLASH: return Keys::Backslash;
|
||||||
|
case GLFW_KEY_RIGHT_BRACKET: return Keys::RightBracket;
|
||||||
|
case GLFW_KEY_GRAVE_ACCENT: return Keys::GraveAccent;
|
||||||
|
case GLFW_KEY_WORLD_1: return Keys::World1;
|
||||||
|
case GLFW_KEY_WORLD_2: return Keys::World2;
|
||||||
|
case GLFW_KEY_ESCAPE: return Keys::Escape;
|
||||||
|
case GLFW_KEY_ENTER: return Keys::Enter;
|
||||||
|
case GLFW_KEY_TAB: return Keys::Tab;
|
||||||
|
case GLFW_KEY_BACKSPACE: return Keys::Backspace;
|
||||||
|
case GLFW_KEY_INSERT: return Keys::Insert;
|
||||||
|
case GLFW_KEY_DELETE: return Keys::Delete;
|
||||||
|
case GLFW_KEY_RIGHT: return Keys::Right;
|
||||||
|
case GLFW_KEY_LEFT: return Keys::Left;
|
||||||
|
case GLFW_KEY_DOWN: return Keys::Down;
|
||||||
|
case GLFW_KEY_UP: return Keys::Up;
|
||||||
|
case GLFW_KEY_PAGE_UP: return Keys::PageUp;
|
||||||
|
case GLFW_KEY_PAGE_DOWN: return Keys::PageDown;
|
||||||
|
case GLFW_KEY_HOME: return Keys::Home;
|
||||||
|
case GLFW_KEY_END: return Keys::End;
|
||||||
|
case GLFW_KEY_CAPS_LOCK: return Keys::CapsLock;
|
||||||
|
case GLFW_KEY_SCROLL_LOCK: return Keys::ScrollLock;
|
||||||
|
case GLFW_KEY_NUM_LOCK: return Keys::NumLock;
|
||||||
|
case GLFW_KEY_PRINT_SCREEN: return Keys::PrintScreen;
|
||||||
|
case GLFW_KEY_PAUSE: return Keys::Pause;
|
||||||
|
case GLFW_KEY_F1: return Keys::F1;
|
||||||
|
case GLFW_KEY_F2: return Keys::F2;
|
||||||
|
case GLFW_KEY_F3: return Keys::F3;
|
||||||
|
case GLFW_KEY_F4: return Keys::F4;
|
||||||
|
case GLFW_KEY_F5: return Keys::F5;
|
||||||
|
case GLFW_KEY_F6: return Keys::F6;
|
||||||
|
case GLFW_KEY_F7: return Keys::F7;
|
||||||
|
case GLFW_KEY_F8: return Keys::F8;
|
||||||
|
case GLFW_KEY_F9: return Keys::F9;
|
||||||
|
case GLFW_KEY_F10: return Keys::F10;
|
||||||
|
case GLFW_KEY_F11: return Keys::F11;
|
||||||
|
case GLFW_KEY_F12: return Keys::F12;
|
||||||
|
case GLFW_KEY_F13: return Keys::F13;
|
||||||
|
case GLFW_KEY_F14: return Keys::F14;
|
||||||
|
case GLFW_KEY_F15: return Keys::F15;
|
||||||
|
case GLFW_KEY_F16: return Keys::F16;
|
||||||
|
case GLFW_KEY_F17: return Keys::F17;
|
||||||
|
case GLFW_KEY_F18: return Keys::F18;
|
||||||
|
case GLFW_KEY_F19: return Keys::F19;
|
||||||
|
case GLFW_KEY_F20: return Keys::F20;
|
||||||
|
case GLFW_KEY_F21: return Keys::F21;
|
||||||
|
case GLFW_KEY_F22: return Keys::F22;
|
||||||
|
case GLFW_KEY_F23: return Keys::F23;
|
||||||
|
case GLFW_KEY_F24: return Keys::F24;
|
||||||
|
case GLFW_KEY_F25: return Keys::F25;
|
||||||
|
case GLFW_KEY_KP_0: return Keys::KeyPad0;
|
||||||
|
case GLFW_KEY_KP_1: return Keys::KeyPad1;
|
||||||
|
case GLFW_KEY_KP_2: return Keys::KeyPad2;
|
||||||
|
case GLFW_KEY_KP_3: return Keys::KeyPad3;
|
||||||
|
case GLFW_KEY_KP_4: return Keys::KeyPad4;
|
||||||
|
case GLFW_KEY_KP_5: return Keys::KeyPad5;
|
||||||
|
case GLFW_KEY_KP_6: return Keys::KeyPad6;
|
||||||
|
case GLFW_KEY_KP_7: return Keys::KeyPad7;
|
||||||
|
case GLFW_KEY_KP_8: return Keys::KeyPad8;
|
||||||
|
case GLFW_KEY_KP_9: return Keys::KeyPad9;
|
||||||
|
case GLFW_KEY_KP_DECIMAL: return Keys::KeyPadDecimal;
|
||||||
|
case GLFW_KEY_KP_DIVIDE: return Keys::KeyPadDivide;
|
||||||
|
case GLFW_KEY_KP_MULTIPLY: return Keys::KeyPadMultiply;
|
||||||
|
case GLFW_KEY_KP_SUBTRACT: return Keys::KeyPadSubtract;
|
||||||
|
case GLFW_KEY_KP_ADD: return Keys::KeyPadAdd;
|
||||||
|
case GLFW_KEY_KP_ENTER: return Keys::KeyPadEnter;
|
||||||
|
case GLFW_KEY_KP_EQUAL: return Keys::KeyPadEqual;
|
||||||
|
case GLFW_KEY_MENU: return Keys::Menu;
|
||||||
|
default: return Keys::Invalid;
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@
|
|||||||
#include <imgui_internal.h>
|
#include <imgui_internal.h>
|
||||||
|
|
||||||
#define GLFW_EXPOSE_NATIVE_WIN32
|
#define GLFW_EXPOSE_NATIVE_WIN32
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
#include <GLFW/glfw3native.h>
|
#include <GLFW/glfw3native.h>
|
||||||
#undef GLFW_EXPOSE_NATIVE_WIN32
|
#undef GLFW_EXPOSE_NATIVE_WIN32
|
||||||
|
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
#include <content/popups/popup_unsaved_changes.hpp>
|
#include <content/popups/popup_unsaved_changes.hpp>
|
||||||
#include <content/popups/popup_crash_recovered.hpp>
|
#include <content/popups/popup_crash_recovered.hpp>
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
namespace hex::plugin::builtin {
|
namespace hex::plugin::builtin {
|
||||||
|
|
||||||
static void openFile(const std::fs::path &path) {
|
static void openFile(const std::fs::path &path) {
|
||||||
|
@ -26,6 +26,8 @@
|
|||||||
#include <romfs/romfs.hpp>
|
#include <romfs/romfs.hpp>
|
||||||
#include <ui/menu_items.hpp>
|
#include <ui/menu_items.hpp>
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
using namespace std::literals::string_literals;
|
using namespace std::literals::string_literals;
|
||||||
using namespace wolv::literals;
|
using namespace wolv::literals;
|
||||||
|
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#include <romfs/romfs.hpp>
|
#include <romfs/romfs.hpp>
|
||||||
#include <wolv/utils/guards.hpp>
|
#include <wolv/utils/guards.hpp>
|
||||||
|
|
||||||
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
namespace hex::plugin::builtin {
|
namespace hex::plugin::builtin {
|
||||||
|
|
||||||
// Function that draws the provider popup, defiend in the ui_items.cpp file
|
// Function that draws the provider popup, defiend in the ui_items.cpp file
|
||||||
|
Loading…
x
Reference in New Issue
Block a user