Пример #1
0
    public void ExecuteThreadedWork()
    {
        download = new ResumingDownloadFile(DownloadUrl, LocalPath);

        download.onCompleted             += OnFileDownloaded;
        download.onCancelled             += OnDownloadCancelled;
        download.onGetFileWriteException += OnDownloadCancelled;

        download.StartDownload();
    }
Пример #2
0
    void OnFileDownloaded(byte[] fileBytes)
    {
        if (fileBytes == null || fileBytes.Length <= 0)
        {
            NotiData data = new NotiData(NotiConst.UPDATE_FAILED, this.FileName, LanguageTips.UPDATE_FAILED);
            if (OnComplete != null)
            {
                OnComplete(data);                      //回调逻辑层
            }
            //MessageBox.DisplayMessageBox(string.Format("{0}: {1}", UpdateTips.UPDATE_FAILED, FileName), 0, (go) =>
            //{
            //    AssetsCtrl.downloadFailed = true;
            //});

            if (OnWorkDone != null)
            {
                OnWorkDone(this);
            }
            download = null;
            return;
        }

        string path = Path.GetDirectoryName(LocalPath);

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }

        if (LocalPath.CustomEndsWith(".ab"))
        {
            BeginDecompressExtract(LocalPath, fileBytes);
        }
        else
        {
            DownloadFileMD5 = MD5.ComputeHashString(fileBytes);
            if (DownloadFileMD5 != SrcMD5)
            {
                throw new Exception(LanguageTips.UPDATE_MD5_ERROR);
            }
            if (File.Exists(LocalPath))
            {
                File.Delete(LocalPath);
            }
            File.WriteAllBytes(LocalPath, fileBytes);
        }
        download = null;
        if (OnWorkDone != null)
        {
            OnWorkDone(this);
        }
    }
Пример #3
0
    void OnDownloadCancelled(Exception e)
    {
        NotiData data = new NotiData(NotiConst.UPDATE_CANCELLED, this.FileName, LanguageTips.UPDATE_CANCELLED);

        if (OnComplete != null)
        {
            OnComplete(data);                      //回调逻辑层
        }
        if (OnWorkDone != null)
        {
            OnWorkDone(this);
        }
        download = null;
    }