Example #1
0
/****************************************
    Callback called from GetFiles and PutFiles each time whole buffer
    sended or received to refresh state of copy progress
    Can be called in any plugin state (quite, not show, etc)
 ****************************************/
BOOL TrafficInformation::Callback(int Size)
{
	double tmDiff;
	DWORD     tm;
	time_t        tmt;
	char          str[MAX_PATH];
	double        TotalPercent,db;
	GET_TIME(tm);
	tmDiff = Abs(CMP_TIME(tm,LastTime));
	tmt = time(NULL);
	FileSize     += Size;
	FullFileSize  = Max(FileSize,FullFileSize);

	if(Size && FTP_Info->CheckForEsc(FALSE,FALSE))
	{
		Log(("User cancel"));
		return FALSE;
	}

	if(Size && tmDiff*1000 < FTP_Info->GetOpt()->IdleShowPeriod)
		return TRUE;

	memmove(&LastTime,&tm,sizeof(LastTime));
	TotalPercent = ToPercent(TotalSz(),TotalFullSize);

	//Avg
	if(tmDiff > 0)
	{
		AvCps[0] = AvCps[1];
		AvCps[1] = AvCps[2];
		AvCps[2] = (FileSize - LastSize) / tmDiff;
	}

	LastSize = FileSize;
	//Cur
	db = ((double)tmt-FileStartTime-FileWaitTime);

	if(db > 0)
		Cps = FileSize / db;
	else
		Cps = 0;

	//Total
	db = ((double)tmt-TotalStartTime-TotalWaitTime);

	if(db > 0)
		TotalCps = (TotalSize+FileSize) / db;
	else
		TotalCps = 0;

//Show QUIET progressing
	if(!ShowStatus)
	{
		_snprintf(str,ARRAYSIZE(str),
		         "{%2.1lf%%} %s: %.26s",
		         TotalPercent,
		         FTP_Info->GetMsg(TitleMsg),
		         FTP_Info->PointToName(SrcFileName));
		FTP_Info->IdleMessage(str,FTP_Info->GetOpt()->ProcessColor);
		return TRUE;
	}

//Window caption
	if(FTP_Info->FtpGetRetryCount())
		_snprintf(str,ARRAYSIZE(str),"%d: {%2.1lf%%} %s - Far",
		         FTP_Info->FtpGetRetryCount(), TotalPercent,
		         FTP_Info->GetMsg(TitleMsg));
	else
		_snprintf(str,ARRAYSIZE(str),"{%2.1lf%%} %s - Far",
		         TotalPercent,FTP_Info->GetMsg(TitleMsg));

	if(StrCmp(str,ConsoleTitle,-1,TRUE) != 0)
	{
		if(FTP_Info->WinVer->dwPlatformId != VER_PLATFORM_WIN32_NT)
			OemToChar(str,str);

		SetConsoleTitle(str);
		StrCpy(ConsoleTitle,str,ARRAYSIZE(ConsoleTitle));
	}

//Mark CMD window invisible
	FTP_Info->FtpCmdBlock(TRUE);
//Show message
	LPCSTR MsgItems[MAX_TRAF_LINES+1];
	DrawInfos(tmt);

	if(FTP_Info->FtpGetRetryCount())
		_snprintf(str,ARRAYSIZE(str),"%d: %s",FTP_Info->FtpGetRetryCount(),FTP_Info->GetMsg(TitleMsg));
	else
		StrCpy(str,FTP_Info->GetMsg(TitleMsg),ARRAYSIZE(str));

	MsgItems[0] = str;
	int n;

	for(n = 0; n < LineCount; n++)
		MsgItems[n+1] = Lines[n];

	FTP_Info->FMessage(FMSG_LEFTALIGN, NULL,
	                   (LPCSTR *)MsgItems, LineCount+1, 0);
	return TRUE;
}
Example #2
0
/****************************************
   TrafficInformation
 ****************************************/
void TrafficInformation::DrawInfo(InfoItem* it,time_t tm)
{
	static char str[MAX_PATH+1];
	double db;
	int    cn;
	time_t tmp;
	struct tm *ltm;
	int    len;

	switch(it->Type)
	{
			//00 " " ---- Space
		case 00:
			break;
			//01 "SrcPathname" ---- Source filename
		case 01: FTP_Info->StrCpy(str,SrcFileName,ARRAYSIZE(str));
			break;
			//02 "SrcPath",
		case 02: FTP_Info->StrCpy(str,SrcFileName,ARRAYSIZE(str));
			FTP_Info->PointToName(str)[0] = 0;
			break;
			//03 "SrcName",
		case 03: FTP_Info->StrCpy(str,FTP_Info->PointToName(SrcFileName),ARRAYSIZE(str));
			break;
			//04 "DestPathname" ---- Target filename
		case 04: FTP_Info->StrCpy(str,DestFileName,ARRAYSIZE(str));
			break;
			//05 "DestPath",
		case 05: FTP_Info->StrCpy(str,DestFileName,ARRAYSIZE(str));
			FTP_Info->PointToName(str)[0] = 0;
			break;
			//06 "DestName",
		case 06: FTP_Info->StrCpy(str,FTP_Info->PointToName(DestFileName),ARRAYSIZE(str));
			break;
			//07 "CurSize" ---- Current processed size
		case 07: FTP_Info->FDigit(str,CurrentSz(),-1);
			break;
			//08 "CurESize" ---- Full size of current file
			//09 "CurFSize",
		case  8:
		case  9: FTP_Info->FDigit(str,FullFileSize,-1);
			break;
			//10 "CurRSize" ---- Remain size of current file
		case 10: FTP_Info->FDigit(str,CurrentRemain(),-1);
			break;
			//11 "CurTime" ---- Time from start of current file
		case 11: cn = (int)(tm - FileStartTime);
			_snprintf(str,ARRAYSIZE(str), "%02d:%02d:%02d", cn/3600, (cn/60)%60, cn%60);
			break;
			//12 "CurFTime" ---- Full time to process current file
		case 12: db = Cps;

			if(db > 0)
				cn = (int)(CurrentDoRemain() / db);
			else
				cn = 0;

			cn = Max(cn,0);
			_snprintf(str,ARRAYSIZE(str), "%02d:%02d:%02d", cn/3600, (cn/60)%60, cn%60);
			break;
			//13 "CurRTime" ---- Remain time to process current file
		case 13: db = Cps;

			if(db > 0)
				cn = (int)(CurrentRemain() / db);
			else
				cn = 0;

			cn = Max(cn,0);
			_snprintf(str,ARRAYSIZE(str), "%02d:%02d:%02d", cn/3600, (cn/60)%60, cn%60);
			break;
			//14 "CurETime" ---- End time to process current file
		case 14: db = Cps;

			if(db > 0)
				tmp = tm + (time_t)(CurrentRemain() / db);
			else
				tmp = tm;

			tmp = Max(tmp,tm);
			ltm = Localtime(&tmp);
			StrTTime(str,ltm);
			break;
			//15 "CurEDate" ---- End date to process current file
		case 15: db = Cps;

			if(db > 0)
				tmp = tm + (time_t)(CurrentRemain() / db);
			else
				tmp = tm;

			tmp = Max(tmp,tm);
			ltm = Localtime(&tmp);
			StrYTime(str,ltm);
			break;
			//16 "TotSize" ---- Current processed size
		case 16: FTP_Info->FDigit(str,TotalSz(),-1);
			break;
			//17 "TotESize" ---- Full size of current file
			//18 "TotFSize",
		case 17:
		case 18: FTP_Info->FDigit(str,TotalFullSize,-1);
			break;
			//19 "TotRSize" ---- Remain size of current file
		case 19: FTP_Info->FDigit(str,TotalRemain(),-1);
			break;
			//20 "TotTime" ---- Time from start of current file
		case 20: cn = (int)(tm - TotalStartTime);
			_snprintf(str,ARRAYSIZE(str), "%02d:%02d:%02d", cn/3600, (cn/60)%60, cn%60);
			break;
			//21 "TotFTime" ---- Full time to process current file
		case 21: db = (AvCps[0] + AvCps[1] + AvCps[2])/3;

			if(db > 0)
				cn = (int)(TotalDoRemain() / db);
			else
				cn = 0;

			cn = Max(cn,0);
			_snprintf(str,ARRAYSIZE(str), "%02d:%02d:%02d", cn/3600, (cn/60)%60, cn%60);
			break;
			//22 "TotRTime" ----- Remain time to process current file
		case 22: db = (AvCps[0] + AvCps[1] + AvCps[2])/3;

			if(db > 0)
				cn = (int)(TotalRemain() / db);
			else
				cn = 0;

			cn = Max(cn,0);
			_snprintf(str,ARRAYSIZE(str), "%02d:%02d:%02d", cn/3600, (cn/60)%60, cn%60);
			break;
			//23 "TotETime" ---- End time to process all files
		case 23: db = TotalCps;

			if(db > 0)
				tmp = tm + (time_t)(TotalRemain() / db);
			else
				tmp = tm;

			ltm = Localtime(&tmp);
			StrTTime(str,ltm);
			break;
			//24 "TotEDate" ----- End date to process current file
		case 24: db = TotalCps;

			if(db > 0)
				tmp = tm + (time_t)(TotalRemain() / db);
			else
				tmp = tm;

			ltm = Localtime(&tmp);
			StrYTime(str,ltm);
			break;
			//25 "CurCPS"   ----- CP of current file
		case 25: FTP_Info->FCps(str,Cps);
			break;
			//26 "CPS"      -----  Summary CPS
		case 26: FTP_Info->FCps(str,(AvCps[0] + AvCps[1] + AvCps[2])/3);
			break;
			//27 "TotCPS"   ----- Total CPS
		case 27: FTP_Info->FCps(str,TotalCps);
			break;
			//28 "Progress" ----- Current progress bar
			//42 "Pg"       ----- ALIAS `Progress`
		case 42:
		case 28: PPercent(str,0,it->Size-1,(int)ToPercent(CurrentSz(),FullFileSize));
			break;
			//29 "FProgress"----- Total progress bar
			//43 "FPg"      ----- ALIAS `FProgress`
		case 43:
		case 29: PPercent(str,0,it->Size-1,(int)ToPercent(TotalSz(),TotalFullSize));
			break;
			//40 "Pc"       ----- ALIAS `Percent`
			//30 "PerCent"  ----- Current "99.9%" percent
		case 40:
		case 30: db = ToPercent(CurrentSz(),FullFileSize);

			if(((int)db) == 100)
				FTP_Info->StrCpy(str,"100%",-1);
			else
				sprintf(str,"%2.1lf%%",db);

			break;
			//41 "FPc" ---- ALIAS `FPercent`
			//31 "FPerCent" ----- Total "99.9%" percent
		case 41:
		case 31: db = ToPercent(TotalSz(),TotalFullSize);

			if(((int)db) == 100)
				FTP_Info->StrCpy(str,"100%",-1);
			else
				sprintf(str,"%2.1lf%%",db);

			break;
			//32 "Cn" ---- Complete count
		case 32: FTP_Info->FDigit(str,TotalComplete,-1);
			break;
			//33 "CnSkip" ---- Skipped count
		case 33: FTP_Info->FDigit(str,TotalSkipped,-1);
			break;
			//34 "CnR" ---- Remain count
		case 34: FTP_Info->FDigit(str,TotalFiles-TotalComplete-TotalSkipped,-1);
			break;
			//35 "CnF" ---- Count
		case 35: FTP_Info->FDigit(str,TotalFiles,-1);
			break;
			//36 "CurPc" ---- Current percent
		case 36: db = ToPercent(TotalComplete,TotalFiles);

			if(((int)db) == 100)
				FTP_Info->StrCpy(str,"100%",-1);
			else
				sprintf(str,"%2.1lf%%",db);

			break;
			//37 "SkipPc" ---- Skipped percent
		case 37: db = ToPercent(TotalSkipped,TotalFiles);

			if(((int)db) == 100)
				FTP_Info->StrCpy(str,"100%",-1);
			else
				sprintf(str,"%2.1lf%%",db);

			break;
			//38 "CurPg"     ---- Current percent progress
		case 38: PPercent(str,0,it->Size-1,(int)ToPercent(TotalComplete,TotalFiles));
			break;
			//39 "SkipPg"    ---- Skipped percent progress
		case 39: PPercent(str,0,it->Size-1,(int)ToPercent(TotalSkipped,TotalFiles));
			break;
			//44 "CurCPS4"   ----- CP of current file
		case 44: FCps4(str,Cps);
			break;
			//45 "CPS4"      -----  Summary CPS
		case 45: FCps4(str,(AvCps[0] + AvCps[1] + AvCps[2])/3);
			break;
			//46 "TotCPS4"   ----- Total CPS
		case 46: FCps4(str,TotalCps);
			break;
			//47 "IPc"       ----- Current "99%" percent
		case 47: db = ToPercent(CurrentSz(),FullFileSize);

			if(((int)db) == 100)
				FTP_Info->StrCpy(str,"100%",-1);
			else
				sprintf(str,"%d%%",(int)db);

			break;
			//48 "IFPc"      ----- Total "99%" percent
		case 48: db = ToPercent(TotalSz(),TotalFullSize);

			if(((int)db) == 100)
				FTP_Info->StrCpy(str,"100%",-1);
			else
				sprintf(str,"%d%%",(int)db);

			break;
	}

	if(it->Type)
	{
		len = static_cast<int>(strlen(str));

		if(!it->Size && it->Align == tCenter)
			it->Pos -= len/2;

		if(!it->Size)
			it->Size = len;

		if(len > it->Size && it->Align == tCenter)
			it->Align = tLeft;

		if(it->Pos+it->Size > MAX_TRAF_WIDTH)
			return;

		if(len > it->Size)
		{
			if(it->Align == tLeft)
			{
				memmove(Lines[it->Line]+it->Pos,str+len-it->Size,it->Size);
				Lines[it->Line][it->Pos] = FAR_LEFT_CHAR;
			}
			else
			{
				memmove(Lines[it->Line]+it->Pos,str,it->Size);
				Lines[it->Line][it->Pos+it->Size] = FAR_RIGHT_CHAR;
			}
		}
		else
		{
			//Clear
			if(it->Align != tCenter)
				memset(Lines[it->Line]+it->Pos,it->Fill,it->Size);

			//Draw
			if(it->Align == tLeft)
				memmove(Lines[it->Line]+it->Pos, str, len);
			else if(it->Align == tRight)
				memmove(Lines[it->Line]+it->Pos + it->Size - len, str, len);
			else
				memmove(Lines[it->Line]+it->Pos + it->Size/2 - len/2, str, len);
		}
	}
	else
	{
		memset(Lines[it->Line]+it->Pos,it->Fill,it->Size);
	}
}