Exemple #1
0
        private static void OnGetModfile(Modfile modfile, ModBinaryRequest request)
        {
            string tempFilePath = request.binaryFilePath + ".download";

            request.modfile    = modfile;
            request.webRequest = UnityWebRequest.Get(modfile.downloadLocator.binaryURL);

            try
            {
                Directory.CreateDirectory(Path.GetDirectoryName(tempFilePath));
                request.webRequest.downloadHandler = new DownloadHandlerFile(tempFilePath);
            }
            catch (Exception e)
            {
                string warningInfo = ("[mod.io] Failed to create download file on disk."
                                      + "\nFile: " + tempFilePath + "\n\n");

                Debug.LogWarning(warningInfo
                                 + Utility.GenerateExceptionDebugString(e));

                request.NotifyFailed();

                return;
            }

            var operation = request.webRequest.SendWebRequest();

            operation.completed += (o) => DownloadClient.OnModBinaryRequestCompleted(operation,
                                                                                     request);
        }
Exemple #2
0
        private static void OnModBinaryRequestCompleted(UnityWebRequestAsyncOperation operation,
                                                        ModBinaryRequest request)
        {
            UnityWebRequest webRequest = operation.webRequest;

            request.isDone = true;

            if (webRequest.isNetworkError || webRequest.isHttpError)
            {
                request.error = WebRequestError.GenerateFromWebRequest(webRequest);

                request.NotifyFailed();
            }
            else
            {
                #if DEBUG
                if (GlobalSettings.LOG_ALL_WEBREQUESTS)
                {
                    var responseTimeStamp = ServerTimeStamp.Now;
                    Debug.Log("DOWNLOAD SUCEEDED"
                              + "\nDownload completed at: " + ServerTimeStamp.ToLocalDateTime(responseTimeStamp)
                              + "\nURL: " + webRequest.url
                              + "\nFilePath: " + request.binaryFilePath);
                }
                #endif

                try
                {
                    if (File.Exists(request.binaryFilePath))
                    {
                        File.Delete(request.binaryFilePath);
                    }

                    File.Move(request.binaryFilePath + ".download", request.binaryFilePath);
                }
                catch (Exception e)
                {
                    string warningInfo = ("[mod.io] Failed to save mod binary."
                                          + "\nFile: " + request.binaryFilePath + "\n\n");

                    Debug.LogWarning(warningInfo
                                     + Utility.GenerateExceptionDebugString(e));

                    request.NotifyFailed();
                }

                request.NotifySucceeded();
            }
        }
Exemple #3
0
        // ---------[ BINARY DOWNLOADS ]---------
        public static ModBinaryRequest DownloadModBinary(int modId, int modfileId,
                                                         string downloadFilePath)
        {
            ModBinaryRequest request = new ModBinaryRequest();

            request.isDone         = false;
            request.binaryFilePath = downloadFilePath;

            // - Acquire Download URL -
            APIClient.GetModfile(modId, modfileId,
                                 (mf) => DownloadClient.OnGetModfile(mf, request),
                                 (e) => { request.error = e; request.NotifyFailed(); });

            return(request);
        }
Exemple #4
0
        public static ModBinaryRequest GetActiveModBinary(ModProfile profile)
        {
            string zipFilePath = CacheClient.GenerateModBinaryZipFilePath(profile.id,
                                                                          profile.activeBuild.id);
            ModBinaryRequest request;

            if (File.Exists(zipFilePath))
            {
                request                = new ModBinaryRequest();
                request.isDone         = true;
                request.binaryFilePath = zipFilePath;
            }
            else
            {
                request = DownloadClient.DownloadModBinary(profile.id,
                                                           profile.activeBuild.id,
                                                           CacheClient.GenerateModBinaryZipFilePath(profile.id, profile.activeBuild.id));

                request.succeeded += (r) => CacheClient.SaveModfile(r.modfile);
            }

            return(request);
        }