Optimization of project structure and code cleanup
This commit is contained in:
parent
2b751fe84e
commit
6eef61fb94
@ -18,7 +18,7 @@ public:
|
|||||||
HTTPClient();
|
HTTPClient();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void get(const std::string& url, 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) throw (CouldNotConnectException);
|
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) throw (CouldNotConnectException);
|
void postJson(const std::string& url, const std::string& json, std::ostream& dstStream);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -22,6 +22,6 @@ public:
|
|||||||
virtual boost::optional<Module> findModule(const std::string& moduleId) = 0;
|
virtual boost::optional<Module> findModule(const std::string& moduleId) = 0;
|
||||||
virtual void storeModule(const Module& module) = 0;
|
virtual void storeModule(const Module& module) = 0;
|
||||||
|
|
||||||
protected:
|
public:
|
||||||
~IModuleDatabase() {}
|
virtual ~IModuleDatabase() {}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -27,6 +27,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
void init();
|
void init();
|
||||||
bool isActivated() const { return m_activationData.has_value(); }
|
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 tryPreactivate(HTTPClient &httpClient);
|
||||||
bool activate(HTTPClient &httpClient, const std::string& licenseNumber );
|
bool activate(HTTPClient &httpClient, const std::string& licenseNumber );
|
||||||
auto licensedModules() { if (!isActivated()) { throw std::runtime_error("Not active"); } return m_activationData->licensedModules; }
|
auto licensedModules() { if (!isActivated()) { throw std::runtime_error("Not active"); } return m_activationData->licensedModules; }
|
||||||
|
|||||||
@ -9,14 +9,6 @@
|
|||||||
<Configuration>Release</Configuration>
|
<Configuration>Release</Configuration>
|
||||||
<Platform>Win32</Platform>
|
<Platform>Win32</Platform>
|
||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
<ProjectConfiguration Include="Debug|x64">
|
|
||||||
<Configuration>Debug</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
<ProjectConfiguration Include="Release|x64">
|
|
||||||
<Configuration>Release</Configuration>
|
|
||||||
<Platform>x64</Platform>
|
|
||||||
</ProjectConfiguration>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<VCProjectVersion>15.0</VCProjectVersion>
|
<VCProjectVersion>15.0</VCProjectVersion>
|
||||||
@ -39,19 +31,6 @@
|
|||||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||||
<CharacterSet>MultiByte</CharacterSet>
|
<CharacterSet>MultiByte</CharacterSet>
|
||||||
</PropertyGroup>
|
</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" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||||
<ImportGroup Label="ExtensionSettings">
|
<ImportGroup Label="ExtensionSettings">
|
||||||
</ImportGroup>
|
</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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
<Import Project="project-common.props" />
|
<Import Project="project-common.props" />
|
||||||
</ImportGroup>
|
</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 Label="UserMacros" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<LinkIncremental>true</LinkIncremental>
|
<LinkIncremental>true</LinkIncremental>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
|
||||||
<LinkIncremental>true</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<LinkIncremental>false</LinkIncremental>
|
<LinkIncremental>false</LinkIncremental>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
|
||||||
<LinkIncremental>false</LinkIncremental>
|
|
||||||
</PropertyGroup>
|
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
@ -101,21 +66,6 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</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'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
<PrecompiledHeader>NotUsing</PrecompiledHeader>
|
||||||
@ -128,7 +78,6 @@
|
|||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||||
<CreateHotpatchableImage>false</CreateHotpatchableImage>
|
<CreateHotpatchableImage>false</CreateHotpatchableImage>
|
||||||
<RuntimeTypeInfo>false</RuntimeTypeInfo>
|
|
||||||
<DebugInformationFormat>None</DebugInformationFormat>
|
<DebugInformationFormat>None</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
@ -142,25 +91,6 @@
|
|||||||
<FullProgramDatabaseFile>false</FullProgramDatabaseFile>
|
<FullProgramDatabaseFile>false</FullProgramDatabaseFile>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</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>
|
<ItemGroup>
|
||||||
<ClInclude Include="api\CachedDownloader.h" />
|
<ClInclude Include="api\CachedDownloader.h" />
|
||||||
<ClInclude Include="api\CryptoUtils.h" />
|
<ClInclude Include="api\CryptoUtils.h" />
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
<ItemDefinitionGroup>
|
<ItemDefinitionGroup>
|
||||||
<ClCompile>
|
<ClCompile>
|
||||||
<AdditionalIncludeDirectories>$(ProjectDir)api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>$(ProjectDir)api;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||||
<PreprocessorDefinitions>BOOST_EXCEPTION_DISABLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions Condition="'$(Configuration)'=='Release'">BOOST_EXCEPTION_DISABLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
|
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
|
|||||||
@ -13,8 +13,6 @@ namespace
|
|||||||
void dump(const char *text,
|
void dump(const char *text,
|
||||||
FILE *stream, unsigned char *ptr, size_t size)
|
FILE *stream, unsigned char *ptr, size_t size)
|
||||||
{
|
{
|
||||||
size_t i;
|
|
||||||
size_t c;
|
|
||||||
unsigned int width = 0x10;
|
unsigned int width = 0x10;
|
||||||
|
|
||||||
fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n",
|
fprintf(stream, "%s, %10.10ld bytes (0x%8.8lx)\n",
|
||||||
@ -22,25 +20,6 @@ namespace
|
|||||||
|
|
||||||
fwrite(ptr, 1, size, stream);
|
fwrite(ptr, 1, size, stream);
|
||||||
fputc('\n', stream); // newline
|
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
|
static
|
||||||
@ -92,7 +71,7 @@ static size_t reader(char *ptr, size_t size, size_t nmemb, std::istream *is)
|
|||||||
totalRead = is->gcount();
|
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)
|
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());
|
throw std::runtime_error(oss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEBUG:
|
#ifndef NDEBUG
|
||||||
code = curl_easy_setopt(conn.get(), CURLOPT_DEBUGFUNCTION, my_trace);
|
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);
|
code = curl_easy_setopt(conn.get(), CURLOPT_VERBOSE, 1);
|
||||||
if (code != CURLE_OK)
|
if (code != CURLE_OK)
|
||||||
{
|
{
|
||||||
@ -204,6 +189,7 @@ DownloadSession initCurlRequest(const std::string& url, std::ostream &os)
|
|||||||
oss << "Failed to set verbose mode";
|
oss << "Failed to set verbose mode";
|
||||||
throw std::runtime_error(oss.str());
|
throw std::runtime_error(oss.str());
|
||||||
}
|
}
|
||||||
|
#endif // !NDEBUG
|
||||||
|
|
||||||
result.conn = std::move(conn);
|
result.conn = std::move(conn);
|
||||||
|
|
||||||
|
|||||||
@ -176,6 +176,40 @@ namespace
|
|||||||
const Fields_type m_fields;
|
const Fields_type m_fields;
|
||||||
std::promise<Result_type> m_resultPromise;
|
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
|
namespace detail
|
||||||
@ -187,33 +221,7 @@ namespace detail
|
|||||||
{
|
{
|
||||||
HRESULT hres = 0;
|
HRESULT hres = 0;
|
||||||
|
|
||||||
// Initialize COM. ------------------------------------------
|
initializeCOM();
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obtain the initial locator to WMI -------------------------
|
// Obtain the initial locator to WMI -------------------------
|
||||||
hres = CoCreateInstance(
|
hres = CoCreateInstance(
|
||||||
|
|||||||
@ -65,6 +65,9 @@
|
|||||||
</ImportGroup>
|
</ImportGroup>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
<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="$(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>
|
||||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<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="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user