| 206 | } |
| 207 | |
| 208 | bool BeLibFile::Finish() |
| 209 | { |
| 210 | BP_ZONE("BeLibFile::Finish"); |
| 211 | |
| 212 | //mOldEntries.clear(); |
| 213 | |
| 214 | Dictionary<String, BeLibEntry*>* libEntryMaps[2] = { &mEntries, &mOldEntries }; |
| 215 | |
| 216 | Array<BeLibEntry*> libEntries; |
| 217 | |
| 218 | bool isAllReferenced = true; |
| 219 | for (auto entryMap : libEntryMaps) |
| 220 | { |
| 221 | for (auto& libEntryPair : *entryMap) |
| 222 | { |
| 223 | auto libEntry = libEntryPair.mValue; |
| 224 | if (libEntry->mReferenced) |
| 225 | libEntries.push_back(libEntry); |
| 226 | else |
| 227 | isAllReferenced = false; |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | if ((isAllReferenced) && (mEntries.IsEmpty()) && (mOldFileStream.IsOpen())) |
| 232 | { |
| 233 | mOldFileStream.Close(); |
| 234 | String altName = mFilePath + "_"; |
| 235 | if (::MoveFileA(altName.c_str(), mFilePath.c_str())) |
| 236 | { |
| 237 | return true; // There are no changes |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | if (!mFileStream.Open(mFilePath, "wb")) |
| 242 | { |
| 243 | mFailed = true; |
| 244 | return false; |
| 245 | } |
| 246 | |
| 247 | if ((!mOldEntries.IsEmpty()) && (!mOldFileStream.IsOpen())) |
| 248 | { |
| 249 | // We failed to open the old stream but we still had old entries to references.. |
| 250 | mFailed = true; |
| 251 | return false; |
| 252 | } |
| 253 | |
| 254 | mFileStream.Write("!<arch>\n", 8); |
| 255 | |
| 256 | std::sort(libEntries.begin(), libEntries.end(), |
| 257 | [&](BeLibEntry* lhs, BeLibEntry* rhs) |
| 258 | { |
| 259 | return lhs->mName < rhs->mName; |
| 260 | }); |
| 261 | |
| 262 | int longNamesSize = 0; |
| 263 | |
| 264 | int tabSize = 4; // num symbols |
| 265 | int numSymbols = 0; |
nothing calls this directly
no test coverage detected