📄 ui.cpp
字号:
s->screen->setCursorShape(s->screen,s->cursor_shape); } else { // not needed:// s->screen->clearLine(s->screen, s->b_cy);// s->screen->setCursor(s->screen, s->b_cx, s->b_cy); } }#endif /* UI_USE_SCREEN */ cb.reset();#if 0 printf("callback: pass %d, step %6d, updates %6d\n", s->pass, s->step, s->spin_counter);#endif}/*************************************************************************// the callback**************************************************************************/void __acc_cdecl UiPacker::progress_callback(upx_callback_p cb, unsigned isize, unsigned osize){ //printf("%6d %6d %d\n", isize, osize, state); UiPacker *self = (UiPacker *) cb->user; self->doCallback(isize, osize);}void UiPacker::doCallback(unsigned isize, unsigned osize){ int i; static const char spinner[] = "|/-\\"; if (s->pass < 0) // no callback wanted return; if (s->u_len == 0 || isize > s->u_len) return; // check if we should update the display if (s->step > 0 && isize > 0 && isize < s->u_len) { if (isize < s->next_update) return; s->next_update += s->step; } // compute progress position int pos = -1; 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 0 printf("%6d %6d %6d %6d %3d %3d\n", isize, osize, s->step, s->next_update, pos, s->pos); return;#endif if (pos < s->pos) return; if (pos < 0 && pos == s->pos) return; // fill the progress bar char *m = &s->msg_buf[s->bar_pos]; *m++ = progress_filler[2]; for (i = 0; i < s->bar_len; i++) *m++ = progress_filler[i <= pos]; *m++ = progress_filler[3]; // compute current compression ratio unsigned ratio = 1000000; if (osize > 0) ratio = get_ratio(isize, osize); int buflen = (int) (&s->msg_buf[sizeof(s->msg_buf)] - m); upx_snprintf(m, buflen, " %3d.%1d%% %c ", ratio / 10000, (ratio % 10000) / 1000, spinner[s->spin_counter & 3]); assert(strlen(s->msg_buf) < 1 + 80); s->pos = pos; s->spin_counter++; if (s->mode == M_CB_TERM) { const char *msg = &s->msg_buf[0]; int fg = con_fg(stdout,FG_CYAN); con_fprintf(stdout,"%s",msg); // avoid backslash interpretation (void) con_fg(stdout,fg); fflush(stdout); printSetNl(1); UNUSED(fg); return; }#if defined(UI_USE_SCREEN) if (s->mode == M_CB_SCREEN) { const char *msg = &s->msg_buf[1];#if 0 s->screen->putString(s->screen,msg,s->b_cx,s->b_cy);#else // FIXME: this doesn't honor '--mono' etc. int attr = FG_CYAN | s->s_bg; s->screen->putStringAttr(s->screen,msg,attr,s->b_cx,s->b_cy);#endif s->screen->refresh(s->screen); }#endif /* UI_USE_SCREEN */}/*************************************************************************// pack**************************************************************************/void UiPacker::uiPackStart(const OutputFile *fo){ total_files++; UNUSED(fo);}void UiPacker::uiPackEnd(const OutputFile *fo){ uiUpdate(fo->st_size()); if (s->mode == M_QUIET) return; if (s->mode == M_MSG) { // We must put this here and not in endCallback() as we may // have multiple passes. printClearLine(stdout); } const char *name = p->fi->getName(); if (opt->output_name) name = opt->output_name; else if (opt->to_stdout) name = "<stdout>"; con_fprintf(stdout,"%s\n", mkline(p->ph.u_file_size, fo->st_size(), p->ph.u_len, p->ph.c_len, p->getName(), fn_basename(name))); printSetNl(0);}void UiPacker::uiPackTotal(){ uiListTotal(); uiFooter("Packed");}/*************************************************************************// unpack**************************************************************************/void UiPacker::uiUnpackStart(const OutputFile *fo){ total_files++; UNUSED(fo);}void UiPacker::uiUnpackEnd(const OutputFile *fo){ uiUpdate(-1, fo->getBytesWritten()); if (s->mode == M_QUIET) return; const char *name = p->fi->getName(); if (opt->output_name) name = opt->output_name; else if (opt->to_stdout) name = "<stdout>"; con_fprintf(stdout,"%s\n", mkline(fo->getBytesWritten(), p->file_size, p->ph.u_len, p->ph.c_len, p->getName(), fn_basename(name), true)); printSetNl(0);}void UiPacker::uiUnpackTotal(){ uiListTotal(true); uiFooter("Unpacked");}/*************************************************************************// list**************************************************************************/void UiPacker::uiListStart(){ total_files++;}void UiPacker::uiList(long fu_len){ if (fu_len < 0) fu_len = p->ph.u_file_size; const char *name = p->fi->getName(); con_fprintf(stdout,"%s\n", mkline(fu_len, p->file_size, p->ph.u_len, p->ph.c_len, p->getName(), name)); printSetNl(0);}void UiPacker::uiListEnd(){ uiUpdate();}void UiPacker::uiListTotal(bool decompress){ if (opt->verbose >= 1 && total_files >= 2) { char name[32]; upx_snprintf(name, sizeof(name), "[ %ld file%s ]", total_files_done, total_files_done == 1 ? "" : "s"); con_fprintf(stdout, "%s%s\n", header_line2, mkline(total_fu_len, total_fc_len, total_u_len, total_c_len, "", name, decompress)); printSetNl(0); }}/*************************************************************************// test**************************************************************************/void UiPacker::uiTestStart(){ total_files++; if (opt->verbose >= 1) { con_fprintf(stdout,"testing %s ", p->fi->getName()); fflush(stdout); printSetNl(1); }}void UiPacker::uiTestEnd(){ if (opt->verbose >= 1) { con_fprintf(stdout,"[OK]\n"); fflush(stdout); printSetNl(0); } uiUpdate();}void UiPacker::uiTestTotal(){ uiFooter("Tested");}/*************************************************************************// info**************************************************************************/bool UiPacker::uiFileInfoStart(){ total_files++; int fg = con_fg(stdout,FG_CYAN); con_fprintf(stdout,"%s [%s, %s]\n", p->fi->getName(), p->getFullName(opt), p->getName()); fg = con_fg(stdout,fg); UNUSED(fg); if (p->ph.c_len > 0) { 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", p->ph.version, p->ph.method, p->ph.level, p->ph.filter, p->ph.filter_cto); return false; } else { con_fprintf(stdout," %8ld bytes", (long)p->file_size); con_fprintf(stdout,", not compressed by UPX\n"); return true; }}void UiPacker::uiFileInfoEnd(){ uiUpdate();}void UiPacker::uiFileInfoTotal(){}/*************************************************************************// util**************************************************************************/void UiPacker::uiHeader(){ static bool done = false; if (done) return; done = true; if (opt->cmd == CMD_TEST || opt->cmd == CMD_FILEINFO) return; if (opt->verbose >= 1) { con_fprintf(stdout,"%s%s", header_line1, header_line2); }}void UiPacker::uiFooter(const char *t){ static bool done = false; if (done) return; done = true; if (opt->verbose >= 1) { long n1 = total_files; long n2 = total_files_done; long n3 = total_files - total_files_done; if (n3 == 0) con_fprintf(stdout,"\n%s %ld file%s.\n", t, n1, n1 == 1 ? "" : "s"); else con_fprintf(stdout,"\n%s %ld file%s: %ld ok, %ld error%s.\n", t, n1, n1 == 1 ? "" : "s", n2, n3, n3 == 1 ? "" : "s"); }}void UiPacker::uiUpdate(long fc_len, long fu_len){ 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_c_len = p->ph.c_len; update_u_len = p->ph.u_len;}void UiPacker::uiConfirmUpdate(){ total_files_done++; total_fc_len += update_fc_len; total_fu_len += update_fu_len; total_c_len += update_c_len; total_u_len += update_u_len;}/*vi:ts=4:et*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -