public override void Enter(AutoUpdateMgr target)
        {
            Reset();
            var f = target.LocalUpdateFile;

            if (f.Count <= 0)
            {
                ToNextState();
                return;
            }

            m_Items = f.ToArray();
            if (m_Items == null || m_Items.Length <= 0)
            {
                ToNextState();
                return;
            }

            if (!IsMultThreadMode)
            {
                m_Curr = 0;
                StartCurrDownload();
            }
            else
            {
                m_ThreadClients            = new HttpClientThreadFileStream(m_Items, AutoUpdateMgr.Instance.ThreadCount);
                m_ThreadClients.OnError    = OnMultThreadDownloadError;
                m_ThreadClients.OnFinished = OnMultThreadDownloadFinish;
                m_ThreadClients.Start();
            }
        }
Exemple #2
0
 public override void Enter(AutoUpdateMgr target)
 {
     target.ServerFileListToClientFileList();
     target.ChangeUpdateFileNames();
     target.ServerResVerToClientResVer();
     ToNextState();
 }
        public override void Enter(AutoUpdateMgr target)
        {
            string writePath = target.WritePath;

            if (string.IsNullOrEmpty(writePath))
            {
                target.EndAutoUpdate();
                return;
            }

            m_FileListName = string.Format("{0}/{1}", writePath, AutoUpdateMgr._cFileListTxt);
            m_VersionName  = string.Format("{0}/{1}", writePath, AutoUpdateMgr._cVersionTxt);
            if (!File.Exists(m_FileListName))
            {
                CopyFileList();
            }
            else
            {
                if (!File.Exists(m_VersionName))
                {
                    CopyVersion();
                }
                else
                {
                    ToNextState();
                }
            }
        }
        public override void Enter(AutoUpdateMgr target)
        {
            // 解压
            string zipFileMd5 = target.CurrUpdateZipFileMd5;
            string writePath  = target.WritePath;

            if (string.IsNullOrEmpty(zipFileMd5) || string.IsNullOrEmpty(writePath))
            {
                AutoUpdateMgr.Instance.EndAutoUpdate();
            }
            string zipFileName = string.Format("{0}/{1}", writePath, zipFileMd5);

            if (!File.Exists(zipFileName))
            {
                target.Error(AutoUpdateErrorType.auError_ResZipVerReq, 0);
                return;
            }

            // 未写完, 解压完要改名,删除冗余的
            ZipTools.UnCompress(zipFileMd5);
            if (m_UnZipTimer == null)
            {
                m_UnZipTimer = TimerMgr.Instance.CreateTimer(false, 0, true, true);
                m_UnZipTimer.AddListener(OnUnZipTimer);
            }
            else
            {
                m_UnZipTimer.Start();
            }
        }
 public override void Exit(AutoUpdateMgr target)
 {
     if (m_UnZipTimer != null)
     {
         m_UnZipTimer.Dispose();
         m_UnZipTimer = null;
     }
 }
        public override void Enter(AutoUpdateMgr target)
        {
            string oldVer = target.LocalResVersion;
            string newVer = target.CurrServeResrVersion;

            var updateFile = target.LocalUpdateFile;

            m_ZipFileName = ZipTools.GetZipFileName(oldVer, newVer);

            long read = 0;
            AutoUpdateCfgItem item;

            m_ZipFileName = string.Format("{0}.zip", m_ZipFileName);
            bool isSaveUpdateFile = false;

            if (updateFile.FindItem(m_ZipFileName, out item))
            {
                if (item.isDone)
                {
                    ToNextState();
                    return;
                }

                read = item.readBytes;
            }
            else
            {
                item = new AutoUpdateCfgItem();
                item.fileContentMd5 = m_ZipFileName;
                item.isDone         = false;
                item.readBytes      = 0;
                updateFile.AddOrSet(item);
                isSaveUpdateFile = true;
            }

            isSaveUpdateFile = isSaveUpdateFile || updateFile.RemoveDowningZipFiles(m_ZipFileName);
            if (isSaveUpdateFile)
            {
                updateFile.SaveToLastFile();
            }

            string resAddr = target.ResServerAddr;
            bool   isHttps = resAddr.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase);
            string url;

            if (isHttps)
            {
                url = string.Format("{0}/{1}", resAddr, m_ZipFileName);
            }
            else
            {
                long tt = DateTime.UtcNow.Ticks;
                url = string.Format("{0}/{1}?time={2}", resAddr, m_ZipFileName, tt.ToString());
            }
            target.CreateHttpFile(url, read, OnHttpRead, OnHttpError);
        }
Exemple #7
0
        public override void Enter(AutoUpdateMgr target)
        {
            string writePath = target.WritePath;

            if (string.IsNullOrEmpty(writePath))
            {
                target.EndAutoUpdate();
                return;
            }

            m_FileListName = string.Format("{0}/{1}", writePath, AutoUpdateMgr._cFileListTxt);
            m_VersionName  = string.Format("{0}/{1}", writePath, AutoUpdateMgr._cVersionTxt);
            m_UpdateName   = string.Format("{0}/{1}", writePath, AutoUpdateMgr._cUpdateTxt);

            DoNextCopyVersion();
        }
        public override void Enter(AutoUpdateMgr target)
        {
            string verMd5 = target.ServerZipVerMd5;

            if (string.IsNullOrEmpty(verMd5))
            {
                ToNextStatus();
                return;
            }

            string resAddr = target.ResServerAddr;
            // 已经是内容MD5,所以不需要加时间戳
            string url = string.Format("{0}/{1}.txt", resAddr, verMd5);

            target.CurrUpdateZipFileMd5 = string.Empty;
            target.CreateHttpTxt(url, OnReadEvent, OnError);
        }
Exemple #9
0
        public override void Enter(AutoUpdateMgr target)
        {
            string resAddr = target.ResServerAddr;
            bool   isHttps = resAddr.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase);
            string url;

            if (isHttps)
            {
                url = string.Format("{0}/{1}", resAddr, AutoUpdateMgr._cVersionTxt);
            }
            else
            {
                long t = DateTime.UtcNow.Ticks;
                url = string.Format("{0}/{1}?time={2}", resAddr, AutoUpdateMgr._cVersionTxt, t.ToString());
            }
            target.CreateHttpTxt(url, OnReadEvent, OnError);
        }
Exemple #10
0
        public override void Enter(AutoUpdateMgr target)
        {
            var updateFile = target.LocalUpdateFile;

            m_ZipFileName = target.CurrUpdateZipFileMd5;

            long read = 0;
            AutoUpdateCfgItem item;
            bool isSaveUpdateFile = false;

            if (updateFile.FindItem(m_ZipFileName, out item))
            {
                if (item.isDone)
                {
                    ToUnZipRes();
                    return;
                }

                read = item.readBytes;
            }
            else
            {
                item = new AutoUpdateCfgItem();
                item.fileContentMd5 = m_ZipFileName;
                item.isDone         = false;
                item.readBytes      = 0;
                updateFile.AddOrSet(item);
                isSaveUpdateFile = true;
            }

            isSaveUpdateFile = isSaveUpdateFile || updateFile.RemoveDowningZipFiles(m_ZipFileName);
            if (isSaveUpdateFile)
            {
                updateFile.SaveToLastFile();
            }

            string resAddr = target.ResServerAddr;
            // m_ZipFileName是内容MD5所以不用加时间戳
            string url = string.Format("{0}/{1}", resAddr, m_ZipFileName);

            target.CreateHttpFile(url, read, OnHttpRead, OnHttpError);
        }
        public override void Enter(AutoUpdateMgr target)
        {
            string ver = target.CurrServeResrVersion;

            if (string.IsNullOrEmpty(ver))
            {
                AutoUpdateMgr.Instance.EndAutoUpdate();
                return;
            }

            string writePath = target.WritePath;

            if (string.IsNullOrEmpty(writePath))
            {
                AutoUpdateMgr.Instance.EndAutoUpdate();
                return;
            }

            DoGetServerFileList();
        }
Exemple #12
0
        public override void Enter(AutoUpdateMgr target)
        {
            Reset();
            var f = target.LocalUpdateFile;

            if (f.Count <= 0)
            {
                ToNextState();
                return;
            }

            m_Items = f.ToArray();
            if (m_Items == null || m_Items.Length <= 0)
            {
                ToNextState();
                return;
            }

            m_Curr = 0;
            StartCurrDownload();
        }
        public override void Enter(AutoUpdateMgr target)
        {
            // 解压
            string zipFileMd5 = target.CurrUpdateZipFileMd5;
            string writePath  = target.WritePath;

            if (string.IsNullOrEmpty(zipFileMd5) || string.IsNullOrEmpty(writePath))
            {
                AutoUpdateMgr.Instance.EndAutoUpdate();
            }
            string zipFileName = string.Format("{0}/{1}", writePath, zipFileMd5);

            if (!File.Exists(zipFileName))
            {
                target.Error(AutoUpdateErrorType.auError_ResZipVerReq, 0);
                return;
            }

            // 未写完, 解压完要改名,删除冗余的
            ZipTools.UnCompress(zipFileMd5);
        }
Exemple #14
0
        public override void Enter(AutoUpdateMgr target)
        {
            string ver = target.CurrServeResrVersion;

            if (string.IsNullOrEmpty(ver))
            {
                target.EndAutoUpdate();
                return;
            }

            string writePath = target.WritePath;

            if (string.IsNullOrEmpty(writePath))
            {
                target.EndAutoUpdate();
                return;
            }

            target.TotalDownM = 0;
            target.CurDownM   = 0;
            DoGetServerFileList();
        }
Exemple #15
0
        public override void Enter(AutoUpdateMgr target)
        {
            string url = string.Format("{0}/{1}", target.ResServerAddr, AutoUpdateMgr._cVersionTxt);

            target.CreateHttpTxt(url, OnReadEvent, OnError);
        }
Exemple #16
0
 public override void Enter(AutoUpdateMgr target)
 {
     target.DownProcess = 1.0f;
 }
        // 讲下载文件到等待吗目录
        void DoInit(AutoUpdateMgr target)
        {
            var f = target.LocalUpdateFile;

            if (f.Count <= 0)
            {
                ToNextState();
                return;
            }
            var items = f.ToArray();

            if (items == null || items.Length <= 0)
            {
                ToNextState();
                return;
            }

            if (m_WaitList == null)
            {
                m_WaitList = new LinkedList <AutoUpdateCfgItem>();
            }
            for (int i = 0; i < items.Length; ++i)
            {
                // 判断数量
                var item = items[i];
                if (item.isDone)
                {
                    // 写回到下载
                    double m1    = ((double)item.readBytes) / ((double)(1024 * 1024));
                    double curM1 = AutoUpdateMgr.Instance.CurDownM;
                    curM1 += m1;
                    AutoUpdateMgr.Instance.CurDownM = curM1;
                    continue;
                }

                m_WaitList.AddLast(item);
            }

            DoUpdateDownProcess();

            if (m_WaitList.Count <= 0)
            {
                ToNextState();
                return;
            }

            int threadCount = AutoUpdateMgr.Instance.ThreadCount;

            if (threadCount <= 0)
            {
                threadCount = 1;
            }

            if (m_WaitList.Count < threadCount)
            {
                threadCount = m_WaitList.Count;
            }

            if (m_DownList == null)
            {
                m_DownList = new LinkedList <DonwloadItem>();
            }

            // 创建线程对象
            for (int i = 0; i < threadCount; ++i)
            {
                m_DownList.AddLast(new DonwloadItem());
            }
        }
 public override void Exit(AutoUpdateMgr target)
 {
     Reset();
 }
 public override void Enter(AutoUpdateMgr target)
 {
     target.HttpRelease();
     Reset();
     DoInit(target);
 }
 public override void Process(AutoUpdateMgr target)
 {
     DoUpdate();
 }
Exemple #21
0
 public override void Enter(AutoUpdateMgr target)
 {
     target.HttpRelease();
     target.DownProcess = 1.0f;
     target.CurDownM    = target.TotalDownM;
 }