]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/windows/dir.cpp
Move most platform-specific code into overlay directories
[libs/core.git] / source / fs / windows / dir.cpp
diff --git a/source/fs/windows/dir.cpp b/source/fs/windows/dir.cpp
new file mode 100644 (file)
index 0000000..6adddec
--- /dev/null
@@ -0,0 +1,39 @@
+#include <shlobj.h>
+#include <msp/core/systemerror.h>
+#include "dir.h"
+
+using namespace std;
+
+namespace Msp {
+namespace FS {
+
+void mkdir(const Path &path, int)
+{
+       if(!CreateDirectory(path.str().c_str(), NULL))
+               throw system_error("CreateDirectory");
+}
+
+void rmdir(const Path &path)
+{
+       if(!RemoveDirectory(path.str().c_str()))
+               throw system_error("RemoveDirectory");
+}
+
+Path get_home_dir()
+{
+       char home[MAX_PATH];
+       if(SHGetFolderPath(0, CSIDL_PERSONAL, 0, 0, home)==S_OK)
+               return home;
+       return ".";
+}
+
+Path get_user_data_dir(const string &appname)
+{
+       char datadir[MAX_PATH];
+       if(SHGetFolderPath(0, CSIDL_LOCAL_APPDATA, 0, 0, datadir)==S_OK)
+               return Path(datadir)/appname;
+       return ".";
+}
+
+} // namespace FS
+} // namespace Msp