Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,7 @@ set(IMGUI_BACKEND_SRC
external/imgui/backends/imgui_impl_opengl3.cpp
)

if(WIN32)
# fetch curl
include(FetchContent)
FetchContent_Declare(
curl
URL https://curl.se/download/curl-8.5.0.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP true
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(curl)
else()
# On Linux, we can use the system's libcurl
if(LINUX)
find_package(CURL REQUIRED)
endif()

Expand Down Expand Up @@ -75,7 +64,11 @@ target_link_libraries(ui PUBLIC core imgui glad glfw imguifiledialog imgui_gradi
# --- App library ---
add_library(app STATIC src/app.cpp src/update.cpp)
target_include_directories(app PUBLIC include ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(app PUBLIC core cache ui imgui glad glfw hex_display_feature_manager CURL::libcurl)
if(LINUX)
target_link_libraries(app PUBLIC core cache ui imgui glad glfw hex_display_feature_manager CURL::libcurl)
else()
target_link_libraries(app PUBLIC core cache ui imgui glad glfw hex_display_feature_manager winhttp.lib)
endif()

if(WIN32)
add_executable(EntropyVisualizer WIN32 main.cpp)
Expand Down
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.1
1.9.2
2 changes: 1 addition & 1 deletion include/entropy/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace entropy {

#define EV_VERSION "1.9.1"
#define EV_VERSION "1.9.2"
#define EV_DATE "09.03.2026"

} // namespace entropy
96 changes: 94 additions & 2 deletions src/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
#include <entropy/version.h>

#include <chrono>
#include <curl/curl.h>
#include <iostream>
#include <regex>
#include <sstream>
#include <thread>

#ifdef _WIN32
#include <windows.h>
#include <winhttp.h>
#endif

#if __linux__
#include <curl/curl.h>
#endif

namespace entropy {

static size_t write_callback(void *contents, size_t size, size_t nmemb, void *userp) {
Expand Down Expand Up @@ -55,13 +63,14 @@ void startUpdateCheck(UiState &uiState, const std::string &file_path, bool manua
const std::string full_url = base + file_path;
const std::string release_page = "https://github.com/maede97/EntropyVisualizer/releases";

std::string response;
#ifdef __linux__
CURL *curl = curl_easy_init();
if (!curl) {
uiState.updateChecked = true;
return;
}

std::string response;
curl_easy_setopt(curl, CURLOPT_URL, full_url.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
Expand All @@ -78,6 +87,89 @@ void startUpdateCheck(UiState &uiState, const std::string &file_path, bool manua
}

curl_easy_cleanup(curl);
#endif
#ifdef _WIN32
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
BOOL bResults = FALSE;

HINTERNET hSession = NULL;
HINTERNET hConnect = NULL;
HINTERNET hRequest = NULL;

URL_COMPONENTS urlComp{};
urlComp.dwStructSize = sizeof(urlComp);
urlComp.dwHostNameLength = (DWORD)-1;
urlComp.dwUrlPathLength = (DWORD)-1;

std::wstring wurl(full_url.begin(), full_url.end());

if (!WinHttpCrackUrl(wurl.c_str(), (DWORD)wurl.size(), 0, &urlComp)) {
uiState.updateChecked = true;
return;
}

// Open session
hSession = WinHttpOpen(L"EntropyVisualizer Update Checker/1.0", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);

// Connect
if (hSession) {
std::wstring host(urlComp.lpszHostName, urlComp.dwHostNameLength);

hConnect = WinHttpConnect(hSession, host.c_str(), urlComp.nPort, 0);
}

// Open request
if (hConnect) {
std::wstring path(urlComp.lpszUrlPath, urlComp.dwUrlPathLength);

hRequest = WinHttpOpenRequest(hConnect, L"GET", path.c_str(), NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES,
(urlComp.nScheme == INTERNET_SCHEME_HTTPS) ? WINHTTP_FLAG_SECURE : 0);
}

// Send request
if (hRequest) {
bResults = WinHttpSendRequest(hRequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0);
}

// Receive response
if (bResults)
bResults = WinHttpReceiveResponse(hRequest, NULL);

// Read response
if (bResults) {
do {
dwSize = 0;

if (!WinHttpQueryDataAvailable(hRequest, &dwSize))
break;

if (!dwSize)
break;

std::vector<char> buffer(dwSize + 1);
ZeroMemory(buffer.data(), dwSize + 1);

if (!WinHttpReadData(hRequest, buffer.data(), dwSize, &dwDownloaded)) {
break;
}

response.append(buffer.data(), dwDownloaded);

} while (dwSize > 0);
}

// Cleanup
if (hRequest)
WinHttpCloseHandle(hRequest);
if (hConnect)
WinHttpCloseHandle(hConnect);
if (hSession)
WinHttpCloseHandle(hSession);

uiState.updateChecked = true;
#endif

// Trim whitespace
std::string trimmed = response;
Expand Down