Exemplo n.º 1
0
        public static void LoadCfgInfo(Action <bool> callback)
        {
#if !UNITY_WEBPLAYER
            string cfgStr;
            if (File.Exists(CfgPath))
            {
                cfgStr = Utils.LoadFile(CfgPath);
                //CfgInfo = LoadXMLText<CfgInfo>(cfgStr);
                CfgInfoNew = LoadCfgInfoList(cfgStr);
                if (callback != null)
                {
                    DriverLib.Invoke(() => callback(CfgInfoNew != null && CfgInfoNew.Count > 0 ? true : false));
                }
            }
            else
            {
#endif
            var cfgUrl = Utils.LoadResource(Utils.GetFileNameWithoutExtention(CFG_FILE));
            LoggerHelper.Info("cfgUrl: " + cfgUrl);
            var programVerStr = "";
            var programVer    = Resources.Load(VERSION_URL_KEY) as TextAsset;
            if (programVer && !String.IsNullOrEmpty(programVer.text))
            {
                programVerStr = "V" + VersionManager.Instance.GetVersionInXML(programVer.text).ProgramVersion;
            }

            var s = Application.persistentDataPath.Split('/');
            //Debug.Log(s.Length);
            for (int i = s.Length - 1; i >= 0; i--)
            {
                //Debug.Log(s[i]);
                if (s[i] == "files" && i - 1 >= 0)
                {
                    BundleIdentifier = s[i - 1];
                    LoggerHelper.Info("bundleIdentifier: " + BundleIdentifier);
                    break;
                }
            }

            Action erraction = () =>
            {
                if (callback != null)
                {
                    DriverLib.Invoke(() => callback(false));
                }
            };
            Action <string> suaction = null;
            suaction = (res) =>
            {
                var parentinfo = LoadCfgInfoList(res);
                foreach (var pair in parentinfo)
                {
                    if (!CfgInfoNew.ContainsKey(pair.Key))
                    {
                        CfgInfoNew.Add(pair.Key, pair.Value);
                    }
                }
                if (!string.IsNullOrEmpty(BundleIdentifier) && parentinfo.ContainsKey(BundleIdentifier))//根据包名做特殊处理
                {
                    CfgInfoNew.Clear();
                    DownloadMgr.Instance.AsynDownLoadText(parentinfo[BundleIdentifier], suaction, erraction);
                }
                else if (parentinfo.ContainsKey(programVerStr))//根据版本做特殊处理
                {
                    CfgInfoNew.Clear();
                    DownloadMgr.Instance.AsynDownLoadText(parentinfo[programVerStr], suaction, erraction);
                }
                else if (parentinfo.ContainsKey(CFG_PARENT_KEY))
                {
                    DownloadMgr.Instance.AsynDownLoadText(parentinfo[CFG_PARENT_KEY], suaction, erraction);
                }
                else if (callback != null)
                {
                    DriverLib.Invoke(() => callback(CfgInfoNew != null && CfgInfoNew.Count > 0 ? true : false));
                }
            };
            DownloadMgr.Instance.AsynDownLoadText(cfgUrl, suaction, erraction);
#if !UNITY_WEBPLAYER
        }
#endif
        }