示例#1
0
文件: SACache.cs 项目: sacu/CatchFish
        public void Load(FileStream fs)
        {
            fileStream = fs;

            BinaryReader reader = new BinaryReader(fileStream);

            /*int version = */
            reader.ReadInt32();
            /* encrypt */
            encrypt = reader.ReadInt32();
            /* count */
            int count = reader.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                int    buffLen  = reader.ReadInt32();
                byte[] buff     = reader.ReadBytes(buffLen);
                string filename = SALang.BuffToString(buff, encrypt);

                int size   = reader.ReadInt32();
                int offset = (int)fileStream.Position;
                fileStream.Seek(size, SeekOrigin.Current);

                LuaNode node = new LuaNode(offset, size);
                nodes.Add(filename, node);
                SALang.writeLocalByteWithName(ReadBytes(filename), filename);
            }
        }
示例#2
0
        public void Load(FileStream fs)
        {
            fileStream = fs;

            BinaryReader reader = new BinaryReader(fileStream);

            /*int version = */
            reader.ReadInt32();
            /* encrypt */
            encrypt = reader.ReadInt32();
            /* count */
            int count = reader.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                int    buffLen  = reader.ReadInt32();
                byte[] buff     = reader.ReadBytes(buffLen);
                string filename = SALang.BuffToString(buff, encrypt);

                int size   = reader.ReadInt32();
                int offset = (int)fileStream.Position;
                fileStream.Seek(size, SeekOrigin.Current);

                SALuaFile luaFile = new SALuaFile(offset, size);
                luaFiles.Add(filename.ToLower(), luaFile);
            }
        }
示例#3
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("数据表加载结束");
        }
示例#4
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("版本信息加载结束");
        }
示例#5
0
文件: SACache.cs 项目: sacu/CatchFish
        public void EditorUnpackToDirectory(string dir)
        {
            foreach (var kv in nodes)
            {
                string filename = kv.Key;

                string pathname = Path.Combine(dir, filename);
                SALang.MakDirValid(Path.GetDirectoryName(pathname));

                byte[] bytes = ReadBytes(filename);
                File.WriteAllBytes(pathname, bytes);
            }
        }
示例#6
0
        public byte[] ReadBytes(string filename)
        {
            SALuaFile luaFile;

            if (luaFiles.TryGetValue(filename.ToLower(), out luaFile))
            {
                byte[] buff = new byte[luaFile.size];
                fileStream.Seek(luaFile.offset, SeekOrigin.Begin);
                fileStream.Read(buff, 0, (int)luaFile.size);
                SALang.XorBuff(ref buff, encrypt);
                return(buff);
            }

            Debug.LogWarning(string.Format("VFSPackage ReadBytes fail, filename={0}", filename));

            return(null);
        }
示例#7
0
文件: SACache.cs 项目: sacu/CatchFish
        public byte[] ReadBytes(string filename)
        {
            LuaNode node;

            if (nodes.TryGetValue(filename, out node))
            {
                byte[] buff = new byte[node.size];
                fileStream.Seek(node.offset, SeekOrigin.Begin);
                fileStream.Read(buff, 0, (int)node.size);
                SALang.XorBuff(ref buff, encrypt);
                return(buff);
            }

            Debug.LogWarning(string.Format("LuaPackage ReadBytes fail, filename={0}", filename));

            return(null);
        }
示例#8
0
        static public bool WriteVersionData(string filename, VersionData versionData)
        {
            string path = Path.Combine(SAAppConfig.RemotePath, filename);

            try
            {
                SALang.ForceDeleteFile(path);
                SALang.MakDirValid(Path.GetDirectoryName(path));
                File.WriteAllText(path, versionData.ToString());
            }
            catch (Exception e)
            {
                Debug.LogError(string.Format("WriteVersionData Fail:{0}, {1}", filename, e.ToString()));
                return(false);
            }
            return(true);
        }
示例#9
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);
        }