private static void DownloadModBinary_Internal(ModfileIdPair idPair, string downloadURL) { FileDownloadInfo downloadInfo = modfileDownloadMap[idPair]; downloadInfo.request = UnityWebRequest.Get(downloadURL); string tempFilePath = downloadInfo.target + ".download"; DataStorage.WriteFile(tempFilePath, new byte[0], (p, success) => { if (success) { downloadInfo.request.downloadHandler = new DownloadHandlerFile(tempFilePath); #if PLATFORM_PS4 // NOTE(@jackson): This workaround addresses an issue in UnityWebRequests on the // PS4 whereby redirects fail in specific cases. Special thanks to @Eamon of // Spiderling Studios (http://spiderlinggames.co.uk/) downloadInfo.request.redirectLimit = 0; #endif var operation = downloadInfo.request.SendWebRequest(); #if DEBUG DebugUtilities.DebugDownload(operation, LocalUser.instance, tempFilePath); #endif operation.completed += (o) => DownloadClient.OnModBinaryRequestCompleted(idPair); DownloadClient.StartMonitoringSpeed(); // notify download started if (DownloadClient.modfileDownloadStarted != null) { DownloadClient.modfileDownloadStarted(idPair, downloadInfo); } } else if (DownloadClient.modfileDownloadFailed != null) { string warningInfo = ("Failed to create download file on disk." + "\nSource: " + downloadURL + "\nDestination: " + tempFilePath + "\n\n"); modfileDownloadFailed(idPair, WebRequestError.GenerateLocal(warningInfo)); } }); }
private static void DownloadModBinary_Internal(ModfileIdPair idPair, string downloadURL) { FileDownloadInfo downloadInfo = modfileDownloadMap[idPair]; downloadInfo.request = UnityWebRequest.Get(downloadURL); string tempFilePath = downloadInfo.target + ".download"; try { Directory.CreateDirectory(Path.GetDirectoryName(tempFilePath)); downloadInfo.request.downloadHandler = new DownloadHandlerFile(tempFilePath); #if PLATFORM_PS4 // NOTE(@jackson): This workaround addresses an issue in UnityWebRequests on the // PS4 whereby redirects fail in specific cases. Special thanks to @Eamon of // Spiderling Studios (http://spiderlinggames.co.uk/) downloadInfo.request.redirectLimit = 0; #endif } catch (Exception e) { string warningInfo = ("Failed to create download file on disk." + "\nFile: " + tempFilePath + "\n\n"); Debug.LogWarning("[mod.io] " + warningInfo + Utility.GenerateExceptionDebugString(e)); if (modfileDownloadFailed != null) { modfileDownloadFailed(idPair, WebRequestError.GenerateLocal(warningInfo)); } return; } var operation = downloadInfo.request.SendWebRequest(); #if DEBUG if (PluginSettings.data.logAllRequests) { string requestHeaders = ""; List <string> requestKeys = new List <string>(APIClient.UNITY_REQUEST_HEADER_KEYS); requestKeys.AddRange(APIClient.MODIO_REQUEST_HEADER_KEYS); foreach (string headerKey in requestKeys) { string headerValue = downloadInfo.request.GetRequestHeader(headerKey); if (headerValue != null) { requestHeaders += "\n" + headerKey + ": " + headerValue; } } int timeStamp = ServerTimeStamp.Now; Debug.Log("DOWNLOAD REQUEST SENT" + "\nTimeStamp: [" + timeStamp.ToString() + "] " + ServerTimeStamp.ToLocalDateTime(timeStamp).ToString() + "\nURL: " + downloadInfo.request.url + "\nHeaders: " + requestHeaders); } #endif operation.completed += (o) => DownloadClient.OnModBinaryRequestCompleted(idPair); DownloadClient.StartMonitoringSpeed(); // notify download started if (DownloadClient.modfileDownloadStarted != null) { DownloadClient.modfileDownloadStarted(idPair, downloadInfo); } }