MCPcopy Create free account
hub / github.com/amule-project/amule / SaveList

Method SaveList

src/ClientCreditsList.cpp:169–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

167
168
169void 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
222CClientCredits* CClientCreditsList::GetCredit(const CMD4Hash& key)

Callers

nothing calls this directly

Calls 15

GetTickCount64Function · 0.85
GetConfigDirFunction · 0.85
WriteUInt8Method · 0.80
WriteUInt32Method · 0.80
GetDataStructMethod · 0.80
WriteUInt16Method · 0.80
SeekMethod · 0.80
whatMethod · 0.80
CreateMethod · 0.45
OpenMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected