Beispiel #1
0
        public void GetRemoteVersion()
        {
            string remoteVersionUrl = m_UpdateUrl + "/version.txt";

            TriggerUpdating(UpdateSegment.CompareVersion, UpdateError.OK, "Get Remote Version", 0);
            m_HttpRequest.Get(remoteVersionUrl, (err, www) =>
            {
                if (err != null)
                {
                    //获取远程版本信息失败
                    TriggerUpdating(UpdateSegment.CompareVersion, UpdateError.DownloadRemoteVersionError, "download fail:" + remoteVersionUrl, 1);
                }
                else
                {
                    //获取远程版本信息成功
                    TriggerUpdating(UpdateSegment.CompareVersion, UpdateError.OK, "Get Remote Version", 0.2f);
                    RemoteVersions remoteVersions = new RemoteVersions();
                    if (remoteVersions.Parse(www.text))
                    {
                        //比较版本
                        CompareVersion(remoteVersions); //Step
                    }
                    else
                    {
                        TriggerUpdating(UpdateSegment.CompareVersion, UpdateError.ParseRemoteVersionError, "parse fail:" + www.text, 1);
                    }
                }
            });
        }
Beispiel #2
0
        protected void CompareVersion(RemoteVersions remoteVersions)
        {
            //make sure local version is set.
            InitLocalVersion();

            //check host version and native version
            //1.m_HostVersion==m_NativeHostVersion                        same install package or no temp HostVersion file.
            //    when m_CurrentVersion < m_NativeHostVersion        Update from NativeHostVersion
            //2.m_HostVersion<m_NativeHostVersion                         user remove install package and reinstall new version package.
            //   when m_CurrentVersion < m_NativeHostVersion        Update from NativeHostVersion.Others use currentVersion for update.
            //3.m_HostVersion > m_NativeHostVersion       user remove install package and reinstall old version package.
            //                                                                          must update from native host version.
            if ((m_HostVersion <= m_NativeHostVersion && m_CurrentVersion < m_NativeHostVersion) || m_HostVersion > m_NativeHostVersion)
            {
                //Update from NativeHostVersion
                m_HostVersion    = m_NativeHostVersion;
                m_CurrentVersion = m_NativeHostVersion;
                ClearStorageDir();
                WriteHostVersionToFile();
            }

            //if (m_HostVersion < m_NativeHostVersion)
            //{
            //    //user remove install package and reinstall new version package.
            //    if(m_CurrentVersion<m_NativeHostVersion)
            //    {
            //        //Update from NativeHostVersion
            //        m_HostVersion = m_NativeHostVersion;
            //        m_CurrentVersion = m_NativeHostVersion;
            //        ClearStorageDir();
            //        WriteHostVersionToFile();
            //    }
            //}
            //else if (m_HostVersion > m_NativeHostVersion)
            //{
            //    //user remove install package and reinstall old version package. must update from native host version.
            //    m_HostVersion = m_NativeHostVersion;
            //    m_CurrentVersion = m_NativeHostVersion;
            //    ClearStorageDir();
            //    WriteHostVersionToFile();
            //}

            //first check the host is support
            if (remoteVersions.MinHostVersion > m_NativeHostVersion)
            {
                //the host is out data
                TriggerUpdating(UpdateSegment.CompareVersion, UpdateError.HostIsOutOfDate, "please download the newest application", 1);
                return;
            }

            //check min support version
            if (remoteVersions.MinSupportVersion > m_CurrentVersion)
            {
                TriggerUpdating(UpdateSegment.CompareVersion, UpdateError.CurrentVersionOutOfDate, "please download the newest application", 1);
                return;
            }

            //check is latest version
            if (m_CurrentVersion >= remoteVersions.LatestVersion)
            {
                //the current is latest version,complete the update
                TriggerUpdating(UpdateSegment.Complete, UpdateError.OK, "the assets is latest did not need update", 1);
                return;
            }

            TriggerUpdating(UpdateSegment.CompareVersion, UpdateError.OK, "Compare Complete", 1);

            //do update
            string patchPath = GetPatchPath(m_CurrentVersion, remoteVersions.LatestVersion);

            //TODO download the manifest file.
            //GetManifestHeaderFile(patchPath);
            //download the pack file
            DownLoadPatchPack(patchPath);//Step

            //更新当前版本号,但不保存到文件.等所有补丁执行完成才保存到本地文件。
            m_CurrentVersion = remoteVersions.LatestVersion;
        }