| 167 | |
| 168 | |
| 169 | void CClientCreditsList::SaveList() |
| 170 | { |
| 171 | AddDebugLogLineN( logCredits, "Saved Credit list"); |
| 172 | m_nLastSaved = ::GetTickCount64(); |
| 173 | |
| 174 | wxString name(thePrefs::GetConfigDir() + CLIENTS_MET_FILENAME); |
| 175 | CFile file; |
| 176 | |
| 177 | if ( !file.Create(name, true) ) { |
| 178 | AddDebugLogLineC( logCredits, "Failed to create creditfile" ); |
| 179 | return; |
| 180 | } |
| 181 | |
| 182 | if ( file.Open(name, CFile::write) ) { |
| 183 | try { |
| 184 | uint32 count = 0; |
| 185 | |
| 186 | file.WriteUInt8( CREDITFILE_VERSION ); |
| 187 | // Temporary place-holder for number of structs |
| 188 | file.WriteUInt32( 0 ); |
| 189 | |
| 190 | ClientMap::iterator it = m_mapClients.begin(); |
| 191 | for ( ; it != m_mapClients.end(); ++it ) { |
| 192 | CClientCredits* cur_credit = it->second; |
| 193 | |
| 194 | if ( cur_credit->GetUploadedTotal() || cur_credit->GetDownloadedTotal() ) { |
| 195 | const CreditStruct* const cstruct = cur_credit->GetDataStruct(); |
| 196 | file.WriteHash(cstruct->key); |
| 197 | file.WriteUInt32(static_cast<uint32>(cstruct->uploaded)); |
| 198 | file.WriteUInt32(static_cast<uint32>(cstruct->downloaded)); |
| 199 | file.WriteUInt32(cstruct->nLastSeen); |
| 200 | file.WriteUInt32(static_cast<uint32>(cstruct->uploaded >> 32)); |
| 201 | file.WriteUInt32(static_cast<uint32>(cstruct->downloaded >> 32)); |
| 202 | file.WriteUInt16(cstruct->nReserved3); |
| 203 | file.WriteUInt8(cstruct->nKeySize); |
| 204 | // Doesn't matter if this saves garbage, will be fixed on load. |
| 205 | file.Write(cstruct->abySecureIdent, MAXPUBKEYSIZE); |
| 206 | count++; |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | // Write the actual number of structs |
| 211 | file.Seek( 1 ); |
| 212 | file.WriteUInt32( count ); |
| 213 | } catch (const CIOFailureException& e) { |
| 214 | AddDebugLogLineC(logCredits, "IO failure while saving clients.met: " + e.what()); |
| 215 | } |
| 216 | } else { |
| 217 | AddDebugLogLineC(logCredits, "Failed to open existing creditfile!"); |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | |
| 222 | CClientCredits* CClientCreditsList::GetCredit(const CMD4Hash& key) |
nothing calls this directly
no test coverage detected