]> git.tdb.fi Git - libs/core.git/blob - source/fs/windows/dir.cpp
6b63b471d5bc939fe11a78ccbc668cdb02573c8c
[libs/core.git] / source / fs / windows / dir.cpp
1 #include <shlobj.h>
2 #include <msp/core/systemerror.h>
3 #include "dir.h"
4
5 using namespace std;
6
7 namespace Msp {
8 namespace FS {
9
10 void mkdir(const Path &path, int)
11 {
12         if(!CreateDirectory(path.str().c_str(), NULL))
13                 throw system_error("CreateDirectory");
14 }
15
16 void rmdir(const Path &path)
17 {
18         if(!RemoveDirectory(path.str().c_str()))
19                 throw system_error("RemoveDirectory");
20 }
21
22 Path get_home_dir()
23 {
24         char home[MAX_PATH];
25         if(SHGetFolderPath(0, CSIDL_PERSONAL, 0, 0, home)==S_OK)
26                 return home;
27         return ".";
28 }
29
30 Path get_user_data_dir(const string &appname)
31 {
32         if(appname.empty())
33                 throw invalid_argument("get_user_data_dir");
34         char datadir[MAX_PATH];
35         if(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, datadir)==S_OK)
36                 return Path(datadir)/appname;
37         return ".";
38 }
39
40 } // namespace FS
41 } // namespace Msp