- Completed porting to win32. Added project files for visual studio.net 2005. Now I can go to sleep (almost) pacefully...

git-svn-id: svn://svn.gna.org/svn/sgpemv2/trunk@1185 3ecf2c5c-341e-0410-92b4-d18e462d057c
This commit is contained in:
elvez 2006-09-16 03:23:04 +00:00
parent 997ead080b
commit df862714a0
8 changed files with 1908 additions and 0 deletions

View file

@ -19,6 +19,7 @@
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "config.h"
#include "gettext.h"
#include <glib/gstdio.h>
#include <glibmm/miscutils.h>
@ -30,6 +31,10 @@
// Do not include in header file:
#include <sgpemv2/templates/singleton.tcc>
#ifdef _MSC_VER
#include <shlobj.h>
#endif
using namespace sgpem;
// Explicit template instantiation to allow to export symbols from the DSO.
@ -44,6 +49,48 @@ const Glib::ustring&
GlobalPreferences::get_preferences_dir() const throw(Glib::FileError)
{
using namespace Glib;
// windows-specific part, i don't use ifdef WIN32 since I'm not sure how
// it will behave on MinGW/Cygwin...
#ifdef _MSC_VER
TCHAR raw_path[MAX_PATH];
if(SUCCEEDED(SHGetFolderPath(NULL,
CSIDL_APPDATA,
NULL,
SHGFP_TYPE_CURRENT,
raw_path)))
{
// if UNICODE, characters are 16bit, otherwise plain bytes
# ifdef UNICODE
std::wstring path(raw_path);
# else
std::string path(raw_path);
# endif
path += TEXT("\\sgpemv2");
// Create "Application Data\sgpemv2". if not present,
// otherwise it is a no-op
CreateDirectory(path.c_str(), NULL);
// if UNICODE, we need to convert to utf-8
// I'm not sure if this part is OK, anyway...
# ifdef UNICODE
char raw_path_utf[MAX_PATH];
WideCharToMultiByte(CP_UTF8, 0, path.c_str(), -1, raw_path_utf, MAX_PATH, NULL, NULL);
return Glib::ustring(raw_path_utf);
# else
// no UNICODE, simply return plain string
return path;
# endif //~UNICODE
}
else
throw FileError(FileError::FAILED, _("Unable to obtain Application Data directory"));
#else
static const ustring dir = get_home_dir() + G_DIR_SEPARATOR_S + ".sgpemv2";
if(!file_test(dir, FILE_TEST_IS_DIR))
{
@ -52,6 +99,8 @@ GlobalPreferences::get_preferences_dir() const throw(Glib::FileError)
throw FileError(FileError::FAILED, g_strerror(err));
}
return dir;
#endif //~_MSC_VER
}