Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Pavlov <ipavlov@users.sourceforge.net>2008-08-13 04:00:00 +0400
committerKornel LesiƄski <kornel@geekhood.net>2016-05-28 02:15:56 +0300
commit173c07e166fdf6fcd20f18ea73008f1b628945df (patch)
tree13ebea85cdc4c16ae93714ff0627ee9f91ad7e08 /CPP/7zip/UI/Far/ProgressBox.cpp
parent3901bf0ab88106a5b031cba7bc18d60cdebf7eef (diff)
4.59 beta
Diffstat (limited to 'CPP/7zip/UI/Far/ProgressBox.cpp')
-rwxr-xr-xCPP/7zip/UI/Far/ProgressBox.cpp142
1 files changed, 75 insertions, 67 deletions
diff --git a/CPP/7zip/UI/Far/ProgressBox.cpp b/CPP/7zip/UI/Far/ProgressBox.cpp
index d708331a..b13b0b51 100755
--- a/CPP/7zip/UI/Far/ProgressBox.cpp
+++ b/CPP/7zip/UI/Far/ProgressBox.cpp
@@ -5,100 +5,108 @@
#include <stdio.h>
#include "ProgressBox.h"
-
+#include "Common/IntToString.h"
#include "FarUtils.h"
-using namespace NFar;
-
-static void CopySpaces(char *destString, int numSpaces)
+static void CopySpaces(char *dest, int numSpaces)
{
int i;
- for(i = 0; i < numSpaces; i++)
- destString[i] = ' ';
- destString[i] = '\0';
+ for (i = 0; i < numSpaces; i++)
+ dest[i] = ' ';
+ dest[i] = '\0';
}
-/////////////////////////////////
-// CMessageBox
+void ConvertUInt64ToStringAligned(UInt64 value, char *s, int alignSize)
+{
+ char temp[32];
+ ConvertUInt64ToString(value, temp);
+ int len = (int)strlen(temp);
+ int numSpaces = 0;
+ if (len < alignSize)
+ {
+ numSpaces = alignSize - len;
+ CopySpaces(s, numSpaces);
+ }
+ strcpy(s + numSpaces, temp);
+}
-const int kNumStringsMax = 10;
-void CMessageBox::Init(const CSysString &title, const CSysString &message,
- int numStrings, int width)
-{
- if (numStrings > kNumStringsMax)
- throw 120620;
- m_NumStrings = numStrings;
- m_Width = width;
+// ---------- CMessageBox ----------
- m_Title = title;
- m_Message = message;
-}
+static const int kMaxLen = 255;
-const int kNumStaticStrings = 2;
+void CMessageBox::Init(const AString &title, int width)
+{
+ _title = title;
+ _width = MyMin(width, kMaxLen);
+}
-void CMessageBox::ShowProcessMessages(const char *messages[])
+void CMessageBox::ShowMessages(const char *strings[], int numStrings)
{
+ const int kNumStaticStrings = 1;
+ const int kNumStringsMax = 10;
+
+ if (numStrings > kNumStringsMax)
+ numStrings = kNumStringsMax;
+
const char *msgItems[kNumStaticStrings + kNumStringsMax];
- msgItems[0] = m_Title;
- msgItems[1] = m_Message;
+ msgItems[0] = _title;
- char formattedMessages[kNumStringsMax][256];
+ char formattedMessages[kNumStringsMax][kMaxLen + 1];
- for (int i = 0; i < m_NumStrings; i++)
+ for (int i = 0; i < numStrings; i++)
{
char *formattedMessage = formattedMessages[i];
- int len = (int)strlen(messages[i]);
- int size = MyMax(m_Width, len);
- int startPos = (size - len) / 2;
- CopySpaces(formattedMessage, startPos);
- MyStringCopy(formattedMessage + startPos, messages[i]);
- CopySpaces(formattedMessage + startPos + len, size - startPos - len);
+ const char *s = strings[i];
+ int len = (int)strlen(s);
+ if (len < kMaxLen)
+ {
+ int size = MyMax(_width, len);
+ int startPos = (size - len) / 2;
+ CopySpaces(formattedMessage, startPos);
+ strcpy(formattedMessage + startPos, s);
+ CopySpaces(formattedMessage + startPos + len, size - startPos - len);
+ }
+ else
+ {
+ strncpy(formattedMessage, s, kMaxLen);
+ formattedMessage[kMaxLen] = 0;
+ }
msgItems[kNumStaticStrings + i] = formattedMessage;
}
-
- g_StartupInfo.ShowMessage(0, NULL, msgItems, kNumStaticStrings + m_NumStrings, 0);
+ NFar::g_StartupInfo.ShowMessage(0, NULL, msgItems, kNumStaticStrings + numStrings, 0);
}
-/////////////////////////////////
-// CProgressBox
-
-void CProgressBox::Init(const CSysString &title, const CSysString &message,
- UInt64 step)
-{
- CMessageBox::Init(title, message, 1, 22);
- m_Step = step;
- m_CompletedPrev = 0;
- m_Total = 0;
-}
-
-
-void CProgressBox::ShowProcessMessage(const char *message)
-{
- CMessageBox::ShowProcessMessages(&message);
-}
-void CProgressBox::PrintPercent(UInt64 percent)
-{
- char valueBuffer[32];
- sprintf(valueBuffer, "%I64u%%", percent);
- ShowProcessMessage(valueBuffer);
-}
+// ---------- CProgressBox ----------
-void CProgressBox::SetTotal(UInt64 total)
+void CProgressBox::Init(const AString &title, int width)
{
- m_Total = total;
+ CMessageBox::Init(title, width);
+ _prevMessage.Empty();
+ _prevPercentMessage.Empty();
+ _wasShown = false;
}
-void CProgressBox::PrintCompeteValue(UInt64 completed)
+void CProgressBox::Progress(const UInt64 *total, const UInt64 *completed, const AString &message)
{
- if (completed >= m_CompletedPrev + m_Step || completed < m_CompletedPrev ||
- completed == 0)
+ AString percentMessage;
+ if (total != 0 && completed != 0)
{
- if (m_Total == 0)
- PrintPercent(0);
- else
- PrintPercent(completed * 100 / m_Total);
- m_CompletedPrev = completed;
+ UInt64 totalVal = *total;
+ if (totalVal == 0)
+ totalVal = 1;
+ char buf[32];
+ ConvertUInt64ToStringAligned(*completed * 100 / totalVal, buf, 3);
+ strcat(buf, "%");
+ percentMessage = buf;
+ }
+ if (message != _prevMessage || percentMessage != _prevPercentMessage || !_wasShown)
+ {
+ _prevMessage = message;
+ _prevPercentMessage = percentMessage;
+ const char *strings[] = { message, percentMessage };
+ ShowMessages(strings, sizeof(strings) / sizeof(strings[0]));
+ _wasShown = true;
}
}