Beispiel #1
0
 //将新数据存入存储块
 public void SaveData(char[] newData)
 {
     if (type == 0)
     {
         Data = newData;
     }
     else
     {
         if (Blocks.Count == 0 || Blocks[Blocks.Count - 1].IsFull())
         {
             var freeBlocks = VFS.GetFreeBlocks(1);
             var freeBlock  = (Block)freeBlocks[0];
             freeBlock.SetType(type - 1);
             freeBlock.SaveData(newData);
             Blocks.Add(freeBlock);
         }
         else
         {
             Blocks[Blocks.Count - 1].SaveData(newData);
         }
     }
 }
Beispiel #2
0
        public void Save(String content)
        {
            MTime = Utils.GetUnixTimeStamp();

            ClearBlock();

            char[] contents = content.ToCharArray();

            int length = contents.GetLength(0);

            if (length == 0)
            {
                return;
            }

            int num = length / (int)Configs.BLOCK_SIZE + 1;

            ArrayList freeBlocks = VFS.GetFreeBlocks(15);

            for (int i = 0; i < Math.Min(12, num); i++)
            {
                Blocks[i] = freeBlocks[i] as Block;
                Blocks[i].SetType(0);
            }

            if (num > 12)
            {
                Blocks[12] = freeBlocks[12] as Block;
                Blocks[12].SetType(1);
            }

            if (num > 12 + Configs.BLOCK_SIZE)
            {
                Blocks[13] = freeBlocks[13] as Block;
                Blocks[13].SetType(2);
            }

            if (num > 12 + Configs.BLOCK_SIZE + Configs.BLOCK_SIZE * Configs.BLOCK_SIZE)
            {
                Blocks[14] = freeBlocks[14] as Block;
                Blocks[14].SetType(3);
            }


            int currentIndex = 0;

            for (int i = 0; i < num; i++)
            {
                long   realBlockSize = Math.Min(Configs.BLOCK_SIZE, length - i * Configs.BLOCK_SIZE);
                char[] contentSeq    = new char[realBlockSize];
                Array.Copy(contents, Configs.BLOCK_SIZE * i, contentSeq, 0, realBlockSize);

                if (currentIndex < 12)
                {
                    Blocks[currentIndex].SaveData(contentSeq);
                    currentIndex++;
                }
                else
                {
                    Blocks[currentIndex].SaveData(contentSeq);
                    if (Blocks[currentIndex].IsFull())
                    {
                        currentIndex++;
                    }
                }
            }
        }