bool SaveAdminList(COutStream& stream) { std::string data; data.reserve(1 << 12); // 4kb for (auto itr = admin::adminList.cbegin(); itr != admin::adminList.cend(); ++itr) { data += itr->second.name + ","; data += itr->second.hash + ","; data += m_sprintf("%i\r\n", itr->second.accessLevel.get_level()); } std::wstring adminPathTmp = adminPath + L".tmp"; CTempFile<COutFile> file; if (!file.Open(adminPathTmp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, OPEN_ALWAYS)) { stream << L"can't open admin file : " << adminPath << endl; return false; } DWORD written; if (!file.Write((BYTE*)data.c_str(), data.size(), &written)) { stream << "can't write to new admin file" << endl; return false; } file.Close(); if (!CFile::Move(adminPathTmp, adminPath, true)) { stream << "can't replace old admin file " << adminPath << endl; return false; } file.success(); return true; }