コード例 #1
0
 private void OutputFile(Wz_File fileNew, Wz_File fileOld, Wz_Type type, List <CompareDifference> diffLst, string outputDir)
 {
     OutputFile(new List <Wz_File>()
     {
         fileNew
     },
                new List <Wz_File>()
     {
         fileOld
     },
                type,
                diffLst,
                outputDir);
 }
コード例 #2
0
        public static Wz_Node FindWz(Wz_Type type, Wz_File sourceWzFile)
        {
            FindWzEventArgs e = new FindWzEventArgs(type)
            {
                WzFile = sourceWzFile
            };

            if (WzFileFinding != null)
            {
                WzFileFinding(null, e);
                if (e.WzNode != null)
                {
                    return(e.WzNode);
                }
                if (e.WzFile != null)
                {
                    return(e.WzFile.Node);
                }
            }
            return(null);
        }
コード例 #3
0
        private void OutputFile(List <Wz_File> fileNew, List <Wz_File> fileOld, Wz_Type type, List <CompareDifference> diffLst, string outputDir)
        {
            string htmlFilePath = Path.Combine(outputDir, type.ToString() + ".html");

            for (int i = 1; File.Exists(htmlFilePath); i++)
            {
                htmlFilePath = Path.Combine(outputDir, string.Format("{0}_{1}.html", type, i));
            }
            string srcDirPath = Path.Combine(outputDir, Path.GetFileNameWithoutExtension(htmlFilePath) + "_files");

            if (OutputPng && !Directory.Exists(srcDirPath))
            {
                Directory.CreateDirectory(srcDirPath);
            }

            FileStream   htmlFile = null;
            StreamWriter sw       = null;

            StateInfo   = "正在努力对比文件..." + type;
            StateDetail = "正在构造输出文件";
            try
            {
                htmlFile = new FileStream(htmlFilePath, FileMode.Create, FileAccess.Write);
                sw       = new StreamWriter(htmlFile, Encoding.UTF8);
                sw.WriteLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
                sw.WriteLine("<html>");
                sw.WriteLine("<head>");
                sw.WriteLine("<meta http-equiv=\"content-type\" content=\"text/html;charset=utf-8\">");
                sw.WriteLine("<title>{0} {1}←{2}</title>", type, fileNew[0].Header.WzVersion, fileOld[0].Header.WzVersion);
                sw.WriteLine("<link type=\"text/css\" rel=\"stylesheet\" href=\"style.css\" />");
                sw.WriteLine("</head>");
                sw.WriteLine("<body>");
                //输出概况
                sw.WriteLine("<p class=\"wzf\">");
                sw.WriteLine("<table>");
                sw.WriteLine("<tr><th>&nbsp;</th><th>文件名</th><th>文件大小</th><th>文件版本</th></tr>");
                sw.WriteLine("<tr><td>新文件</td><td>{0}</td><td>{1}</td><td>{2}</td></tr>",
                             string.Join("<br/>", fileNew.Select(wzf => wzf.Header.FileName).ToArray()),
                             string.Join("<br/>", fileNew.Select(wzf => wzf.Header.FileSize.ToString("N0")).ToArray()),
                             string.Join("<br/>", fileNew.Select(wzf => wzf.Header.WzVersion.ToString()).ToArray())
                             );
                sw.WriteLine("<tr><td>旧文件</td><td>{0}</td><td>{1}</td><td>{2}</td></tr>",
                             string.Join("<br/>", fileOld.Select(wzf => wzf.Header.FileName).ToArray()),
                             string.Join("<br/>", fileOld.Select(wzf => wzf.Header.FileSize.ToString("N0")).ToArray()),
                             string.Join("<br/>", fileOld.Select(wzf => wzf.Header.WzVersion.ToString()).ToArray())
                             );
                sw.WriteLine("<tr><td>对比时间</td><td colspan='3'>{0:yyyy-MM-dd HH:mm:ss.fff}</td></tr>", DateTime.Now);
                sw.WriteLine("<tr><td>参数</td><td colspan='3'>{0}</td></tr>", string.Join("<br/>", new[] {
                    this.OutputPng ? "-OutputPng" : null,
                    this.OutputAddedImg ? "-OutputAddedImg" : null,
                    this.OutputRemovedImg ? "-OutputRemovedImg" : null,
                    "-PngComparison " + this.Comparer.PngComparison,
                    this.Comparer.ResolvePngLink ? "-ResolvePngLink" : null,
                }.Where(p => p != null)));
                sw.WriteLine("</table>");
                sw.WriteLine("</p>");

                //输出目录
                StringBuilder[] sb      = { new StringBuilder(), new StringBuilder(), new StringBuilder() };
                int[]           count   = new int[6];
                string[]        diffStr = { "修改", "新增", "移除" };
                foreach (CompareDifference diff in diffLst)
                {
                    int    idx    = -1;
                    string detail = null;
                    switch (diff.DifferenceType)
                    {
                    case DifferenceType.Changed:
                        idx    = 0;
                        detail = string.Format("<a name=\"m_{1}_{2}\" href=\"#a_{1}_{2}\">{0}</a>", diff.NodeNew.FullPathToFile, idx, count[idx]);
                        break;

                    case DifferenceType.Append:
                        idx = 1;
                        if (this.OutputAddedImg)
                        {
                            detail = string.Format("<a name=\"m_{1}_{2}\" href=\"#a_{1}_{2}\">{0}</a>", diff.NodeNew.FullPathToFile, idx, count[idx]);
                        }
                        else
                        {
                            detail = diff.NodeNew.FullPathToFile;
                        }
                        break;

                    case DifferenceType.Remove:
                        idx = 2;
                        if (this.OutputRemovedImg)
                        {
                            detail = string.Format("<a name=\"m_{1}_{2}\" href=\"#a_{1}_{2}\">{0}</a>", diff.NodeOld.FullPathToFile, idx, count[idx]);
                        }
                        else
                        {
                            detail = diff.NodeOld.FullPathToFile;
                        }
                        break;

                    default:
                        continue;
                    }
                    sb[idx].Append("<tr><td>");
                    sb[idx].Append(detail);
                    sb[idx].AppendLine("</td></tr>");
                    count[idx]++;
                }
                StateDetail = "正在输出目录";
                Array.Copy(count, 0, count, 3, 3);
                for (int i = 0; i < sb.Length; i++)
                {
                    sw.WriteLine("<table class=\"lst{0}\">", i);
                    sw.WriteLine("<tr><th>{0}共{1}项</th></tr>", diffStr[i], count[i]);
                    sw.Write(sb[i].ToString());
                    sw.WriteLine("</table>");
                    sb[i]    = null;
                    count[i] = 0;
                }

                foreach (CompareDifference diff in diffLst)
                {
                    switch (diff.DifferenceType)
                    {
                    case DifferenceType.Changed:
                    {
                        StateInfo = string.Format("{0}/{1}正在对比{2}", count[0], count[3], diff.NodeNew.FullPath);
                        Wz_Image imgNew, imgOld;
                        if ((imgNew = diff.ValueNew as Wz_Image) != null &&
                            ((imgOld = diff.ValueOld as Wz_Image) != null))
                        {
                            string anchorName     = "a_0_" + count[0];
                            string menuAnchorName = "m_0_" + count[0];
                            CompareImg(imgNew, imgOld, diff.NodeNew.FullPathToFile, anchorName, menuAnchorName, srcDirPath, sw);
                        }
                        count[0]++;
                    }
                    break;

                    case DifferenceType.Append:
                        if (this.OutputAddedImg)
                        {
                            StateInfo = string.Format("{0}/{1}正在输出新增{2}", count[1], count[4], diff.NodeNew.FullPath);
                            Wz_Image imgNew = diff.ValueNew as Wz_Image;
                            if (imgNew != null)
                            {
                                string anchorName     = "a_1_" + count[1];
                                string menuAnchorName = "m_1_" + count[1];
                                OutputImg(imgNew, diff.DifferenceType, diff.NodeNew.FullPathToFile, anchorName, menuAnchorName, srcDirPath, sw);
                            }
                            count[1]++;
                        }
                        break;

                    case DifferenceType.Remove:
                        if (this.OutputRemovedImg)
                        {
                            StateInfo = string.Format("{0}/{1}正在输出删除{2}", count[2], count[5], diff.NodeOld.FullPath);
                            Wz_Image imgOld = diff.ValueOld as Wz_Image;
                            if (imgOld != null)
                            {
                                string anchorName     = "a_2_" + count[2];
                                string menuAnchorName = "m_2_" + count[2];
                                OutputImg(imgOld, diff.DifferenceType, diff.NodeOld.FullPathToFile, anchorName, menuAnchorName, srcDirPath, sw);
                            }
                            count[2]++;
                        }
                        break;

                    case DifferenceType.NotChanged:
                        break;
                    }
                }
                //html结束
                sw.WriteLine("</body>");
                sw.WriteLine("</html>");
            }
            finally
            {
                try
                {
                    if (sw != null)
                    {
                        sw.Flush();
                        sw.Close();
                    }
                }
                catch
                {
                }
            }
        }
コード例 #4
0
        public void DetectWzType()
        {
            this.type = Wz_Type.Unknown;
            if (this.node == null)
            {
                return;
            }

            if (this.node.Nodes["smap.img"] != null ||
                this.node.Nodes["zmap.img"] != null)
            {
                this.type = Wz_Type.Base;
            }
            else if (this.node.Nodes["00002000.img"] != null ||
                     this.node.Nodes["Accessory"] != null ||
                     this.node.Nodes["Weapon"] != null)
            {
                this.type = Wz_Type.Character;
            }
            else if (this.node.Nodes["BasicEff.img"] != null ||
                     this.node.Nodes["SetItemInfoEff.img"] != null)
            {
                this.type = Wz_Type.Effect;
            }
            else if (this.node.Nodes["Commodity.img"] != null ||
                     this.node.Nodes["Curse.img"] != null)
            {
                this.type = Wz_Type.Etc;
            }
            else if (this.node.Nodes["Cash"] != null ||
                     this.node.Nodes["Consume"] != null)
            {
                this.type = Wz_Type.Item;
            }
            else if (this.node.Nodes["Back"] != null ||
                     this.node.Nodes["Obj"] != null ||
                     this.node.Nodes["Physics.img"] != null)
            {
                this.type = Wz_Type.Map;
            }
            else if (this.node.Nodes["PQuest.img"] != null ||
                     this.node.Nodes["QuestData"] != null)
            {
                this.type = Wz_Type.Quest;
            }
            else if (this.node.Nodes["Attacktype.img"] != null ||
                     this.node.Nodes["Recipe_9200.img"] != null)
            {
                this.type = Wz_Type.Skill;
            }
            else if (this.node.Nodes["Bgm00.img"] != null ||
                     this.node.Nodes["BgmUI.img"] != null)
            {
                this.type = Wz_Type.Sound;
            }
            else if (this.node.Nodes["MonsterBook.img"] != null ||
                     this.node.Nodes["EULA.img"] != null)
            {
                this.type = Wz_Type.String;
            }
            else if (this.node.Nodes["CashShop.img"] != null ||
                     this.node.Nodes["UIWindow.img"] != null)
            {
                this.type = Wz_Type.UI;
            }

            if (this.type == Wz_Type.Unknown) //用文件名来判断
            {
                string wzName = this.node.Text;

                Match m = Regex.Match(wzName, @"^([A-Za-z]+)(\d+)?(?:\.wz)?$");
                if (m.Success)
                {
                    wzName = m.Result("$1");
                }

                try
                {
                    this.type = (Wz_Type)Enum.Parse(typeof(Wz_Type), wzName, true);
                }
                catch
                {
                    this.type = Wz_Type.Unknown;
                }
            }
        }
コード例 #5
0
ファイル: Wz_File.cs プロジェクト: CCCCCCCCZ/WzComparerR2
        public void DetectWzType()
        {
            this.type = Wz_Type.Unknown;
            if (this.node == null)
            {
                return;
            }
            if (this.node.Nodes.Count < 100)
            {
                foreach (Wz_Node subNode in this.node.Nodes)
                {
                    switch (subNode.Text)
                    {
                    case "smap.img":
                    case "zmap.img":
                        this.type = Wz_Type.Base;
                        break;

                    case "00002000.img":
                    case "Accessory":
                    case "Weapon":
                        this.type = Wz_Type.Character;
                        break;

                    case "BasicEff.img":
                    case "SetItemInfoEff.img":
                        this.type = Wz_Type.Effect;
                        break;

                    case "Commodity.img":
                    case "Curse.img":
                        this.type = Wz_Type.Etc;
                        break;

                    case "Cash":
                    case "Consume":
                        this.type = Wz_Type.Item;
                        break;

                    case "Back":
                    case "Physics.img":
                        this.type = Wz_Type.Map;
                        break;

                    case "PQuest.img":
                    case "QuestData":
                        this.type = Wz_Type.Quest;
                        break;

                    case "Attacktype.img":
                    case "MobSkill.img":
                        this.type = Wz_Type.Skill;
                        break;

                    case "Bgm00.img":
                    case "BgmUI.img":
                        this.type = Wz_Type.Sound;
                        break;

                    case "MonsterBook.img":
                    case "EULA.img":
                        this.type = Wz_Type.String;
                        break;

                    case "CashShop.img":
                    case "UIWindow.img":
                        this.type = Wz_Type.UI;
                        break;
                    }
                    if (this.type != Wz_Type.Unknown)
                    {
                        return;
                    }
                }
            }

            if (this.type == Wz_Type.Unknown) //用文件名来判断
            {
                string wzName = this.node.Text;

                Match m = Regex.Match(wzName, @"^([A-Za-z]+)\d+(?:\.wz)?$");
                if (m.Success)
                {
                    wzName = m.Result("$1");
                }

                try
                {
                    this.type = (Wz_Type)Enum.Parse(typeof(Wz_Type), wzName, true);
                }
                catch
                {
                    this.type = Wz_Type.Unknown;
                }
            }
        }
コード例 #6
0
 public FindWzEventArgs(Wz_Type type)
 {
     this.wzType = type;
 }
コード例 #7
0
 /// <summary>
 /// 为CharaSim组件提供全局的搜索Wz_File的方法。
 /// </summary>
 /// <param Name="Type">要搜索wz文件的Wz_Type。</param>
 /// <returns></returns>
 public static Wz_Node FindWz(Wz_Type type)
 {
     return(FindWz(type, null));
 }