forked from ciphrex/mSIGNA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfilesystem.cpp
45 lines (40 loc) · 1.28 KB
/
filesystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
///////////////////////////////////////////////////////////////////
//
// mSIGNA
//
// filesystem.cpp
//
// Copyright (c) 2013-2014 Eric Lombrozo
//
// All Rights Reserved.
#include "filesystem.h"
#ifdef _WIN32
#include <shlobj.h>
#endif
#include <algorithm>
#include <boost/filesystem.hpp>
std::string getDefaultDataDir(const std::string& appName)
{
#ifdef _WIN32
char path[1024] = "";
if (SHGetSpecialFolderPathA(NULL, path, CSIDL_APPDATA, true))
return (boost::filesystem::path(path) / appName).string();
else
throw std::runtime_error("getDefaultDataDir() - SHGetSpecialFolderPathA() failed.");
#else
boost::filesystem::path dataDirPath;
char const* homeDir = getenv("HOME");
if (!homeDir || strlen(homeDir) == 0)
dataDirPath = boost::filesystem::path("/");
else
dataDirPath = boost::filesystem::path(homeDir);
#if defined(__APPLE__) && defined(__MACH__)
// This eventually needs to be put in proper wrapper (to support sandboxing)
return (dataDirPath / "Library/Application Support" / appName).string();
#else
std::string lowerAppName(appName);
std::transform(lowerAppName.begin(), lowerAppName.end(), lowerAppName.begin(), ::tolower);
return (dataDirPath / (std::string(".") + lowerAppName)).string();
#endif
#endif
}