public static void DownloadImageFromUrl(string path, DownloadCallback onFinished) { if (networkController != null) { networkController.downloadImageFromUrl(path, onFinished); } }
public void addDownload(string fileURL, string savePath, DownloadCallback succeedCallback, DownloadCallback failedCallback, LuaFunction progressCallback) { lock (syncLock) { DownloadFileInfo info = new DownloadFileInfo(); info.fileURL = fileURL; info.realFilePath = savePath; // 先下载到一个临时文件,然后再复制到正确路径 info.tmpFilePath = savePath + GameController.getInstance().getMilliseconds(); info.succeedCallback = () => { succeedCallback(); onDownloadOver(); }; info.failedCallback = () => { failedCallback(); onDownloadOver(); }; info.progressCallback = progressCallback; list.Add(info); } }
public DownloadProgressObserver(IDownloadable downloadable) { this.callback = downloadable.GetCallback(); this.bundleName = downloadable.GetBundleName(); this.assetName = downloadable.GetAssetName(); this.options = downloadable.GetParams(); }
private IEnumerator DownloadFromUrl(string url, DownloadCallback onComplete) { #if ENABLE_DEBUG_LOGS Debug.Log($"Downloading file at url: {url}\nSaving at path: {_cacheFilePath}"); #endif using UnityWebRequest request = new UnityWebRequest(url) { downloadHandler = new AssetBundlesDownloadHandler(_cacheFilePath) }; UnityWebRequestAsyncOperation operation = request.SendWebRequest(); while (!operation.isDone) { yield return(new WaitForEndOfFrame()); } bool success = request.result == UnityWebRequest.Result.Success; #if ENABLE_DEBUG_LOGS Debug.Log($"Download request result: {request.result}"); if (!success) { Debug.LogError($"Download request error: {request.error}"); } #endif yield return(onComplete.Invoke(success, _cacheFilePath)); }
private void downloadImageFromUrl(string path, DownloadCallback onFinished) { if (_ready == false) { return; } string filename = System.IO.Path.GetFileName(path); string persistentFile = GetPersistentImagePath(filename); string localUrl = string.Format("file:///{0}", persistentFile); if (System.IO.File.Exists(persistentFile)) { StartCoroutine(_downloadFromUrl(localUrl, onFinished)); } else { StartCoroutine(_downloadFromUrl(path, (www) => { if (Application.platform != RuntimePlatform.WindowsWebPlayer && Application.platform != RuntimePlatform.OSXWebPlayer) { //System.IO.File.WriteAllBytes(persistentFile, www.bytes); if (onFinished != null) { onFinished(www); } } })); } }
public void BeginDownload(string url, DownloadCallback callback, FileStream continueFileStream, object param) { RequestState requestState = new RequestState(); requestState.downloadCallback = callback; requestState.param = param; try { HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "GET"; request.Timeout = 10000; request.ReadWriteTimeout = 10000; if (continueFileStream != null) { requestState.continueFileStream = continueFileStream; continueFileStream.Seek(continueFileStream.Length, SeekOrigin.Current); request.AddRange((int)(continueFileStream.Length)); } requestState.request = request; IAsyncResult result = request.BeginGetResponse(ResponseCallback, requestState); } catch (Exception e) { callback.OnError(param, e); } }
public int download_file1(string file_id, DownloadCallback callback) { long file_offset = 0; long download_bytes = 0; return(this.download_file1(file_id, file_offset, download_bytes, callback)); }
public WWWData(string url, WWW www, DownloadCallback onFinished, DownloadCallback onProgress) { this.www = www; this.url = url; this.onFinished = onFinished; this.onProgress = onProgress; }
public void LoadRecording(string fileName, DownloadCallback callback) { string uri = serverAddress + "/" + downloadEndPoint + "/" + fileName + ".xml"; // A correct website page. StartCoroutine(Get(uri, callback)); }
private IEnumerator WaitForDownload(DownloadCallback callBack) { Debug.Log("Yielding"); yield return(wwwData); Debug.Log("Yielded"); callBack(wwwData.text, wwwData.error); }
private void downloadFromUrl(string path, Dictionary <string, object> postData, DownloadCallback onFinished) { if (!_ready || onFinished == null) { return; } StartCoroutine(_downloadFromUrlWithPOST(path, postData, onFinished)); }
public static WWWData DownloadFromUrl(string path, DownloadCallback onFinished, DownloadCallback onProgress) { if (networkController != null) { return(networkController.downloadFromUrl(path, onFinished, onProgress)); } return(null); }
public static WWWData DownloadFromUrl(string path, DownloadCallback onFinished) { Debug.LogWarning(path); if (networkController != null) { return(networkController.downloadFromUrl(path, onFinished, null)); } return(null); }
private WWWData downloadFromUrl(string path, DownloadCallback onFinished, DownloadCallback onProgress) { if (_ready == false || onFinished == null) { return(null); } StartCoroutine(_downloadFromUrl(path, onFinished)); return(null); }
internal static void download(int id, DownloadCallback callback) { CraftManager.status_info = "Downloading craft from KerbalX..."; api.download_craft(id, (craft_file_string, code) => { if (code == 200) { ConfigNode craft = ConfigNode.Parse(craft_file_string); check_download_queue(); callback(craft); } CraftManager.status_info = ""; }); }
public override void DownloadAll(ProgressCallback onProgress, DownloadCallback onFinish) { // //if (Config.ignoreAssetBundle) { // if (onFinish != null) // onFinish(true, null); // return; //} StopAllCoroutines(); StartCoroutine(Download(assetBundleNames, onProgress, onFinish)); }
private void StartDownload(string sURL, DownloadCallback fn) { try { wwwData = new WWW(sURL); Debug.Log("Starting download."); StartCoroutine("WaitForDownload", fn); } catch (Exception e) { Debug.Log(e.ToString()); } }
public static IEnumerator DownloadAsseBundle(string path, int ver, DownloadCallback callback) { UnityWebRequest req = UnityWebRequest.GetAssetBundle(path, (uint)ver, 0); yield return(req.SendWebRequest()); AssetBundle asset = DownloadHandlerAssetBundle.GetContent(req); loadedInfo[asset.name] = asset; if (callback != null) { callback(asset); } }
public Job(string path, DownloadCallback callback, bool saveToLocal, int downloadRetries, FailScript failscript) { this.path = path; this.callback = callback; this.saveToLocal = saveToLocal; this.failscript = failscript; if (downloadRetries != default(int)) { this.downloadRetries = downloadRetries; } else { this.downloadRetries = 0; } }
/// <summary> /// Attempts to start downloading a shared file. /// </summary> /// <returns>True if the download has successfully started</returns> public bool Download(DownloadCallback onSuccess = null, FailureCallback onFailure = null) { if (!_isUgc) { return(false); } if (_isDownloading) { return(false); } if (IsDownloaded) { return(false); } _isDownloading = true; remoteStorage.native.UGCDownload(_handle, 1000, (result, error) => { _isDownloading = false; if (error || result.Result != Result.OK) { onFailure?.Invoke(result.Result == 0 ? Callbacks.Result.IOFailure : (Callbacks.Result)result.Result); return; } _ownerId = result.SteamIDOwner; _sizeInBytes = result.SizeInBytes; _fileName = result.PchFileName; unsafe { _downloadedData = new byte[_sizeInBytes]; fixed(byte *bufferPtr = _downloadedData) { remoteStorage.native.UGCRead(_handle, (IntPtr)bufferPtr, _sizeInBytes, 0, UGCReadAction.ontinueReading); } } onSuccess?.Invoke(); }); return(true); }
public void DownloadLatestMap(DownloadCallback callback) { reference.GetMetadataAsync().ContinueWith((Task <StorageMetadata> metadataTask) => { if (metadataTask.IsFaulted || metadataTask.IsCanceled) { Debug.Log("Failed to download metadata."); Debug.Log(metadataTask.Exception.InnerException.Message); } else if (metadataTask.IsCompleted) { Debug.Log("Metadata successfully downloaded."); StorageMetadata meta = metadataTask.Result; // If there's no local map or local map is old, download new map from cloud. if (!MapExists || meta.CreationTimeMillis > File.GetLastWriteTimeUtc(WorldMapPath)) { Debug.Log("Beginning map download."); DownloadInProgress = true; reference.GetFileAsync(FirebaseWorldMapPath).ContinueWith(mapTask => { DownloadInProgress = false; if (mapTask.IsFaulted || mapTask.IsCanceled) { Debug.Log("Failed to download map."); Debug.Log(mapTask.Exception.InnerException.Message); } else if (mapTask.IsCompleted) { Debug.Log("Map successfully downloaded."); callback(); } }); } else { Debug.Log("No need to download new map."); callback(); } } }); }
private IEnumerator _downloadFromUrl(string path, DownloadCallback callback) { WWW www = new WWW(path); yield return(www); if (www.error == null) { if (callback != null && www.isDone) { callback(www); } } else { Debug.LogWarning("NetworkController retrying download: " + path + ". With error: " + www.error); //StartCoroutine(_downloadFromUrl(path, callback)); } }
public static void DownloadUrls(string DownloadPath, List <string> Urls, DownloadCallback finishedCallback) { GameObject gameObject = new GameObject("Downloader"); UrlDownloader dl; for (int u = 0; u < Urls.Count; u++) { if (UrlIsValid(Urls[u])) { Debug.Log("Attempting Download from: " + Urls[u]); dl = gameObject.AddComponent <UrlDownloader>(); dl.FinishedCallback = finishedCallback; dl.StartDownload(Urls[u], Fyo.DefaultPaths.MarqueeData + @"/" + DownloadPath + @"File" + u.ToString() + ".download"); } else { Debug.LogWarning("Invalid URL: " + Urls[u]); } } }
/// <summary> /// Asynchronously download an object from an XML stream. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="url">The url to download from</param> /// <param name="postData">The http POST data to pass with the url. May be null.</param> /// <param name="callback">A callback invoked on the UI thread</param> /// <returns></returns> public static void DownloadXMLAsync <T>(string url, HttpPostData postData, DownloadCallback <T> callback) where T : class { EveClient.HttpWebService.DownloadXmlAsync(url, postData, // Callback (asyncResult, userState) => { T result = null; string errorMessage = ""; // Was there an HTTP error ?? if (asyncResult.Error != null) { errorMessage = asyncResult.Error.Message; } // No http error, let's try to deserialize else { try { // Deserialize using (XmlNodeReader reader = new XmlNodeReader(asyncResult.Result)) { XmlSerializer xs = new XmlSerializer(typeof(T)); result = (T)xs.Deserialize(reader); } } // An error occured during the deserialization catch (InvalidOperationException exc) { ExceptionHandler.LogException(exc, true); errorMessage = (exc.InnerException == null ? exc.Message : exc.InnerException.Message); } } // We got the result, let's invoke the callback on this actor Dispatcher.Invoke(() => callback.Invoke(result, errorMessage)); }, null); }
static int _m_DownloadAsseBundle_xlua_st_(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); { string path = LuaAPI.lua_tostring(L, 1); int ver = LuaAPI.xlua_tointeger(L, 2); DownloadCallback callback = translator.GetDelegate <DownloadCallback>(L, 3); System.Collections.IEnumerator __cl_gen_ret = BoyApp.DownloadAsseBundle(path, ver, callback); translator.PushAny(L, __cl_gen_ret); return(1); } } catch (System.Exception __gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + __gen_e)); } }
IEnumerator Get(string uri, DownloadCallback callback) { using (UnityWebRequest webRequest = UnityWebRequest.Get(uri)) { // Request and wait for the desired page. yield return(webRequest.SendWebRequest()); string[] pages = uri.Split('/'); int page = pages.Length - 1; if (webRequest.isNetworkError) { Debug.Log(pages[page] + ": Error: " + webRequest.error); callback?.Invoke(webRequest.error, ""); } else { Debug.Log(pages[page] + ":\nReceived: " + webRequest.downloadHandler.text); callback?.Invoke("OK", webRequest.downloadHandler.text); } } }
/// <summary> /// Downloads a file Async and sends it to the callback. /// caches image files to local disk /// retries the failed download a set number of times /// </summary> public static void Async(string path, DownloadCallback callback, bool saveToLocal, int downloadRetries) { Job job = new Job(path, callback, saveToLocal, downloadRetries, null); _singleton.Enqueue(job); }
/// <summary> /// Downloads a file Async and sends it to the callback. /// Invokes the failscript if the download failed /// </summary> public static void Async(string path, DownloadCallback callback, FailScript failscript) { Job job = new Job(path, callback, false, 0, failscript); _singleton.Enqueue(job); }
/// <summary> /// Downloads a file Async and sends it to the callback. /// </summary> public static void Async(string path, DownloadCallback callback) { Job job = new Job(path, callback, false, 0, null); _singleton.Enqueue(job); }
public System.IAsyncResult BeginDownload( String remFileName, System.AsyncCallback callback ) { DownloadCallback ftpCallback = new DownloadCallback(this.Download); return ftpCallback.BeginInvoke(remFileName, callback, null); }
/// <summary> /// Downloads a file Async and sends it to the callback. /// retries the failed download a set number of times /// </summary> public static void Async(string path, DownloadCallback callback, int downloadRetries) { Async(path, callback, false, downloadRetries); }
private void downloadFromUrl(string path, Dictionary<string, object> postData, DownloadCallback onFinished) { if (!_ready || onFinished == null) { return; } StartCoroutine(_downloadFromUrlWithPOST(path, postData, onFinished)); }
private IEnumerator _downloadFromUrlWithPOST(string path, Dictionary<string, object> postData, DownloadCallback onFinished) { DressRoom.ShowInfiniteProgres(true); ShowWaiting(true); WWWForm wwwform = new WWWForm(); if (postData != null) { foreach (var postKey in postData.Keys) { var postValue = postData[postKey]; if (postValue is string) { wwwform.AddField(postKey, (string)postValue); } if (postValue is byte[]) { string filename = Md5Sum("screenshot-" + System.DateTime.Now.ToString()); wwwform.AddBinaryData(postKey, (byte[])postValue, filename + ".png"); } } } WWW www = new WWW(path, wwwform); yield return www; DressRoom.ShowInfiniteProgres(true); ShowWaiting(false); if (www.error == null) { if (onFinished != null && www.isDone) { onFinished(www); } } else { Debug.LogWarning("NetworkController retrying download with POST: " + path + ". With error: " + www.error); } }
private IEnumerator _downloadFromUrl(string path, DownloadCallback callback) { DressRoom.ShowInfiniteProgres(true); ShowWaiting(true); WWW www = new WWW(path); yield return www; ShowWaiting(false); if (www.error == null) { DressRoom.ShowInfiniteProgres(false); if (callback != null && www.isDone) { callback(www); } } else { Debug.LogWarning("NetworkController retrying download: " + path + ". With error: " + www.error); //StartCoroutine(_downloadFromUrl(path, callback)); } }
private void downloadImageFromUrl(string path, DownloadCallback onFinished) { if (_ready == false) { return; } string filename = System.IO.Path.GetFileName(path); string persistentFile = GetPersistentImagePath(filename); string localUrl = string.Format("file:///{0}", persistentFile); if (System.IO.File.Exists(persistentFile)) { StartCoroutine(_downloadFromUrl(localUrl, onFinished)); } else { StartCoroutine(_downloadFromUrl(path, (www) => { try { #if !UNITY_WEBPLAYER System.IO.File.WriteAllBytes(persistentFile, www.bytes); #endif if (onFinished != null) { onFinished(www); } } catch (Exception) { Debug.LogWarning("Failed to save image cache: " + persistentFile); } })); } }
private IEnumerator _downloadImageFromUrl(string path, DownloadCallback onFinished) { yield return null; }
public static WWWData DownloadFromUrl(string path, DownloadCallback onFinished, DownloadCallback onProgress) { if (networkController != null) { return networkController.downloadFromUrl(path, onFinished, onProgress); } return null; }
/// <summary> /// Downloads a file Async and sends it to the callback. /// caches image files to local disk /// </summary> public static void Async(string path, DownloadCallback callback, bool saveToLocal) { Async(path, callback, saveToLocal, 0); }
private WWWData downloadFromUrl(string path, DownloadCallback onFinished, DownloadCallback onProgress) { if (_ready == false || onFinished == null) { return null; } StartCoroutine(_downloadFromUrl(path, onFinished)); return null; }
public static void DownloadFromUrl(string path, Dictionary<string, object> postData, DownloadCallback onFinished) { if (networkController != null) { Debug.LogWarning("DownloadFromUrl: " + path); networkController.downloadFromUrl(path, postData, onFinished); } }
public static WWWData DownloadFromUrl(string path, DownloadCallback onFinished) { Debug.LogWarning("DownloadFromUrl: " + path); if (networkController != null) { return networkController.downloadFromUrl(path, onFinished, null); } return null; }