forked from pierr3/ModeS
-
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.
Merge pull request #1 from ogruetzmann/Development
Development
- Loading branch information
Showing
33 changed files
with
166 additions
and
5,297 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "stdafx.h" | ||
#include "Helpers.h" | ||
|
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 |
---|---|---|
@@ -1,45 +1,28 @@ | ||
#include "stdafx.h" | ||
#include "HttpHelper.hpp" | ||
|
||
// | ||
// HttpHelper Class by Even Rognlien, used with permission | ||
// | ||
|
||
std::string HttpHelper::downloadedContents; | ||
|
||
HttpHelper::HttpHelper() { | ||
|
||
} | ||
|
||
// Used for downloading strings from web: | ||
size_t HttpHelper::handle_data(void *ptr, size_t size, size_t nmemb, void *stream) { | ||
int numbytes = size*nmemb; | ||
// The data is not null-terminated, so get the last character, and replace it with '\0'. | ||
char lastchar = *((char *)ptr + numbytes - 1); | ||
*((char *)ptr + numbytes - 1) = '\0'; | ||
downloadedContents.append((char *)ptr); | ||
downloadedContents.append(1, lastchar); | ||
*((char *)ptr + numbytes - 1) = lastchar; // Might not be necessary. | ||
return size*nmemb; | ||
} | ||
|
||
std::string HttpHelper::downloadStringFromURL(std::string url) { | ||
CURL *curl = curl_easy_init(); | ||
if (curl) | ||
std::string LoadUpdateString(std::string url) | ||
{ | ||
HINTERNET connect = InternetOpen("MyBrowser", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); | ||
if (!connect) | ||
throw(std::exception { "Connection Failed. Error: " + GetLastError() }); | ||
|
||
HINTERNET OpenAddress = InternetOpenUrl(connect, url.c_str(), NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE, 0); | ||
if (!OpenAddress) | ||
{ | ||
downloadedContents = ""; | ||
// Tell libcurl the URL | ||
curl_easy_setopt(curl, CURLOPT_URL, url); | ||
// Tell libcurl what function to call when it has data | ||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HttpHelper::handle_data); | ||
// Do it! | ||
CURLcode res = curl_easy_perform(curl); | ||
curl_easy_cleanup(curl); | ||
return downloadedContents; | ||
InternetCloseHandle(connect); | ||
throw(std::exception { "Failed to open URL. Error: " + GetLastError() }); | ||
} | ||
return ""; | ||
} | ||
|
||
HttpHelper::~HttpHelper() { | ||
char DataReceived[4096]; | ||
DWORD NumberOfBytesRead = 0; | ||
std::string answer {}; | ||
while (InternetReadFile(OpenAddress, DataReceived, 100, &NumberOfBytesRead) && NumberOfBytesRead) | ||
{ | ||
answer.append(DataReceived, NumberOfBytesRead); | ||
} | ||
|
||
InternetCloseHandle(OpenAddress); | ||
InternetCloseHandle(connect); | ||
return answer; | ||
} |
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,17 +1,7 @@ | ||
#pragma once | ||
#include "stdafx.h" | ||
#include <string> | ||
#include <curl\curl.h> | ||
#include <curl\easy.h> | ||
#include <exception> | ||
#include <WinInet.h> | ||
|
||
class HttpHelper | ||
{ | ||
private: | ||
static std::string downloadedContents; | ||
static size_t handle_data(void *ptr, size_t size, size_t nmemb, void *stream); | ||
|
||
public: | ||
HttpHelper(); | ||
std::string downloadStringFromURL(std::string url); | ||
~HttpHelper(); | ||
|
||
}; | ||
std::string LoadUpdateString(std::string url); |
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 was deleted.
Oops, something went wrong.
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,27 +1 @@ | ||
// ModeS.h : main header file for the ModeS DLL | ||
// | ||
|
||
#pragma once | ||
|
||
#ifndef __AFXWIN_H__ | ||
#error "include 'stdafx.h' before including this file for PCH" | ||
#endif | ||
|
||
#include "resource.h" // main symbols | ||
|
||
|
||
// CModeSApp | ||
// See ModeS.cpp for the implementation of this class | ||
// | ||
|
||
class CModeSApp : public CWinApp | ||
{ | ||
public: | ||
CModeSApp(); | ||
|
||
// Overrides | ||
public: | ||
virtual BOOL InitInstance(); | ||
|
||
DECLARE_MESSAGE_MAP() | ||
}; |
Binary file not shown.
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
Oops, something went wrong.