📄 crepc.cpp
字号:
//---------------------------------------------------------------------------
#pragma hdrstop
#include <stdio>
#include "crepc.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
CCommonReportingClass::CCommonReportingClass() {
FStatus=ST_COMMON;
FLogFileName[0]=0;
#ifdef PROTECTOR
Protector=new CProtector;
Protector->Above();
Protector->Beyond();
#endif
}
CCommonReportingClass::~CCommonReportingClass() {
#ifdef PROTECTOR
delete Protector;
#endif
}
// settings
void CCommonReportingClass::SetOutput(TStrings *Output) {
FOutput=Output;
}
void CCommonReportingClass::SetDataDisplay(TListView *DataDisplay) {
FDataDisplay=DataDisplay;
}
void CCommonReportingClass::SetProgress(TProgressBar *Progress) {
FProgress=Progress;
}
void CCommonReportingClass::SetStatusBar(TStatusBar *StatusBar) {
FStatusBar=StatusBar;
}
void CCommonReportingClass::SetLogFileName(char *LogFileName) {
if (LogFileName)
strcpy(FLogFileName, LogFileName);
}
#ifdef URS_LOGGER
void CCommonReportingClass::SetHost(char *Host) {
if (Host)
strcpy(FHost, Host);
}
void CCommonReportingClass::SetLogin(char *Login) {
if (Login)
strcpy(FLogin, Login);
}
void CCommonReportingClass::SetPasswd(char *Passwd) {
if (Passwd)
strcpy(FPasswd, Passwd);
}
#endif
// outputs
void CCommonReportingClass::OutReport(char *Txt) {
FOutput->Add(Txt);
StatusReport(Txt);
Application->ProcessMessages();
LogReport(Txt);
}
void CCommonReportingClass::ErrReport(char *Txt) {
char OutBuff[255];
sprintf(OutBuff, "Error. %s", Txt);
FOutput->Add(OutBuff);
// StatusReport(OutBuff);
Application->ProcessMessages();
LogReport(TxtBuff);
}
void CCommonReportingClass::WarnReport(char *Txt) {
char OutBuff[255];
sprintf(OutBuff, "Warning. %s", Txt);
FOutput->Add(OutBuff);
// StatusReport(OutBuff);
Application->ProcessMessages();
LogReport(TxtBuff);
}
void CCommonReportingClass::DataReport(char *Item, char *Value) {
TListItem *AddedItem;
char Mixed[100];
int i;
// is data already here?
for (i=0; i<FDataDisplay->Items->Count; i++)
if (strcmp(FDataDisplay->Items->Item[i]->Caption.c_str(), Item)==0)
return;
AddedItem=FDataDisplay->Items->Add();
AddedItem->Caption=Item;
AddedItem->SubItems->Add(Value);
sprintf(Mixed, "%s %s", Item, Value);
LogReport(Mixed);
Application->ProcessMessages();
}
void CCommonReportingClass::LogReport(char *Txt) {
// report to log file
FILE *f;
if (strlen(FLogFileName)>0) {
// FLogFileName specified -> create log
f=fopen(FLogFileName, "at");
if (f) {
// file open ok
fprintf(f, "%s %s %s\n", DateToStr(Date()), TimeToStr(Time()), Txt);
fclose(f);
}
}
}
void CCommonReportingClass::StatusReport(char *Txt) {
// report to status bar
FStatusBar->Panels->Items[0]->Text=Txt;
Application->ProcessMessages();
}
void CCommonReportingClass::MultiReport(char *Txt) {
unsigned int i;
int j=0;
for (i=0; i<strlen(Txt); i++, j++) {
if (Txt[i]!='\n')
TxtBuff[j]=Txt[i];
else {
TxtBuff[j]=0;
j=-1;
OutReport(TxtBuff);
}
}
TxtBuff[j]=0;
if (strlen(TxtBuff)>1)
OutReport(TxtBuff);
}
// progress
void CCommonReportingClass::Progress(int Position) {
// set progress
FProgress->Position=Position;
if (Position==0) {
FProgress->Visible=false;
strcpy(TxtBuff, "");
SetupProgress(0, 100, 1);
}
else {
FProgress->Visible=true;
sprintf(TxtBuff, "%d %%", (Position*100)/FProgress->Max);
}
FStatusBar->Panels->Items[1]->Text=TxtBuff;
Application->ProcessMessages();
}
void CCommonReportingClass::SetupProgress(int Min, int Max, int Step) {
FProgress->Min=Min;
FProgress->Max=Max;
FProgress->Step=Step;
}
void CCommonReportingClass::StepProgress() {
FProgress->StepIt();
Application->ProcessMessages();
}
// prologue
void CCommonReportingClass::Prologue() {
// clear outputs
FOutput->Clear();
FDataDisplay->Clear();
// timers
QueryPerformanceFrequency((_LARGE_INTEGER*)(&TmrFreq));
QueryPerformanceCounter((_LARGE_INTEGER*)(&TmrStart));
// dongle
#ifdef PROTECTOR
ProtectorReport();
#endif
}
void CCommonReportingClass::ProtectorReport() {
#ifdef PROTECTOR
unsigned char Lic[64], Sn[64];
Protector->GetLicInfo(Lic, Sn);
sprintf(TxtBuff, "GSMkey USB dongle: SN %s (%s)", Sn, Lic);
OutReport(TxtBuff);
#endif
}
// termination
void CCommonReportingClass::Termination(BOOL Ok) {
int TmrOp;
// progress
Progress(0);
// timers
QueryPerformanceCounter((_LARGE_INTEGER*)(&TmrStop));
TmrOp=(TmrStop-TmrStart)/TmrFreq;
sprintf(TxtBuff, "Operation time: %02d:%02d.", TmrOp/60, TmrOp%60);
OutReport(TxtBuff);
// message to user
if (Ok) {
FStatus=ST_DONE;
OutReport(TXT_SUCCESS);
}
else {
FStatus=ST_ERROR;
OutReport(ERR);
}
}
// helpers
#ifdef PROTECTOR
void CCommonReportingClass::CryptBlockForDongle(unsigned char *Block, unsigned int BlockLn, unsigned char *Key, char *FileName) {
unsigned int i;
FILE *f=fopen(FileName, "wt");
Protector->Crypt(Block, BlockLn, Key);
for (i=0; i<BlockLn; i++) {
fprintf(f, "0x%02X, ", Block[i]);
if (!(i%16))
fprintf(f, "\n");
}
fclose(f);
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -