Пример #1
0
        public static void UpdateDownloadSpeed(ModfileIdPair idPair)
        {
            FileDownloadInfo downloadInfo            = null;
            DownloadProgressMarkerCollection markers = null;

            if (DownloadClient.modfileDownloadMap.TryGetValue(idPair, out downloadInfo) &&
                DownloadClient.modfileProgressMarkers.TryGetValue(idPair, out markers) &&
                !downloadInfo.isDone)
            {
                Int64 bytesReceived = (downloadInfo.request == null ? 0
                                       : (Int64)downloadInfo.request.downloadedBytes);

                DownloadClient.AddDownloadProgressMarker(markers, bytesReceived);
                downloadInfo.bytesPerSecond = DownloadClient.CalculateAverageDownloadSpeed(markers);
            }
        }
Пример #2
0
        private static System.Collections.IEnumerator SpeedMonitorCoroutine()
        {
            while (DownloadClient.modfileDownloadMap.Count > 0)
            {
                int downloadCount          = DownloadClient.modfileDownloadMap.Count;
                int monitoredDownloadCount = 0;
                FileDownloadInfo[] infos
                    = new FileDownloadInfo[downloadCount];
                DownloadProgressMarkerCollection[] markerCollections
                    = new DownloadProgressMarkerCollection[downloadCount];

                // collect downloads to update
                foreach (var kvp in DownloadClient.modfileDownloadMap)
                {
                    DownloadProgressMarkerCollection markers = null;

                    if (!kvp.Value.isDone &&
                        DownloadClient.modfileProgressMarkers.TryGetValue(kvp.Key, out markers))
                    {
                        infos[monitoredDownloadCount]             = kvp.Value;
                        markerCollections[monitoredDownloadCount] = markers;

                        ++monitoredDownloadCount;
                    }
                }

                // update progress
                for (int i = 0;
                     i < monitoredDownloadCount;
                     ++i)
                {
                    FileDownloadInfo downloadInfo            = infos[i];
                    DownloadProgressMarkerCollection markers = markerCollections[i];

                    Int64 bytesReceived = (downloadInfo.request == null ? 0
                                           : (Int64)downloadInfo.request.downloadedBytes);

                    DownloadClient.AddDownloadProgressMarker(markers, bytesReceived);
                    downloadInfo.bytesPerSecond = DownloadClient.CalculateAverageDownloadSpeed(markers);
                }

                yield return(new WaitForSecondsRealtime(DownloadClient.DOWNLOAD_SPEED_UPDATE_INTERVAL));
            }

            DownloadClient.monitorBehaviour.coroutine = null;
        }