Skip to content

Commit

Permalink
Comparer: ResolvePngLink optimized, bug fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kagamia committed May 18, 2017
1 parent 57e0991 commit 5cc6402
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 30 deletions.
13 changes: 6 additions & 7 deletions WzComparerR2/Comparer/EasyComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ private void OutputFile(List<Wz_File> fileNew, List<Wz_File> fileOld, Wz_Type ty
sw.WriteLine("<tr><th>{0}共{1}项</th></tr>", diffStr[i], count[i]);
sw.Write(sb[i].ToString());
sw.WriteLine("</table>");
sw.WriteLine("<br />");
sb[i] = null;
count[i] = 0;
}
Expand Down Expand Up @@ -381,13 +380,13 @@ private void CompareImg(Wz_Image imgNew, Wz_Image imgOld, string imgName, string
count[idx]++;
}
StateDetail = "正在输出对比报告";
sw.WriteLine("<table class=\"img\">");
sw.WriteLine("<tr><th class=\"{5}\" colspan=\"3\"><a name=\"{1}\">{0}</a> 修改:{2} 新增:{3} 移除:{4}</th></tr>",
imgName, anchorName, count[0], count[1], count[2], count.Any(c => c > 0) ? "" : "noChange");
bool noChange = diffList.Count <= 0;
sw.WriteLine("<table class=\"img{0}\">", noChange ? " noChange" : "");
sw.WriteLine("<tr><th colspan=\"3\"><a name=\"{1}\">{0}</a> 修改:{2} 新增:{3} 移除:{4}</th></tr>",
imgName, anchorName, count[0], count[1], count[2]);
sw.WriteLine(sb.ToString());
sw.WriteLine("<tr><td colspan=\"3\"><a href=\"#{1}\">{0}</a></td></tr>", "回到目录", menuAnchorName);
sw.WriteLine("</table>");
sw.WriteLine("<br />");
imgNew.Unextract();
imgOld.Unextract();
sb = null;
Expand Down Expand Up @@ -439,7 +438,6 @@ private void OutputImg(Wz_Image img, DifferenceType diffType, string imgName, st
fnOutput(img.Node);
sw.WriteLine("<tr><td colspan=\"2\"><a href=\"#{1}\">{0}</a></td></tr>", "回到目录", menuAnchorName);
sw.WriteLine("</table>");
sw.WriteLine("<br />");
img.Unextract();
}

Expand Down Expand Up @@ -511,15 +509,16 @@ public virtual void CreateStyleSheet(string outputDir)
sw.WriteLine("body { font-size:12px; }");
sw.WriteLine("p.wzf { }");
sw.WriteLine("table, tr, th, td { border:1px solid #ff8000; border-collapse:collapse; }");
sw.WriteLine("table { margin-bottom:16px; }");
sw.WriteLine("th { text-align:left; }");
sw.WriteLine("th.noChange { color:#aaa; }");
sw.WriteLine("table.lst0 { }");
sw.WriteLine("table.lst1 { }");
sw.WriteLine("table.lst2 { }");
sw.WriteLine("table.img { }");
sw.WriteLine("table.img tr.r0 { background-color:#fff4c4; }");
sw.WriteLine("table.img tr.r1 { background-color:#ebf2f8; }");
sw.WriteLine("table.img tr.r2 { background-color:#ffffff; }");
sw.WriteLine("table.img.noChange { display:none; }");
sw.Flush();
sw.Close();
}
Expand Down
82 changes: 65 additions & 17 deletions WzComparerR2/Comparer/WzFileComparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ private IEnumerable<CompareDifference> CompareSortedNodes(IList<ComparableNode>
{
ComparableNode nodeNew = arrayNew[l],
nodeOld = arrayOld[r];
bool linkNew = IsLinkedPng(nodeNew),
linkOld = IsLinkedPng(nodeOld);
PngLinkInfo linkInfoNew, linkInfoOld;
bool linkNew = TryGetLink(nodeNew, out linkInfoNew),
linkOld = TryGetLink(nodeOld, out linkInfoOld);

if (linkNew && !linkOld && nodeOld.Value is Wz_Png) //图片转化为link
{
Expand Down Expand Up @@ -214,19 +215,27 @@ private IEnumerable<CompareDifference> CompareSortedNodes(IList<ComparableNode>
}
else if (linkNew && linkOld) //两边都是link
{
var newPng = GetLinkedPng(nodeNew.LinkNode);
var oldPng = GetLinkedPng(nodeOld.LinkNode);
if (newPng != null && oldPng != null)
if (linkInfoNew.LinkType == linkInfoOld.LinkType
&& linkInfoNew.LinkUrl == linkInfoOld.LinkUrl) //link没有变动
{
if (newPng != oldPng && !CompareData(newPng, oldPng)) //对比有差异 不输出dummy
{
//yield return new CompareDifference(nodeNew.LinkNode, nodeOld.LinkNode, DifferenceType.Changed);
}
else
compared = true;
}
else
{
var newPng = GetLinkedPng(nodeNew.LinkNode);
var oldPng = GetLinkedPng(nodeOld.LinkNode);
if (newPng != null && oldPng != null)
{
linkFilter = true;
if (newPng != oldPng && !CompareData(newPng, oldPng)) //对比有差异 不输出dummy
{
//yield return new CompareDifference(nodeNew.LinkNode, nodeOld.LinkNode, DifferenceType.Changed);
}
else
{
linkFilter = true;
}
compared = true;
}
compared = true;
}
}
}
Expand Down Expand Up @@ -288,12 +297,26 @@ private bool CompareChild(ComparableNode node1, ComparableNode node2)
return true;
}

private bool IsLinkedPng(ComparableNode node)
private bool TryGetLink(ComparableNode node, out PngLinkInfo linkInfo)
{
linkInfo = new PngLinkInfo();
var png = node.Value as Wz_Png;
if (png != null && png.Width == 1 && png.Height == 1)
{
return node.Children.Any(child => child.Name == "_inlink" || child.Name == "_outlink");
var node1 = node.LinkNode;
WzLib.Wz_Node linkNode;
if ((linkNode = node1.Nodes["_inlink"]) != null)
{
linkInfo.LinkType = PngLinkType.Inlink;
linkInfo.LinkUrl = linkNode.GetValue<string>();
return true;
}
else if ((linkNode = node1.Nodes["_outlink"]) != null)
{
linkInfo.LinkType = PngLinkType.Inlink;
linkInfo.LinkUrl = linkNode.GetValue<string>();
return true;
}
}
return false;
}
Expand All @@ -316,7 +339,7 @@ private Wz_Png GetLinkedPng(Wz_Node node)
{
_disposeQueue = new DisposeQueue(32);
}
_disposeQueue.Add(linkImg);
_disposeQueue.Add(linkImg, _currentWzImg);
}
}

Expand Down Expand Up @@ -589,6 +612,11 @@ public DisposeQueue(int maxCount)
private Dictionary<Wz_Image, LinkedListNode<Wz_Image>> _dict;

public void Add(Wz_Image wzImage)
{
Add(wzImage, null);
}

public void Add(Wz_Image wzImage, List<Wz_Image> currentImages)
{
LinkedListNode<Wz_Image> node;
if (_dict.TryGetValue(wzImage, out node))
Expand All @@ -605,7 +633,7 @@ public void Add(Wz_Image wzImage)
//添加item
while (_list.Count >= MaxCount && _list.Count > 0)
{
DisposeLast();
DisposeLast(currentImages);
}

node = _list.AddFirst(wzImage);
Expand All @@ -622,13 +650,33 @@ public void DisposeAll()
}

private void DisposeLast()
{
this.DisposeLast(null);
}

private void DisposeLast(List<Wz_Image> currentImages)
{
var last = _list.Last;
last.Value.Unextract();
if (currentImages == null || !currentImages.Contains(last.Value))
{
last.Value.Unextract();
}
_dict.Remove(last.Value);
_list.Remove(last);
}
}

private struct PngLinkInfo
{
public PngLinkType LinkType { get; set; }
public string LinkUrl { get; set; }
}

private enum PngLinkType
{
None = 0,
Inlink = 1,
Outlink = 2
}
}
}
21 changes: 15 additions & 6 deletions WzComparerR2/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,28 @@ void CharaSimLoader_WzFileFinding(object sender, FindWzEventArgs e)
return;
}

//拼接剩余路径
string[] fullPath2 = new string[fullPath.Length - 1];
Array.Copy(fullPath, 1, fullPath2, 0, fullPath2.Length);

foreach (var wzFileNode in preSearch)
{
e.WzNode = wzFileNode.FindNodeByPath(true, true, fullPath2);
if (e.WzNode != null)
var searchNode = wzFileNode;
for (int i = 1; i < fullPath.Length && searchNode != null; i++)
{
searchNode = searchNode.Nodes[fullPath[i]];
var img = searchNode.GetValueEx<Wz_Image>(null);
if (img != null)
{
searchNode = img.TryExtract() ? img.Node : null;
}
}

if (searchNode != null)
{
e.WzNode = searchNode;
e.WzFile = wzFileNode.Value as Wz_File;
return;
}
}
//寻找失败
e.WzNode = null;
}

#region 界面主题配置
Expand Down

0 comments on commit 5cc6402

Please sign in to comment.