Exemplo n.º 1
0
        public void updateState()
        {
            DownloadManager manager = EditorBase.mDownloadManager;
            FileWrap        file    = manager.getCurDownloadingFile();

            if (file != null && file.getFileName() != CommonDefine.VERSION && file.getFileName() != CommonDefine.FILELIST)
            {
                // 当前进度
                float percent = file.getTotalSize() > 0 ? (float)file.getCurSize() / (float)file.getTotalSize() : 0.0f;
                mCurFileProgress.Value  = percent * mCurFileProgress.Maximum;
                mCurFilePercent.Content = StringUtility.floatToString((float)mCurFileProgress.Value, 2) + "%";
                float curSize   = file.getCurSize() / 1024.0f;
                float totalSize = file.getTotalSize() / 1024.0f;
                mCurSizeLabel.Content = StringUtility.floatToString(MathUtility.KBToMBOrG(curSize), 3) + StringUtility.unitConversion(curSize) + "/" + StringUtility.floatToString(MathUtility.KBToMBOrG(totalSize), 3) + StringUtility.unitConversion(totalSize);
                // 总文件体积
                float downLoadTotalSize = manager.getTotalSize() / 1024.0f;
                mTotalSizeLabel.Content = StringUtility.floatToString(MathUtility.KBToMBOrG(downLoadTotalSize), 3) + StringUtility.unitConversion(downLoadTotalSize);
                // 当前下载速度
                float curDownLoadSpeed = manager.getCurSpeed() / 1024.0f;
                mCurSpeedLabel.Content = StringUtility.floatToString(MathUtility.KBToMBOrG(curDownLoadSpeed), 3) + StringUtility.unitConversion(curDownLoadSpeed) + "/S";
                // 总进度
                float totalPercent = (float)manager.getDownloadedSize() / manager.getTotalSize();
                mTotalProgress.Value        = totalPercent * mTotalProgress.Maximum;
                mTotalFileCountText.Content = StringUtility.intToString(manager.getDownloadedCount()) + "/" + StringUtility.intToString(manager.getTotalCount());
                mTotalPercent.Content       = StringUtility.floatToString((float)mTotalProgress.Value, 2) + "%";
                // 预计剩余时间
                int hours = 0, minutes = 0, seconds = 0;
                MathUtility.secondsToHoursMinutesSeconds((int)manager.getRemainTime(), ref hours, ref minutes, ref seconds);
                string timeString = StringUtility.intToString(hours, 2) + "小时" + StringUtility.intToString(minutes, 2) + "分" + StringUtility.intToString(seconds, 2) + "秒";
                mTotalTimeLabel.Content = timeString;
            }
        }
Exemplo n.º 2
0
        public void update(float elapsedTime)
        {
            DownloadManager manager = EditorBase.mDownloadManager;
            FileWrap        file    = manager.getCurDownloadingFile();

            if (manager.getDownloading() && file != null && file.getTotalSize() > 0 && manager.getTotalCount() > 0)
            {
                updateState();
            }
        }
Exemplo n.º 3
0
 //----------------------------------------------------------------------------------------------------------------------------------------------------
 // 返回值表示是否继续下载
 protected bool downloading(byte[] pBuffer, int nSize)
 {
     if (!mCurDownloading.writeFile(pBuffer, nSize))
     {
         logError("文件写入失败! 文件 : " + mCurDownloading.getFileName(), true);
         return(false);
     }
     mSpeedInSecond       = mSpeedInSecond + nSize;
     mLastDownloadingTime = 0.0f;
     if (mCurDownloading.getFileName() == CommonDefine.FILELIST)
     {
         mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_DOWNLOADING_LIST_FILE, StringUtility.floatToString((float)mCurDownloading.getCurSize() / mCurDownloading.getTotalSize() * 100.0f, 2));
     }
     // 如果取消更新,则需要返回非0,中断下载
     if (mCancel)
     {
         pushDelayCommand <CommandDownloadManagerCancel>(this);
     }
     logConsole("已下载 : " + mCurDownloading.getCurSize() + "/" + mCurDownloading.getTotalSize() + "Bytes");
     return(!mCancel);
 }
Exemplo n.º 4
0
    protected void onFinish(string fileName, bool downloadSuccess)
    {
        if (!mDownloadingFileList.ContainsKey(fileName))
        {
            return;
        }
        // 如果没有下载成功,则不再继续执行后续更新逻辑
        if (!downloadSuccess)
        {
            setState(UPGRADE_STATE.US_NONE);
            return;
        }
        mLastDownloadingTime = -1.0f;
        FileWrap file = mDownloadingFileList[fileName];

        if (fileName == CommonDefine.VERSION)
        {
            notifyVersionDownloaded(file);
        }
        else if (fileName == CommonDefine.FILELIST)
        {
            notifyFileListDownloaded(file);
        }
        else
        {
            string md5 = "";
            if (mRemoteFileList.ContainsKey(file.getFileName()))
            {
                md5 = mRemoteFileList[file.getFileName()].mMD5;
            }
            // 如果失败,则不再继续更新
            int ret = file.finishWrite(md5);
            if (ret != 0)
            {
                if (ret == 1)
                {
                    logError("文件下载失败," + fileName + "文件校验失败, 可能是上次未更新完成且长时间没有更新,请重新更新", true);
                }
                else if (ret == 2)
                {
                    logError("文件下载失败,文件可能被占用 : " + fileName, true);
                }
                setState(UPGRADE_STATE.US_NONE);
                pushDelayCommand <CommandDownloadManagerCancel>(mDownloadManager);
            }
            else
            {
                mDownloadedSize += file.getTotalSize();
                // 加入下载完成的列表
                mDownloadedList.Add(fileName, file);
                mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_FINISH_DOWNLOAD, file.getFileName());
                // 全部文件都下载完毕,则版本更新完毕
                if (mDownloadedList.Count() == mModifiedList.Count())
                {
                    notifyAllDownloaded();
                    // 更新完成
                    mEditorCore.sendDelayEvent(CORE_EVENT_TYPE.CET_UPDATE_DONE);
                    // 更新版本号
                    done();
                }
            }
        }
    }