| 67 | } |
| 68 | |
| 69 | bool IXmlFile::WriteFile() { |
| 70 | if (filename_.empty()) { |
| 71 | MDF_ERROR() << "No file name defined"; |
| 72 | return false; |
| 73 | } |
| 74 | try { |
| 75 | std::ofstream file(fs::u8path(filename_), |
| 76 | std::ofstream::out | std::ofstream::trunc); |
| 77 | if (!file.is_open()) { |
| 78 | MDF_ERROR() << "Couldn't open file for writing. File: " << filename_; |
| 79 | return false; |
| 80 | } |
| 81 | |
| 82 | // Start with byte order characters if the encoding is UTF-8 |
| 83 | if (Platform::stricmp(encoding_.c_str(), "UTF-8") == 0) { |
| 84 | file << "\xEF\xBB\xBF"; |
| 85 | } |
| 86 | WriteRoot(file, false); |
| 87 | |
| 88 | file.close(); |
| 89 | |
| 90 | } catch (const std::exception &err) { |
| 91 | MDF_ERROR() << "Failed to write the file. Error: " << err.what() |
| 92 | << ", File: " << FileName(); |
| 93 | return false; |
| 94 | } |
| 95 | return true; |
| 96 | } |
| 97 | |
| 98 | std::string IXmlFile::WriteString(bool skip_header) { |
| 99 | std::ostringstream temp; |