Amend previous commit

The utf8 conversion is only used in the Windows specific section so there's no
need to define an overloaded function on std::string in this case.
Also CMakeLists.txt doesn't require the MingW specific library name setting
for boost::filesystem. Just removing the hardcoded one allows the build to
pick the right name up from the Boost_LIBRARIES variable.
This commit is contained in:
Geert Janssens 2017-09-04 22:04:04 +02:00
parent d6677ff39f
commit d96bb3ebd5
2 changed files with 15 additions and 32 deletions

View File

@ -116,13 +116,8 @@ SET(core_utils_noinst_HEADERS
gnc-path.h
)
if (MINGW64)
SET(BOOST_FILESYSTEM -lboost_filesystem-mt)
else()
SET(BOOST_FILESYSTEM -lboost_filesystem)
endif()
SET(core_utils_ALL_SOURCES ${core_utils_SOURCES} ${core_utils_noinst_HEADERS})
SET(core_utils_ALL_LIBRARIES ${Boost_LIBRARIES} ${BOOST_FILESYSTEM} ${GUILE_LDFLAGS} ${GLIB2_LDFLAGS} ${GOBJECT_LDFLAGS} ${GTK_MAC_LDFLAGS})
SET(core_utils_ALL_LIBRARIES ${Boost_LIBRARIES} ${GUILE_LDFLAGS} ${GLIB2_LDFLAGS} ${GOBJECT_LDFLAGS} ${GTK_MAC_LDFLAGS})
SET(core_utils_ALL_INCLUDES
${CMAKE_SOURCE_DIR}/common
${CMAKE_BINARY_DIR}/common

View File

@ -61,31 +61,16 @@ extern "C" {
#endif
}
#include <codecvt>
#include <string>
#include <boost/filesystem.hpp>
#if PLATFORM(WINDOWS)
#include <codecvt>
#include <locale>
#endif
namespace bfs = boost::filesystem;
namespace bst = boost::system;
/*
* Converts UTF16 to UTF8. Pinched from Nicolai M. Josuttis, "The C++
* Standard Library, Second Edition", 2012, Addison-Wesley.
*/
static std::string utf8(const std::wstring& str)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
return myconv.to_bytes(str);
}
/*
* Does nothing, it's just here so to save a bunch of ifdefs later.
*/
static std::string utf8(const std::string& str)
{
return str;
}
/**
* Scrubs a filename by changing "strange" chars (e.g. those that are not
* valid in a win32 file name) to "_".
@ -394,7 +379,7 @@ copy_recursive(const bfs::path& src, const bfs::path& dest)
{
g_warning("An error occured while trying to migrate the user configation from\n%s to\n%s"
"The reported failure is\n%s",
src.c_str(), gnc_userdata_home.string(),
src.string().c_str(), gnc_userdata_home.string().c_str(),
ex.what());
return false;
}
@ -408,30 +393,33 @@ copy_recursive(const bfs::path& src, const bfs::path& dest)
* So this function is a copy of glib's internal get_special_folder
* and minimally adjusted to fetch CSIDL_APPDATA
*/
static gchar *
static char *
win32_get_userdata_home (void)
{
wchar_t path[MAX_PATH+1];
HRESULT hr;
LPITEMIDLIST pidl = NULL;
BOOL b;
gchar *retval = NULL;
char *retval = NULL;
hr = SHGetSpecialFolderLocation (NULL, CSIDL_APPDATA, &pidl);
if (hr == S_OK)
{
b = SHGetPathFromIDListW (pidl, path);
if (b)
retval = g_strdup(utf8(path).c_str());
{
std::wstring_convert<std::codecvt_utf8<wchar_t>> utf8_conv;
retval = g_strdup(utf8_conv.to_bytes(path).c_str());
}
CoTaskMemFree (pidl);
}
return retval;
}
#elif defined MAC_INTEGRATION
static gchar*
static char*
quarz_get_userdata_home(void)
{
gchar *retval = NULL;
char *retval = NULL;
NSFileManager*fm = [NSFileManager defaultManager];
NSArray* appSupportDir = [fm URLsForDirectory:NSApplicationSupportDirectory
inDomains:NSUserDomainMask];