From 9c844f666405eaa94df3740c5423ab0e932d4ea8 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Mon, 12 Jan 2009 20:54:21 +0000 Subject: fix directory warnings on win32 --- src/filesystem/filesystem.cc | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/filesystem/filesystem.cc b/src/filesystem/filesystem.cc index 19869a9..d275667 100644 --- a/src/filesystem/filesystem.cc +++ b/src/filesystem/filesystem.cc @@ -57,10 +57,19 @@ void init(std::string const & basename, std::string const & modname) filesystem_basename.assign("base"); filesystem_modname.assign(modname); + #ifndef _WIN32 + // UNIX home directory is $HOME/.osirion filesystem_homedir.assign(getenv("HOME")); - filesystem_homedir.append("/.osirion/"); + filesystem_homedir.append("/.osirion"); + + // create homedir if necessary + if (!sys::isdirectory(filesystem_homedir)) + sys::mkdir(filesystem_homedir); + filesystem_homedir += '/'; + #else + // windows home directory is My Documents\My Games\Osirion char mydocuments[512]; memset(mydocuments, 0, sizeof(mydocuments)); @@ -75,10 +84,15 @@ void init(std::string const & basename, std::string const & modname) filesystem_homedir.append("\\Osirion"); if (!sys::isdirectory(filesystem_homedir)) sys::mkdir(filesystem_homedir); - filesystem_homedir.append("\\"); + } else { - filesystem_homedir.assign("home/"); + con_warn << "using fallback home directory" << std::endl; + + filesystem_homedir.assign("home"); + if (!sys::isdirectory(filesystem_homedir)) + sys::mkdir(filesystem_homedir); + filesystem_homedir += '/'; } #endif @@ -91,15 +105,15 @@ void init(std::string const & basename, std::string const & modname) if (filesystem_modname.size()) { // append modname to writedir filesystem_writedir.append(filesystem_modname); - filesystem_writedir += '/'; } else { // append basename to writedir - filesystem_writedir.append(filesystem_basename); - filesystem_writedir += '/'; + filesystem_writedir.append(filesystem_basename); } - sys::mkdir(filesystem_homedir); - sys::mkdir(filesystem_writedir); + // create writedir if necessary + if (!sys::isdirectory(filesystem_writedir)) + sys::mkdir(filesystem_writedir); + filesystem_writedir += '/'; // modname search path if (filesystem_modname.size()) { -- cgit v1.2.3