Skip to content

Commit

Permalink
Merge pull request #1 from ogruetzmann/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
ogruetzmann committed May 11, 2016
2 parents 43b0eec + d3442ca commit 0209287
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 5,297 deletions.
3 changes: 3 additions & 0 deletions ModeS/Helpers.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "stdafx.h"
#include "Helpers.h"

27 changes: 27 additions & 0 deletions ModeS/Helpers.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#pragma once
#include <vector>
#include <string>
#include <sstream>
#include <iomanip>
#include <EuroScopePlugIn.h>

inline bool startsWith(const char *pre, const char *str)
Expand Down Expand Up @@ -32,3 +34,28 @@ inline bool isApModeS(std::string icao, std::vector<std::string>& ICAO_MODES)
}
return false;
}

inline std::string padWithZeros(int padding, int s)
{
std::stringstream ss;
ss << std::setfill('0') << std::setw(padding) << s;
return ss.str();
}

inline std::vector<std::string> &split(const std::string &s, char delim, std::vector<std::string> &elems)
{
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim))
{
elems.push_back(item);
}
return elems;
}

inline std::vector<std::string> split(const std::string &s, char delim)
{
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
57 changes: 20 additions & 37 deletions ModeS/HttpHelper.cpp
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;
}
18 changes: 4 additions & 14 deletions ModeS/HttpHelper.hpp
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);
40 changes: 20 additions & 20 deletions ModeS/ModeS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
//

#include "stdafx.h"
#include "ModeS.h"
//#include "ModeS.h"
#include "ModeS2.h"
#include "EuroScopePlugIn.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//#ifdef _DEBUG
//#define new DEBUG_NEW
//#endif

//
//TODO: If this DLL is dynamically linked against the MFC DLLs,
Expand Down Expand Up @@ -38,32 +38,32 @@

// CHoldingListPluginApp

BEGIN_MESSAGE_MAP(CModeSApp, CWinApp)
END_MESSAGE_MAP()
//BEGIN_MESSAGE_MAP(CModeSApp, CWinApp)
//END_MESSAGE_MAP()


// CHoldingListPluginApp construction

CModeSApp::CModeSApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
//CModeSApp::CModeSApp()
//{
// // TODO: add construction code here,
// // Place all significant initialization in InitInstance
//}


// The one and only CHoldingListPluginApp object

CModeSApp theApp;
//CModeSApp theApp;


// CHoldingListPluginApp initialization

BOOL CModeSApp::InitInstance()
{
CWinApp::InitInstance();

return TRUE;
}
//BOOL CModeSApp::InitInstance()
//{
// CWinApp::InitInstance();
//
// return TRUE;
//}


CModeS * gpMyPlugin = NULL;
Expand All @@ -72,7 +72,7 @@ CModeS * gpMyPlugin = NULL;

void __declspec (dllexport) EuroScopePlugInInit(EuroScopePlugIn::CPlugIn ** ppPlugInInstance)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
//AFX_MANAGE_STATE(AfxGetStaticModuleState())

// create the instance
* ppPlugInInstance = gpMyPlugin = new CModeS();
Expand All @@ -83,7 +83,7 @@ void __declspec (dllexport) EuroScopePlugInInit(EuroScopePlugIn::CPlugIn *

void __declspec (dllexport) EuroScopePlugInExit(void)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState())
//AFX_MANAGE_STATE(AfxGetStaticModuleState())

// delete the instance
delete gpMyPlugin;
Expand Down
6 changes: 0 additions & 6 deletions ModeS/ModeS.def

This file was deleted.

26 changes: 0 additions & 26 deletions ModeS/ModeS.h
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 removed ModeS/ModeS.rc
Binary file not shown.
23 changes: 9 additions & 14 deletions ModeS/ModeS.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140_xp</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<UseOfMfc>false</UseOfMfc>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
Expand Down Expand Up @@ -60,8 +60,9 @@
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
<ModuleDefinitionFile>.\ModeS.def</ModuleDefinitionFile>
<AdditionalDependencies>EuroScopePlugInDll.lib;libcurld.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
<AdditionalDependencies>EuroScopePlugInDll.lib;WinInet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\Olli\Documents\GitHub\ModeS\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Midl>
Expand Down Expand Up @@ -90,8 +91,9 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<ModuleDefinitionFile>.\ModeS.def</ModuleDefinitionFile>
<AdditionalDependencies>EuroScopePlugInDll.lib;libcurl.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ModuleDefinitionFile>
</ModuleDefinitionFile>
<AdditionalDependencies>EuroScopePlugInDll.lib;WinInet.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\Olli\Documents\GitHub\ModeS\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
</Link>
<Midl>
Expand All @@ -108,6 +110,7 @@
<Text Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Helpers.cpp" />
<ClCompile Include="HttpHelper.cpp" />
<ClCompile Include="ModeS.cpp" />
<ClCompile Include="ModeS2.cpp" />
Expand All @@ -123,17 +126,9 @@
<ClInclude Include="ModeS.h" />
<ClInclude Include="ModeS2.h" />
<ClInclude Include="ModeSDisplay.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<None Include="ModeS.def" />
<None Include="res\ModeS.rc2" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ModeS.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
Expand Down
19 changes: 3 additions & 16 deletions ModeS/ModeS.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<ClCompile Include="ModeSDisplay.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Helpers.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="ModeS.h">
Expand All @@ -44,9 +47,6 @@
<ClInclude Include="targetver.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Resource.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ModeS2.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand All @@ -60,17 +60,4 @@
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="ModeS.def">
<Filter>Source Files</Filter>
</None>
<None Include="res\ModeS.rc2">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ModeS.rc">
<Filter>Resource Files</Filter>
</ResourceCompile>
</ItemGroup>
</Project>
Loading

0 comments on commit 0209287

Please sign in to comment.