void CFriend::LoadFromFile(CFileDataIO* file) { file->ReadHash16(m_abyUserhash); m_dwHasHash = md4cmp(m_abyUserhash, sm_abyNullHash) ? 1 : 0; m_dwLastUsedIP = file->ReadUInt32(); m_nLastUsedPort = file->ReadUInt16(); m_dwLastSeen = file->ReadUInt32(); m_dwLastChatted = file->ReadUInt32(); UINT tagcount = file->ReadUInt32(); for (UINT j = 0; j < tagcount; j++){ CTag* newtag = new CTag(file, false); switch (newtag->GetNameID()){ case FF_NAME:{ ASSERT( newtag->IsStr() ); if (newtag->IsStr()){ if (m_strName.IsEmpty()) m_strName = newtag->GetStr(); } break; } } delete newtag; } }
void CFriend::LoadFromFile(CFileDataIO* file) { file->ReadHash16(m_abyUserhash); m_dwLastUsedIP = file->ReadUInt32(); m_nLastUsedPort = file->ReadUInt16(); m_dwLastSeen = ConvertFromTime32(file->ReadUInt32()); m_dwLastChatted = file->ReadUInt32(); UINT tagcount = file->ReadUInt32(); for (UINT j = 0; j < tagcount; j++){ CTag* newtag = new CTag(file, false); switch (newtag->GetNameID()){ case FF_NAME:{ ASSERT( newtag->IsStr() ); if (newtag->IsStr()){ if (m_strName.IsEmpty()) m_strName = newtag->GetStr(); } break; } case FF_KADID:{ ASSERT( newtag->IsHash() ); if (newtag->IsHash()) md4cpy(m_abyKadID, newtag->GetHash()); break; } } delete newtag; } }
void CFileDataIO::WriteTag(const CTag& tag) { try { WriteUInt8(tag.GetType()); if (!tag.GetName().IsEmpty()) { WriteString(tag.GetName(),utf8strNone); } else { WriteUInt16(1); WriteUInt8(tag.GetNameID()); } switch (tag.GetType()) { case TAGTYPE_HASH16: // Do NOT use this to transfer any tags for at least half a year!! WriteHash(CMD4Hash(tag.GetHash())); break; case TAGTYPE_STRING: WriteString(tag.GetStr(), utf8strRaw); // Always UTF8 break; case TAGTYPE_UINT64: WriteUInt64(tag.GetInt()); break; case TAGTYPE_UINT32: WriteUInt32(tag.GetInt()); break; case TAGTYPE_FLOAT32: WriteFloat(tag.GetFloat()); break; case TAGTYPE_BSOB: WriteBsob(tag.GetBsob(), tag.GetBsobSize()); break; case TAGTYPE_UINT16: WriteUInt16(tag.GetInt()); break; case TAGTYPE_UINT8: WriteUInt8(tag.GetInt()); break; case TAGTYPE_BLOB: // NOTE: This will break backward compatibility with met files for eMule versions prior to 0.44a // and any aMule prior to SVN 26/02/2005 WriteUInt32(tag.GetBlobSize()); Write(tag.GetBlob(), tag.GetBlobSize()); break; default: //TODO: Support more tag types // With the if above, this should NEVER happen. AddLogLineNS(CFormat(wxT("CFileDataIO::WriteTag: Unknown tag: type=0x%02X")) % tag.GetType()); wxFAIL; break; } } catch (...) { AddLogLineNS(wxT("Exception in CDataIO:WriteTag")); throw; } }
CTag* CAbstractFile::GetTag(LPCSTR tagname) const { for (int i = 0; i < taglist.GetSize(); i++){ CTag* pTag = taglist[i]; if (pTag->GetNameID()==0 && CmpED2KTagName(pTag->GetName(), tagname)==0) return pTag; } return NULL; }
CTag* CAbstractFile::GetTag(uint8 tagname) const { for (int i = 0; i < taglist.GetSize(); i++){ CTag* pTag = taglist[i]; if (pTag->GetNameID()==tagname) return pTag; } return NULL; }
void CAbstractFile::DeleteTag(uint8 tagname) { for (int i = 0; i < taglist.GetSize(); i++){ CTag* pTag = taglist[i]; if (pTag->GetNameID()==tagname){ taglist.RemoveAt(i); delete pTag; return; } } }
void CAbstractFile::SetStrTagValue(uint8 tagname, LPCTSTR pszValue) { for (int i = 0; i < taglist.GetSize(); i++){ CTag* pTag = taglist[i]; if (pTag->GetNameID()==tagname && pTag->IsStr()){ pTag->SetStr(pszValue); return; } } CTag* pTag = new CTag(tagname, pszValue); taglist.Add(pTag); }
void CAbstractFile::SetInt64TagValue(uint8 tagname, uint64 uValue) { for (int i = 0; i < taglist.GetSize(); i++){ CTag* pTag = taglist[i]; if (pTag->GetNameID()==tagname && pTag->IsInt64(true)){ pTag->SetInt64(uValue); return; } } CTag* pTag = new CTag(tagname, uValue); taglist.Add(pTag); }
void CAbstractFile::AddTagUnique(const CTag &rTag) { ArrayOfCTag::iterator it = m_taglist.begin(); for (; it != m_taglist.end(); ++it) { if ( ( ((*it).GetNameID() != 0 && (*it).GetNameID() == rTag.GetNameID()) || (!(*it).GetName().IsEmpty() && !rTag.GetName().IsEmpty() && (*it).GetName() == rTag.GetName()) ) && (*it).GetType() == rTag.GetType()){ m_taglist.erase(it); m_taglist.insert(it, rTag); return; } } m_taglist.push_back(rTag); }