forked from WerWolv/ImHex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
83 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 57 additions & 53 deletions
110
lib/libimhex/include/hex/helpers/http_requests_emscripten.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,76 @@ | ||
#pragma once | ||
|
||
#include <future> | ||
#if defined(OS_WEB) | ||
|
||
#include <emscripten/fetch.h> | ||
#include <future> | ||
|
||
namespace hex { | ||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::downloadFile(const std::fs::path &path) { | ||
return std::async(std::launch::async, [this, path] { | ||
std::vector<u8> response; | ||
#include <emscripten/fetch.h> | ||
|
||
// Execute the request | ||
auto result = this->executeImpl<T>(response); | ||
namespace hex { | ||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::downloadFile(const std::fs::path &path) { | ||
return std::async(std::launch::async, [this, path] { | ||
std::vector<u8> response; | ||
|
||
// Write the result to the file | ||
wolv::io::File file(path, wolv::io::File::Mode::Create); | ||
file.writeBuffer(reinterpret_cast<const u8*>(result.getData().data()), result.getData().size()); | ||
// Execute the request | ||
auto result = this->executeImpl<T>(response); | ||
|
||
return result; | ||
}); | ||
} | ||
// Write the result to the file | ||
wolv::io::File file(path, wolv::io::File::Mode::Create); | ||
file.writeBuffer(reinterpret_cast<const u8*>(result.getData().data()), result.getData().size()); | ||
|
||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(const std::fs::path &path, const std::string &mimeName) { | ||
hex::unused(path, mimeName); | ||
throw std::logic_error("Not implemented"); | ||
} | ||
return result; | ||
}); | ||
} | ||
|
||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(std::vector<u8> data, const std::string &mimeName, const std::fs::path &fileName) { | ||
hex::unused(data, mimeName, fileName); | ||
throw std::logic_error("Not implemented"); | ||
} | ||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(const std::fs::path &path, const std::string &mimeName) { | ||
hex::unused(path, mimeName); | ||
throw std::logic_error("Not implemented"); | ||
} | ||
|
||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::execute() { | ||
return std::async(std::launch::async, [this] { | ||
std::vector<u8> responseData; | ||
|
||
return this->executeImpl<T>(responseData); | ||
}); | ||
} | ||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::uploadFile(std::vector<u8> data, const std::string &mimeName, const std::fs::path &fileName) { | ||
hex::unused(data, mimeName, fileName); | ||
throw std::logic_error("Not implemented"); | ||
} | ||
|
||
template<typename T> | ||
HttpRequest::Result<T> HttpRequest::executeImpl(std::vector<u8> &data) { | ||
strcpy(m_attr.requestMethod, m_method.c_str()); | ||
m_attr.attributes = EMSCRIPTEN_FETCH_SYNCHRONOUS | EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; | ||
template<typename T> | ||
std::future<HttpRequest::Result<T>> HttpRequest::execute() { | ||
return std::async(std::launch::async, [this] { | ||
std::vector<u8> responseData; | ||
|
||
if (!m_body.empty()) { | ||
m_attr.requestData = m_body.c_str(); | ||
m_attr.requestDataSize = m_body.size(); | ||
return this->executeImpl<T>(responseData); | ||
}); | ||
} | ||
|
||
std::vector<const char*> headers; | ||
for (auto it = m_headers.begin(); it != m_headers.end(); it++) { | ||
headers.push_back(it->first.c_str()); | ||
headers.push_back(it->second.c_str()); | ||
} | ||
headers.push_back(nullptr); | ||
m_attr.requestHeaders = headers.data(); | ||
template<typename T> | ||
HttpRequest::Result<T> HttpRequest::executeImpl(std::vector<u8> &data) { | ||
strcpy(m_attr.requestMethod, m_method.c_str()); | ||
m_attr.attributes = EMSCRIPTEN_FETCH_SYNCHRONOUS | EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; | ||
|
||
if (!m_body.empty()) { | ||
m_attr.requestData = m_body.c_str(); | ||
m_attr.requestDataSize = m_body.size(); | ||
} | ||
|
||
// Send request | ||
emscripten_fetch_t* fetch = emscripten_fetch(&m_attr, m_url.c_str()); | ||
std::vector<const char*> headers; | ||
for (auto it = m_headers.begin(); it != m_headers.end(); it++) { | ||
headers.push_back(it->first.c_str()); | ||
headers.push_back(it->second.c_str()); | ||
} | ||
headers.push_back(nullptr); | ||
m_attr.requestHeaders = headers.data(); | ||
|
||
data.resize(fetch->numBytes); | ||
std::copy(fetch->data, fetch->data + fetch->numBytes, data.begin()); | ||
// Send request | ||
emscripten_fetch_t* fetch = emscripten_fetch(&m_attr, m_url.c_str()); | ||
|
||
data.resize(fetch->numBytes); | ||
std::copy(fetch->data, fetch->data + fetch->numBytes, data.begin()); | ||
|
||
return Result<T>(fetch->status, { data.begin(), data.end() }); | ||
} | ||
|
||
return Result<T>(fetch->status, { data.begin(), data.end() }); | ||
} | ||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
|
||
#include <hex.hpp> | ||
|
||
#include <array> | ||
|
||
#include <capstone/capstone.h> | ||
|
||
namespace hex::plugin::disasm { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ add_imhex_plugin( | |
INCLUDES | ||
include | ||
LIBRARIES | ||
libpl | ||
libpl-gen | ||
fonts | ||
LIBRARY_PLUGIN | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
|
||
#include <functional> | ||
#include <string> | ||
#include <vector> | ||
#include <set> | ||
|
||
namespace hex::ui { | ||
|
||
|