libLicenseClient/api/OSUtils.cpp
Peter Sykora dd366eaf5b [impl] Logging into AppData folder
[chore] Change API appId parameter => productId parameter
2018-05-01 16:27:38 +02:00

34 lines
746 B
C++

#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");
}