Beispiel #1
0
        private static byte[] __SyncReadBytesByPath(string originName, string destName, string path, VersionFile.Type fileType, bool removeImpurity = true)
        {
            if (instance == null || instance.platformLoader == null)
            {
                return(null);
            }

            byte[] data = null;
            if (fileType == VersionFile.Type.COMBINE_FILE)
            {
                CombineFile cf = CombineFileManager.GetInstance().GetCombineFile(destName);
                data = cf.Read(originName);
            }
            else
            {
                data = instance.platformLoader.SyncReadBytes(path);
            }

            if (data != null)
            {
                if (removeImpurity)
                {
                    DataDecode(data, data.Length);
                }
            }

            return(data);
        }
Beispiel #2
0
        public CombineFile GetCombineFile(string name)
        {
            CombineFile cf;

            if (!combineFileDic.TryGetValue(name, out cf))
            {
                cf = new CombineFile(name);
                combineFileDic.Add(name, cf);
            }

            return(cf);
        }
Beispiel #3
0
        private static void __AsynReadBytesByPath(string originName, string destName, string path, VersionFile.Type fileType, EndReadBytes endRead, System.Object obj, bool cb_whatever = false, bool needRemoveImpurity = true)
        {
            if (instance == null || instance.platformLoader == null)
            {
                return;
            }

            byte[] arr = null;
            if (fileType == VersionFile.Type.COMBINE_FILE)
            {
                CombineFile cf = CombineFileManager.GetInstance().GetCombineFile(destName);
                arr = cf.Read(originName);
            }
            else
            {
                arr = instance.platformLoader.SyncReadBytes(path);
            }

            if (arr != null)
            {
                if (needRemoveImpurity)
                {
                    ThreadTask.RunAsync(() =>
                    {
                        DataDecode(arr, arr.Length);
                    },
                                        () =>
                    {
                        if (endRead != null)
                        {
                            endRead(arr, obj);
                        }
                    });
                }
                else
                {
                    if (endRead != null)
                    {
                        endRead(arr, obj);
                    }
                }
            }
            else
            {
                if (cb_whatever)
                {
                    if (endRead != null)
                    {
                        endRead(arr, obj);
                    }
                }
            }
        }
Beispiel #4
0
        //private bool early = false;
        private LuaLoader()
        {
            instance = this;
            beZip    = false;
            Debug.LogError("lua loader init->" + Application.platform);
            if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.WindowsPlayer)
            {
#if LUA_FILE_COMBINE
                Debug.LogError("lua loader init 1");
                combineFile = new CombineFile("all_lua.cf");
                Timer.CreateTimer(1, -1, DoUpdate, null);
#endif
            }
            else
            {
                Debug.LogError("lua loader init 2");
                AddSearchPath(Application.dataPath + "/Lua/?.lua");
                AddSearchPath(Application.dataPath + "/ToLua/Lua/?.lua");
                //AddSearchPath(Application.dataPath + "/ToLua/Lua/protobuf/?.lua");
                AddSearchPath(Application.dataPath + "/Lua/Proto/?.lua");
            }
        }
Beispiel #5
0
        private void CreateAssetBundle(string originName, string destName, string path, Example.VersionFile.Type fileType, Request request, EndLoadBundle endLoad, System.Object ud, bool assetBundle)//, bool cb_whatever)
        {
            if (fileType == Example.VersionFile.Type.DEFAULT)
            {
                CoroutineHelper.CreateCoroutineHelper(CreateAssetBundle_Offset(originName, path, 0, request, endLoad, ud, assetBundle));
            }
            else if (fileType == Example.VersionFile.Type.COMBINE_FILE)
            {
                CombineFile cf = CombineFileManager.GetInstance().GetCombineFile(destName);
                int         offset;
                int         size;
                bool        encrypt;
                cf.GetFileDetail(originName, out offset, out size, out encrypt);

                if (encrypt)
                {
                    Debugger.LogError("asset bundle resource in combine file should not encrypt");
                    return;
                }

                CoroutineHelper.CreateCoroutineHelper(CreateAssetBundle_Offset(originName, path, (ulong)offset, request, endLoad, ud, assetBundle));
            }
        }
Beispiel #6
0
        private void Collect(string root)
        {
            string[] paths = Directory.GetFiles(root);
            if (paths != null)
            {
                string fileName = null;
                for (int i = 0, count = paths.Length; i < count; i++)
                {
                    fileName = Path.GetFileName(paths[i]);
                    if (files.ContainsKey(fileName))
                    {
                        Debug.LogError("duplicate files->" + files[fileName] + "^" + paths[i]);
                        continue;
                    }

                    if (fileName == null || fileName == "")
                    {
                        continue;
                    }

                    string path   = paths[i];
                    string suffix = Path.GetExtension(path);
                    if (suffix == ".cf")
                    {
                        RelationData rd = new RelationData();
                        rd.origin   = fileName;
                        rd.dest     = fileName;
                        rd.path     = path;
                        rd.encrypt  = false;
                        rd.fileType = VersionFile.Type.COMBINE_FILE;

                        files.Add(fileName, rd);

                        CombineFile   cf  = new CombineFile(fileName);
                        List <string> lst = new List <string>();
                        cf.CollectAllFilePath(lst);
                        for (int a = 0, acount = lst.Count; a < acount; a++)
                        {
                            files.Add(lst[a], rd);
                        }
                    }
                    else if (suffix == ".rf")
                    {
                        RelationData rd = new RelationData();
                        rd.origin   = fileName;
                        rd.dest     = fileName;
                        rd.path     = path;
                        rd.encrypt  = false;
                        rd.fileType = VersionFile.Type.RELATION_FILE;

                        files.Add(fileName, rd);

                        using (FileStream fs = File.OpenRead(path))
                        {
                            var rf = RelationFile.Deserialize(fs);
                            files.Add(rf.Name, rd);
                        }
                    }
                    else
                    {
                        RelationData rd = new RelationData();
                        rd.origin   = fileName;
                        rd.dest     = fileName;
                        rd.path     = path;
                        rd.encrypt  = false;
                        rd.fileType = VersionFile.Type.DEFAULT;

                        files.Add(fileName, rd);
                    }
                }
            }

            string[] dirs = Directory.GetDirectories(root);
            if (dirs != null)
            {
                for (int i = 0, count = dirs.Length; i < count; i++)
                {
                    Collect(dirs[i]);
                }
            }
        }