[impl] Logging into AppData folder
[chore] Change API appId parameter => productId parameter
This commit is contained in:
parent
6eef61fb94
commit
dd366eaf5b
@ -11,7 +11,7 @@
|
||||
struct ActivationData
|
||||
{
|
||||
std::string activationId;
|
||||
std::string appId;
|
||||
std::string productId;
|
||||
SystemParams systemParams;
|
||||
std::set<std::string> licensedModules;
|
||||
};
|
||||
|
||||
33
api/OSUtils.cpp
Normal file
33
api/OSUtils.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "OSUtils.h"
|
||||
|
||||
#include <ShlObj.h>
|
||||
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
boost::filesystem::path ensureLogFolder(const std::string& appName)
|
||||
{
|
||||
char szPath[MAX_PATH] = { 0 };
|
||||
|
||||
if (SUCCEEDED(SHGetFolderPathA(NULL,
|
||||
CSIDL_APPDATA | CSIDL_FLAG_CREATE,
|
||||
NULL,
|
||||
0,
|
||||
szPath)))
|
||||
{
|
||||
auto logPath = fs::path(szPath) / appName / "Log";
|
||||
if (!fs::exists(logPath))
|
||||
{
|
||||
fs::create_directories(logPath);
|
||||
}
|
||||
if (!fs::is_directory(logPath))
|
||||
{
|
||||
throw std::runtime_error("Could not access log directory");
|
||||
}
|
||||
|
||||
return logPath;
|
||||
}
|
||||
|
||||
throw std::runtime_error("Could not find application data folder");
|
||||
}
|
||||
5
api/OSUtils.h
Normal file
5
api/OSUtils.h
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include <boost/filesystem/path.hpp>
|
||||
|
||||
boost::filesystem::path ensureLogFolder(const std::string& appName);
|
||||
@ -103,6 +103,7 @@
|
||||
<ClInclude Include="api\ModuleManager.h" />
|
||||
<ClInclude Include="api\ModuleUpdate.h" />
|
||||
<ClInclude Include="api\ModuleVersion.h" />
|
||||
<ClInclude Include="api\OSUtils.h" />
|
||||
<ClInclude Include="api\SystemParams.h" />
|
||||
<ClInclude Include="api\SystemParamsProvider.h" />
|
||||
<ClInclude Include="api\SystemParamsProvider_win.h" />
|
||||
@ -110,6 +111,7 @@
|
||||
<ClInclude Include="src\SafeFileUtils.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="api\OSUtils.cpp" />
|
||||
<ClCompile Include="src\CachedDownloader.cpp" />
|
||||
<ClCompile Include="src\CryptoUtils.cpp" />
|
||||
<ClCompile Include="src\HashUtils.cpp" />
|
||||
|
||||
@ -63,6 +63,9 @@
|
||||
<ClInclude Include="src\SafeFileUtils.h">
|
||||
<Filter>src</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="api\OSUtils.h">
|
||||
<Filter>api</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\HashUtils.cpp">
|
||||
@ -101,5 +104,8 @@
|
||||
<ClCompile Include="src\SafeFileUtils.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="api\OSUtils.cpp">
|
||||
<Filter>src</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -51,7 +51,8 @@ namespace ASN1 = CryptoPP::ASN1;
|
||||
namespace
|
||||
{
|
||||
|
||||
static const std::string appId = "coc";
|
||||
static const std::string productId = "coc";
|
||||
static const std::string serverPath = "http://localhost:3000/api/v1";
|
||||
|
||||
static const uint32_t initializationVectorSize = AES::BLOCKSIZE;
|
||||
static const uint32_t macTagSize = 16;
|
||||
@ -125,13 +126,13 @@ std::string readBinaryFile(const std::string& filename)
|
||||
|
||||
struct PreactivationRequest
|
||||
{
|
||||
std::string appId = appId;
|
||||
std::string productId = productId;
|
||||
SystemParams systemParams;
|
||||
};
|
||||
|
||||
struct ActivationRequest
|
||||
{
|
||||
std::string appId = appId;
|
||||
std::string productId = productId;
|
||||
SystemParams systemParams;
|
||||
std::string licenseNumber;
|
||||
};
|
||||
@ -146,6 +147,7 @@ struct CheckUpdatesRequest
|
||||
{
|
||||
SystemParams systemParams;
|
||||
std::string activationId;
|
||||
std::string productId = productId;
|
||||
std::map<std::string, ModuleVersion> moduleVersions;
|
||||
};
|
||||
|
||||
@ -163,8 +165,8 @@ void serialize(std::ostream& os, const ActivationData& a)
|
||||
os << "{";
|
||||
os << "\"activationId\":";
|
||||
serialize(os, a.activationId);
|
||||
os << ",\"appId\":";
|
||||
serialize(os, a.appId);
|
||||
os << ",\"productId\":";
|
||||
serialize(os, a.productId);
|
||||
os << ",\"systemParams\":";
|
||||
serialize(os, a.systemParams);
|
||||
os << ",\"licensedModules\":";
|
||||
@ -175,7 +177,7 @@ void serialize(std::ostream& os, const ActivationData& a)
|
||||
void deserialize(const pt::ptree& tree, ActivationData& a)
|
||||
{
|
||||
deserialize(tree.get_child("activationId"), a.activationId);
|
||||
deserialize(tree.get_child("appId"), a.appId);
|
||||
deserialize(tree.get_child("productId"), a.productId);
|
||||
deserialize(tree.get_child("systemParams"), a.systemParams);
|
||||
deserialize(tree.get_child("licensedModules"), a.licensedModules);
|
||||
}
|
||||
@ -199,8 +201,8 @@ void deserialize(const pt::ptree& tree, SignedData& d)
|
||||
void serialize(std::ostream& os, const PreactivationRequest& a)
|
||||
{
|
||||
os << "{";
|
||||
os << "\"appId\":";
|
||||
::serialize(os, a.appId);
|
||||
os << "\"productId\":";
|
||||
::serialize(os, a.productId);
|
||||
os << ",\"systemParams\":";
|
||||
::serialize(os, a.systemParams);
|
||||
os << "}";
|
||||
@ -209,8 +211,8 @@ void serialize(std::ostream& os, const PreactivationRequest& a)
|
||||
void serialize(std::ostream& os, const ActivationRequest& a)
|
||||
{
|
||||
os << "{";
|
||||
os << "\"appId\":";
|
||||
::serialize(os, a.appId);
|
||||
os << "\"productId\":";
|
||||
::serialize(os, a.productId);
|
||||
os << ",\"systemParams\":";
|
||||
::serialize(os, a.systemParams);
|
||||
os << ",\"licenseNumber\":";
|
||||
@ -241,6 +243,8 @@ void serialize(std::ostream& os, const CheckUpdatesRequest& r)
|
||||
::serialize(os, r.systemParams);
|
||||
os << ",\"activationId\":";
|
||||
::serialize(os, r.activationId);
|
||||
os << ",\"productId\":";
|
||||
serialize(os, r.productId);
|
||||
os << ",\"moduleVersions\":";
|
||||
::serialize(os, r.moduleVersions);
|
||||
os << "}";
|
||||
@ -260,7 +264,10 @@ void deserialize(const pt::ptree& tree, CheckUpdatesResponse& r)
|
||||
{
|
||||
r.licenseFile = {};
|
||||
}
|
||||
deserialize(tree.get_child("moduleUpdates"), r.moduleUpdates);
|
||||
if (r.success)
|
||||
{
|
||||
deserialize(tree.get_child("moduleUpdates"), r.moduleUpdates);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -291,7 +298,7 @@ void LicenseClient::init()
|
||||
|
||||
bool LicenseClient::tryPreactivate(HTTPClient &httpClient)
|
||||
{
|
||||
PreactivationRequest req{ appId, m_systemParams };
|
||||
PreactivationRequest req{ productId, m_systemParams };
|
||||
|
||||
std::string jsonReq;
|
||||
{
|
||||
@ -303,7 +310,7 @@ bool LicenseClient::tryPreactivate(HTTPClient &httpClient)
|
||||
std::string jsonRes;
|
||||
{
|
||||
std::ostringstream ss2;
|
||||
httpClient.postJson("http://localhost:3000/activate0", jsonReq, ss2);
|
||||
httpClient.postJson(serverPath + "/activate0", jsonReq, ss2);
|
||||
jsonRes = ss2.str();
|
||||
}
|
||||
|
||||
@ -330,11 +337,11 @@ bool LicenseClient::activate(HTTPClient &httpClient, const std::string & license
|
||||
|
||||
std::ostringstream ss1;
|
||||
|
||||
ActivationRequest req{ appId, m_systemParams, licenseNumber };
|
||||
ActivationRequest req{ productId, m_systemParams, licenseNumber };
|
||||
serialize(ss1, req);
|
||||
|
||||
std::stringstream ss2;
|
||||
httpClient.postJson("http://localhost:3000/activate", ss1.str() , ss2);
|
||||
httpClient.postJson(serverPath + "/activate", ss1.str() , ss2);
|
||||
|
||||
ActivationResponse activationResponse;
|
||||
pt::ptree root;
|
||||
@ -356,13 +363,13 @@ std::vector<ModuleUpdate> LicenseClient::checkForUpdates(HTTPClient & httpClient
|
||||
{
|
||||
if (!isActivated()) { throw std::runtime_error("Not active"); }
|
||||
|
||||
CheckUpdatesRequest req{ m_systemParams, m_activationData->activationId, currentVersions };
|
||||
CheckUpdatesRequest req{ m_systemParams, m_activationData->activationId, productId, currentVersions };
|
||||
|
||||
std::ostringstream ss1;
|
||||
serialize(ss1, req);
|
||||
|
||||
std::stringstream ss2;
|
||||
httpClient.postJson("http://localhost:3000/check", ss1.str(), ss2);
|
||||
httpClient.postJson(serverPath + "/check", ss1.str(), ss2);
|
||||
|
||||
CheckUpdatesResponse checkUpdatesResponse;
|
||||
pt::ptree root;
|
||||
@ -371,7 +378,7 @@ std::vector<ModuleUpdate> LicenseClient::checkForUpdates(HTTPClient & httpClient
|
||||
|
||||
if (!checkUpdatesResponse.success)
|
||||
{
|
||||
throw std::exception("Could not check for updates");
|
||||
throw std::runtime_error("Could not check for updates");
|
||||
}
|
||||
|
||||
if (checkUpdatesResponse.licenseFile)
|
||||
@ -581,7 +588,7 @@ bool LicenseClient::validateActivationData(const ActivationData & activationData
|
||||
return false;
|
||||
}
|
||||
|
||||
if (activationData.appId != appId)
|
||||
if (activationData.productId != productId)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user