예제 #1
0
 public static T GetValueEx <T>(this Wz_Node node, T defaultValue)
 {
     if (node == null)
     {
         return(defaultValue);
     }
     return(node.GetValue <T>(defaultValue));
 }
예제 #2
0
 public static T?GetValueEx <T>(this Wz_Node node) where T : struct
 {
     if (node == null)
     {
         return(null);
     }
     return(node.GetValue <T>());
 }
예제 #3
0
        public void GetDirTree(Wz_Node parent, bool useBaseWz = false, bool loadWzAsFolder = false)
        {
            List <string> dirs = new List <string>();
            string        name = null;
            int           size = 0;
            int           cs32 = 0;
            //int offs = 0;

            int count = ReadInt32();

            for (int i = 0; i < count; i++)
            {
                switch ((int)this.BReader.ReadByte())
                {
                case 0x02:
                    name = this.ReadStringAt(this.Header.HeaderSize + 1 + this.BReader.ReadInt32());
                    goto case 0xffff;

                case 0x04:
                    name = this.ReadString();
                    goto case 0xffff;

                case 0xffff:
                    size = this.ReadInt32();
                    cs32 = this.ReadInt32();
                    uint pos        = (uint)this.bReader.BaseStream.Position;
                    uint hashOffset = this.bReader.ReadUInt32();

                    Wz_Image img       = new Wz_Image(name, size, cs32, hashOffset, pos, this);
                    Wz_Node  childNode = parent.Nodes.Add(name);
                    childNode.Value = img;
                    img.OwnerNode   = childNode;

                    this.imageCount++;
                    break;

                case 0x03:
                    name = this.ReadString();
                    size = this.ReadInt32();
                    cs32 = this.ReadInt32();
                    this.FileStream.Position += 4;
                    dirs.Add(name);
                    break;
                }
            }

            int  dirCount       = dirs.Count;
            bool willLoadBaseWz = useBaseWz ? parent.Text.Equals("base.wz", StringComparison.OrdinalIgnoreCase) : false;

            var baseFolder = Path.GetDirectoryName(this.header.FileName);

            if (willLoadBaseWz && this.WzStructure.AutoDetectExtFiles)
            {
                for (int i = 0; i < dirCount; i++)
                {
                    //检测文件名
                    var m = Regex.Match(dirs[i], @"^([A-Za-z]+)$");
                    if (m.Success)
                    {
                        string wzTypeName = m.Result("$1");

                        //检测扩展wz文件
                        for (int fileID = 2; ; fileID++)
                        {
                            string extDirName = wzTypeName + fileID;
                            string extWzFile  = Path.Combine(baseFolder, extDirName + ".wz");
                            if (File.Exists(extWzFile))
                            {
                                if (!dirs.Take(dirCount).Any(dir => extDirName.Equals(dir, StringComparison.OrdinalIgnoreCase)))
                                {
                                    dirs.Add(extDirName);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        //检测KMST1058的wz文件
                        for (int fileID = 1; ; fileID++)
                        {
                            string extDirName = wzTypeName + fileID.ToString("D3");
                            string extWzFile  = Path.Combine(baseFolder, extDirName + ".wz");
                            if (File.Exists(extWzFile))
                            {
                                if (!dirs.Take(dirCount).Any(dir => extDirName.Equals(dir, StringComparison.OrdinalIgnoreCase)))
                                {
                                    dirs.Add(extDirName);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < dirs.Count; i++)
            {
                string  dir = dirs[i];
                Wz_Node t   = parent.Nodes.Add(dir);
                if (i < dirCount)
                {
                    GetDirTree(t, false);
                }

                if (t.Nodes.Count == 0)
                {
                    this.WzStructure.has_basewz |= willLoadBaseWz;

                    try
                    {
                        if (loadWzAsFolder)
                        {
                            string wzFolder = willLoadBaseWz ? Path.Combine(Path.GetDirectoryName(baseFolder), dir) : Path.Combine(baseFolder, dir);
                            if (Directory.Exists(wzFolder))
                            {
                                this.wzStructure.LoadWzFolder(wzFolder, ref t, false);
                                if (!willLoadBaseWz)
                                {
                                    var dirWzFile = t.GetValue <Wz_File>();
                                    dirWzFile.Type     = Wz_Type.Unknown;
                                    dirWzFile.isSubDir = true;
                                }
                            }
                        }
                        else if (willLoadBaseWz)
                        {
                            string filePath = Path.Combine(baseFolder, dir + ".wz");
                            if (File.Exists(filePath))
                            {
                                this.WzStructure.LoadFile(filePath, t, false, loadWzAsFolder);
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            parent.Nodes.Trim();
        }