private CKnownFileAttributes m_IsKnown(string name, DateTime date) { if ((m_KnownMetList == null) || (m_KnownMetList.Count == 0)) { return(null); } CKnownFileAttributes attributesKnownFile = (CKnownFileAttributes)m_KnownMetList[name + (date.Ticks / 10000000L).ToString()]; if (attributesKnownFile != null) { return(attributesKnownFile); } return(null); }
private bool m_LoadKnownFiles(string filefullpath, bool showErrorMessage) { FileStream knownmet = null; BinaryReader reader = null; if (filefullpath.Length == 0) { filefullpath = Path.Combine(CKernel.DllDirectory, "known.met"); } try { knownmet = File.OpenRead(filefullpath); reader = new BinaryReader(knownmet); if (!Enum.IsDefined(typeof(Protocol.KnownMet), reader.ReadByte())) // if (reader.ReadByte() != 0x0E) { reader.Close(); knownmet.Close(); CLog.Log(Constants.Log.Notify, "KNWMET_INVALID"); return(false); } int nFiles = reader.ReadInt32(); m_KnownMetList = new Hashtable(nFiles); for (uint i = 0; i != nFiles; i++) { CKnownFileAttributes attributesKnownFile = new CKnownFileAttributes(); attributesKnownFile.Date = new DateTime(((long)reader.ReadUInt32() * 10000000L) + 621355968000000000L); attributesKnownFile.FileHash = reader.ReadBytes(16); ushort nChunks = reader.ReadUInt16(); attributesKnownFile.HashSet = new ArrayList(nChunks); for (uint chunk = 0; chunk != nChunks; chunk++) { attributesKnownFile.HashSet.Add(reader.ReadBytes(16)); } CParameterReader ParameterReader; uint nparameters = reader.ReadUInt32(); for (uint parameter = 0; parameter != nparameters; parameter++) { ParameterReader = new CParameterReader(reader); switch ((Protocol.FileTag)ParameterReader.id) { case Protocol.FileTag.Name: attributesKnownFile.FileName = ParameterReader.valorString; break; case Protocol.FileTag.Size: attributesKnownFile.Size = ParameterReader.valorNum; break; case Protocol.FileTag.Priority: attributesKnownFile.Priority = (Constants.Priority)ParameterReader.valorNum; break; case Protocol.FileTag.Permissions: attributesKnownFile.Permisions = (byte)ParameterReader.valorNum; break; case Protocol.FileTag.Comment: attributesKnownFile.Comment = ParameterReader.valorString; break; case Protocol.FileTag.Rating: attributesKnownFile.Rating = (byte)ParameterReader.valorNum; break; default: break; //faltan los parametros para las estadisticas.... } } if (!m_KnownMetList.ContainsKey(attributesKnownFile.FileName + (attributesKnownFile.Date.Ticks / 10000000L).ToString())) { m_KnownMetList.Add(attributesKnownFile.FileName + (attributesKnownFile.Date.Ticks / 10000000L).ToString(), attributesKnownFile); } } reader.Close(); knownmet.Close(); return(true); } catch (Exception e) { Debug.WriteLine(e.ToString()); if (showErrorMessage) { CLog.Log(Constants.Log.Notify, "Can not load known.met, hashing shared files"); } try { if (reader != null) { reader.Close(); } if (knownmet != null) { knownmet.Close(); } } catch {}; return(false); } }