示例#1
0
        // 获取数据信息
        private Types.VirtualDataInfo GetDataInfo(long pos)
        {
            Types.VirtualDataInfo res = new Types.VirtualDataInfo();
            res.Position = pos;

            using (dpz3.File.BinaryFile file = new File.BinaryFile(workPath, System.IO.FileMode.OpenOrCreate)) {
                file.Position = pos * Data_Info_Size;

                // 读取Sign
                try {
                    // 读取NextPosition
                    res.NextPosition  = file.Read();
                    res.NextPosition += file.Read() * 256;
                    res.NextPosition += file.Read() * 256 * 256;
                    res.NextPosition += file.Read() * 256 * 256 * 256;

                    // 读取FirstChildPosition
                    res.Length  = file.Read();
                    res.Length += file.Read() * 256;
                } catch (Exception ex) {
                    throw new Exception("磁盘数据损坏", ex);
                }
            }

            return(res);
        }
示例#2
0
        // 获取数据信息
        private void ReadData(ref Types.VirtualDataInfo info)
        {
            using (dpz3.File.BinaryFile file = new File.BinaryFile(workPath, System.IO.FileMode.OpenOrCreate)) {
                file.Position = info.Position * Data_Info_Size + 6;

                // 读取Sign
                try {
                    // 读取Data
                    info.Data = file.Read(info.Length);
                } catch (Exception ex) {
                    throw new Exception("磁盘数据损坏", ex);
                }
            }
        }
示例#3
0
        // 保存磁盘信息
        private void SaveDiskInfo()
        {
            using (dpz3.File.BinaryFile file = new File.BinaryFile(workPath, System.IO.FileMode.OpenOrCreate)) {
                file.Position = 0;

                // 输出Sign
                file.Write(diskInfo.Sign);

                // 输出Version
                file.Write(GetBytesFromInt(diskInfo.Version));

                // 输出DataBlocks
                file.Write(GetBytesFromLong(diskInfo.DataBlocks));
            }
        }
示例#4
0
        // 保存数据信息
        private void SaveDataInfo(Types.VirtualDataInfo info)
        {
            using (dpz3.File.BinaryFile file = new File.BinaryFile(workPath, System.IO.FileMode.OpenOrCreate)) {
                file.Position = info.Position * Data_Info_Size;

                // 读取Sign
                try {
                    // 输出NextPosition
                    file.Write(GetBytesFromLong(info.NextPosition));

                    // 输出Length
                    file.Write(GetBytesFromInt(info.Length));
                } catch (Exception ex) {
                    throw new Exception("磁盘数据损坏", ex);
                }
            }
        }
示例#5
0
        // 保存路径信息
        private void SavePathInfo(Types.VirtualPathInfo info)
        {
            using (dpz3.File.BinaryFile file = new File.BinaryFile(workPath, System.IO.FileMode.OpenOrCreate)) {
                file.Position = info.Position * Data_Info_Size;

                // 输出NextPosition
                file.Write(GetBytesFromLong(info.NextPosition));

                // 输出FirstChildPosition
                file.Write(GetBytesFromLong(info.FirstChildPosition));

                // 读取Type
                file.Write(new byte[] { info.Type });

                // 读取Name
                file.Write(info.Name);
            }
        }
示例#6
0
        // 加载磁盘信息
        private void LoadDiskInfo()
        {
            diskInfo      = new Types.VirtualDiskInfo();
            diskInfo.Sign = new byte[4];

            // 判断文件是否存在,不存在则创建
            if (System.IO.File.Exists(workPath))
            {
                using (dpz3.File.BinaryFile file = new File.BinaryFile(workPath, System.IO.FileMode.Open)) {
                    file.Position = 0;

                    // 读取Sign
                    if (!file.IsEnd)
                    {
                        diskInfo.Sign[0] = file.Read();
                    }
                    if (!file.IsEnd)
                    {
                        diskInfo.Sign[1] = file.Read();
                    }
                    if (!file.IsEnd)
                    {
                        diskInfo.Sign[2] = file.Read();
                    }
                    if (!file.IsEnd)
                    {
                        diskInfo.Sign[3] = file.Read();
                    }

                    if (System.Text.Encoding.ASCII.GetString(diskInfo.Sign) != "dvdk")
                    {
                        throw new Exception("磁盘数据损坏");
                    }

                    // 读取Version
                    if (!file.IsEnd)
                    {
                        diskInfo.Version = file.Read();
                    }
                    if (!file.IsEnd)
                    {
                        diskInfo.Version += file.Read() * 256;
                    }

                    // 读取DataBlocks
                    if (!file.IsEnd)
                    {
                        diskInfo.DataBlocks = file.Read();
                    }
                    if (!file.IsEnd)
                    {
                        diskInfo.DataBlocks += file.Read() * 256;
                    }
                    if (!file.IsEnd)
                    {
                        diskInfo.DataBlocks += file.Read() * 256 * 256;
                    }
                    if (!file.IsEnd)
                    {
                        diskInfo.DataBlocks += file.Read() * 256 * 256 * 256;
                    }
                }
            }
            else
            {
                diskInfo.Sign[0] = (byte)'d';
                diskInfo.Sign[1] = (byte)'v';
                diskInfo.Sign[2] = (byte)'d';
                diskInfo.Sign[3] = (byte)'k';

                diskInfo.Version    = 1;
                diskInfo.DataBlocks = 0;

                // 保存信息
                SaveDiskInfo();
            }
        }