Esempio n. 1
0
    /// <summary>
    /// 下载
    /// </summary>
    /// <param name="filePath"></param>
    /// <param name="onProgress"></param>
    /// <param name="onRequestFinished"></param>
    public static void Download(string filePath, OnDownloadProgressDelegate onProgress, OnRequestFinishedDelegate onRequestFinished)
    {
        var request = new HTTPRequest(new Uri(filePath), onRequestFinished);

        request.OnProgress += onProgress;
        request.Send();
    }
Esempio n. 2
0
 public DownloadProgressBar()
 {
     InitializeComponent();
     OdPDelegate = new OnDownloadProgressDelegate(OnDownloadProgressView);
     OdFDelegate = new OnDownloadFinishedDelegate(OnDownloadFinishedView);
     OSCDelegate = new OnStateChangedDelegate(OnStateChangedView);
 }
Esempio n. 3
0
 // Token: 0x06005153 RID: 20819 RVA: 0x001BDFAC File Offset: 0x001BC3AC
 public static void DownloadAssetBundle(ApiWorld world, OnDownloadProgressDelegate onProgress = null, AssetBundleDownloadManager.OnDownloadCompleted onSuccess = null, AssetBundleDownloadManager.OnDownloadError onError = null, AssetBundleDownloadManager.UnpackType unpackType = AssetBundleDownloadManager.UnpackType.Async)
 {
     if (Downloader.downloadManager == null)
     {
         Downloader.InitializeDownloadManager();
     }
     AssetBundleDownloadManager.Instance.DownloadAssetBundle(world, onProgress, onSuccess, onError, unpackType);
 }
Esempio n. 4
0
    public void RequestDownload(string saveFile, string url, OnDownloadProgressDelegate progressCallback, OnFinishDownloadDelegate finishCallBack)
    {
        downloaded            = 0;
        downloadLength        = 0;
        this.progressCallback = progressCallback;
        this.finishCallBack   = finishCallBack;

        string directoryName = Path.GetDirectoryName(saveFile);

        if (!Directory.Exists(directoryName))
        {
            Directory.CreateDirectory(directoryName);
        }
        fileWriteStream = File.Create(saveFile);

        HTTPRequest request = new HTTPRequest(new System.Uri(url), OnDownloadFile);

        request.DisableCache       = true;
        request.UseStreaming       = true;
        request.StreamFragmentSize = HTTPResponse.MinBufferSize;//4 metabyte

        request.Send();
    }
    // Token: 0x06005129 RID: 20777 RVA: 0x001BB3F0 File Offset: 0x001B97F0
    private IEnumerator DownloadAndUnpackAssetBundleCoroutine(string url, string assetId, int assetVersion, string pluginUrl, OnDownloadProgressDelegate onProgress, AssetBundleDownloadManager.OnDownloadCompleted onSuccess, AssetBundleDownloadManager.OnDownloadError onError, AssetBundleDownloadManager.UnpackType unpackType, int retryCount = 0, int downloadId = 0, bool forceRefreshCache = false)
    {
        AssetBundleDownload download = new AssetBundleDownload(url, unpackType);

        download.onDownloadCompleted = onSuccess;
        download.onDownloadError     = onError;
        download.onProgress          = onProgress;
        download.retryCount          = retryCount;
        download.forceRefreshCache   = forceRefreshCache;
        download.assetId             = assetId;
        download.assetVersion        = assetVersion;
        download.pluginUrl           = pluginUrl;
        download.onPluginLoadError   = delegate(string message)
        {
            Debug.LogError("Plugin failed to load: " + message);
            if (!download.forceRefreshCache)
            {
                download.forceRefreshCache = true;
                this.StartCoroutine(this.DownloadAndUnpackAssetBundleCoroutine(download));
            }
            else
            {
                download.OnDownloadError("Plugin failed to load: " + message, LoadErrorReason.PluginLoadFailed);
            }
        };
        if (Player.Instance != null && Player.Instance.isInternal)
        {
            Debug.Log(string.Concat(new object[]
            {
                "[",
                download.downloadId,
                "] Downloading asset: '",
                download.assetUrl,
                "'"
            }));
        }
        if (string.IsNullOrEmpty(download.assetUrl))
        {
            download.OnDownloadError("URL is empty", LoadErrorReason.InvalidURL);
            yield break;
        }
        if (downloadId > 0)
        {
            download.downloadId = downloadId;
        }
        bool hasExistingDownload = this.mAssetBundleDownloads.ContainsKey(download.assetUrl);

        if (!hasExistingDownload)
        {
            this.mAssetBundleDownloads[download.assetUrl] = download;
        }
        if (download.assetUrl.StartsWith("file"))
        {
            if (!string.IsNullOrEmpty(download.pluginUrl))
            {
                yield return(this.DownloadAndLoadLocalPlugin(download));
            }
            if (download.currentState == AssetBundleDownload.State.Error)
            {
                yield break;
            }
            if (this.CheckForCancellation(download))
            {
                yield break;
            }
            if (!string.IsNullOrEmpty(download.assetUrl))
            {
                yield return(this.RequestLocalAssetBundle(download, hasExistingDownload));
            }
            yield return(this.WaitForAssetToLoad(download));
        }
        else
        {
            UnityEngine.Object asset = AssetBundleDownloadManager.Instance.GetLoadedAsset(download.assetUrl);
            if (asset == null)
            {
                download.currentState = AssetBundleDownload.State.WaitingForRequestToBeSent;
                if (!string.IsNullOrEmpty(download.pluginUrl) && PluginManager.IsAllowedUrl(download.pluginUrl))
                {
                    yield return(this.DownloadAndLoadRemotePlugin(download));
                }
                else
                {
                    download.pluginUrl = null;
                }
                if (download.currentState == AssetBundleDownload.State.Error)
                {
                    yield break;
                }
                if (this.CheckForCancellation(download))
                {
                    yield break;
                }
                if (!string.IsNullOrEmpty(download.assetUrl))
                {
                    yield return(this.RequestRemoteAssetBundle(download, hasExistingDownload));
                }
                yield return(this.WaitForAssetToLoad(download));
            }
            else
            {
                VRC.Core.Logger.Log(string.Concat(new object[]
                {
                    "[",
                    download.downloadId,
                    "] Asset: ",
                    download.assetUrl,
                    " already loaded."
                }), DebugLevel.AssetBundleDownloadManager);
                download.asset = asset;
                download.OnDownloadCompleted();
            }
        }
        yield break;
    }
 // Token: 0x06005119 RID: 20761 RVA: 0x001BAC8C File Offset: 0x001B908C
 public void DownloadAssetBundle(ApiAvatar avatar, OnDownloadProgressDelegate onProgress, AssetBundleDownloadManager.OnDownloadCompleted onSuccess, AssetBundleDownloadManager.OnDownloadError onError, AssetBundleDownloadManager.UnpackType unpackType)
 {
     base.StartCoroutine(this.DownloadAndUnpackAssetBundleCoroutine(avatar.assetUrl, avatar.id, avatar.version, null, onProgress, onSuccess, onError, unpackType, 0, 0, false));
 }
 // Token: 0x06005118 RID: 20760 RVA: 0x001BAC50 File Offset: 0x001B9050
 public void DownloadAssetBundle(ApiWorld world, OnDownloadProgressDelegate onProgress, AssetBundleDownloadManager.OnDownloadCompleted onSuccess, AssetBundleDownloadManager.OnDownloadError onError, AssetBundleDownloadManager.UnpackType unpackType)
 {
     base.StartCoroutine(this.DownloadAndUnpackAssetBundleCoroutine(world.assetUrl, world.id, world.version, world.pluginUrl, onProgress, onSuccess, onError, unpackType, 0, 0, false));
 }
        /// <summary>
        /// See <see cref="IUrlRequestClient.OnDownloadProgress(IUrlRequest, long, long)"/> for details.
        /// </summary>
        /// <param name="action">Action to be executed when <see cref="IUrlRequestClient.OnDownloadProgress(IUrlRequest, long, long)"/>
        /// is called</param>
        /// <returns>
        /// Fluent Builder, call <see cref="UrlRequestClientBuilder.Build"/> to create
        /// a new <see cref="IUrlRequestClient"/> instance
        /// </returns>
        public UrlRequestClientBuilder OnDownloadProgress(OnDownloadProgressDelegate action)
        {
            client.SetOnDownloadProgress(action);

            return(this);
        }
Esempio n. 9
0
 internal void SetOnDownloadProgress(OnDownloadProgressDelegate action)
 {
     onDownloadProgress = action;
 }