mirror of
https://github.com/upx/upx
synced 2025-09-28 19:06:07 +08:00
Increased precision of get_ratio() and swapped parameters.
committer: mfx <mfx> 977342070 +0000
This commit is contained in:
parent
a42e72094a
commit
7d652fa42b
28
src/ui.cpp
28
src/ui.cpp
|
@ -117,20 +117,15 @@ static const char *mkline(unsigned long fu_len, unsigned long fc_len,
|
|||
char r[7+1];
|
||||
const char *f;
|
||||
|
||||
#if 0
|
||||
unsigned ratio = get_ratio(fc_len,fu_len);
|
||||
upx_snprintf(r,sizeof(r)," %1d.%03d", ratio / 10000, (ratio % 10000) / 10);
|
||||
#else
|
||||
unsigned ratio = get_ratio(fc_len,fu_len, 1000);
|
||||
upx_snprintf(r,sizeof(r),"%3d.%02d%%", ratio / 1000, (ratio % 1000) / 10);
|
||||
UNUSED(u_len); UNUSED(c_len);
|
||||
#endif
|
||||
unsigned ratio = get_ratio(fu_len, fc_len);
|
||||
upx_snprintf(r,sizeof(r),"%3d.%02d%%", ratio / 10000, (ratio % 10000) / 100);
|
||||
if (decompress)
|
||||
f = "%10ld <-%10ld %7s %13s %s";
|
||||
else
|
||||
f = "%10ld ->%10ld %7s %13s %s";
|
||||
upx_snprintf(buf,sizeof(buf),f,
|
||||
fu_len, fc_len, r, center_string(format_name,13), filename);
|
||||
UNUSED(u_len); UNUSED(c_len);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
@ -351,7 +346,7 @@ void __UPX_ENTRY UiPacker::callback(upx_uint isize, upx_uint osize, int state, v
|
|||
|
||||
void UiPacker::doCallback(unsigned isize, unsigned osize)
|
||||
{
|
||||
static const char spinner[] = "|\\-/";
|
||||
static const char spinner[] = "|/-\\";
|
||||
|
||||
if (s->pass < 0) // no callback wanted
|
||||
return;
|
||||
|
@ -373,8 +368,13 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|||
|
||||
// compute progress position
|
||||
int pos = -1;
|
||||
if (isize > 0)
|
||||
pos = get_ratio(isize,s->u_len) * s->bar_len / 10000;
|
||||
if (isize >= s->u_len)
|
||||
pos = s->bar_len;
|
||||
else if (isize > 0)
|
||||
{
|
||||
pos = get_ratio(s->u_len, isize) * s->bar_len / 1000000;
|
||||
assert(pos >= 0); assert(pos <= s->bar_len);
|
||||
}
|
||||
if (pos < s->pos)
|
||||
return;
|
||||
if (pos < 0 && pos == s->pos)
|
||||
|
@ -397,12 +397,12 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|||
*m++ = ']';
|
||||
|
||||
// compute current compression ratio
|
||||
unsigned ratio = 100*100;
|
||||
unsigned ratio = 1000000;
|
||||
if (osize > 0)
|
||||
ratio = get_ratio(osize,isize);
|
||||
ratio = get_ratio(isize, osize);
|
||||
|
||||
sprintf(m," %3d.%1d%% %c ",
|
||||
ratio / 100, (ratio % 100) / 10,
|
||||
ratio / 10000, (ratio % 10000) / 1000,
|
||||
spinner[s->counter]);
|
||||
assert((int)strlen(s->msg_buf) < 1 + 80);
|
||||
|
||||
|
|
26
src/util.cpp
26
src/util.cpp
|
@ -443,23 +443,21 @@ bool isafile(int fd)
|
|||
|
||||
|
||||
/*************************************************************************
|
||||
//
|
||||
// return compression ratio, where 100% == 1000*1000 == 1e6
|
||||
**************************************************************************/
|
||||
|
||||
unsigned get_ratio (unsigned long packedsize, unsigned long size,
|
||||
unsigned long scale)
|
||||
unsigned get_ratio (unsigned u_len, unsigned c_len)
|
||||
{
|
||||
unsigned long n1, n2;
|
||||
|
||||
n1 = 100 * scale; n2 = 1;
|
||||
if (size <= 0)
|
||||
return (unsigned) n1;
|
||||
while (n1 > 1 && packedsize > (ULONG_MAX / n1))
|
||||
{
|
||||
n1 /= 10;
|
||||
n2 *= 10;
|
||||
}
|
||||
return (unsigned) ((packedsize * n1) / (size / n2)) + 5;
|
||||
#if defined(__GNUC__)
|
||||
const unsigned long long n = 1000000;
|
||||
#elif defined(_MSC_VER)
|
||||
const unsigned __int64 n = 1000000;
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
if (u_len <= 0)
|
||||
return (unsigned) n;
|
||||
return (unsigned) ((c_len * n) / u_len) + 5;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -48,8 +48,7 @@ bool maketempname(char *ofilename, const char *ifilename,
|
|||
bool makebakname(char *ofilename, const char *ifilename, bool force=true);
|
||||
bool isafile(int fd);
|
||||
|
||||
unsigned get_ratio(unsigned long packedsize, unsigned long size,
|
||||
unsigned long scale=100);
|
||||
unsigned get_ratio(unsigned u_len, unsigned c_len);
|
||||
char *center_string(const char *name, size_t s);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user