Replace partition size pretty printing with a version by Ingo copied
from file Partitioner.cpp. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24708 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
f4a2c0f945
commit
3c3b25a889
@ -1,6 +1,10 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008, Michael Pfeiffer, laplace@users.sourceforge.net. All rights reserved.
|
* Copyright 2008, Haiku, Inc. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Michael Pfeiffer, laplace@users.sourceforge.net
|
||||||
|
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +18,7 @@
|
|||||||
#include <TextControl.h>
|
#include <TextControl.h>
|
||||||
#include <TextView.h>
|
#include <TextView.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
|
|
||||||
@ -301,30 +306,23 @@ static const char kPrefix[] = " KMGTPE";
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
PartitionsPage::_CreateSizeText(int64 size, BString* text)
|
PartitionsPage::_CreateSizeText(int64 _size, BString* text)
|
||||||
{
|
{
|
||||||
if (size < 0) {
|
const char* suffixes[] = {
|
||||||
(*text) << "Error";
|
"", "K", "M", "G", "T", NULL
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
|
double size = _size;
|
||||||
int index = 0;
|
int index = 0;
|
||||||
int n = 7;
|
while (size > 1024 && suffixes[index + 1]) {
|
||||||
int64 remainder = 0;
|
size /= 1024;
|
||||||
for (; size >= 1000 && index <= n; index ++) {
|
index++;
|
||||||
remainder = size % 1000;
|
|
||||||
size /= 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// round
|
char buffer[128];
|
||||||
size = size + ((remainder + 500) / 1000);
|
snprintf(buffer, sizeof(buffer), "%.2f%s", size, suffixes[index]);
|
||||||
|
|
||||||
if (index == 0)
|
*text = buffer;
|
||||||
(*text) << size << " B";
|
|
||||||
else if (index < n)
|
|
||||||
(*text) << size << " " << kPrefix[index] << "B";
|
|
||||||
else
|
|
||||||
(*text) << "-";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user