upx-clang-format -i ui.cpp
This commit is contained in:
+1
-1
@@ -132,7 +132,7 @@ endif
|
|||||||
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
|
CLANG_FORMAT_FILES += s_djgpp2.cpp s_object.cpp s_vcsa.cpp s_win32.cpp screen.h
|
||||||
CLANG_FORMAT_FILES += snprintf.cpp
|
CLANG_FORMAT_FILES += snprintf.cpp
|
||||||
CLANG_FORMAT_FILES += stdcxx.h stdcxx.cpp
|
CLANG_FORMAT_FILES += stdcxx.h stdcxx.cpp
|
||||||
CLANG_FORMAT_FILES += ui.h util.h
|
CLANG_FORMAT_FILES += ui.cpp ui.h util.h
|
||||||
clang-format:
|
clang-format:
|
||||||
$(top_srcdir)/src/stub/scripts/upx-clang-format -i $(addprefix $(top_srcdir)/src/,$(CLANG_FORMAT_FILES))
|
$(top_srcdir)/src/stub/scripts/upx-clang-format -i $(addprefix $(top_srcdir)/src/,$(CLANG_FORMAT_FILES))
|
||||||
.PHONY: clang-format
|
.PHONY: clang-format
|
||||||
|
|||||||
+86
-207
@@ -25,19 +25,16 @@
|
|||||||
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
<markus@oberhumer.com> <ml1050@users.sourceforge.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "conf.h"
|
#include "conf.h"
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
#include "screen.h"
|
#include "screen.h"
|
||||||
#include "packer.h"
|
#include "packer.h"
|
||||||
|
|
||||||
|
|
||||||
#if 1 && (USE_SCREEN)
|
#if 1 && (USE_SCREEN)
|
||||||
#define UI_USE_SCREEN 1
|
#define UI_USE_SCREEN 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
M_QUIET, // nothing at all '-qqq'
|
M_QUIET, // nothing at all '-qqq'
|
||||||
M_INFO, // print a one line info after compression '-qq'
|
M_INFO, // print a one line info after compression '-qq'
|
||||||
@@ -46,9 +43,7 @@ enum {
|
|||||||
M_CB_SCREEN // 2 line callback using screen
|
M_CB_SCREEN // 2 line callback using screen
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct UiPacker::State {
|
||||||
struct UiPacker::State
|
|
||||||
{
|
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
unsigned u_len;
|
unsigned u_len;
|
||||||
@@ -81,7 +76,6 @@ struct UiPacker::State
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
long UiPacker::total_files = 0;
|
long UiPacker::total_files = 0;
|
||||||
long UiPacker::total_files_done = 0;
|
long UiPacker::total_files_done = 0;
|
||||||
long UiPacker::total_c_len = 0;
|
long UiPacker::total_c_len = 0;
|
||||||
@@ -93,21 +87,16 @@ long UiPacker::update_u_len = 0;
|
|||||||
long UiPacker::update_fc_len = 0;
|
long UiPacker::update_fc_len = 0;
|
||||||
long UiPacker::update_fu_len = 0;
|
long UiPacker::update_fu_len = 0;
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// constants
|
// constants
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static const char header_line1[] =
|
static const char header_line1[] = " File size Ratio Format Name\n";
|
||||||
" File size Ratio Format Name\n";
|
static char header_line2[] = " -------------------- ------ ----------- -----------\n";
|
||||||
static char header_line2[] =
|
|
||||||
" -------------------- ------ ----------- -----------\n";
|
|
||||||
|
|
||||||
static char progress_filler[] = ".*[]";
|
static char progress_filler[] = ".*[]";
|
||||||
|
|
||||||
|
static void init_global_constants(void) {
|
||||||
static void init_global_constants(void)
|
|
||||||
{
|
|
||||||
#if 0 && (ACC_OS_DOS16 || ACC_OS_DOS32)
|
#if 0 && (ACC_OS_DOS16 || ACC_OS_DOS32)
|
||||||
// FIXME: should test codepage here
|
// FIXME: should test codepage here
|
||||||
|
|
||||||
@@ -133,16 +122,13 @@ static void init_global_constants(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
static const char *mkline(unsigned long fu_len, unsigned long fc_len,
|
static const char *mkline(unsigned long fu_len, unsigned long fc_len, unsigned long u_len,
|
||||||
unsigned long u_len, unsigned long c_len,
|
unsigned long c_len, const char *format_name, const char *filename,
|
||||||
const char *format_name, const char *filename,
|
bool decompress = false) {
|
||||||
bool decompress=false)
|
|
||||||
{
|
|
||||||
static char buf[2048];
|
static char buf[2048];
|
||||||
char r[7 + 1];
|
char r[7 + 1];
|
||||||
char fn[13 + 1];
|
char fn[13 + 1];
|
||||||
@@ -167,18 +153,16 @@ static const char *mkline(unsigned long fu_len, unsigned long fc_len,
|
|||||||
center_string(fn, sizeof(fn), format_name);
|
center_string(fn, sizeof(fn), format_name);
|
||||||
assert(strlen(fn) == 13);
|
assert(strlen(fn) == 13);
|
||||||
upx_snprintf(buf, sizeof(buf), f, fu_len, fc_len, r, fn, filename);
|
upx_snprintf(buf, sizeof(buf), f, fu_len, fc_len, r, fn, filename);
|
||||||
UNUSED(u_len); UNUSED(c_len);
|
UNUSED(u_len);
|
||||||
|
UNUSED(c_len);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
//
|
//
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
UiPacker::UiPacker(const Packer *p_) :
|
UiPacker::UiPacker(const Packer *p_) : ui_pass(0), ui_total_passes(0), p(p_), s(NULL) {
|
||||||
ui_pass(0), ui_total_passes(0), p(p_), s(NULL)
|
|
||||||
{
|
|
||||||
init_global_constants();
|
init_global_constants();
|
||||||
|
|
||||||
cb.reset();
|
cb.reset();
|
||||||
@@ -204,34 +188,29 @@ UiPacker::UiPacker(const Packer *p_) :
|
|||||||
s->mode = M_CB_SCREEN;
|
s->mode = M_CB_SCREEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UiPacker::~UiPacker() {
|
||||||
UiPacker::~UiPacker()
|
|
||||||
{
|
|
||||||
cb.reset();
|
cb.reset();
|
||||||
delete s; s = NULL;
|
delete s;
|
||||||
|
s = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// start callback
|
// start callback
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void UiPacker::printInfo(int nl)
|
void UiPacker::printInfo(int nl) {
|
||||||
{
|
|
||||||
if (opt->all_methods && s->total_passes > 1)
|
if (opt->all_methods && s->total_passes > 1)
|
||||||
con_fprintf(stdout, "Compressing %s [%s]%s", p->fi->getName(), p->getName(), nl ? "\n" : "");
|
con_fprintf(stdout, "Compressing %s [%s]%s", p->fi->getName(), p->getName(),
|
||||||
else
|
nl ? "\n" : "");
|
||||||
{
|
else {
|
||||||
char method_name[32 + 1];
|
char method_name[32 + 1];
|
||||||
set_method_name(method_name, sizeof(method_name), p->ph.method, p->ph.level);
|
set_method_name(method_name, sizeof(method_name), p->ph.method, p->ph.level);
|
||||||
con_fprintf(stdout, "Compressing %s [%s, %s]%s", p->fi->getName(), p->getName(), method_name, nl ? "\n" : "");
|
con_fprintf(stdout, "Compressing %s [%s, %s]%s", p->fi->getName(), p->getName(),
|
||||||
|
method_name, nl ? "\n" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::startCallback(unsigned u_len, unsigned step, int pass, int total_passes) {
|
||||||
void UiPacker::startCallback(unsigned u_len, unsigned step,
|
|
||||||
int pass, int total_passes)
|
|
||||||
{
|
|
||||||
s->u_len = u_len;
|
s->u_len = u_len;
|
||||||
s->step = step;
|
s->step = step;
|
||||||
s->next_update = step;
|
s->next_update = step;
|
||||||
@@ -253,10 +232,8 @@ void UiPacker::startCallback(unsigned u_len, unsigned step,
|
|||||||
|
|
||||||
if (s->mode <= M_INFO)
|
if (s->mode <= M_INFO)
|
||||||
return;
|
return;
|
||||||
if (s->mode == M_MSG)
|
if (s->mode == M_MSG) {
|
||||||
{
|
if (pass <= 1) {
|
||||||
if (pass <= 1)
|
|
||||||
{
|
|
||||||
printInfo(0);
|
printInfo(0);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
printSetNl(2);
|
printSetNl(2);
|
||||||
@@ -271,12 +248,10 @@ void UiPacker::startCallback(unsigned u_len, unsigned step,
|
|||||||
#endif
|
#endif
|
||||||
cb.user = this; // parameter for static function UiPacker::progress_callback()
|
cb.user = this; // parameter for static function UiPacker::progress_callback()
|
||||||
|
|
||||||
if (s->mode == M_CB_TERM)
|
if (s->mode == M_CB_TERM) {
|
||||||
{
|
|
||||||
const char *fname = fn_basename(p->fi->getName());
|
const char *fname = fn_basename(p->fi->getName());
|
||||||
int l = (int) strlen(fname);
|
int l = (int) strlen(fname);
|
||||||
if (l > 0 && l <= 30)
|
if (l > 0 && l <= 30) {
|
||||||
{
|
|
||||||
strcpy(&s->msg_buf[s->bar_pos], fname);
|
strcpy(&s->msg_buf[s->bar_pos], fname);
|
||||||
s->bar_pos += l;
|
s->bar_pos += l;
|
||||||
s->msg_buf[s->bar_pos++] = ' ';
|
s->msg_buf[s->bar_pos++] = ' ';
|
||||||
@@ -286,29 +261,24 @@ void UiPacker::startCallback(unsigned u_len, unsigned step,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set pass
|
// set pass
|
||||||
if (total_passes > 1)
|
if (total_passes > 1) {
|
||||||
{
|
|
||||||
int buflen, l;
|
int buflen, l;
|
||||||
do {
|
do {
|
||||||
s->pass_digits++;
|
s->pass_digits++;
|
||||||
total_passes /= 10;
|
total_passes /= 10;
|
||||||
} while (total_passes > 0);
|
} while (total_passes > 0);
|
||||||
buflen = sizeof(s->msg_buf) - s->bar_pos;
|
buflen = sizeof(s->msg_buf) - s->bar_pos;
|
||||||
l = upx_snprintf(&s->msg_buf[s->bar_pos], buflen, "%*d/%*d ",
|
l = upx_snprintf(&s->msg_buf[s->bar_pos], buflen, "%*d/%*d ", s->pass_digits, s->pass,
|
||||||
s->pass_digits, s->pass,
|
|
||||||
s->pass_digits, s->total_passes);
|
s->pass_digits, s->total_passes);
|
||||||
if (l > 0 && s->bar_len - l > 10)
|
if (l > 0 && s->bar_len - l > 10) {
|
||||||
{
|
|
||||||
s->bar_len -= l;
|
s->bar_len -= l;
|
||||||
s->bar_pos += l;
|
s->bar_pos += l;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if (UI_USE_SCREEN)
|
#if (UI_USE_SCREEN)
|
||||||
if (s->mode == M_CB_SCREEN)
|
if (s->mode == M_CB_SCREEN) {
|
||||||
{
|
if (!s->screen_init_done) {
|
||||||
if (!s->screen_init_done)
|
|
||||||
{
|
|
||||||
s->screen_init_done = 1;
|
s->screen_init_done = 1;
|
||||||
if (s->screen->hideCursor)
|
if (s->screen->hideCursor)
|
||||||
s->cursor_shape = s->screen->hideCursor(s->screen);
|
s->cursor_shape = s->screen->hideCursor(s->screen);
|
||||||
@@ -324,40 +294,32 @@ void UiPacker::startCallback(unsigned u_len, unsigned step,
|
|||||||
#endif /* UI_USE_SCREEN */
|
#endif /* UI_USE_SCREEN */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// may only get called directly after startCallback()
|
// may only get called directly after startCallback()
|
||||||
void UiPacker::firstCallback()
|
void UiPacker::firstCallback() {
|
||||||
{
|
|
||||||
if (s->pos == -2)
|
if (s->pos == -2)
|
||||||
doCallback(0, 0);
|
doCallback(0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// make sure we reach 100% in the progress bar
|
// make sure we reach 100% in the progress bar
|
||||||
void UiPacker::finalCallback(unsigned u_len, unsigned c_len)
|
void UiPacker::finalCallback(unsigned u_len, unsigned c_len) {
|
||||||
{
|
|
||||||
s->next_update = u_len;
|
s->next_update = u_len;
|
||||||
doCallback(u_len, c_len);
|
doCallback(u_len, c_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// end callback
|
// end callback
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void UiPacker::endCallback()
|
void UiPacker::endCallback() {
|
||||||
{
|
|
||||||
bool done = (s->total_passes <= 0 || s->pass >= s->total_passes);
|
bool done = (s->total_passes <= 0 || s->pass >= s->total_passes);
|
||||||
endCallback(done);
|
endCallback(done);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiPacker::endCallback(bool done)
|
void UiPacker::endCallback(bool done) {
|
||||||
{
|
|
||||||
if (s->pass < 0) // no callback wanted
|
if (s->pass < 0) // no callback wanted
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (s->mode == M_CB_TERM)
|
if (s->mode == M_CB_TERM) {
|
||||||
{
|
|
||||||
if (done)
|
if (done)
|
||||||
printClearLine(stdout);
|
printClearLine(stdout);
|
||||||
else
|
else
|
||||||
@@ -366,10 +328,8 @@ void UiPacker::endCallback(bool done)
|
|||||||
|
|
||||||
// restore screen
|
// restore screen
|
||||||
#if (UI_USE_SCREEN)
|
#if (UI_USE_SCREEN)
|
||||||
if (s->mode == M_CB_SCREEN)
|
if (s->mode == M_CB_SCREEN) {
|
||||||
{
|
if (done) {
|
||||||
if (done)
|
|
||||||
{
|
|
||||||
int cx, cy, sy;
|
int cx, cy, sy;
|
||||||
assert(s->screen_init_done);
|
assert(s->screen_init_done);
|
||||||
s->screen_init_done = 0;
|
s->screen_init_done = 0;
|
||||||
@@ -383,9 +343,7 @@ void UiPacker::endCallback(bool done)
|
|||||||
s->screen->setBg(s->screen, s->s_bg);
|
s->screen->setBg(s->screen, s->s_bg);
|
||||||
if (s->cursor_shape > 0)
|
if (s->cursor_shape > 0)
|
||||||
s->screen->setCursorShape(s->screen, s->cursor_shape);
|
s->screen->setCursorShape(s->screen, s->cursor_shape);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
// not needed:
|
// not needed:
|
||||||
// s->screen->clearLine(s->screen, s->b_cy);
|
// s->screen->clearLine(s->screen, s->b_cy);
|
||||||
// s->screen->setCursor(s->screen, s->b_cx, s->b_cy);
|
// s->screen->setCursor(s->screen, s->b_cx, s->b_cy);
|
||||||
@@ -400,21 +358,17 @@ void UiPacker::endCallback(bool done)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// the callback
|
// the callback
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void __acc_cdecl UiPacker::progress_callback(upx_callback_p cb, unsigned isize, unsigned osize)
|
void __acc_cdecl UiPacker::progress_callback(upx_callback_p cb, unsigned isize, unsigned osize) {
|
||||||
{
|
|
||||||
// printf("%6d %6d %d\n", isize, osize, state);
|
// printf("%6d %6d %d\n", isize, osize, state);
|
||||||
UiPacker *self = (UiPacker *) cb->user;
|
UiPacker *self = (UiPacker *) cb->user;
|
||||||
self->doCallback(isize, osize);
|
self->doCallback(isize, osize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::doCallback(unsigned isize, unsigned osize) {
|
||||||
void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|
||||||
{
|
|
||||||
int i;
|
int i;
|
||||||
static const char spinner[] = "|/-\\";
|
static const char spinner[] = "|/-\\";
|
||||||
|
|
||||||
@@ -424,8 +378,7 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|||||||
if (s->u_len == 0 || isize > s->u_len)
|
if (s->u_len == 0 || isize > s->u_len)
|
||||||
return;
|
return;
|
||||||
// check if we should update the display
|
// check if we should update the display
|
||||||
if (s->step > 0 && isize > 0 && isize < s->u_len)
|
if (s->step > 0 && isize > 0 && isize < s->u_len) {
|
||||||
{
|
|
||||||
if (isize < s->next_update)
|
if (isize < s->next_update)
|
||||||
return;
|
return;
|
||||||
s->next_update += s->step;
|
s->next_update += s->step;
|
||||||
@@ -435,10 +388,10 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|||||||
int pos = -1;
|
int pos = -1;
|
||||||
if (isize >= s->u_len)
|
if (isize >= s->u_len)
|
||||||
pos = s->bar_len;
|
pos = s->bar_len;
|
||||||
else if (isize > 0)
|
else if (isize > 0) {
|
||||||
{
|
|
||||||
pos = get_ratio(s->u_len, isize) * s->bar_len / 1000000;
|
pos = get_ratio(s->u_len, isize) * s->bar_len / 1000000;
|
||||||
assert(pos >= 0); assert(pos <= s->bar_len);
|
assert(pos >= 0);
|
||||||
|
assert(pos <= s->bar_len);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@@ -464,16 +417,14 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|||||||
ratio = get_ratio(isize, osize);
|
ratio = get_ratio(isize, osize);
|
||||||
|
|
||||||
int buflen = (int) (&s->msg_buf[sizeof(s->msg_buf)] - m);
|
int buflen = (int) (&s->msg_buf[sizeof(s->msg_buf)] - m);
|
||||||
upx_snprintf(m, buflen, " %3d.%1d%% %c ",
|
upx_snprintf(m, buflen, " %3d.%1d%% %c ", ratio / 10000, (ratio % 10000) / 1000,
|
||||||
ratio / 10000, (ratio % 10000) / 1000,
|
|
||||||
spinner[s->spin_counter & 3]);
|
spinner[s->spin_counter & 3]);
|
||||||
assert(strlen(s->msg_buf) < 1 + 80);
|
assert(strlen(s->msg_buf) < 1 + 80);
|
||||||
|
|
||||||
s->pos = pos;
|
s->pos = pos;
|
||||||
s->spin_counter++;
|
s->spin_counter++;
|
||||||
|
|
||||||
if (s->mode == M_CB_TERM)
|
if (s->mode == M_CB_TERM) {
|
||||||
{
|
|
||||||
const char *msg = &s->msg_buf[0];
|
const char *msg = &s->msg_buf[0];
|
||||||
int fg = con_fg(stdout, FG_CYAN);
|
int fg = con_fg(stdout, FG_CYAN);
|
||||||
con_fprintf(stdout, "%s", msg); // avoid backslash interpretation
|
con_fprintf(stdout, "%s", msg); // avoid backslash interpretation
|
||||||
@@ -485,8 +436,7 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if (UI_USE_SCREEN)
|
#if (UI_USE_SCREEN)
|
||||||
if (s->mode == M_CB_SCREEN)
|
if (s->mode == M_CB_SCREEN) {
|
||||||
{
|
|
||||||
const char *msg = &s->msg_buf[1];
|
const char *msg = &s->msg_buf[1];
|
||||||
#if 0
|
#if 0
|
||||||
s->screen->putString(s->screen,msg,s->b_cx,s->b_cy);
|
s->screen->putString(s->screen,msg,s->b_cx,s->b_cy);
|
||||||
@@ -500,26 +450,21 @@ void UiPacker::doCallback(unsigned isize, unsigned osize)
|
|||||||
#endif /* UI_USE_SCREEN */
|
#endif /* UI_USE_SCREEN */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// pack
|
// pack
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void UiPacker::uiPackStart(const OutputFile *fo)
|
void UiPacker::uiPackStart(const OutputFile *fo) {
|
||||||
{
|
|
||||||
total_files++;
|
total_files++;
|
||||||
UNUSED(fo);
|
UNUSED(fo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiPackEnd(const OutputFile *fo) {
|
||||||
void UiPacker::uiPackEnd(const OutputFile *fo)
|
|
||||||
{
|
|
||||||
uiUpdate(fo->st_size());
|
uiUpdate(fo->st_size());
|
||||||
|
|
||||||
if (s->mode == M_QUIET)
|
if (s->mode == M_QUIET)
|
||||||
return;
|
return;
|
||||||
if (s->mode == M_MSG)
|
if (s->mode == M_MSG) {
|
||||||
{
|
|
||||||
// We must put this here and not in endCallback() as we may
|
// We must put this here and not in endCallback() as we may
|
||||||
// have multiple passes.
|
// have multiple passes.
|
||||||
printClearLine(stdout);
|
printClearLine(stdout);
|
||||||
@@ -530,34 +475,26 @@ void UiPacker::uiPackEnd(const OutputFile *fo)
|
|||||||
name = opt->output_name;
|
name = opt->output_name;
|
||||||
else if (opt->to_stdout)
|
else if (opt->to_stdout)
|
||||||
name = "<stdout>";
|
name = "<stdout>";
|
||||||
con_fprintf(stdout,"%s\n",
|
con_fprintf(stdout, "%s\n", mkline(p->ph.u_file_size, fo->st_size(), p->ph.u_len, p->ph.c_len,
|
||||||
mkline(p->ph.u_file_size, fo->st_size(),
|
|
||||||
p->ph.u_len, p->ph.c_len,
|
|
||||||
p->getName(), fn_basename(name)));
|
p->getName(), fn_basename(name)));
|
||||||
printSetNl(0);
|
printSetNl(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiPackTotal() {
|
||||||
void UiPacker::uiPackTotal()
|
|
||||||
{
|
|
||||||
uiListTotal();
|
uiListTotal();
|
||||||
uiFooter("Packed");
|
uiFooter("Packed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// unpack
|
// unpack
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void UiPacker::uiUnpackStart(const OutputFile *fo)
|
void UiPacker::uiUnpackStart(const OutputFile *fo) {
|
||||||
{
|
|
||||||
total_files++;
|
total_files++;
|
||||||
UNUSED(fo);
|
UNUSED(fo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiUnpackEnd(const OutputFile *fo) {
|
||||||
void UiPacker::uiUnpackEnd(const OutputFile *fo)
|
|
||||||
{
|
|
||||||
uiUpdate(-1, fo->getBytesWritten());
|
uiUpdate(-1, fo->getBytesWritten());
|
||||||
|
|
||||||
if (s->mode == M_QUIET)
|
if (s->mode == M_QUIET)
|
||||||
@@ -568,88 +505,60 @@ void UiPacker::uiUnpackEnd(const OutputFile *fo)
|
|||||||
name = opt->output_name;
|
name = opt->output_name;
|
||||||
else if (opt->to_stdout)
|
else if (opt->to_stdout)
|
||||||
name = "<stdout>";
|
name = "<stdout>";
|
||||||
con_fprintf(stdout,"%s\n",
|
con_fprintf(stdout, "%s\n", mkline(fo->getBytesWritten(), p->file_size, p->ph.u_len,
|
||||||
mkline(fo->getBytesWritten(), p->file_size,
|
p->ph.c_len, p->getName(), fn_basename(name), true));
|
||||||
p->ph.u_len, p->ph.c_len,
|
|
||||||
p->getName(), fn_basename(name), true));
|
|
||||||
printSetNl(0);
|
printSetNl(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiUnpackTotal() {
|
||||||
void UiPacker::uiUnpackTotal()
|
|
||||||
{
|
|
||||||
uiListTotal(true);
|
uiListTotal(true);
|
||||||
uiFooter("Unpacked");
|
uiFooter("Unpacked");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// list
|
// list
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void UiPacker::uiListStart()
|
void UiPacker::uiListStart() { total_files++; }
|
||||||
{
|
|
||||||
total_files++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void UiPacker::uiList(long fu_len) {
|
||||||
void UiPacker::uiList(long fu_len)
|
|
||||||
{
|
|
||||||
if (fu_len < 0)
|
if (fu_len < 0)
|
||||||
fu_len = p->ph.u_file_size;
|
fu_len = p->ph.u_file_size;
|
||||||
const char *name = p->fi->getName();
|
const char *name = p->fi->getName();
|
||||||
con_fprintf(stdout, "%s\n",
|
con_fprintf(stdout, "%s\n",
|
||||||
mkline(fu_len, p->file_size,
|
mkline(fu_len, p->file_size, p->ph.u_len, p->ph.c_len, p->getName(), name));
|
||||||
p->ph.u_len, p->ph.c_len,
|
|
||||||
p->getName(), name));
|
|
||||||
printSetNl(0);
|
printSetNl(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiListEnd() { uiUpdate(); }
|
||||||
|
|
||||||
void UiPacker::uiListEnd()
|
void UiPacker::uiListTotal(bool decompress) {
|
||||||
{
|
if (opt->verbose >= 1 && total_files >= 2) {
|
||||||
uiUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UiPacker::uiListTotal(bool decompress)
|
|
||||||
{
|
|
||||||
if (opt->verbose >= 1 && total_files >= 2)
|
|
||||||
{
|
|
||||||
char name[32];
|
char name[32];
|
||||||
upx_snprintf(name, sizeof(name), "[ %ld file%s ]",
|
upx_snprintf(name, sizeof(name), "[ %ld file%s ]", total_files_done,
|
||||||
total_files_done, total_files_done == 1 ? "" : "s");
|
total_files_done == 1 ? "" : "s");
|
||||||
con_fprintf(stdout, "%s%s\n",
|
con_fprintf(stdout, "%s%s\n", header_line2, mkline(total_fu_len, total_fc_len, total_u_len,
|
||||||
header_line2,
|
total_c_len, "", name, decompress));
|
||||||
mkline(total_fu_len, total_fc_len,
|
|
||||||
total_u_len, total_c_len,
|
|
||||||
"", name, decompress));
|
|
||||||
printSetNl(0);
|
printSetNl(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// test
|
// test
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void UiPacker::uiTestStart()
|
void UiPacker::uiTestStart() {
|
||||||
{
|
|
||||||
total_files++;
|
total_files++;
|
||||||
|
|
||||||
if (opt->verbose >= 1)
|
if (opt->verbose >= 1) {
|
||||||
{
|
|
||||||
con_fprintf(stdout, "testing %s ", p->fi->getName());
|
con_fprintf(stdout, "testing %s ", p->fi->getName());
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
printSetNl(1);
|
printSetNl(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiTestEnd() {
|
||||||
void UiPacker::uiTestEnd()
|
if (opt->verbose >= 1) {
|
||||||
{
|
|
||||||
if (opt->verbose >= 1)
|
|
||||||
{
|
|
||||||
con_fprintf(stdout, "[OK]\n");
|
con_fprintf(stdout, "[OK]\n");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
printSetNl(0);
|
printSetNl(0);
|
||||||
@@ -657,102 +566,76 @@ void UiPacker::uiTestEnd()
|
|||||||
uiUpdate();
|
uiUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiTestTotal() { uiFooter("Tested"); }
|
||||||
void UiPacker::uiTestTotal()
|
|
||||||
{
|
|
||||||
uiFooter("Tested");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// info
|
// info
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
bool UiPacker::uiFileInfoStart()
|
bool UiPacker::uiFileInfoStart() {
|
||||||
{
|
|
||||||
total_files++;
|
total_files++;
|
||||||
|
|
||||||
int fg = con_fg(stdout, FG_CYAN);
|
int fg = con_fg(stdout, FG_CYAN);
|
||||||
con_fprintf(stdout, "%s [%s, %s]\n", p->fi->getName(), p->getFullName(opt), p->getName());
|
con_fprintf(stdout, "%s [%s, %s]\n", p->fi->getName(), p->getFullName(opt), p->getName());
|
||||||
fg = con_fg(stdout, fg);
|
fg = con_fg(stdout, fg);
|
||||||
UNUSED(fg);
|
UNUSED(fg);
|
||||||
if (p->ph.c_len > 0)
|
if (p->ph.c_len > 0) {
|
||||||
{
|
|
||||||
con_fprintf(stdout, " %8ld bytes", (long) p->file_size);
|
con_fprintf(stdout, " %8ld bytes", (long) p->file_size);
|
||||||
con_fprintf(stdout, ", compressed by UPX %d, method %d, level %d, filter 0x%02x/0x%02x\n",
|
con_fprintf(stdout, ", compressed by UPX %d, method %d, level %d, filter 0x%02x/0x%02x\n",
|
||||||
p->ph.version, p->ph.method, p->ph.level, p->ph.filter, p->ph.filter_cto);
|
p->ph.version, p->ph.method, p->ph.level, p->ph.filter, p->ph.filter_cto);
|
||||||
return false;
|
return false;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
con_fprintf(stdout, " %8ld bytes", (long) p->file_size);
|
con_fprintf(stdout, " %8ld bytes", (long) p->file_size);
|
||||||
con_fprintf(stdout, ", not compressed by UPX\n");
|
con_fprintf(stdout, ", not compressed by UPX\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UiPacker::uiFileInfoEnd()
|
void UiPacker::uiFileInfoEnd() { uiUpdate(); }
|
||||||
{
|
|
||||||
uiUpdate();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void UiPacker::uiFileInfoTotal()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
void UiPacker::uiFileInfoTotal() {}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
// util
|
// util
|
||||||
**************************************************************************/
|
**************************************************************************/
|
||||||
|
|
||||||
void UiPacker::uiHeader()
|
void UiPacker::uiHeader() {
|
||||||
{
|
|
||||||
static bool done = false;
|
static bool done = false;
|
||||||
if (done)
|
if (done)
|
||||||
return;
|
return;
|
||||||
done = true;
|
done = true;
|
||||||
if (opt->cmd == CMD_TEST || opt->cmd == CMD_FILEINFO)
|
if (opt->cmd == CMD_TEST || opt->cmd == CMD_FILEINFO)
|
||||||
return;
|
return;
|
||||||
if (opt->verbose >= 1)
|
if (opt->verbose >= 1) {
|
||||||
{
|
|
||||||
con_fprintf(stdout, "%s%s", header_line1, header_line2);
|
con_fprintf(stdout, "%s%s", header_line1, header_line2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiFooter(const char *t) {
|
||||||
void UiPacker::uiFooter(const char *t)
|
|
||||||
{
|
|
||||||
static bool done = false;
|
static bool done = false;
|
||||||
if (done)
|
if (done)
|
||||||
return;
|
return;
|
||||||
done = true;
|
done = true;
|
||||||
if (opt->verbose >= 1)
|
if (opt->verbose >= 1) {
|
||||||
{
|
|
||||||
long n1 = total_files;
|
long n1 = total_files;
|
||||||
long n2 = total_files_done;
|
long n2 = total_files_done;
|
||||||
long n3 = total_files - total_files_done;
|
long n3 = total_files - total_files_done;
|
||||||
if (n3 == 0)
|
if (n3 == 0)
|
||||||
con_fprintf(stdout,"\n%s %ld file%s.\n",
|
con_fprintf(stdout, "\n%s %ld file%s.\n", t, n1, n1 == 1 ? "" : "s");
|
||||||
t, n1, n1 == 1 ? "" : "s");
|
|
||||||
else
|
else
|
||||||
con_fprintf(stdout,"\n%s %ld file%s: %ld ok, %ld error%s.\n",
|
con_fprintf(stdout, "\n%s %ld file%s: %ld ok, %ld error%s.\n", t, n1,
|
||||||
t, n1, n1 == 1 ? "" : "s", n2, n3, n3 == 1 ? "" : "s");
|
n1 == 1 ? "" : "s", n2, n3, n3 == 1 ? "" : "s");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiUpdate(long fc_len, long fu_len) {
|
||||||
void UiPacker::uiUpdate(long fc_len, long fu_len)
|
|
||||||
{
|
|
||||||
update_fc_len = (fc_len >= 0) ? fc_len : p->file_size;
|
update_fc_len = (fc_len >= 0) ? fc_len : p->file_size;
|
||||||
update_fu_len = (fu_len >= 0) ? fu_len : p->ph.u_file_size;
|
update_fu_len = (fu_len >= 0) ? fu_len : p->ph.u_file_size;
|
||||||
update_c_len = p->ph.c_len;
|
update_c_len = p->ph.c_len;
|
||||||
update_u_len = p->ph.u_len;
|
update_u_len = p->ph.u_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UiPacker::uiConfirmUpdate() {
|
||||||
void UiPacker::uiConfirmUpdate()
|
|
||||||
{
|
|
||||||
total_files_done++;
|
total_files_done++;
|
||||||
total_fc_len += update_fc_len;
|
total_fc_len += update_fc_len;
|
||||||
total_fu_len += update_fu_len;
|
total_fu_len += update_fu_len;
|
||||||
@@ -760,8 +643,4 @@ void UiPacker::uiConfirmUpdate()
|
|||||||
total_u_len += update_u_len;
|
total_u_len += update_u_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* vim:set ts=4 sw=4 et: */
|
||||||
/*
|
|
||||||
vi:ts=4:et
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user