| 64 | } |
| 65 | |
| 66 | bool CEditorMap::Save(const char *pFilename, const FErrorHandler &ErrorHandler) |
| 67 | { |
| 68 | char aFilenameTmp[IO_MAX_PATH_LENGTH]; |
| 69 | IStorage::FormatTmpPath(aFilenameTmp, sizeof(aFilenameTmp), pFilename); |
| 70 | |
| 71 | log_info("editor/save", "Saving map to '%s'...", aFilenameTmp); |
| 72 | |
| 73 | if(!PerformPreSaveSanityChecks(ErrorHandler)) |
| 74 | { |
| 75 | return false; |
| 76 | } |
| 77 | |
| 78 | CDataFileWriter Writer; |
| 79 | if(!Writer.Open(m_pEditor->Storage(), aFilenameTmp)) |
| 80 | { |
| 81 | char aBuf[IO_MAX_PATH_LENGTH + 64]; |
| 82 | str_format(aBuf, sizeof(aBuf), "Error: Failed to open file '%s' for writing.", aFilenameTmp); |
| 83 | ErrorHandler(aBuf); |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | // save version |
| 88 | { |
| 89 | CMapItemVersion Item; |
| 90 | Item.m_Version = 1; |
| 91 | Writer.AddItem(MAPITEMTYPE_VERSION, 0, sizeof(Item), &Item); |
| 92 | } |
| 93 | |
| 94 | // save map info |
| 95 | { |
| 96 | CMapItemInfoSettings Item; |
| 97 | Item.m_Version = 1; |
| 98 | Item.m_Author = Writer.AddDataString(m_MapInfo.m_aAuthor); |
| 99 | Item.m_MapVersion = Writer.AddDataString(m_MapInfo.m_aVersion); |
| 100 | Item.m_Credits = Writer.AddDataString(m_MapInfo.m_aCredits); |
| 101 | Item.m_License = Writer.AddDataString(m_MapInfo.m_aLicense); |
| 102 | |
| 103 | Item.m_Settings = -1; |
| 104 | if(!m_vSettings.empty()) |
| 105 | { |
| 106 | int Size = 0; |
| 107 | for(const auto &Setting : m_vSettings) |
| 108 | { |
| 109 | Size += str_length(Setting.m_aCommand) + 1; |
| 110 | } |
| 111 | |
| 112 | char *pSettings = (char *)malloc(maximum(Size, 1)); |
| 113 | char *pNext = pSettings; |
| 114 | for(const auto &Setting : m_vSettings) |
| 115 | { |
| 116 | int Length = str_length(Setting.m_aCommand) + 1; |
| 117 | mem_copy(pNext, Setting.m_aCommand, Length); |
| 118 | pNext += Length; |
| 119 | } |
| 120 | Item.m_Settings = Writer.AddData(Size, pSettings); |
| 121 | free(pSettings); |
| 122 | } |
| 123 |
nothing calls this directly
no test coverage detected