コード例 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="other"></param>
        /// <param name="testList"> 限制清单,用于测试</param>
        public void Intersect(DllTypesComparer other)
        {
            int sameTypeName = 0;

            string       fn = "CompareResult";
            FileStream   fp = new FileStream(UnityEngine.Application.streamingAssetsPath + "/" + fn + ".txt", FileMode.Create);
            StreamWriter sw = new StreamWriter(fp);

            int index = 0;

            foreach (var p in dic)
            {
                if (index % 100 == 0)
                {
                    EditorUtility.DisplayProgressBar("Compare: 完全相同名字的(类) ", " ", (float)index / dic.Count);
                }

                if (other.dic.ContainsKey(p.Key))
                {
                    sw.WriteLine("\t" + sameTypeName++ + "  " + p.Key + " ;" + p.Value.TypeWithNS);
                }

                index++;
            }
            UnityEngine.Debug.Log("Compare: 完全相同名字的(类): sameTypeName=" + sameTypeName);

            sw.WriteLine("\r\n");

            //交叉相似性:
            index = 0;
            foreach (var p in dic)
            {
                EditorUtility.DisplayProgressBar("Compare: 交叉相似性(类) ", p.Key, (float)index / dic.Count);
                p.Value.Compare(other.dic);
                //p.Value.Dump(sw);
                index++;
            }
            //TODO: 基于模糊算法的一致性检查:

            sw.Close();
            fp.Close();
        }
コード例 #2
0
        public static void TestDllTypesComparer()
        {
            //
            string[] pub_class = File.ReadAllLines(Application.streamingAssetsPath + "/pub_class.txt");

            DllTypesComparer dr   = new DllTypesComparer();
            string           path = "G:/Aotu/worksapce100/DClient2/Trunk/Assets/StreamingAssets/";

            dr.Load(path + "Type_Assembly-CSharp.txt");
            dr.Load(path + "Type_Assembly-CSharp-firstpass.txt");

            dr.Filter(pub_class, true, false);

            //过滤安全类型(已经确认的私有函数)
            string[] safe_class = File.ReadAllLines(Application.streamingAssetsPath + "/safe_class.txt");
            dr.Filter(safe_class, false, false);

            //string[] test_Left = new string[] { "MobaGo.Game.CChangeSkillRule" };
            //dr.Filter(test_Left, false, true);

            //参考
            DllTypesComparer dr2   = new DllTypesComparer();
            string           path2 = Application.streamingAssetsPath + "/ReliefCSharp/";

            dr2.Load(path2 + "Type_Assembly-CSharp.txt");
            dr2.Load(path2 + "Type_Assembly-CSharp-firstpass.txt");
            dr2.Filter(pub_class, true, false);

            //string[] test_Left2 = new string[] { "BackgroundWorker" };
            //dr2.Filter(test_Left2, false, true);

            //跟参考求交集: :8
            dr.Intersect(dr2);

            //
            dr.Dump("TypeNamePercent50", delegate(CSharpType_t t)
            {
                if (t.CompareNSResult.Count > 0 &&
                    t.CompareNSResult[0].percent > 300
                    )
                {
                    return(true);
                }
                return(false);
            }
                    , CSharpType_t.NSResultCompare, delegate(CSharpType_t t, StreamWriter sw)
            {
                t.DumpNSResult(sw, 50);
            }
                    , false);

            //
            dr.Dump("Percent100", delegate(CSharpType_t t)
            {
                if (t.CompareResult.Count == 1 &&
                    t.CompareResult[0].percent > 30 &&
                    !t.TypeWithNS.StartsWith("io.marsdigtal.") &&
                    !t.TypeWithNS.StartsWith("project1615_mobago.")
                    )
                {
                    return(true);
                }
                return(false);
            }
                    , null, null, false);


            dr.Dump("Percent100", delegate(CSharpType_t t)
            {
                if (t.CompareResult.Count == 1 &&
                    t.CompareResult[0].percent > 30 &&
                    !t.TypeWithNS.StartsWith("io.marsdigtal.") &&
                    !t.TypeWithNS.StartsWith("project1615_mobago.")
                    )
                {
                    return(true);
                }
                return(false);
            }
                    , null, null, true);

            dr.Dump("marsdigtal", delegate(CSharpType_t t)
            {
                if (t.CompareResult.Count == 1 &&
                    t.CompareResult[0].percent > 30 &&
                    (t.TypeWithNS.StartsWith("io.marsdigtal.") || t.TypeWithNS.StartsWith("project1615_mobago"))
                    )
                {
                    return(true);
                }
                return(false);
            }
                    , null, null, true);

            //智能判断:1. 如果都是MonoBahaviour,那么如果只有1个公共函数[]
            string[] mono_public = new string[] { "Awake", "Start", "Update", "LateUpdate", "OnDestroy", "OnDrawGizmos", "OnDrawGizmosSelected" };

            dr.Dump("Percent_Left", delegate(CSharpType_t t)
            {
                return(true);
            }
                    , null, null, true);

            EditorUtility.ClearProgressBar();
            UnityEngine.Debug.LogError("TestDllTypesComparer: end ");
        }