]> git.tdb.fi Git - libs/core.git/blob - source/fs/windows/dir_location.cpp
Add move semantics to Variant
[libs/core.git] / source / fs / windows / dir_location.cpp
1 #include <shlobj.h>
2 #include <msp/core/application.h>
3 #include <msp/core/except.h>
4 #include "dir.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace FS {
10
11 Path get_home_dir()
12 {
13         char home[MAX_PATH];
14         if(SHGetFolderPath(nullptr, CSIDL_PERSONAL, nullptr, 0, home)==S_OK)
15                 return home;
16         return ".";
17 }
18
19 Path get_user_data_dir()
20 {
21         const string &appname = Application::get_name();
22         if(appname.empty())
23                 throw invalid_state("no application name");
24
25         char datadir[MAX_PATH];
26         if(SHGetFolderPath(nullptr, CSIDL_LOCAL_APPDATA, nullptr, 0, datadir)==S_OK)
27                 return Path(datadir)/appname;
28         return ".";
29 }
30
31 } // namespace FS
32 } // namespace Msp