Esempio n. 1
0
        void DownloadPatchConfig()
        {
            string url      = _patchUrl + "patchs.txt";
            string savepath = Application.persistentDataPath + "/patchs.txt";

            Downloader.DownloadFiles(new List <DownloadFile>()
            {
                new DownloadFile(url, savepath)
            },
                                     (arg) =>
            {
                if (!File.Exists(savepath))
                {
                    object[] obj = new object[2];
                    obj[0]       = 50000;
                    obj[1]       = _versionUpdateTips;
                    _currentProgress.TotalSize = 50000;
                    ChangeCurrentUpdateState(UpdateState.DownloadNewClient, false, obj);
                }
                else
                {
                    string str         = File.ReadAllText(savepath);
                    bool find          = false;
                    int totalSize      = 50000;
                    PatchConfig config = JsonMapper.ToObject <PatchConfig>(str);
                    if (_targetVersion == (int)GetVersionValue(config.newVersion))
                    {
                        string channelName = ILRuntimeHelper.GetChannelName();
                        for (int i = 0; i < config.channels.Count; ++i)
                        {
                            var channel = config.channels[i];
                            if (channelName == channel.name)
                            {
                                totalSize  = channel.size_mini;
                                _targetMd5 = GameClient.Instance.BuildSettings.MiniBuild ? channel.md5_mini : channel.md5_all;
                                for (int j = 0; j < channel.patchs.Count; ++j)
                                {
                                    var patch = channel.patchs[j];
                                    if (ResourceManager.CodeVersion == GetVersionValue(patch.oldVersion))
                                    {
                                        string md5 = FileHelper.GetFileMd5(Application.dataPath);
                                        if ((GameClient.Instance.BuildSettings.MiniBuild && md5 == patch.oldmd5_mini) || (!GameClient.Instance.BuildSettings.MiniBuild && md5 == patch.oldmd5_all))
                                        {
                                            _patchFileUrl = GameClient.Instance.BuildSettings.MiniBuild ? _patchUrl + patch.patch_mini : _patchUrl + patch.patch_all;
                                            totalSize     = GameClient.Instance.BuildSettings.MiniBuild ? patch.size_mini : patch.size_all;
                                            find          = true;
                                        }

                                        break;
                                    }
                                }

                                if (find)
                                {
                                    break;
                                }
                            }
                        }
                    }

                    File.Delete(savepath);
                    _currentProgress.TotalSize = totalSize;
                    if (find)
                    {
                        object[] obj = new object[2];
                        obj[0]       = totalSize;
                        obj[1]       = _versionUpdateTips;
                        ChangeCurrentUpdateState(UpdateState.DownloadNewClientPatch, false, obj);
                    }
                    else
                    {
                        object[] obj = new object[2];
                        obj[0]       = totalSize;
                        obj[1]       = _versionUpdateTips;
                        ChangeCurrentUpdateState(UpdateState.DownloadNewClient, false, obj);
                    }
                }
            });
        }
Esempio n. 2
0
        void ComparServerVersion()
        {
            string url      = ResourceManager.ResourceUrl + "version.txt";
            string savepath = Application.persistentDataPath + "/version.txt";

            Downloader.DownloadFiles(new List <DownloadFile>()
            {
                new DownloadFile(url, savepath)
            },
                                     (obj) =>
            {
                if (!File.Exists(savepath))
                {
                    _onShowUpdateStepFail(0);
                    return;
                }

                string str    = File.ReadAllText(savepath);
                string[] strs = str.Split(' ');
                if (strs.Length != 3)
                {
                    _onShowUpdateStepFail(1);
                    return;
                }

                float serverCodeVersion;
                if (!float.TryParse(strs[0], out serverCodeVersion))
                {
                    _onShowUpdateStepFail(2);
                    return;
                }

                uint crc;
                if (!uint.TryParse(strs[1], out crc))
                {
                    _onShowUpdateStepFail(3);
                    return;
                }

                GameClient.Instance.targetVersion = strs[2];
                File.Delete(savepath);

                if ((int)serverCodeVersion > (int)ResourceManager.CodeVersion)
                {
#if UNITY_ANDROID && !UNITY_EDITOR
                    bool updateInGame = ILRuntimeHelper.GetUpdateInGame();
                    if (updateInGame)
                    {
                        _targetVersion = (int)serverCodeVersion;
                        ChangeCurrentUpdateState(UpdateState.DownloadPatchConfig);
                    }
                    else
                    {
                        ChangeCurrentUpdateState(UpdateState.OpenNewClientUrl, false);
                    }
#else
                    ChangeCurrentUpdateState(UpdateState.OpenNewClientUrl, false);
#endif
                }
                else
                {
                    uint localCrc = FileHelper.GetFileCrc(ResourceManager.DataPath + "ResourceList.ab");
                    if (crc != localCrc)
                    {
                        _resourceCrc = crc;
                        ChangeCurrentUpdateState(UpdateState.DownloadResourceList);
                    }
                    else
                    {
                        ChangeCurrentUpdateState(UpdateState.CheckLoacalResource);
                    }
                }
            });
        }
Esempio n. 3
0
        void DownloadServerResource()
        {
            if (_currentDownloader != null)
            {
                _currentDownloader.PauseDownload(false);
                GameClient.Instance.StartCoroutine(CheckDownloadingNetWork());
                return;
            }

            _currentProgress.Progreess = 0f;
            _onShowUpdateProgress(_currentProgress);

            string newResourceListPath = Application.persistentDataPath + "/ResourceList.ab";

            if (File.Exists(newResourceListPath))
            {
                _finishDatas.Clear();
                var itor = ResourceManager.Instance.ResourceList.Resources.GetEnumerator();
                while (itor.MoveNext())
                {
                    _currentResourclist.Resources.Add(itor.Current.Key, itor.Current.Value);
                }
            }

            int toltalSize = 0;
            List <DownloadFile> downloadfiles = new List <DownloadFile>(_needUpdateResources.Count);
            var a = new TraverseInThread <string>(_needUpdateResources, _needUpdateResources.Count,
                                                  (arg) =>
            {
                string key                = arg as string;
                ResourceData rd           = _newResources.Resources[key];
                string filename           = ResourceManager.GetResourceFileName(key);
                string saveName           = rd.IsOptional() ? ResourceManager.OptionalPath + filename : ResourceManager.DataPath + filename;
                DownloadFile downloadFile = new DownloadFile(ResourceManager.ResourceUrl + key + ".ab", saveName, rd.Size, rd.Crc);
                toltalSize               += rd.Size;
                lock (_threadLock)
                {
                    downloadfiles.Add(downloadFile);
                }

                if (rd.Path.Contains("Install/Unpackage/GameLogic.bytes") || rd.Path.Contains("Scenes/Install/UI"))
                {
                    _needRestart = true;
                }
                else if (rd.Path.Contains("Install/Unpackage/Data/"))
                {
                    _needReload = true;
                }
            },
                                                  () =>
            {
                _currentProgress.Progreess = 0f;
                _currentProgress.TotalSize = toltalSize;
                _onShowUpdateProgress(_currentProgress);

                _lastSaveTime = DateTime.Now;

                _currentDownloader = Downloader.DownloadFiles(downloadfiles,
                                                              (arg) => //onFinish
                {
                    _currentDownloader = null;
                    _currentResourclist.Resources.Clear();
                    _finishDatas.Clear();
                    if (_needUpdateResources.Count > 0)
                    {
                        _onShowUpdateStepFail(0);
                        return;
                    }

                    if (File.Exists(newResourceListPath))
                    {
                        try
                        {
                            lock (_threadLock)
                            {
                                File.Copy(newResourceListPath, ResourceManager.DataPath + "ResourceList.ab", true);
                            }
                            File.Delete(newResourceListPath);
                        }
                        catch (Exception ex)
                        {
                            Debugger.LogException(ex);
                        }
                        ResourceManager.Instance.LoadResourceList();
                    }

                    if (_needRestart)
                    {
                        ChangeCurrentUpdateState(UpdateState.RestartClient, false);
                    }
                    else
                    {
                        _newResources.Resources.Clear();
                        _newResources = null;
                        if (_needReload)
                        {
                            ChangeCurrentUpdateState(UpdateState.ReloadConfigs);
                        }
                        else
                        {
                            ChangeCurrentUpdateState(UpdateState.UpdateFinish);
                        }
                    }
                },
                                                              (arg) => //onProgress;
                {
                    object[] args = arg as object[];
                    _currentProgress.Progreess = (float)args[0];
                    _currentProgress.TotalSize = toltalSize;
                    _onShowUpdateProgress(_currentProgress);
                },
                                                              (arg) => //onSingleFileFinish
                {
                    if (!File.Exists(newResourceListPath))
                    {
                        return;
                    }

                    DownloadFile file = arg as DownloadFile;
                    string key        = Path.GetFileNameWithoutExtension(file.savePath);
                    if (File.Exists(file.savePath))
                    {
                        ResourceData rd = _newResources.Resources[key];
                        KeyValuePair <string, ResourceData> pair = new KeyValuePair <string, ResourceData>(key, rd);
                        lock (_saveThreadLock)
                        {
                            _finishDatas.Add(pair);
                        }
                        _needUpdateResources.Remove(key);
                    }

                    if (_currentDownloader != null && !_isSaving && (_lastSaveTime - DateTime.Now).Seconds > 20)
                    {
                        _isSaving     = true;
                        _lastSaveTime = DateTime.Now;
                        Thread thread = new Thread(SaveResourceList);
                        thread.Start();
                        _isSaving = false;
                    }
                }
                                                              );
                GameClient.Instance.StartCoroutine(CheckDownloadingNetWork());
            });
        }
Esempio n. 4
0
        void DownloadGateway()
        {
            GameClient.Instance.ips.Clear();
            GameClient.Instance.ports.Clear();
#if UNITY_EDITOR
            if (File.Exists(Application.dataPath + "/../gateway.txt"))
            {
                string   str  = File.ReadAllText(Application.dataPath + "/../gateway.txt");
                string[] strs = str.Split(' ');
                GameClient.Instance.ips.Add(strs[0]);
                GameClient.Instance.ports.Add(int.Parse(strs[1]));
            }
            ChangeCurrentUpdateState(UpdateState.UpdateFinish);
#else
#if ILRUNTIME_DEBUG && UNITY_STANDALONE_WIN
            if (ResourceManager.IsILRuntimeDebug)
            {
                if (File.Exists(Application.dataPath + "/gateway.txt"))
                {
                    string   str  = File.ReadAllText(Application.dataPath + "/gateway.txt");
                    string[] strs = str.Split(' ');
                    GameClient.Instance.ips.Add(strs[0]);
                    GameClient.Instance.ports.Add(int.Parse(strs[1]));
                }
                ChangeCurrentUpdateState(UpdateState.UpdateFinish);
            }
            else
            {
#endif
            string url = ILRuntimeHelper.GetGatewayUrl();
            Debugger.Log("gateway url : " + url, true);
            string savepath = Application.persistentDataPath + "/gateway.txt";
            Downloader.DownloadFiles(new List <DownloadFile>()
            {
                new DownloadFile(url, savepath)
            },
                                     (obj) =>
            {
                if (!File.Exists(savepath))
                {
                    Debugger.LogError("DownloadGateway  0");
                    _onShowUpdateStepFail(0);
                    return;
                }

                string json = File.ReadAllText(savepath);
                GatewayConfig gatewayConfig = JsonMapper.ToObject <GatewayConfig>(json);
                _resourceUpdateTips         = gatewayConfig.resourceTips;
                _versionUpdateTips          = gatewayConfig.versionTips;
                _versionUrl = gatewayConfig.versionUrl;
                _patchUrl   = gatewayConfig.patchUrl;
                Debugger.Log("vesion url : " + _versionUrl, true);
                Debugger.Log("patch url : " + _patchUrl, true);
                string version     = ResourceManager.CodeVersion.ToString();
                string channelName = ILRuntimeHelper.GetChannelName();
                bool find          = false;
                for (int i = 0; i < gatewayConfig.gameVersions.Count; ++i)
                {
                    if (gatewayConfig.gameVersions[i].version == version)
                    {
                        for (int j = 0; j < gatewayConfig.gameVersions[i].channels.Count; ++j)
                        {
                            var channel = gatewayConfig.gameVersions[i].channels[j];
                            if (channel.channelName == channelName)
                            {
                                GameClient.Instance.isShenHe = channel.isShenHe;
                                ResourceManager.ResourceUrl  = channel.resourceUrl;
                                Debugger.Log("resource url : " + ResourceManager.ResourceUrl, true);
                                GameClient.Instance.ips.AddRange(channel.ips);
                                GameClient.Instance.ports.AddRange(channel.ports);
                                find = true;
                                break;
                            }
                        }
                    }
                }
                if (!find)
                {
                    _onShowUpdateStepFail(1);
                    return;
                }

                File.Delete(savepath);

                if (GameClient.Instance.isShenHe && !GameClient.Instance.BuildSettings.MiniBuild)
                {
                    ChangeCurrentUpdateState(UpdateState.UpdateFinish);
                }
                else
                {
                    ChangeCurrentUpdateState(UpdateState.ComparServerVersion);
                }
            });
#if ILRUNTIME_DEBUG && UNITY_STANDALONE_WIN
        }
#endif
#endif
        }