Exemple #1
0
        private void CB_EndReadVersionFile(byte[] data, System.Object obj)
        {
            if (data != null)
            {
                GameUtils.MemoryStreamClear();
                GameUtils.ms.Write(data, 0, data.Length);
                GameUtils.ms.Position = 0;

                versionInfo = VersionInfo.Deserialize(GameUtils.ms);

                versionFileData            = new VersionFileData();
                versionFileData.fileLocate = new List <byte>();

                nameToRelation.Clear();

                VersionInfoToData(versionInfo, (byte)FileLocate.None);

                if (obj != null)
                {
                    ((Action)obj)();
                }
            }
            else
            {
                if (readVersionStamp == 0)
                {
                    ResLoader.AsynReadBytesByPath(Application.streamingAssetsPath + "/MeData/" + versionFileName, VersionFile.Type.DEFAULT, CB_EndReadVersionFile, obj);
                    readVersionStamp = 1;
                }
                else
                {
                    if (obj != null)
                    {
                        ((Action)obj)();
                    }
                }
            }
        }
Exemple #2
0
        private void DownloadVersionFile(string url, byte[] data, System.Object obj)
        {
            if (data == null)
            {
                if (Config.Detail_Debug_Log())
                {
                    Debug.LogError("download version data failed");
                }

                LuaInterface.LuaFunction func = LuaManager.GetFunction("OnDownloadVersionDataFailed");
                if (func != null)
                {
                    LuaManager.CallFunc_VX(func);
                }
                else
                {
                    Debug.LogError("script function 'OnDownloadVersionDataFailed' is null");
                }

                return;
            }

            if (Config.Detail_Debug_Log())
            {
                Debug.Log("download version");
            }

            GameUtils.BytesMD5Value(data, (md5Str) =>
            {
                if (Config.Detail_Debug_Log())
                {
                    Debug.Log("download version 1->" + md5Str + "^" + vfc.Md5);
                }
                if (md5Str != vfc.Md5.ToLower())
                {
                    Debugger.LogError("versionInfo file is invalid->" + md5Str + "^" + vfc.Md5);
                    return;
                }

                versionInfoData = new byte[data.Length];
                System.Array.Copy(data, versionInfoData, data.Length);
                ResLoader.RemoveImpurity(data, (arr) =>
                {
                    GameUtils.MemoryStreamClear();
                    GameUtils.ms.Write(data, 0, data.Length);
                    GameUtils.ms.Position = 0;

                    versionInfo = VersionInfo.Deserialize(GameUtils.ms);

                    if (Config.Detail_Debug_Log())
                    {
                        Debugger.Log("download version 2->" + versionInfo.Files.Count);
                    }

                    versionFileData            = new VersionFileData();
                    versionFileData.fileLocate = new List <byte>();

                    nameToRelation.Clear();

                    VersionInfoToData(versionInfo, (byte)FileLocate.None);

                    totalNum = 0;

                    StartCoroutine(BeginCheckUpdateFiles());
                });
            });
        }
Exemple #3
0
        private void CheckVersion(string url, byte[] data, System.Object obj)
        {
            if (data == null)
            {
                if (Config.Detail_Debug_Log())
                {
                    Debug.LogError("download check version data failed");
                }

                LuaInterface.LuaFunction func = LuaManager.GetFunction("OnDownloadCheckVersionDataFailed");
                if (func != null)
                {
                    LuaManager.CallFunc_VX(func);
                }
                else
                {
                    Debug.LogError("script function 'OnDownloadCheckVersionDataFailed' is null");
                }

                return;
            }

            GameUtils.MemoryStreamClear();
            GameUtils.ms.Write(data, 0, data.Length);
            GameUtils.ms.Position = 0;

            vfc           = VersionForCheck.Deserialize(GameUtils.ms);
            updateVersion = false;
            if (Config.Detail_Debug_Log())
            {
                Debugger.Log("versionInfo->" + (versionInfo == null) + "^" + vfc.Version);
            }
            if (versionInfo != null)
            {
                Debugger.Log("vi->" + versionInfo.Version);
            }
            else if (streamingAssetVersionInfo != null)
            {
                versionInfo = streamingAssetVersionInfo;

                versionFileData            = new VersionFileData();
                versionFileData.fileLocate = new List <byte>();

                nameToRelation.Clear();

                VersionInfoToData(versionInfo, (byte)FileLocate.StreamingAsset);
            }

            if (versionInfo == null || vfc.Version != versionInfo.Version)
            {
                Debugger.LogError("version not match, need update.");
                updateVersion = true;
                GameUtils.StringBuilderClear();
                GameUtils.stringBuilder.Append(remoteAssetPath);
                GameUtils.stringBuilder.Append(versionInfoFileName);
                GameUtils.stringBuilder.Append(GameUtils.GetSuffixOfURL());
                StartCoroutine(ResLoader.BeginDownload(GameUtils.stringBuilder.ToString(), DownloadVersionFile, null, updatePBar));
            }
            else
            {
                canUpdate = true;
                Debugger.Log("update nothing");
            }
        }
Exemple #4
0
        private void EarlyInitVersion(VersionInfo earlyStreamingAssetVersionInfo, Action callback)
        {
            if (Config.Detail_Debug_Log())
            {
                UnityEngine.Debug.LogError("early init process->" + (versionInfo == null) + "^" + (earlyStreamingAssetVersionInfo == null));
            }

            if (versionInfo == null)
            {
                if (earlyStreamingAssetVersionInfo != null && earlyStreamingAssetVersionInfo.Files != null && earlyStreamingAssetVersionInfo.Files.Count > 0)
                {
                    versionFileData            = new VersionFileData();
                    versionFileData.fileLocate = new List <byte>();
                    nameToRelation.Clear();

                    VersionInfoToData(earlyStreamingAssetVersionInfo, (byte)FileLocate.StreamingAsset);

                    versionInfo = earlyStreamingAssetVersionInfo;
                }
            }
            else
            {
                if (versionInfo.Files != null && versionInfo.Files.Count > 0)
                {
                    versionFileData            = new VersionFileData();
                    versionFileData.fileLocate = new List <byte>();

                    nameToRelation.Clear();

                    VersionInfoToData(versionInfo, (byte)FileLocate.None);

                    Dictionary <string, byte> streamDic = new Dictionary <string, byte>();
                    for (int i = 0, max = earlyStreamingAssetVersionInfo.Files.Count; i < max; i++)
                    {
                        streamDic.Add(earlyStreamingAssetVersionInfo.Files[i].Guid, 0);
                    }

                    if (Config.Detail_Debug_Log())
                    {
                        Debugger.Log("early init version info->" + (versionInfo == null) + "^" + (earlyStreamingAssetVersionInfo == null));
                    }
                    if (streamDic.Count > 0)
                    {
                        for (int i = 0, max = versionInfo.Files.Count; i < max; i++)
                        {
                            string guid = versionInfo.Files[i].Guid;
                            if (streamDic.ContainsKey(guid))
                            {
                                versionFileData.fileLocate[i] = (byte)FileLocate.StreamingAsset;
                            }
                            else
                            {
                                versionFileData.fileLocate[i] = (byte)FileLocate.Download;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0, max = versionInfo.Files.Count; i < max; i++)
                        {
                            versionFileData.fileLocate[i] = ((byte)FileLocate.Download);
                        }
                    }
                }
            }

            Debugger.Log("early init over");
            if (callback != null)
            {
                callback();
            }
        }
        private void createVersionFile()
        {
            if ("" == m_Url)
            {
                m_conetent = "please set url!";
                Repaint();
                return;
            }

            m_conetent = "begin ...";
            Repaint();

            CustomTools.textFile2Txt();
            AssetDatabase.Refresh();

            string        str     = Application.dataPath + "/StreamingAssets";
            DirectoryInfo dirInfo = new DirectoryInfo(str);

            if (!dirInfo.Exists)
            {
                dirInfo.Create();
            }
            foreach (FileSystemInfo fsInfo in dirInfo.GetFileSystemInfos())
            {
                if (fsInfo is DirectoryInfo)
                {
                    DirectoryInfo subDir = new DirectoryInfo(fsInfo.FullName);
                    subDir.Delete(true);
                }
                else
                {
                    File.Delete(fsInfo.FullName);
                }
            }

            //打包资源路径(参数1:资源保存路径   参数2:压缩格式    参数3:选择平台,各个平台间不能混用)
            BuildPipeline.BuildAssetBundles(str, BuildAssetBundleOptions.ChunkBasedCompression, target[m_Index]);

            VersionFileData vfd = new VersionFileData();

            vfd.version = m_Version;
            vfd.url     = m_Url;
            vfd.data    = null;

            DirectoryInfo resDir = new DirectoryInfo(Application.dataPath + "/Resources");

            if (!resDir.Exists)
            {
                resDir.Create();
            }

            File.WriteAllBytes(Application.dataPath + "/Resources/" + ResourcesManager.s_VersionFileName, System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(vfd)));

            vfd.data = new Dictionary <string, FileData>();
            // 生成版本文件
            createVersionFileData(vfd.data, "");
            File.WriteAllBytes(Application.dataPath + "/Resources/file_data.txt", System.Text.Encoding.Default.GetBytes(JsonConvert.SerializeObject(vfd)));

            CustomTools.textFileRecover();
            AssetDatabase.Refresh();

            m_conetent = "complete!";
            m_Version  = vfd.version;
            m_Url      = vfd.url;
            Repaint();
        }