Exemple #1
0
 /// <summary>
 /// 保存索引信息。
 /// </summary>
 public override void SaveIndexInfo()
 {
     lock (m_locker)
     {
         uint indexPosition = (uint)m_fileStream.Position;
         var  indexInfos    = new List <Byte>();
         foreach (var item in m_fileIndexes)
         {
             indexInfos.AddRange(item.Value.GetEncodeData());
         }
         foreach (var item in m_deletedIndexes)
         {
             indexInfos.AddRange(item.GetEncodeData());
         }
         var indexInfo = indexInfos.ToArray();
         if (indexInfo.Length > 0)
         {
             indexInfo = DESCrypto.Encrypt(indexInfo, m_number); //加密索引数据
         }
         m_fileStream.Position = m_packageInfo.IndexOffset;      //将文件偏移重置为索引偏移起始位置
         m_fileStream.Write(indexInfo, 0, indexInfo.Length);
         m_fileStream.Flush();
         SavePackageInfo(m_fileStream);
         m_fileStream.Position = indexPosition;
     }
 }
 public void SaveIndexInfo()
 {
     lock (m_locker)
     {
         uint        position = (uint)this.m_fileStream.Position;
         List <byte> list     = new List <byte>();
         foreach (KeyValuePair <string, IndexInfo> pair in this.m_fileIndexes)
         {
             list.AddRange(pair.Value.GetEncodeData());
         }
         foreach (IndexInfo info in this.m_deletedIndexes)
         {
             list.AddRange(info.GetEncodeData());
         }
         byte[] toEncrypt = list.ToArray();
         if (toEncrypt.Length > 0)
         {
             toEncrypt = DESCrypto.Encrypt(toEncrypt, this.m_number);
         }
         this.m_fileStream.Position = this.m_packageInfo.IndexOffset;
         this.m_fileStream.Write(toEncrypt, 0, toEncrypt.Length);
         this.m_fileStream.Flush();
         this.SavePackageInfo(this.m_fileStream);
         this.m_fileStream.Position = position;
     }
 }
Exemple #3
0
        private void LoadIndexInfo(Byte[] indexData, bool needBackUpIndex)
        {
            if (indexData.Length > 0)
            {
                if (needBackUpIndex)
                {
                    BackupIndexInfo(indexData);
                }
                indexData = DESCrypto.Decrypt(indexData, m_number);//解密索引数据
            }

            m_deletedIndexes.Clear();
            m_fileIndexes.Clear();
            var index = 0;

            while (index < indexData.Length)
            {
                var info = IndexInfo.Decode(indexData, ref index);
                if (info.Deleted)
                {
                    m_deletedIndexes.Add(info);
                }
                else
                {
                    m_fileIndexes[info.Id.PathNormalize()] = info;
                }
            }

            m_memoryStream.Position = m_packageInfo.IndexOffset;//重置回文件信息结尾处
        }
        private void LoadIndexInfo(byte[] indexData, bool needBackUpIndex)
        {
            if (indexData.Length > 0)
            {
                if (needBackUpIndex)
                {
                    this.BackupIndexInfo(indexData);
                }
                indexData = DESCrypto.Decrypt(indexData, this.m_number);
            }
            this.m_deletedIndexes.Clear();
            this.m_fileIndexes.Clear();
            int offset = 0;

            while (offset < indexData.Length)
            {
                IndexInfo item = IndexInfo.Decode(indexData, ref offset);
                if (item.Deleted)
                {
                    this.m_deletedIndexes.Add(item);
                }
                else
                {
                    this.m_fileIndexes[item.Id.PathNormalize()] = item;
                }
            }
            this.m_fileStream.Position = this.m_packageInfo.IndexOffset;
        }