Exemplo n.º 1
0
        static public bool MakDirValid(string dir)
        {
            if (string.IsNullOrEmpty(dir))
            {
                SAUtils.LogError("MakeDirValidFail1, Empty");
                return(false);
            }

            if (Directory.Exists(dir))
            {
                return(true);
            }

            try
            {
                Directory.CreateDirectory(dir);
            }
            catch (System.Exception e)
            {
                SAUtils.LogError("MakeDirValidFail2: {0}, {1}", dir, e.ToString());
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public IEnumerator loadDataTable()
        {
            if (!PlayerPrefs.HasKey("data_version") || PlayerPrefs.GetInt("data_version") != SAGameVersion.Instance.data_version)
            {
                string random      = DateTime.Now.ToString("yyyymmddhhmmss");
                string versionFile = (SAAppConfig.ConfigRelease ? SAAppConfig.VersionPath : SAAppConfig.DevResDir + SAAppConfig.DataDir) + SAAppConfig.dataTable + "?rd=" + random;
                WWW    www         = new WWW(versionFile);
                SAUtils.Log(versionFile);
                yield return(www);

                if (www.error != null && www.error.Length > 0)
                {
                    SAUtils.LogError("error : " + www.error);
                    yield break;
                }
                iostring = www.text;
                SAUtils.Log("本地写入:" + SAAppConfig.RemotePath);
                if (SALang.MakDirValid(SAAppConfig.RemotePath))
                {
                    SALang.writeLocalByteWithName(System.Text.Encoding.UTF8.GetBytes(iostring), SAAppConfig.dataTable);
                    PlayerPrefs.SetInt("data_version", SAGameVersion.Instance.data_version);
                }
                else
                {
                    SAUtils.Log("写入路径创建错误");
                }
            }
            else
            {
                iostring = System.Text.Encoding.UTF8.GetString(SALang.readLocalByteWithName(SAAppConfig.dataTable));
            }
            SAProtoDecode.parsing(iostring);
            SAUtils.Log("数据表加载结束");
        }
Exemplo n.º 3
0
        public IEnumerator loadVersion()
        {
            string random = DateTime.Now.ToString("yyyymmddhhmmss");

            string versionFile = (SAAppConfig.ConfigRelease ? SAAppConfig.VersionPath : SAAppConfig.DevResDir + SAAppConfig.DataDir) + SAAppConfig.versionXML + "?" + random;

            SAUtils.Log(versionFile);
            WWW www = new WWW(versionFile);

            yield return(www);

            if (www.error != null && www.error.Length > 0)
            {
                SAUtils.LogError("error : " + www.error);
                yield break;
            }
            XmlDocument convertXML = SALang.stringConvertXML(www.text);

            ip       = Convert.ToString(convertXML.GetElementsByTagName("ip").Item(0).InnerText);
            port     = Convert.ToInt32(convertXML.GetElementsByTagName("port").Item(0).InnerText);
            asset_ip = Convert.ToString(convertXML.GetElementsByTagName("asset_ip").Item(0).InnerText);
#if UNITY_IPHONE
            asset_port = Convert.ToInt32(convertXML.GetElementsByTagName("asset_ios_port").Item(0).InnerText);
            asset_path = "http://";
#elif UNITY_ANDROID
            asset_port = Convert.ToInt32(convertXML.GetElementsByTagName("asset_android_port").Item(0).InnerText);
            asset_path = "http://";
#else
            asset_port = Convert.ToInt32(convertXML.GetElementsByTagName("asset_android_port").Item(0).InnerText);
            asset_path = "http://";
#endif
            ioc_version       = Convert.ToInt32(convertXML.GetElementsByTagName("ioc_version").Item(0).InnerText);
            data_version      = Convert.ToInt32(convertXML.GetElementsByTagName("data_version").Item(0).InnerText);
            resources_version = Convert.ToInt32(convertXML.GetElementsByTagName("resources_version").Item(0).InnerText);
            language          = Convert.ToString(convertXML.GetElementsByTagName("language").Item(0).InnerText);

            asset_path += asset_ip + ":" + asset_port + "/" + SAAppConfig.GameName + "/";
            if (!Directory.Exists(Path.Combine(SAAppConfig.RemotePath, SAAppConfig.versionXML)))
            {
                PlayerPrefs.DeleteKey("ioc_version");
                PlayerPrefs.DeleteKey("data_version");
                PlayerPrefs.DeleteKey("resources_version");
                PlayerPrefs.DeleteKey("language");
            }
            if (SALang.MakDirValid(SAAppConfig.RemotePath))
            {
                SALang.writeLocalByteWithName(System.Text.Encoding.UTF8.GetBytes(www.text), SAAppConfig.versionXML);
            }
            else
            {
                SAUtils.Log("写入路径创建错误");
            }
            SAUtils.Log("版本信息加载结束");
        }
Exemplo n.º 4
0
        public IEnumerator loadIOC()
        {
            string xmlText;

            if (!PlayerPrefs.HasKey("ioc_version") || PlayerPrefs.GetInt("ioc_version") != SAGameVersion.Instance.ioc_version)
            {
                string random      = DateTime.Now.ToString("yyyymmddhhmmss");
                string versionFile = (SAAppConfig.ConfigRelease ? SAAppConfig.VersionPath : SAAppConfig.DevResDir + SAAppConfig.DataDir) + SAAppConfig.iocXML + "?rd=" + random;
                WWW    www         = new WWW(versionFile);
                SAUtils.Log(versionFile);
                yield return(www);

                if (www.error != null && www.error.Length > 0)
                {
                    SAUtils.LogError("error : " + www.error);
                    yield break;
                }
                xmlText = www.text;
                SALang.MakDirValid(SAAppConfig.RemotePath);
                SALang.writeLocalByteWithName(System.Text.Encoding.Default.GetBytes(xmlText), SAAppConfig.iocXML);
                PlayerPrefs.SetInt("ioc_version", SAGameVersion.Instance.ioc_version);
            }
            else
            {
                xmlText = System.Text.Encoding.Default.GetString(SALang.readLocalByteWithName(SAAppConfig.iocXML));
            }
            factorys.Clear();
            datas.Clear();
            List <string>  defaultStart = new List <string>();
            XmlDocument    convertXML   = SALang.stringConvertXML(xmlText);
            XmlNodeList    nodeList     = convertXML.DocumentElement.ChildNodes;
            XmlNode        node;
            XmlNode        workerNode;
            IOCDataWorker  dataWorker;
            IOCGraphWorker graphWorker;
            bool           isGrap;
            XmlNodeList    workerList;
            SAFactory      factory;
            string         factoryName;
            int            i, j;

            for (i = 0; i < nodeList.Count; i++)
            {
                node = nodeList[i];
                if (node.Name.Equals("factory"))
                {
                    workerList  = node.ChildNodes;
                    factoryName = node.Attributes.GetNamedItem("name").Value;
                    if (node.Attributes.GetNamedItem("defaultStart").Value.Equals("true"))
                    {
                        defaultStart.Add(factoryName);
                    }
                    Type factoryType = Type.GetType(SAACollection.FactoryStr + factoryName);
                    if (null == factoryType)
                    {
                        factory = new SAFactory(factoryName);
                    }
                    else
                    {
                        factory = (SAFactory)factoryType.GetConstructor(new Type[] { typeof(string) }).Invoke(new System.Object[] { factoryName });//构造;
                    }
                    factorys.Add(factoryName, factory);
                    for (j = 0; j < workerList.Count; j++)
                    {
                        workerNode = workerList[j];
                        if (workerNode.Name.Equals("worker"))
                        {
                            isGrap = workerNode.Attributes.GetNamedItem("type").Value.Equals("graph");// ? IOCType.GRAPH_WORKER : IOCType.DATA_WORKER;
                            if (isGrap)
                            {
                                graphWorker                 = new IOCGraphWorker();
                                graphWorker.name            = workerNode.Attributes.GetNamedItem("name").Value;
                                graphWorker.isLocal         = workerNode.Attributes.GetNamedItem("isLocal").Value.Equals("true");
                                graphWorker.defaultStart    = workerNode.Attributes.GetNamedItem("defaultStart").Value.Equals("true");
                                graphWorker.type            = IOCType.GRAPH_WORKER;
                                graphWorker.isActiveDispose = workerNode.Attributes.GetNamedItem("isActiveDispose").Value.Equals("true");
                                factory.addWorker(graphWorker);
                            }
                            else
                            {
                                dataWorker         = new IOCDataWorker();
                                dataWorker.type    = IOCType.DATA_WORKER;
                                dataWorker.name    = workerNode.Attributes.GetNamedItem("name").Value;
                                dataWorker.command = workerNode.Attributes.GetNamedItem("command").Value;
                                factory.addWorker(dataWorker);
                            }
                        }
                    }
                }
            }
            for (i = 0; i < defaultStart.Count; ++i)
            {
                if (factorys.ContainsKey(defaultStart[i]))
                {
                    factorys[defaultStart[i]].startFactory(null);
                }
            }
            yield return(null);
        }