From c92a67dbe3ab03b3fed6125000e91cb3977ad38e Mon Sep 17 00:00:00 2001 From: Akash Mozumdar Date: Thu, 13 Dec 2018 07:54:25 -0500 Subject: [PATCH] automatically check for new updates --- GUI/CMakeLists.txt | 2 +- GUI/mainwindow.cpp | 1 + GUI/misc.cpp | 19 +++++++++++++++++++ GUI/misc.h | 1 + include/text.h | 11 +++++++---- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/GUI/CMakeLists.txt b/GUI/CMakeLists.txt index 07497cc..d164cce 100644 --- a/GUI/CMakeLists.txt +++ b/GUI/CMakeLists.txt @@ -18,6 +18,6 @@ set(gui_SRCS ${RESOURCE_FILES} ) add_executable(${PROJECT_NAME} WIN32 ${gui_SRCS}) -target_link_libraries(${PROJECT_NAME} Qt5::Widgets) +target_link_libraries(${PROJECT_NAME} Qt5::Widgets winhttp) install_qt5_libs(${PROJECT_NAME}) diff --git a/GUI/mainwindow.cpp b/GUI/mainwindow.cpp index 8da1aa3..279b60e 100644 --- a/GUI/mainwindow.cpp +++ b/GUI/mainwindow.cpp @@ -31,6 +31,7 @@ MainWindow::MainWindow(QWidget *parent) : [&](TextThread* thread, std::wstring& output) { return SentenceReceived(thread, output); } ); Host::AddConsoleOutput(ABOUT); + std::thread([] { if (UpdateAvailable(CURRENT_VERSION)) Host::AddConsoleOutput(UPDATE_AVAILABLE); }).detach(); } MainWindow::~MainWindow() diff --git a/GUI/misc.cpp b/GUI/misc.cpp index e356d2b..b75e541 100644 --- a/GUI/misc.cpp +++ b/GUI/misc.cpp @@ -2,6 +2,7 @@ #include "const.h" #include "host/util.h" #include +#include #include QMultiHash GetAllProcesses() @@ -248,3 +249,21 @@ QString GenerateCode(HookParam hp, DWORD processId) if (hp.type & DIRECT_READ) return GenerateRCode(hp); else return GenerateHCode(hp, processId); } + +bool UpdateAvailable(std::string currentVersion) +{ + // Queries GitHub releases API https://developer.github.com/v3/repos/releases/ and checks the last release tag to check if it's the same + struct InternetHandleCloser { void operator()(void* h) { WinHttpCloseHandle(h); } }; + if (AutoHandle internet = WinHttpOpen(L"Mozilla/5.0 Textractor", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, NULL, NULL, 0)) + if (AutoHandle connection = WinHttpConnect(internet, L"api.github.com", INTERNET_DEFAULT_HTTPS_PORT, 0)) + if (AutoHandle request = WinHttpOpenRequest(connection, L"GET", L"/repos/Artikash/Textractor/releases", NULL, NULL, NULL, WINHTTP_FLAG_SECURE)) + if (WinHttpSendRequest(request, NULL, 0, NULL, 0, 0, NULL)) + { + DWORD bytesRead; + char buffer[1000] = {}; + WinHttpReceiveResponse(request, NULL); + WinHttpReadData(request, buffer, 1000, &bytesRead); + if (abs(strstr(buffer, "/tag/") - strstr(buffer, currentVersion.c_str())) > 10) return true; + } + return false; +} diff --git a/GUI/misc.h b/GUI/misc.h index 7ba0b1a..1c6d9cb 100644 --- a/GUI/misc.h +++ b/GUI/misc.h @@ -15,3 +15,4 @@ private: QMultiHash GetAllProcesses(); std::optional ParseCode(QString HCode); QString GenerateCode(HookParam hp, DWORD processId); +bool UpdateAvailable(std::string currentVersion); \ No newline at end of file diff --git a/include/text.h b/include/text.h index 390ec91..4482554 100644 --- a/include/text.h +++ b/include/text.h @@ -1,5 +1,6 @@ #pragma once +#define CURRENT_VERSION "3.5.1" constexpr auto SELECT_PROCESS = u8"Select Process"; constexpr auto ATTACH_INFO = u8"If you don't see the process you want to attach, try running with admin rights\r\n" "You can also type in the process id"; @@ -20,11 +21,13 @@ constexpr auto UNHOOK = u8"Unhook"; constexpr auto REMOVE_HOOK = u8"Which hook to remove?"; constexpr auto SELECT_EXTENSION = u8"Select Extension"; constexpr auto EXTENSIONS = u8"Extensions (*.dll)"; -constexpr auto ABOUT = L"Textractor beta v3.5.0 (project homepage: https://github.com/Artikash/Textractor)\r\n" -"Made with love by Artikash (email: akashmozumdar@gmail.com)\r\n" -"Please contact Artikash with any problems, feature requests, or questions relating to Textractor\r\n" +constexpr auto ABOUT = L"Textractor beta v" CURRENT_VERSION " (project homepage: https://github.com/Artikash/Textractor)\r\n" +"Made by me: Artikash (email: akashmozumdar@gmail.com)\r\n" +"Please contact me with any problems, feature requests, or questions relating to Textractor\r\n" "You can do so via the project homepage (issues section) or via email\r\n" -"Source code available under GPLv3 at project homepage"; +"Source code available under GPLv3 at project homepage\r\n" +"I'm currently on the job market: please email me if you're hiring US software engineers"; +constexpr auto UPDATE_AVAILABLE = L"Update available: download it from https://github.com/Artikash/Textractor/releases"; constexpr auto ALREADY_INJECTED = L"Textractor: already injected"; constexpr auto ARCHITECTURE_MISMATCH = L"Textractor: architecture mismatch: try 32 bit Textractor instead"; constexpr auto INJECT_FAILED = L"Textractor: couldn't inject";