예제 #1
0
        // 添加一个所属记录
        private void AddToParentPath(Types.VirtualPathInfo parent, long posInfo)
        {
            // 父对象为根目录,且当前位置为1时,不保存直接退出
            if (parent.Type == Path_Type_Root && posInfo == 1)
            {
                return;
            }

            // 指针移向子路径
            long pos = parent.FirstChildPosition;

            // 当父路径中无子路径时,直接设置FirstChildPosition
            if (pos == 0)
            {
                parent.FirstChildPosition = posInfo;
                SavePathInfo(parent);
                return;
            }

            while (pos > 0)
            {
                // 读取对应路径的路径信息
                var info = GetPathInfo(pos);

                // 判断是否为最后一个子目录
                pos = info.NextPosition;
                if (info.NextPosition == 0)
                {
                    info.NextPosition = posInfo;
                    SavePathInfo(info);
                }
            }
        }
예제 #2
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);
        }
예제 #3
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);
            }
        }
예제 #4
0
        // 获取路径寻址
        private Types.VirtualPathInfo GetPathInfo(Types.VirtualPathInfo parent, string name)
        {
            long pos = parent.FirstChildPosition;

            while (pos > 0)
            {
                // 读取对应路径的路径信息
                var info = GetPathInfo(pos);

                // 生成名称
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < Path_Name_Size; i += 2)
                {
                    int code = info.Name[i] + info.Name[i + 1] * 256;

                    if (code > 0)
                    {
                        sb.Append((char)code);
                    }
                    else
                    {
                        break;
                    }
                }
                string pName = sb.ToString();

                // 判断名称是否匹配
                if (pName == name)
                {
                    return(info);
                }
                else
                {
                    // 对比下一个路径
                    pos = info.NextPosition;
                }
            }

            return(new Types.VirtualPathInfo());
        }
예제 #5
0
        // 获取路径信息
        private Types.VirtualPathInfo GetPathInfo(string path)
        {
            // 判断路径是否为空
            if (path.IsNoneOrNull())
            {
                throw new Exception("尚未指定父路径");
            }

            // 定义路径信息
            Types.VirtualPathInfo info = new Types.VirtualPathInfo();
            info.Position           = 0;
            info.Type               = Path_Type_Root;
            info.FirstChildPosition = 1;

            // 当路径为根路径时,直接返回一个Root的特有信息
            if (path == "/")
            {
                return(info);
            }

            // 获取所有的子路径
            string parentPath = GetParentFolder(path);
            var    parentInfo = GetPathInfo(parentPath);

            // 当类型为空时,表示路径不存在,则直接返回空信息
            if (parentInfo.Type == 0)
            {
                return(parentInfo);
            }
            if ((parentInfo.Type & Path_Type_File) == Path_Type_File)
            {
                throw new Exception($"路径\"{parentPath}\"不是目录");
            }

            // 获取路径名称信息
            string name = GetName(path);

            return(GetPathInfo(parentInfo, name));
        }