mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Bug 798885 - Accented character in folder name on Account Export (bis)
Pass a boost::filesystem's c_str() rv to the ofstream constructor to keep libstdc++ from transcoding it back to UTF8 and creating a broken name or failing to match the directory name. Implemented in gnc-filepath-utils to avoid spreading the boost::filesystem dependency throughout the code base. See https://github.com/boostorg/filesystem/issues/181 for why other approaches don't work.
This commit is contained in:
parent
73337cff5a
commit
d696f0cfcb
@ -32,6 +32,7 @@
|
|||||||
#include "gnucash-commands.hpp"
|
#include "gnucash-commands.hpp"
|
||||||
#include "gnucash-core-app.hpp"
|
#include "gnucash-core-app.hpp"
|
||||||
|
|
||||||
|
#include <gnc-filepath-utils.h>
|
||||||
#include <gnc-engine-guile.h>
|
#include <gnc-engine-guile.h>
|
||||||
#include <gnc-prefs.h>
|
#include <gnc-prefs.h>
|
||||||
#include <gnc-prefs-utils.h>
|
#include <gnc-prefs-utils.h>
|
||||||
@ -107,7 +108,7 @@ static inline void
|
|||||||
write_report_file (const char *html, const char* file)
|
write_report_file (const char *html, const char* file)
|
||||||
{
|
{
|
||||||
if (!file || !html || !*html) return;
|
if (!file || !html || !*html) return;
|
||||||
std::ofstream ofs{file};
|
auto ofs{gnc_open_filestream(file)};
|
||||||
if (!ofs)
|
if (!ofs)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open file " << file << " for writing\n";
|
std::cerr << "Failed to open file " << file << " for writing\n";
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <unordered_set>
|
#include <unordered_set>
|
||||||
|
|
||||||
|
#include <gnc-filepath-utils.h>
|
||||||
#include "gnc-commodity.h"
|
#include "gnc-commodity.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
#include "Query.h"
|
#include "Query.h"
|
||||||
@ -350,9 +351,6 @@ void csv_transactions_export (CsvExportInfo *info)
|
|||||||
ENTER("");
|
ENTER("");
|
||||||
DEBUG("File name is : %s", info->file_name);
|
DEBUG("File name is : %s", info->file_name);
|
||||||
|
|
||||||
/* Open File for writing */
|
|
||||||
auto ss{std::ofstream (info->file_name, std::ofstream::out)};
|
|
||||||
|
|
||||||
StringVec headers;
|
StringVec headers;
|
||||||
bool num_action = qof_book_use_split_action_for_num_field (gnc_get_current_book());
|
bool num_action = qof_book_use_split_action_for_num_field (gnc_get_current_book());
|
||||||
|
|
||||||
@ -398,6 +396,7 @@ void csv_transactions_export (CsvExportInfo *info)
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Write header line */
|
/* Write header line */
|
||||||
|
auto ss{gnc_open_filestream(info->file_name)};
|
||||||
info->failed = !gnc_csv_add_line (ss, headers, info->use_quotes, info->separator_str);
|
info->failed = !gnc_csv_add_line (ss, headers, info->use_quotes, info->separator_str);
|
||||||
|
|
||||||
/* Go through list of accounts */
|
/* Go through list of accounts */
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
#include <gnc-filepath-utils.h>
|
||||||
#include "gnc-commodity.h"
|
#include "gnc-commodity.h"
|
||||||
#include "gnc-ui-util.h"
|
#include "gnc-ui-util.h"
|
||||||
#include "csv-tree-export.h"
|
#include "csv-tree-export.h"
|
||||||
@ -52,7 +53,7 @@ csv_tree_export (CsvExportInfo *info)
|
|||||||
DEBUG("File name is : %s", info->file_name);
|
DEBUG("File name is : %s", info->file_name);
|
||||||
|
|
||||||
/* Open File for writing */
|
/* Open File for writing */
|
||||||
auto ss{std::ofstream (info->file_name, std::ofstream::out)};
|
auto ss{gnc_open_filestream(info->file_name)};
|
||||||
|
|
||||||
/* Header string */
|
/* Header string */
|
||||||
StringVec headervec = {
|
StringVec headervec = {
|
||||||
|
@ -1347,4 +1347,11 @@ gboolean gnc_filename_is_datafile (const char *filename)
|
|||||||
std::regex_match (filename, datafile_regex);
|
std::regex_match (filename, datafile_regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ofstream
|
||||||
|
gnc_open_filestream(const char* path)
|
||||||
|
{
|
||||||
|
bfs::path bfs_path(path, cvt);
|
||||||
|
bfs_path.imbue(bfs_locale);
|
||||||
|
return std::ofstream(bfs_path.c_str());
|
||||||
|
}
|
||||||
/* =============================== END OF FILE ========================== */
|
/* =============================== END OF FILE ========================== */
|
||||||
|
@ -29,6 +29,8 @@
|
|||||||
#ifndef GNC_FILEPATH_UTILS_H
|
#ifndef GNC_FILEPATH_UTILS_H
|
||||||
#define GNC_FILEPATH_UTILS_H
|
#define GNC_FILEPATH_UTILS_H
|
||||||
|
|
||||||
|
#include <glib-2.0/glib.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
@ -199,7 +201,22 @@ gboolean gnc_filename_is_backup (const char *filename);
|
|||||||
gboolean gnc_filename_is_datafile (const char *filename);
|
gboolean gnc_filename_is_datafile (const char *filename);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
} //extern "C"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
/** Open std::ofstream from a UTF-8 encoded path. This is harder than
|
||||||
|
* it should because std::ofstream's constructor needs to be tricked
|
||||||
|
* into taking a wchar_t filename: Simply converting path to a
|
||||||
|
* wchar_t* with g_utf8_to_utf16() wouldn't compile. The workaround
|
||||||
|
* came from https://github.com/boostorg/filesystem/issues/181. As
|
||||||
|
* noted there passing the boost path directly to
|
||||||
|
* boost::filesystem::fstream doesn't work either.
|
||||||
|
* @param path UTF-8 path to the file
|
||||||
|
* @return a std::ofstream on the stack.
|
||||||
|
*/
|
||||||
|
std::ofstream gnc_open_filestream(const char *path);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* GNC_FILEPATH_UTILS_H */
|
#endif /* GNC_FILEPATH_UTILS_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user