2 #include <msp/core/mutex.h>
3 #include <msp/core/systemerror.h>
11 void mkdir(const Path &path, int)
13 if(!CreateDirectory(path.str().c_str(), NULL))
14 throw system_error("CreateDirectory");
17 void rmdir(const Path &path)
19 if(!RemoveDirectory(path.str().c_str()))
20 throw system_error("RemoveDirectory");
23 /* Windows documentation says Get/SetCurrentDirectory use a global buffer and
24 are not thread safe. */
25 static Mutex &cwd_mutex()
33 MutexLock lock(cwd_mutex());
37 DWORD len = GetCurrentDirectory(sizeof(buf), buf);
40 vector<char> buf2(len+1);
41 len = GetCurrentDirectory(buf2.size(), buf2.data());
48 throw system_error("GetCurrentDirectory");
53 void chdir(const Path &path)
55 MutexLock lock(cwd_mutex());
56 if(!SetCurrentDirectory(path.c_str()))
57 throw system_error("SetCurrentDirectory");
63 if(SHGetFolderPath(0, CSIDL_PERSONAL, 0, 0, home)==S_OK)
68 Path get_user_data_dir(const string &appname)
71 throw invalid_argument("get_user_data_dir");
72 char datadir[MAX_PATH];
73 if(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, datadir)==S_OK)
74 return Path(datadir)/appname;