Textractor_test/GUI/main.cpp

32 lines
1.3 KiB
C++
Raw Normal View History

2018-07-21 15:40:16 -07:00
#include "mainwindow.h"
#include "module.h"
#include <winhttp.h>
2018-07-21 15:40:16 -07:00
extern const wchar_t* UPDATE_AVAILABLE;
2018-07-21 15:40:16 -07:00
int main(int argc, char *argv[])
{
std::thread([]
{
2019-09-01 09:27:51 -04:00
if (!*VERSION) return;
using InternetHandle = AutoHandle<Functor<WinHttpCloseHandle>>;
// Queries GitHub releases API https://developer.github.com/v3/repos/releases/ and checks the last release tag to check if it's the same
if (InternetHandle internet = WinHttpOpen(L"Mozilla/5.0 Textractor", WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, NULL, NULL, 0))
if (InternetHandle connection = WinHttpConnect(internet, L"api.github.com", INTERNET_DEFAULT_HTTPS_PORT, 0))
if (InternetHandle 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))
{
char buffer[1000] = {};
WinHttpReceiveResponse(request, NULL);
WinHttpReadData(request, buffer, 1000, DUMMY);
2020-02-11 23:34:03 -07:00
if (abs(strstr(buffer, "/tag/") - strstr(buffer, VERSION)) > 10) TEXTRACTOR_MESSAGE(UPDATE_AVAILABLE);
}
}).detach();
QDir::setCurrent(QFileInfo(S(GetModuleFilename().value())).absolutePath());
QApplication app(argc, argv);
app.setFont(QFont("MS Shell Dlg 2", 10));
return MainWindow().show(), app.exec();
2018-07-21 15:40:16 -07:00
}