35 lines
886 B
C++
35 lines
886 B
C++
#include "OSUtils.h"
|
|
|
|
struct IUnknown; // Workaround for "combaseapi.h(229): error C2187: syntax error: 'identifier' was unexpected here" when using /permissive-
|
|
#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");
|
|
}
|