From e494209440c3b5b1a8c28ffd186501209cd15971 Mon Sep 17 00:00:00 2001 From: James Turner Date: Fri, 15 Jul 2016 16:35:17 +0100 Subject: [PATCH] Further SGPath API usage improvements. --- src/Main/fg_commands.cxx | 2 +- src/Scripting/NasalSys.cxx | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Main/fg_commands.cxx b/src/Main/fg_commands.cxx index 1040b5f9e..ab8760693 100644 --- a/src/Main/fg_commands.cxx +++ b/src/Main/fg_commands.cxx @@ -331,7 +331,7 @@ do_save (const SGPropertyNode * arg) bool write_all = arg->getBoolValue("write-all", false); SG_LOG(SG_INPUT, SG_INFO, "Saving flight"); - ofstream output(validated_path.c_str()); + sg_ofstream output(validated_path); if (output.good() && fgSaveFlight(output, write_all)) { output.close(); SG_LOG(SG_INPUT, SG_INFO, "Saved flight to " << file); diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx index 993190511..83abdd167 100644 --- a/src/Scripting/NasalSys.cxx +++ b/src/Scripting/NasalSys.cxx @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -693,8 +694,14 @@ static naRef f_open(naContext c, naRef me, int argc, naRef* args) return naNil(); } - f = fopen(filename.c_str(), modestr); - +#if defined(SG_WINDOWS) + std::wstring fp = filename.wstr(); + std::wstring wmodestr = simgear::strutils::convertUtf8ToWString(modestr); + f = _wfopen(fp.c_str(), wmodestr.c_str()); +#else + std::string fp = filename.local8BitStr(); + f = fopen(fp.c_str(), modestr); +#endif if(!f) naRuntimeError(c, strerror(errno)); return naIOGhost(c, f); } @@ -728,13 +735,13 @@ static naRef f_parsexml(naContext c, naRef me, int argc, naRef* args) naRuntimeError(c, "parsexml(): access denied (unauthorized directory)"); return naNil(); } - sg_ifstream input(file); + NasalXMLVisitor visitor(c, argc, args); try { - readXML(input, visitor); + readXML(file, visitor); } catch (const sg_exception& e) { - naRuntimeError(c, "parsexml(): file '%s' %s", - file.c_str(), e.getFormattedMessage().c_str()); + std::string fp = file.utf8Str(); + naRuntimeError(c, "parsexml(): file '%s' %s", fp.c_str(), e.getFormattedMessage().c_str()); return naNil(); } -- 2.39.5