Example #1
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;//重置回文件信息结尾处
        }
Example #2
0
        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;
        }
Example #3
0
 public static void DecompressToMogoFileAndDirectory(string targetPath, string zipFilePath)
 {
     if (File.Exists(zipFilePath))
     {
         FileStream baseInputStream = File.OpenRead(zipFilePath);
         MogoFileSystem.Instance.Open();
         MogoFileSystem.Instance.GetAndBackUpIndexInfo();
         using (ZipInputStream stream2 = new ZipInputStream(baseInputStream))
         {
             ZipEntry entry;
             while ((entry = stream2.GetNextEntry()) != null)
             {
                 if (!entry.IsDirectory)
                 {
                     string name = entry.Name;
                     if (!string.IsNullOrEmpty(name))
                     {
                         int    num;
                         byte[] buffer = new byte[0x800];
                         if (name.EndsWith(".u"))
                         {
                             name = Path.Combine(targetPath, name);
                             string directoryName = Path.GetDirectoryName(name);
                             if (!(string.IsNullOrEmpty(directoryName) || Directory.Exists(directoryName)))
                             {
                                 Directory.CreateDirectory(directoryName);
                             }
                             using (FileStream stream3 = File.Create(name))
                             {
                                 while ((num = stream2.Read(buffer, 0, buffer.Length)) > 0)
                                 {
                                     stream3.Write(buffer, 0, num);
                                 }
                             }
                         }
                         else
                         {
                             IndexInfo info = MogoFileSystem.Instance.BeginSaveFile(name, entry.Size);
                             while ((num = stream2.Read(buffer, 0, buffer.Length)) > 0)
                             {
                                 MogoFileSystem.Instance.WriteFile(info, buffer, 0, num);
                             }
                             MogoFileSystem.Instance.EndSaveFile(info);
                         }
                     }
                 }
             }
         }
         MogoFileSystem.Instance.SaveIndexInfo();
         MogoFileSystem.Instance.CleanBackUpIndex();
         MogoFileSystem.Instance.Close();
     }
     else
     {
         LoggerHelper.Error("Zip file not exist: " + zipFilePath, true);
     }
 }
Example #4
0
        public static byte[] Encode(IndexInfo info)
        {
            var result = new List <byte>();

            result.AddRange(EncodeDecoder.EncodeString(info.Id));
            result.AddRange(EncodeDecoder.EncodeString(info.FileName));
            result.AddRange(EncodeDecoder.EncodeString(info.Path));
            result.AddRange(EncodeDecoder.EncodeUInt32(info.Offset));
            result.AddRange(EncodeDecoder.EncodeUInt32(info.Length));
            result.AddRange(EncodeDecoder.EncodeUInt32(info.PageLength));
            result.AddRange(EncodeDecoder.EncodeBoolean(info.Deleted));
            return(result.ToArray());
        }
Example #5
0
        public static IndexInfo Decode(byte[] data, ref int offset)
        {
            var info = new IndexInfo();

            info.Id         = EncodeDecoder.DecodeString(data, ref offset);
            info.FileName   = EncodeDecoder.DecodeString(data, ref offset);
            info.Path       = EncodeDecoder.DecodeString(data, ref offset);
            info.Offset     = EncodeDecoder.DecodeUInt32(data, ref offset);
            info.Length     = EncodeDecoder.DecodeUInt32(data, ref offset);
            info.PageLength = EncodeDecoder.DecodeUInt32(data, ref offset);
            info.Deleted    = EncodeDecoder.DecodeBoolean(data, ref offset);
            return(info);
        }
Example #6
0
 public void WriteFile(IndexInfo info, byte[] buffer, int offset, int count)
 {
     info.Length += (uint)count;
     if (this.m_encodeData)
     {
         this.m_bitCryto.Reset();
         int length = buffer.Length;
         for (int i = 0; i < length; i++)
         {
             buffer[i] = this.m_bitCryto.Encode(buffer[i]);
         }
     }
     this.m_fileStream.Write(buffer, offset, count);
 }
Example #7
0
 /// <summary>
 /// 写入文件信息。
 /// </summary>
 /// <param name="info"></param>
 /// <param name="buffer"></param>
 /// <param name="offset"></param>
 /// <param name="count"></param>
 public override void WriteFile(IndexInfo info, Byte[] buffer, int offset, int count)
 {
     info.Length += (uint)count;
     if (m_encodeData)
     {
         m_bitCryto.Reset();
         int len = buffer.Length;
         for (int i = 0; i < len; ++i)
         {
             buffer[i] = m_bitCryto.Encode(buffer[i]);
         }
     }
     m_memoryStream.Write(buffer, offset, count);
 }
Example #8
0
 public void DeleteFile(string fileFullName)
 {
     lock (m_locker)
     {
         fileFullName = fileFullName.PathNormalize();
         if (this.m_fileIndexes.ContainsKey(fileFullName))
         {
             IndexInfo item = this.m_fileIndexes[fileFullName];
             item.Deleted = true;
             item.Id      = "";
             this.m_fileIndexes.Remove(fileFullName);
             this.m_deletedIndexes.Add(item);
         }
     }
 }
Example #9
0
        /// <summary>
        /// 开始存储文件。
        /// </summary>
        /// <param name="fileFullName"></param>
        /// <param name="fileSize"></param>
        /// <returns></returns>
        public override IndexInfo BeginSaveFile(string fileFullName, long fileSize)
        {
            IndexInfo info;

            lock (m_locker)
            {
                fileFullName = fileFullName.PathNormalize();
                if (m_fileIndexes.ContainsKey(fileFullName))//文件已存在
                {
                    var fileInfo = m_fileIndexes[fileFullName];
                    if (fileSize > fileInfo.PageLength)//新文件大小超出预留页大小
                    {
                        DeleteFile(fileFullName);

                        info = new IndexInfo()
                        {
                            Id = fileFullName, FileName = fileInfo.FileName, Path = fileInfo.Path, Offset = m_packageInfo.IndexOffset, FileState = FileState.New
                        };
                        m_fileStream.Position       = m_packageInfo.IndexOffset;
                        m_fileIndexes[fileFullName] = info;
                    }
                    else//新文件大小没有超出预留页大小
                    {
                        info                  = fileInfo;
                        info.Length           = 0;
                        info.FileState        = FileState.Modify;
                        m_fileStream.Position = info.Offset;
                    }
                }
                else//文件不存在,在索引最后新建
                {
                    info = new IndexInfo()
                    {
                        Id        = fileFullName,
                        FileName  = Path.GetFileName(fileFullName),
                        Path      = Path.GetDirectoryName(fileFullName),
                        Offset    = m_packageInfo.IndexOffset,
                        FileState = FileState.New
                    };
                    m_fileStream.Position       = m_packageInfo.IndexOffset;
                    m_fileIndexes[fileFullName] = info;
                }
            }
            return(info);
        }
Example #10
0
 public void SaveFile(string fileFullName)
 {
     if (File.Exists(fileFullName))
     {
         FileInfo  info   = new FileInfo(fileFullName);
         IndexInfo info2  = this.BeginSaveFile(fileFullName, info.Length);
         byte[]    buffer = new byte[0x800];
         using (FileStream stream = File.OpenRead(fileFullName))
         {
             int num;
             while ((num = stream.Read(buffer, 0, buffer.Length)) > 0)
             {
                 this.WriteFile(info2, buffer, 0, num);
             }
         }
         this.EndSaveFile(info2);
     }
 }
Example #11
0
        private byte[] DoLoadFile(string fileFullName)
        {
            IndexInfo info = this.m_fileIndexes[fileFullName];

            byte[] buffer = new byte[info.Length];
            this.m_fileStream.Position = info.Offset;
            this.m_fileStream.Read(buffer, 0, buffer.Length);
            if (this.m_encodeData)
            {
                this.m_bitCryto.Reset();
                int length = buffer.Length;
                for (int i = 0; i < length; i++)
                {
                    buffer[i] = this.m_bitCryto.Decode(buffer[i]);
                }
            }
            return(buffer);
        }
Example #12
0
        public IndexInfo BeginSaveFile(string fileFullName, long fileSize)
        {
            IndexInfo info;

            lock (m_locker)
            {
                fileFullName = fileFullName.PathNormalize();
                if (this.m_fileIndexes.ContainsKey(fileFullName))
                {
                    IndexInfo info2 = this.m_fileIndexes[fileFullName];
                    if (fileSize > info2.PageLength)
                    {
                        this.DeleteFile(fileFullName);
                        info = new IndexInfo {
                            Id        = fileFullName,
                            FileName  = info2.FileName,
                            Path      = info2.Path,
                            Offset    = this.m_packageInfo.IndexOffset,
                            FileState = FileState.New
                        };
                        this.m_fileStream.Position       = this.m_packageInfo.IndexOffset;
                        this.m_fileIndexes[fileFullName] = info;
                        return(info);
                    }
                    info                       = info2;
                    info.Length                = 0;
                    info.FileState             = FileState.Modify;
                    this.m_fileStream.Position = info.Offset;
                    return(info);
                }
                info = new IndexInfo {
                    Id        = fileFullName,
                    FileName  = Path.GetFileName(fileFullName),
                    Path      = Path.GetDirectoryName(fileFullName),
                    Offset    = this.m_packageInfo.IndexOffset,
                    FileState = FileState.New
                };
                this.m_fileStream.Position       = this.m_packageInfo.IndexOffset;
                this.m_fileIndexes[fileFullName] = info;
            }
            return(info);
        }
Example #13
0
 public void EndSaveFile(IndexInfo info)
 {
     lock (m_locker)
     {
         uint num = info.Length % 0x200;
         if (num != 0)
         {
             uint   num2   = 0x200 - num;
             byte[] buffer = new byte[num2];
             this.m_fileStream.Write(buffer, 0, buffer.Length);
             info.PageLength = info.Length + num2;
         }
         else
         {
             info.PageLength = info.Length;
         }
         this.m_fileStream.Flush();
         if (info.FileState == FileState.New)
         {
             this.m_packageInfo.IndexOffset = (uint)this.m_fileStream.Position;
         }
     }
 }
Example #14
0
        /// <summary>
        /// 存储文件结束。
        /// </summary>
        /// <param name="info"></param>
        public override void EndSaveFile(IndexInfo info)
        {
            lock (m_locker)
            {
                var leftSize = info.Length % m_pageSize;
                if (leftSize != 0)
                {
                    var empty     = m_pageSize - leftSize;
                    var emptyData = new Byte[empty];
                    m_memoryStream.Write(emptyData, 0, emptyData.Length);
                    info.PageLength = info.Length + empty;
                }
                else
                {
                    info.PageLength = info.Length;
                }

                m_memoryStream.Flush();
                if (info.FileState == FileState.New)//修改状态不用修改索引偏移
                {
                    m_packageInfo.IndexOffset = (uint)m_memoryStream.Position;
                }
            }
        }
Example #15
0
 /// <summary>
 /// 写入文件信息。
 /// </summary>
 /// <param name="info"></param>
 /// <param name="buffer"></param>
 /// <param name="offset"></param>
 /// <param name="count"></param>
 public void WriteFile(IndexInfo info, Byte[] buffer, int offset, int count)
 {
     info.Length += (uint)count;
     if (m_encodeData)
     {
         m_bitCryto.Reset();
         int len = buffer.Length;
         for (int i = 0; i < len; ++i)
         {
             buffer[i] = m_bitCryto.Encode(buffer[i]);
         }
     }
     m_fileStream.Write(buffer, offset, count);
 }
Example #16
0
        /// <summary>
        /// 存储文件结束。
        /// </summary>
        /// <param name="info"></param>
        public void EndSaveFile(IndexInfo info)
        {
            lock (m_locker)
            {
                var leftSize = info.Length % m_pageSize;
                if (leftSize != 0)
                {
                    var empty = m_pageSize - leftSize;
                    var emptyData = new Byte[empty];
                    m_fileStream.Write(emptyData, 0, emptyData.Length);
                    info.PageLength = info.Length + empty;
                }
                else
                    info.PageLength = info.Length;

                m_fileStream.Flush();
                if (info.FileState == FileState.New)//修改状态不用修改索引偏移
                    m_packageInfo.IndexOffset = (uint)m_fileStream.Position;
            }
        }
Example #17
0
 /// <summary>
 /// 存储文件结束。
 /// </summary>
 /// <param name="info"></param>
 public abstract void EndSaveFile(IndexInfo info);
Example #18
0
 /// <summary>
 /// 写入文件信息。
 /// </summary>
 /// <param name="info"></param>
 /// <param name="buffer"></param>
 /// <param name="offset"></param>
 /// <param name="count"></param>
 public abstract void WriteFile(IndexInfo info, Byte[] buffer, int offset, int count);
Example #19
0
 public static byte[] Encode(IndexInfo info)
 {
     var result = new List<byte>();
     result.AddRange(EncodeDecoder.EncodeString(info.Id));
     result.AddRange(EncodeDecoder.EncodeString(info.FileName));
     result.AddRange(EncodeDecoder.EncodeString(info.Path));
     result.AddRange(EncodeDecoder.EncodeUInt32(info.Offset));
     result.AddRange(EncodeDecoder.EncodeUInt32(info.Length));
     result.AddRange(EncodeDecoder.EncodeUInt32(info.PageLength));
     result.AddRange(EncodeDecoder.EncodeBoolean(info.Deleted));
     return result.ToArray();
 }
Example #20
0
 public static IndexInfo Decode(byte[] data, ref int offset)
 {
     var info = new IndexInfo();
     info.Id = EncodeDecoder.DecodeString(data, ref offset);
     info.FileName = EncodeDecoder.DecodeString(data, ref offset);
     info.Path = EncodeDecoder.DecodeString(data, ref offset);
     info.Offset = EncodeDecoder.DecodeUInt32(data, ref offset);
     info.Length = EncodeDecoder.DecodeUInt32(data, ref offset);
     info.PageLength = EncodeDecoder.DecodeUInt32(data, ref offset);
     info.Deleted = EncodeDecoder.DecodeBoolean(data, ref offset);
     return info;
 }
Example #21
0
        /// <summary>
        /// 开始存储文件。
        /// </summary>
        /// <param name="fileFullName"></param>
        /// <param name="fileSize"></param>
        /// <returns></returns>
        public IndexInfo BeginSaveFile(string fileFullName, long fileSize)
        {
            IndexInfo info;
            lock (m_locker)
            {
                fileFullName = fileFullName.PathNormalize();
                if (m_fileIndexes.ContainsKey(fileFullName))//文件已存在
                {
                    var fileInfo = m_fileIndexes[fileFullName];
                    if (fileSize > fileInfo.PageLength)//新文件大小超出预留页大小
                    {
                        DeleteFile(fileFullName);

                        info = new IndexInfo() { Id = fileFullName, FileName = fileInfo.FileName, Path = fileInfo.Path, Offset = m_packageInfo.IndexOffset, FileState = FileState.New };
                        m_fileStream.Position = m_packageInfo.IndexOffset;
                        m_fileIndexes[fileFullName] = info;
                    }
                    else//新文件大小没有超出预留页大小
                    {
                        info = fileInfo;
                        info.Length = 0;
                        info.FileState = FileState.Modify;
                        m_fileStream.Position = info.Offset;
                    }
                }
                else//文件不存在,在索引最后新建
                {
                    info = new IndexInfo()
                    {
                        Id = fileFullName,
                        FileName = Path.GetFileName(fileFullName),
                        Path = Path.GetDirectoryName(fileFullName),
                        Offset = m_packageInfo.IndexOffset,
                        FileState = FileState.New
                    };
                    m_fileStream.Position = m_packageInfo.IndexOffset;
                    m_fileIndexes[fileFullName] = info;
                }
            }
            return info;
        }