Files
GDevelop/Core/GDCore/Tools/XmlLoader.cpp
T
Florian Rival a8559bfbbc Add clang-format to format (C++) source files automatically (#491)
* Update all CMakeLists of extensions to use clang-format
* Run clang-format on all Extensions
* Update GDCore CMakeLists.txt to add clang-format
* Run clang-format on GDCore files
* Update GDJS and GDCpp CMakeLists.txt to add clang-format
* Run clang-format on GDCpp and GDJS files
2018-05-09 15:57:38 -07:00

40 lines
908 B
C++

#include "GDCore/Tools/XmlLoader.h"
#include <cstdio>
namespace gd {
namespace {
FILE* GetFileHandle(const gd::String& filename, const gd::String& mode) {
#if defined(WINDOWS)
return _wfopen(filename.ToWide().c_str(), mode.ToWide().c_str());
#else
return fopen(filename.ToLocale().c_str(), mode.ToLocale().c_str());
#endif
}
} // namespace
bool GD_CORE_API LoadXmlFromFile(TiXmlDocument& doc,
const gd::String& filepath) {
FILE* xmlFile = GetFileHandle(filepath, "rb");
if (!xmlFile) return false;
bool res = doc.LoadFile(xmlFile);
fclose(xmlFile);
return res;
}
bool GD_CORE_API SaveXmlToFile(const TiXmlDocument& doc,
const gd::String& filepath) {
FILE* xmlFile = GetFileHandle(filepath, "wb");
if (!xmlFile) return false;
bool res = doc.SaveFile(xmlFile);
fclose(xmlFile);
return res;
}
} // namespace gd