* add support for unicode (utf16) paths on windows

This commit is contained in:
artem@windows 2013-05-21 09:42:55 -07:00
parent 35a8582043
commit 154c93017a
3 changed files with 19 additions and 3 deletions

View file

@ -50,6 +50,8 @@ dbf_file::dbf_file(std::string const& file_name)
record_length_(0), record_length_(0),
#ifdef SHAPE_MEMORY_MAPPED_FILE #ifdef SHAPE_MEMORY_MAPPED_FILE
file_(), file_(),
#elif defined(_WINDOWS)
file_(mapnik::utf8_to_utf16(file_name), std::ios::in | std::ios::binary),
#else #else
file_(file_name.c_str() ,std::ios::in | std::ios::binary), file_(file_name.c_str() ,std::ios::in | std::ios::binary),
#endif #endif

View file

@ -2,7 +2,7 @@
* *
* This file is part of Mapnik (c++ mapping toolkit) * This file is part of Mapnik (c++ mapping toolkit)
* *
* Copyright (C) 2011 Artem Pavlenko * Copyright (C) 2013 Artem Pavlenko
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public * modify it under the terms of the GNU Lesser General Public
@ -34,6 +34,7 @@
// mapnik // mapnik
#include <mapnik/debug.hpp> #include <mapnik/debug.hpp>
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/utils.hpp>
#include <mapnik/boolean.hpp> #include <mapnik/boolean.hpp>
#include <mapnik/util/conversions.hpp> #include <mapnik/util/conversions.hpp>
#include <mapnik/geom_util.hpp> #include <mapnik/geom_util.hpp>
@ -76,18 +77,28 @@ shape_datasource::shape_datasource(const parameters &params)
shape_name_ = *file; shape_name_ = *file;
boost::algorithm::ireplace_last(shape_name_,".shp",""); boost::algorithm::ireplace_last(shape_name_,".shp","");
#ifdef _WINDOWS
if (!boost::filesystem::exists(mapnik::utf8_to_utf16(shape_name_) + L".shp"))
#else
if (!boost::filesystem::exists(shape_name_ + ".shp")) if (!boost::filesystem::exists(shape_name_ + ".shp"))
#endif
{ {
throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist"); throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' does not exist");
} }
#ifdef _WINDOWS
if (boost::filesystem::is_directory(mapnik::utf8_to_utf16(shape_name_) + L".shp"))
#else
if (boost::filesystem::is_directory(shape_name_ + ".shp")) if (boost::filesystem::is_directory(shape_name_ + ".shp"))
#endif
{ {
throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' appears to be a directory not a file"); throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".shp' appears to be a directory not a file");
} }
#ifdef _WINDOWS
if (!boost::filesystem::exists(mapnik::utf8_to_utf16(shape_name_) + L".dbf"))
#else
if (!boost::filesystem::exists(shape_name_ + ".dbf")) if (!boost::filesystem::exists(shape_name_ + ".dbf"))
#endif
{ {
throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".dbf' does not exist"); throw datasource_exception("Shape Plugin: shapefile '" + shape_name_ + ".dbf' does not exist");
} }

View file

@ -29,6 +29,7 @@
// mapnik // mapnik
#include <mapnik/global.hpp> #include <mapnik/global.hpp>
#include <mapnik/utils.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
#include <mapnik/mapped_memory_cache.hpp> #include <mapnik/mapped_memory_cache.hpp>
#include <mapnik/noncopyable.hpp> #include <mapnik/noncopyable.hpp>
@ -149,6 +150,8 @@ public:
shape_file(std::string const& file_name) : shape_file(std::string const& file_name) :
#ifdef SHAPE_MEMORY_MAPPED_FILE #ifdef SHAPE_MEMORY_MAPPED_FILE
file_() file_()
#elif defined (_WINDOWS)
file_(mapnik::utf8_to_utf16(file_name), std::ios::in | std::ios::binary)
#else #else
file_(file_name.c_str(), std::ios::in | std::ios::binary) file_(file_name.c_str(), std::ios::in | std::ios::binary)
#endif #endif