// ---------[ UI FUNCTIONALITY ]---------
        /// <summary>Displays the appropriate field of a given modfile.</summary>
        public void DisplayDownload(FileDownloadInfo download)
        {
            this.m_download = download;

            string displayText = string.Empty;

            if (download != null)
            {
                if (download.request == null ||
                    download.request.downloadedBytes == 0)
                {
                    displayText = this.m_unstartedText;
                }
                else if (download.isDone)
                {
                    displayText = this.m_completedText;
                }
                else if (download.bytesPerSecond <= 1)
                {
                    displayText = this.m_notDownloadingText;
                }
                else
                {
                    int secondsRemaining = (int)((download.fileSize - (Int64)download.request.downloadedBytes)
                                                 / download.bytesPerSecond);

                    displayText = ValueFormatting.SecondsAsTime(secondsRemaining);
                }
            }

            this.m_textComponent.text = displayText;
        }
Ejemplo n.º 2
0
        // ---------[ FUNCTIONALITY ]---------
        /// <summary>Formats a value as a display string.</summary>
        public static string FormatValue(object value, Method method, string toStringParameter)
        {
            string displayString = string.Empty;

            if (string.IsNullOrEmpty(toStringParameter))
            {
                // Default value for ToString() in most cases is (G)eneral
                toStringParameter = "G";
            }

            switch (method)
            {
            case Method.ByteCount:
            {
                Int64 bytes = 0;

                if (value != null)
                {
                    bytes = (Int64)value;
                }

                displayString = ValueFormatting.ByteCount(bytes, toStringParameter);
            }
            break;

            case Method.AbbreviatedNumber:
            {
                int number = 0;

                if (value != null)
                {
                    number = (int)value;
                }

                displayString = ValueFormatting.AbbreviateInteger(number, toStringParameter);
            }
            break;

            case Method.TimeStampAsDateTime:
            {
                if (value == null)
                {
                    displayString = "--";
                }
                else
                {
                    displayString = ServerTimeStamp.ToLocalDateTime((int)value).ToString(toStringParameter);
                }
            }
            break;

            case Method.Percentage:
            {
                if (value == null)
                {
                    displayString = "--%";
                }
                else
                {
                    displayString = ((float)value * 100.0f).ToString(toStringParameter) + "%";
                }
            }
            break;

            case Method.SecondsAsTime:
            {
                int seconds = 0;

                if (value != null)
                {
                    seconds = (int)value;
                }

                displayString = ValueFormatting.SecondsAsTime(seconds);
            }
            break;

            default:
            {
                displayString = null;

                if (value != null &&
                    !string.IsNullOrEmpty(toStringParameter))
                {
                    if (value is float)
                    {
                        displayString = ((float)value).ToString(toStringParameter);
                    }
                    else if (value is int)
                    {
                        displayString = ((int)value).ToString(toStringParameter);
                    }
                    else if (value is Int64)
                    {
                        displayString = ((Int64)value).ToString(toStringParameter);
                    }
                }

                if (displayString == null)
                {
                    if (value != null)
                    {
                        displayString = value.ToString();
                    }
                    else
                    {
                        displayString = string.Empty;
                    }
                }
            }
            break;
            }
            return(displayString);
        }