/// <summary> /// Напечатать цветную строку с позиционированием по идентификатору /// </summary> public void WriteLine(int id, PaintedConsoleString str) { if (!SetCursorPos(LineByID(id))) { return; } str.Print(); }
/// <summary> /// Обновить информацию о конкретной закачке /// </summary> public void UpdateInfo(DownloadInfo info) { if (info.mDownloadStatus == DownloadStatus.NotStarted) { return; // Не выводим инфу о неначатых } int progressStringSize = (10 * 2 + 3 + 2); var paintedString = new PaintedConsoleString(); paintedString.Append(info.mNumber.ToString(mNumberFormat)); paintedString.Append("/"); paintedString.Append(mMaxNumber.ToString(mNumberFormat)); paintedString.Append(" "); int count_progress_symbols = 0; string progress_string = ""; ConsoleColor colorForProgress = Console.BackgroundColor; if (info.mDownloadStatus == DownloadStatus.Started) { StringBuilder sb_prog = new StringBuilder(); if (info.mBytes > 0) { string left = Helpers.FormatBytes(info.mDownloadedBytes); string center = " "; string right = Helpers.FormatBytes(info.mBytes); progress_string = ProgressStringAligner(left, center, right, progressStringSize); count_progress_symbols = calcProgressSymbols( info.mDownloadedBytes, info.mBytes, progress_string.Count()); } else { progress_string = ProgressStringAligner(" ... ", progressStringSize); count_progress_symbols = calcProgressSymbols(0, 1, progress_string.Count()); } colorForProgress = ConsoleColor.DarkGray; } else if (info.mDownloadStatus == DownloadStatus.Finished) { if (info.mError != "") { string str_in_prog; if (info.mHttpErrorCode != 0) { str_in_prog = info.mHttpErrorCode.ToString(); } else { str_in_prog = "ERROR"; } colorForProgress = ConsoleColor.DarkRed; progress_string = ProgressStringAligner(str_in_prog, progressStringSize); } else { string str_in_prog = Helpers.FormatBytes(info.mBytes); colorForProgress = ConsoleColor.DarkGreen; progress_string = ProgressStringAligner("", "", str_in_prog, progressStringSize); } count_progress_symbols = calcProgressSymbols(1, 1, progress_string.Count()); } int start_progress = paintedString.SetColor(colorForProgress); paintedString.Append(progress_string); paintedString.SetDefaultColor(start_progress + count_progress_symbols); paintedString.Append(" "); paintedString.Append(info.GetFileCaption()); mConsole.WriteLine(info.mNumber, paintedString); }