예제 #1
0
        // 获取路径信息
        private Types.VirtualPathInfo GetPathInfo(long pos)
        {
            Types.VirtualPathInfo res = new Types.VirtualPathInfo();
            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.FirstChildPosition  = file.Read();
                    res.FirstChildPosition += file.Read() * 256;
                    res.FirstChildPosition += file.Read() * 256 * 256;
                    res.FirstChildPosition += file.Read() * 256 * 256 * 256;

                    // 读取Type
                    res.Type = file.Read();

                    // 读取Name
                    res.Name = file.Read(Path_Name_Size);
                } 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 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();
            }
        }