Esempio n. 1
0
        public static void LoadMetaOfResource(string path, Action cb = null)
        {
            //meta现已全部拷到sd卡
            //if (!File.Exists(Path.Combine(SystemConfig.ResourceFolder, path)))
            //{
            //    Driver.Instance.StartCoroutine(Driver.Instance.LoadWWWText(Utils.GetStreamPath(path),
            //        (xmlText) =>
            //        {
            //            var xml = XMLParser.LoadXML(xmlText);
            //            if (xml == null)
            //            {
            //                if (cb != null)
            //                {
            //                    cb();
            //                }
            //                return;
            //            }
            //            foreach (SecurityElement item in xml.Children)
            //            {
            //                var meta = new ResourceMetaData();
            //                meta.RelativePath = item.Attribute("path");
            //                meta.MD5 = item.Attribute("md5");

            //                var dependencies = item.Children;
            //                if (dependencies != null && dependencies.Count > 0)
            //                {
            //                    meta.Dependencies = new List<string>();

            //                    foreach (SecurityElement dependency in dependencies)
            //                    {
            //                        meta.Dependencies.Add(dependency.Attribute("path"));
            //                    }
            //                }
            //                metaOfResource[meta.RelativePath] = meta;
            //            }
            //            if (cb != null)
            //            {
            //                cb();
            //            }
            //        }));
            //}
            //else
            //{
            var xml = XMLParser.LoadXML(FileAccessManager.LoadText(path));

            if (xml == null)
            {
                if (cb != null)
                {
                    cb();
                }
                return;
            }
            for (int i = 0; i < xml.Children.Count; i++)
            {
                SecurityElement item = xml.Children[i] as SecurityElement;
                var             meta = new ResourceMetaData();
                meta.RelativePath = item.Attribute("path");
                meta.MD5          = item.Attribute("md5");

                var dependencies = item.Children;
                if (dependencies != null && dependencies.Count > 0)
                {
                    meta.Dependencies = new List <string>();

                    foreach (SecurityElement dependency in dependencies)
                    {
                        meta.Dependencies.Add(dependency.Attribute("path"));
                    }
                }
                metaOfResource[meta.RelativePath] = meta;
            }
            if (cb != null)
            {
                cb();
            }
            //}
        }
Esempio n. 2
0
        public static void GenerateKey()
        {
            string text = new RSACryptoServiceProvider().ToXmlString(true);

            XMLParser.SaveText(@"E:\key.xml", text);
        }
Esempio n. 3
0
        public static void LoadMetaOfMeta(Action cb, Action <int, int> process)
        {
            metaOfMeta = new Dictionary <string, string>();
            //meta现已全部拷到sd卡
            //if (!File.Exists(Path.Combine(SystemConfig.ResourceFolder, ResourceManager.MetaFileName)))
            //{
            //    Driver.Instance.StartCoroutine(Driver.Instance.LoadWWWText(Utils.GetStreamPath(ResourceManager.MetaFileName),
            //        (xmlText) =>
            //        {
            //            var xml = XMLParser.LoadXML(xmlText);
            //            if (xml == null)
            //            {
            //                if (cb != null)
            //                {
            //                    cb();
            //                }
            //                return;
            //            }
            //            foreach (SecurityElement item in xml.Children)
            //            {
            //                metaOfMeta[item.Attribute("path")] = item.Attribute("md5");
            //            }

            //            RecursiveLoadMetaOfResource(metaOfMeta.Keys.ToList(), 0, metaOfMeta.Keys.Count, () =>
            //            {
            //                AssetCacheMgr.AssetMgr.SetPathMap();
            //                if (cb != null)
            //                {
            //                    cb();
            //                }
            //            }, process);
            //        }));
            //}
            //else
            //{

            Action action = () =>
            {
                var xml = XMLParser.LoadXML(FileAccessManager.LoadText(ResourceManager.MetaFileName));
                if (xml == null)
                {
                    if (cb != null)
                    {
                        Driver.Invoke(cb);
                    }
                    return;
                }
                for (int i = 0; i < xml.Children.Count; i++)
                {
                    SecurityElement item = xml.Children[i] as SecurityElement;
                    metaOfMeta[item.Attribute("path")] = item.Attribute("md5");
                }
                RecursiveLoadMetaOfResource(metaOfMeta.Keys.ToList(), 0, metaOfMeta.Keys.Count, () =>
                {
                    AssetCacheMgr.AssetMgr.SetPathMap();
                    if (cb != null)
                    {
                        Driver.Invoke(cb);
                    }
                }, process);
            };

            action.BeginInvoke(null, null);
            //}
        }
Esempio n. 4
0
        private static List <T> LoadXMLText <T>(string text)
        {
            Exception exception;
            List <T>  list = new List <T>();

            try
            {
                if (string.IsNullOrEmpty(text))
                {
                    return(list);
                }
                System.Type type = typeof(T);
                Dictionary <int, Dictionary <string, string> > dictionary = XMLParser.LoadIntMap(XMLParser.LoadXML(text), text);
                PropertyInfo[] properties = type.GetProperties(~BindingFlags.Static);
                foreach (KeyValuePair <int, Dictionary <string, string> > pair in dictionary)
                {
                    object obj2 = type.GetConstructor(System.Type.EmptyTypes).Invoke(null);
                    foreach (PropertyInfo info in properties)
                    {
                        if (info.Name == "id")
                        {
                            info.SetValue(obj2, pair.Key, null);
                        }
                        else
                        {
                            try
                            {
                                if (pair.Value.ContainsKey(info.Name))
                                {
                                    object obj3 = Utils.GetValue(pair.Value[info.Name], info.PropertyType);
                                    info.SetValue(obj2, obj3, null);
                                }
                            }
                            catch (Exception exception1)
                            {
                                exception = exception1;
                                LoggerHelper.Debug(string.Concat(new object[] { "LoadXML error: ", pair.Value[info.Name], " ", info.PropertyType }), true, 0);
                                LoggerHelper.Except(exception, null);
                            }
                        }
                    }
                    list.Add((T)obj2);
                }
            }
            catch (Exception exception2)
            {
                exception = exception2;
                LoggerHelper.Except(exception, null);
                LoggerHelper.Error("error text: \n" + text, true);
            }
            return(list);
        }