From a4e7df603774a8f4f5fc87ae986bcd9b607f37a8 Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 20 May 2015 15:33:34 -0300 Subject: [PATCH] Fix loading/saving .gpl files inside folders with Unicode chars on Windows --- src/base/fstream_path.h | 19 +++++++++++++++++++ src/doc/file/gpl_file.cpp | 11 ++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 src/base/fstream_path.h diff --git a/src/base/fstream_path.h b/src/base/fstream_path.h new file mode 100644 index 000000000..ae1df28b5 --- /dev/null +++ b/src/base/fstream_path.h @@ -0,0 +1,19 @@ +// Aseprite Base Library +// Copyright (c) 2001-2015 David Capello +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifndef BASE_FSTREAM_PATH_H_INCLUDED +#define BASE_FSTREAM_PATH_H_INCLUDED +#pragma once + +#include "base/string.h" + +#ifdef _WIN32 + #define FSTREAM_PATH(path) (base::from_utf8(path).c_str()) +#else + #define FSTREAM_PATH(path) ((path).c_str()) +#endif + +#endif diff --git a/src/doc/file/gpl_file.cpp b/src/doc/file/gpl_file.cpp index 716f5289b..77a05e562 100644 --- a/src/doc/file/gpl_file.cpp +++ b/src/doc/file/gpl_file.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2015 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -8,24 +8,25 @@ #include "config.h" #endif +#include "base/fstream_path.h" #include "base/split_string.h" #include "base/trim_string.h" #include "base/unique_ptr.h" #include "doc/image.h" #include "doc/palette.h" +#include #include +#include #include #include -#include -#include namespace doc { namespace file { Palette* load_gpl_file(const char *filename) { - std::ifstream f(filename); + std::ifstream f(FSTREAM_PATH(filename)); if (f.bad()) return NULL; // Read first line, it must be "GIMP Palette" @@ -68,7 +69,7 @@ Palette* load_gpl_file(const char *filename) bool save_gpl_file(const Palette *pal, const char *filename) { - std::ofstream f(filename); + std::ofstream f(FSTREAM_PATH(filename)); if (f.bad()) return false; f << "GIMP Palette\n"