Optimization of project structure and code cleanup

This commit is contained in:
Peter Sykora 2018-04-08 23:27:29 +02:00
parent 2b751fe84e
commit 6eef61fb94
8 changed files with 54 additions and 126 deletions

View File

@ -18,7 +18,7 @@ public:
HTTPClient();
public:
void get(const std::string& url, std::ostream& dstStream) throw (CouldNotConnectException);
void postJson(const std::string& url, std::istream& json, size_t length, std::ostream& dstStream) throw (CouldNotConnectException);
void postJson(const std::string& url, const std::string& json, std::ostream& dstStream) throw (CouldNotConnectException);
void get(const std::string& url, std::ostream& dstStream);
void postJson(const std::string& url, std::istream& json, size_t length, std::ostream& dstStream);
void postJson(const std::string& url, const std::string& json, std::ostream& dstStream);
};

View File

@ -22,6 +22,6 @@ public:
virtual boost::optional<Module> findModule(const std::string& moduleId) = 0;
virtual void storeModule(const Module& module) = 0;
protected:
~IModuleDatabase() {}
public:
virtual ~IModuleDatabase() {}
};

View File

@ -27,6 +27,7 @@ public:
public:
void init();
bool isActivated() const { return m_activationData.has_value(); }
std::optional<std::string> activationNumber() const { return m_activationData.has_value() ? m_activationData->activationId : std::optional<std::string>(); }
bool tryPreactivate(HTTPClient &httpClient);
bool activate(HTTPClient &httpClient, const std::string& licenseNumber );
auto licensedModules() { if (!isActivated()) { throw std::runtime_error("Not active"); } return m_activationData->licensedModules; }

View File

@ -9,14 +9,6 @@
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>15.0</VCProjectVersion>
@ -39,19 +31,6 @@
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
@ -65,27 +44,13 @@
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="project-common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="project-common.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="project-common.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
@ -101,21 +66,6 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
@ -128,7 +78,6 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<CreateHotpatchableImage>false</CreateHotpatchableImage>
<RuntimeTypeInfo>false</RuntimeTypeInfo>
<DebugInformationFormat>None</DebugInformationFormat>
</ClCompile>
<Link>
@ -142,25 +91,6 @@
<FullProgramDatabaseFile>false</FullProgramDatabaseFile>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Windows</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="api\CachedDownloader.h" />
<ClInclude Include="api\CryptoUtils.h" />

View File

@ -11,7 +11,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>$(ProjectDir)api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>BOOST_EXCEPTION_DISABLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(Configuration)'=='Release'">BOOST_EXCEPTION_DISABLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
</ClCompile>
<Link>

View File

@ -13,8 +13,6 @@ namespace
void dump(const char *text,
FILE *stream, unsigned char *ptr, size_t size)
{
size_t i;
size_t c;
unsigned int width = 0x10;
fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n",
@ -22,25 +20,6 @@ namespace
fwrite(ptr, 1, size, stream);
fputc('\n', stream); // newline
/* for (i = 0; i<size; i += width) {
fprintf(stream, "%4.4lx: ", (long)i);
// show hex to the left
for (c = 0; c < width; c++) {
if (i + c < size)
fprintf(stream, "%02x ", ptr[i + c]);
else
fputs(" ", stream);
}
// show data on the right
for (c = 0; (c < width) && (i + c < size); c++) {
char x = (ptr[i + c] >= 0x20 && ptr[i + c] < 0x80) ? ptr[i + c] : '.';
fputc(x, stream);
}
fputc('\n', stream); // newline
} */
}
static
@ -92,7 +71,7 @@ static size_t reader(char *ptr, size_t size, size_t nmemb, std::istream *is)
totalRead = is->gcount();
}
return totalRead;
return static_cast<size_t>(totalRead);
}
static int writer(char *data, size_t size, size_t nmemb, std::ostream *os)
@ -195,8 +174,14 @@ DownloadSession initCurlRequest(const std::string& url, std::ostream &os)
throw std::runtime_error(oss.str());
}
// DEBUG:
#ifndef NDEBUG
code = curl_easy_setopt(conn.get(), CURLOPT_DEBUGFUNCTION, my_trace);
if (code != CURLE_OK)
{
std::ostringstream oss;
oss << "Failed to set debug function";
throw std::runtime_error(oss.str());
}
code = curl_easy_setopt(conn.get(), CURLOPT_VERBOSE, 1);
if (code != CURLE_OK)
{
@ -204,6 +189,7 @@ DownloadSession initCurlRequest(const std::string& url, std::ostream &os)
oss << "Failed to set verbose mode";
throw std::runtime_error(oss.str());
}
#endif // !NDEBUG
result.conn = std::move(conn);

View File

@ -176,6 +176,40 @@ namespace
const Fields_type m_fields;
std::promise<Result_type> m_resultPromise;
};
void initializeCOM()
{
// We need to initialize COM for SystemParamsProvider
HRESULT hres = 0;
// Initialize COM. ------------------------------------------
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
std::ostringstream ostr;
ostr << "Failed to initialize COM library. Error code = 0x" << std::hex << hres;
throw std::runtime_error(ostr.str());
}
// Set general COM security levels --------------------------
hres = CoInitializeSecurity(NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL); // Reserved
if (FAILED(hres) && hres != RPC_E_TOO_LATE) // Ignore error if the security has already been initialized
{
CoUninitialize();
std::ostringstream ostr;
ostr << "Failed to initialize security. Error code = 0x" << std::hex << hres;
throw std::runtime_error(ostr.str());
}
}
}
namespace detail
@ -187,33 +221,7 @@ namespace detail
{
HRESULT hres = 0;
// Initialize COM. ------------------------------------------
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
std::ostringstream ostr;
ostr << "Failed to initialize COM library. Error code = 0x" << std::hex << hres;
throw std::runtime_error(ostr.str());
}
// Set general COM security levels --------------------------
hres = CoInitializeSecurity(NULL,
-1, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL); // Reserved
if (FAILED(hres))
{
CoUninitialize();
std::ostringstream ostr;
ostr << "Failed to initialize security. Error code = 0x" << std::hex << hres;
throw std::runtime_error(ostr.str());
}
initializeCOM();
// Obtain the initial locator to WMI -------------------------
hres = CoCreateInstance(

View File

@ -65,6 +65,9 @@
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\thirdparty\gtest-20180224\gtest-static.props" />
<Import Project="..\..\thirdparty\gtest-20180224\gmock-static.props" />
<Import Project="..\..\thirdparty\boost-1.66.0\boost.props" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />