示例#1
0
        private static void OnModBinaryRequestCompleted(ModfileIdPair idPair)
        {
            FileDownloadInfo downloadInfo = DownloadClient.modfileDownloadMap[idPair];
            UnityWebRequest  request      = downloadInfo.request;
            bool             success      = false;

            downloadInfo.bytesPerSecond = 0;

            if (request.isNetworkError || request.isHttpError)
            {
                if (request.error.ToUpper() == "USER ABORTED" ||
                    request.error.ToUpper() == "REQUEST ABORTED")
                {
                    downloadInfo.wasAborted = true;
                }

                // 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/)
                #if UNITY_PS4 || MODIO_DEV
                else if (downloadInfo.error.webRequest.responseCode == 302) // Redirect limit exceeded
                {
                    string headerLocation = string.Empty;
                    if (downloadInfo.error.webRequest.GetResponseHeaders().TryGetValue("location", out headerLocation) &&
                        !request.url.Equals(headerLocation))
                    {
                        if (PluginSettings.REQUEST_LOGGING.logAllResponses)
                        {
                            Debug.LogFormat("[mod.io] Caught PS4 redirection error. Reattempting.\nURL: {0}", headerLocation);
                        }

                        downloadInfo.error  = null;
                        downloadInfo.isDone = false;
                        DownloadModBinary_Internal(idPair, headerLocation);
                        return;
                    }
                }
                #endif // UNITY_PS4

                else
                {
                    downloadInfo.error = WebRequestError.GenerateFromWebRequest(request);

                    if (modfileDownloadFailed != null)
                    {
                        modfileDownloadFailed(idPair, downloadInfo.error);
                    }
                }
            }
            else
            {
                success = LocalDataStorage.MoveFile(downloadInfo.target + ".download",
                                                    downloadInfo.target);

                if (!success &&
                    DownloadClient.modfileDownloadFailed != null)
                {
                    string errorMessage = ("Download succeeded but failed to rename from"
                                           + " temporary file name."
                                           + "\nTemporary file name: "
                                           + downloadInfo.target + ".download");

                    downloadInfo.error = WebRequestError.GenerateLocal(errorMessage);

                    modfileDownloadFailed(idPair, downloadInfo.error);
                }
            }

            downloadInfo.isDone = true;

            if (success &&
                modfileDownloadSucceeded != null)
            {
                modfileDownloadSucceeded(idPair, downloadInfo);
            }

            modfileDownloadMap.Remove(idPair);
            DownloadClient.modfileProgressMarkers.Remove(idPair);
        }