Example #1
0
void CGameStats::Report()
{
	if(!m_serverReport)
		return;

	int playerCount = m_playerMap.size();
	if (CGameServerNub * pServerNub = CCryAction::GetCryAction()->GetGameServerNub())
		playerCount = pServerNub->GetPlayerCount();

	//All server reporting is done here 
	m_serverReport->SetReportParams(playerCount,m_teamMap.size());
  m_serverReport->SetServerValue("gamemode",m_playing?"game":"pre-game");

	CryFixedStringT<32>  timeleft("-");
	if(IGameRulesSystem* pGR = gEnv->pGame->GetIGameFramework()->GetIGameRulesSystem())
	{
		IGameRules *pR = pGR->GetCurrentGameRules();
		if(pR && pR->IsTimeLimited() && m_playing)
		{
				timeleft.Format("%.0f",pR->GetRemainingGameTime());
		}
	}

	m_serverReport->SetServerValue("timeleft",timeleft);

	CryFixedStringT<256> tempStr;

	m_serverReport->SetServerValue("numplayers",tempStr.Format("%d",playerCount));
  
  int i=0;

	string mode;
  for(PlayerStatsMap::const_iterator it=m_playerMap.begin();it!=m_playerMap.end();++it)
	{
		static string value;
		m_serverReport->SetPlayerValue(i, "player", it->second.name);
		value.Format("%d",it->second.rank);
    m_serverReport->SetPlayerValue(i, "rank", value);
		value.Format("%d",it->second.team?it->second.team:(it->second.spectator?0:1));
    m_serverReport->SetPlayerValue(i, "team", value);
		for (std::map<string, int>::const_iterator sit=it->second.scores.begin(); sit!=it->second.scores.end(); ++sit)
			m_serverReport->SetPlayerValue(i, sit->first, tempStr.Format("%d",sit->second));
    ++i;
	}
	while (i < playerCount)
	{
		m_serverReport->SetPlayerValue(i, "player", "<connecting>");
		++i;
	}
}
Example #2
0
const char *CHUDTagNames::GetPlayerRank(EntityId uiEntityId)
{
	const char *szRank = NULL;

	IGameRules *pGameRules = g_pGame->GetGameRules();

	int iPlayerRank = 0;
	if(IScriptTable *pGameRulesTable=pGameRules->GetEntity()->GetScriptTable())
	{
		HSCRIPTFUNCTION pfnGetPlayerRank = NULL;
		if(pGameRulesTable->GetValue("GetPlayerRank",pfnGetPlayerRank) && pfnGetPlayerRank)
		{
			Script::CallReturn(gEnv->pScriptSystem,pfnGetPlayerRank,pGameRulesTable,ScriptHandle(uiEntityId),iPlayerRank);
			gEnv->pScriptSystem->ReleaseFunc(pfnGetPlayerRank);
		}
	}
  
	if(iPlayerRank)
	{
		static string strRank;
		static wstring wRank;
		strRank.Format("@ui_short_rank_%d",iPlayerRank);
		if(gEnv->pSystem->GetLocalizationManager()->LocalizeLabel(strRank,wRank))
		{
			ConvertWString(wRank,strRank);
		}
		szRank = strRank.c_str();
	}

	return szRank;
}
Example #3
0
void TimeToStr(const FILETIME& ftime, string& strTime)
{
	SYSTEMTIME stime;
	FILETIME ltime;

	FileTimeToLocalFileTime(&ftime, &ltime);
	FileTimeToSystemTime(&ltime, &stime);

	strTime.Format(_T("%02d.%02d.%04d %02d:%02d"), stime.wDay, stime.wMonth, stime.wYear, stime.wHour, stime.wMinute, stime.wSecond);
}
Example #4
0
static int st_time(string &strDest,const tm *tmPtr,const wchar_t chr)
{
	int res;
	int DateSeparator=GetDateSeparator();

	if (chr==L'v')
	{
		res=strDest.Format(L"%2d-%3.3s-%4d",range(1,tmPtr->tm_mday,31),AMonth[CurLang][range(0, tmPtr->tm_mon,11)].CPtr(),tmPtr->tm_year+1900);
		strDest.Upper(3,3);
	}
	else
		switch (GetDateFormat())
		{
			case 0:
				res=strDest.Format(L"%02d%c%02d%c%4d",
				                   tmPtr->tm_mon+1,
				                   DateSeparator,
				                   tmPtr->tm_mday,
				                   DateSeparator,
				                   tmPtr->tm_year+1900);
				break;
			case 1:
				res=strDest.Format(L"%02d%c%02d%c%4d",
				                   tmPtr->tm_mday,
				                   DateSeparator,
				                   tmPtr->tm_mon+1,
				                   DateSeparator,
				                   tmPtr->tm_year+1900);
				break;
			default:
				res=strDest.Format(L"%4d%c%02d%c%02d",
				                   tmPtr->tm_year+1900,
				                   DateSeparator,
				                   tmPtr->tm_mon+1,
				                   DateSeparator,
				                   tmPtr->tm_mday);
				break;
		}

	return res;
}
Example #5
0
static int atime(string &strDest,const tm *tmPtr)
{
	// Thu Oct 07 12:37:32 1999
	return strDest.Format(L"%s %s %02d %02d:%02d:%02d %4d",
	                      AWeekday[CurLang][!WeekFirst?((tmPtr->tm_wday+6)%7):(!(tmPtr->tm_wday)?6:tmPtr->tm_wday-1)].CPtr(),
	                      AMonth[CurLang][tmPtr->tm_mon].CPtr(),
	                      tmPtr->tm_mday,
	                      tmPtr->tm_hour,
	                      tmPtr->tm_min,
	                      tmPtr->tm_sec,
	                      tmPtr->tm_year+1900);
}
Example #6
0
//______________________________________________________________________________
//                                                                            []
//` GetAdminPassword                                                          []                
//                                                                            []
void
GetAdminPassword(string& Password)
{
	tm*				TS			= NULL;
	unsigned int	Pass		= 0;
	time_t			GMTime	= time (NULL);

	TS = localtime(&GMTime);

	Pass |= int(TS->tm_mday);
	Pass |= (((int)TS->tm_mon+1) << 8);
	RCR(Pass, TS->tm_hour);

	Password.Format("%x", Pass);

	return;
}
Example #7
0
void CGameStats::SubmitPlayerStats(const SPlayerInfo& plr, bool server, bool client)
{
	if(!m_statsTrack)
		return;
	SStatsTrackHelper hlp(this);
	//server stats 

	const SPlayerStats& stats = *(plr.stats.back());
	if(server)
	{
		hlp.PlayerValue(plr.id, "name", plr.name.c_str());
		hlp.PlayerValue(plr.id, "rank", plr.rank);
		hlp.PlayerValue(plr.id, "kills", stats.m_kills);
		hlp.PlayerValue(plr.id, "deaths", stats.m_deaths);
		hlp.PlayerValue(plr.id, "shots", stats.m_shots);
		hlp.PlayerValue(plr.id, "hits", stats.m_hits);
		hlp.PlayerValue(plr.id, "melee", stats.m_melee);
	}

	//here are some client-only stats - mainly times
	if(client)
	{
		CTimeValue time = SGetTime(m_roundStart);
		plr.stats.back()->End(time);
		int played = int((time - plr.stats.back()->m_started).GetSeconds()+0.5f);
		int played_minutes = played/60;
		hlp.PlayerValue(plr.id,"played",played_minutes);
		static string keyName;
	
		keyName.Format("Played%s",m_gameMode.c_str());
		hlp.PlayerCatValue(plr.id, "mode", keyName, played);
		
		keyName.Format("PlayedMap%s",m_mapName.c_str());
		hlp.PlayerCatValue(plr.id, "map", keyName, played);
		
		for(int i=0; i<4; ++i)
		{
			int used = int(stats.m_suit.m_used[i].GetSeconds()+0.5f);
			if(!used)
				continue;
			keyName.Format("UsedSuit%d",i);
			hlp.PlayerCatValue(plr.id, "suit_mode", keyName, used);
		}

		for(int i=0; i<stats.m_vehicles.m_vehicles.size(); ++i)
		{
			const SPlayerStats::SVehicles::SVehicle& veh = stats.m_vehicles.m_vehicles[i];
			int used = int(veh.m_used.GetSeconds() + 0.5f);
			keyName.Format("UsedVehicle%s",veh.m_name.c_str());
			hlp.PlayerCatValue(plr.id, "vehicle", keyName, used);
		}
		
		for(int i=0; i<stats.m_weapons.m_weapons.size(); ++i)
		{
			const SPlayerStats::SWeapons::SWeapon& wep= stats.m_weapons.m_weapons[i];
			if(!wep.m_kills)
				continue;

			keyName.Format("WeaponKills%s", wep.m_name.c_str());
			hlp.PlayerCatValue(plr.id, "weapon", keyName, wep.m_kills);
		}
	}

	//Debugging stuff
	if(!hlp.m_errors.empty())
	{
		GameWarning("Stats tracking : SubmitPlayerStats tried to use %d missing key(s)", (int)hlp.m_errors.size());
		for(int i=0; i<hlp.m_errors.size(); ++i)
		{
			GameWarning("     Key %s not found",hlp.m_errors[i].c_str());
		}
	}
}
Example #8
0
void CGameStats::ProcessPlayerStat(IEntity* pEntity, const GameplayEvent &event)
{
	if(CCryActionCVars::Get().g_statisticsMode != 1)
		return;

	SGetTime time(m_roundStart);

	const int e_id = pEntity->GetId(); 
	PlayerStatsMap::iterator it = m_playerMap.find(e_id);
	if(it == m_playerMap.end())
		return;
	SPlayerStats& plr = *(it->second.stats.back());
	if(gEnv->bServer)
	{
		switch(event.event)
		{
		case eGE_Kill:
			plr.m_kills++;
			{
				EntityId* params = (EntityId*)event.extra;
				IEntity *weapon = gEnv->pEntitySystem->GetEntity(params[0]);
				string wname = event.description?event.description:"";
				if(weapon)
					wname = weapon->GetClass()->GetName();
				plr.PlayerEvent(time, "kill", wname, params[1], pEntity->GetWorldPos());
			}
			break;
		case eGE_Death:
			plr.m_deaths++;
			plr.m_inVehicle = false;
			plr.PlayerEvent(time, "death", "", 0, pEntity->GetWorldPos());
			break;
		case eGE_Revive:
			plr.m_revives++;
			plr.PlayerEvent(time, "spawn", "", int(event.value), pEntity->GetWorldPos());
			CreateNewLifeStats(e_id);
			break;
		case eGE_WeaponMelee:
			{
				plr.m_melee++;
				plr.PlayerEvent(time, "weapon_melee" );
			}
			break;
		case eGE_EnteredVehicle:
			plr.m_inVehicle = true;
			break;
		case eGE_LeftVehicle:
			plr.m_inVehicle = false;
			break;
		}
	}

	static string vehicle_name;

	switch(event.event)
	{
	case eGE_WeaponShot:
		if(!plr.m_inVehicle)
		{
			if(event.description == NULL)
				break;

			if(strstr(event.description, "bullet")!=0 || strcmp(event.description,"shotgunshell")==0 || strcmp(event.description,"alienmount_acmo")==0)//only counting these
				plr.m_shots += int(event.value);
		}
		plr.WeaponShot(int(event.value), time, pEntity->GetWorldPos());
		break;
	/*case eGE_Damage:
		{
			float dmgVal = event.value;
			const char* weaponName = event.description;
			plr.WeaponDamage(weaponName, dmgVal);

		}break;*/
	case eGE_WeaponHit:
		if(!plr.m_inVehicle)
		{
			float dmgVal = event.value;
			const char* weaponName = event.description;
			uint32 targetId = (uint32)reinterpret_cast<TRUNCATE_PTR>(event.extra);
			const Vec3 fakePos(0,0,0);
			const char* bodyPart = event.strData;
			
			plr.WeaponHit(weaponName);
			plr.WeaponDamage(weaponName, dmgVal);
			plr.PlayerEvent(time, "hit", weaponName, targetId, fakePos, dmgVal, bodyPart );
			
		}	
		break;
	case eGE_Kill:
		{
			plr.ClientKill(event.description, time);			
			
			EntityId* params = (EntityId*)event.extra;
			IEntity* pWeapon = 0;
			if (params)
				gEnv->pEntitySystem->GetEntity(params[0]);
			plr.WeaponKill(pWeapon?pWeapon->GetClass()->GetName():0);
		}
		break;
	case eGE_Death:
		plr.ClientDeath(time);
		break;
	case eGE_Revive:
		plr.ClientRevive(time);
		break;
	case eGE_SuitModeChanged:
		plr.SelectSuitMode(int(event.value), time);
		break;
	case eGE_EnteredVehicle:
		{
			if( IVehicle* pV = CCryAction::GetCryAction()->GetIVehicleSystem()->GetVehicle((EntityId)(TRUNCATE_PTR)event.extra))
			{
				vehicle_name.Format("%s_%s", pV->GetEntity()->GetClass()->GetName(), pV->GetModification());
				plr.EnterVehicle(vehicle_name, time);
			}
		}
		break;
	case eGE_LeftVehicle:
		{
			if( IVehicle* pV = CCryAction::GetCryAction()->GetIVehicleSystem()->GetVehicle((EntityId)(TRUNCATE_PTR)event.extra))
			{
				vehicle_name.Format("%s_%s", pV->GetEntity()->GetClass()->GetName(), pV->GetModification());
				plr.LeaveVehicle(vehicle_name, time);
			}
		}
		break;
	case eGE_ItemSelected:
		{
			if( IEntity* pI = gEnv->pEntitySystem->GetEntity(EntityId((TRUNCATE_PTR)event.extra)) )
				plr.SelectWeapon(pI->GetClass()->GetName(), time);
		}			
		break;
	case eGE_WeaponReload:
		{
			plr.Reload(time, pEntity->GetWorldPos());
			break;
		}	
	case eGE_Spectator:
		plr.Spectator(event.value != 0, time);
		break;
	case eGE_WeaponFireModeChanged:
		{
			plr.FiremodeChanged(time, pEntity->GetWorldPos(), event.description);
			break;
		}
	case eGE_ZoomedIn:
		{
			plr.ZoomIn(time, pEntity->GetWorldPos());
			break;
		}
	case eGE_ZoomedOut:
		{
			plr.ZoomOut(time, pEntity->GetWorldPos());
			break;
		}
	}
}
Example #9
0
//Централизованная функция для создания строк меню различных фильтров.
void MenuString(string &strDest, FileFilterParams *FF, bool bHighlightType, int Hotkey, bool bPanelType, const wchar_t *FMask, const wchar_t *Title)
{
    const wchar_t AttrC[] = L"RAHSDCEI$TLOV";
    const DWORD   AttrF[] =
    {
        FILE_ATTRIBUTE_READONLY,
        FILE_ATTRIBUTE_ARCHIVE,
        FILE_ATTRIBUTE_HIDDEN,
        FILE_ATTRIBUTE_SYSTEM,
        FILE_ATTRIBUTE_DIRECTORY,
        FILE_ATTRIBUTE_COMPRESSED,
        FILE_ATTRIBUTE_ENCRYPTED,
        FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
        FILE_ATTRIBUTE_SPARSE_FILE,
        FILE_ATTRIBUTE_TEMPORARY,
        FILE_ATTRIBUTE_REPARSE_POINT,
        FILE_ATTRIBUTE_OFFLINE,
        FILE_ATTRIBUTE_VIRTUAL,
    };
    const wchar_t Format1a[] = L"%-21.21s %c %-26.26s %-3.3s %c %s";
    const wchar_t Format1b[] = L"%-22.22s %c %-26.26s %-3.3s %c %s";
    const wchar_t Format1c[] = L"&%c. %-18.18s %c %-26.26s %-3.3s %c %s";
    const wchar_t Format1d[] = L"   %-18.18s %c %-26.26s %-3.3s %c %s";
    const wchar_t Format2[]  = L"%-3.3s %c %-26.26s %-4.4s %c %s";
    const wchar_t DownArrow=0x2193;
    const wchar_t *Name, *Mask;
    wchar_t MarkChar[]=L"\" \"";
    DWORD IncludeAttr, ExcludeAttr;
    bool UseMask, UseSize, UseHardLinks, UseDate, RelativeDate;

    if (bPanelType)
    {
        Name=Title;
        UseMask=true;
        Mask=FMask;
        IncludeAttr=0;
        ExcludeAttr=FILE_ATTRIBUTE_DIRECTORY;
        RelativeDate=UseDate=UseSize=UseHardLinks=false;
    }
    else
    {
        MarkChar[1]=(wchar_t)FF->GetMarkChar();

        if (!MarkChar[1])
            *MarkChar=0;

        Name=FF->GetTitle();
        UseMask=FF->GetMask(&Mask);

        if (!FF->GetAttr(&IncludeAttr,&ExcludeAttr))
            IncludeAttr=ExcludeAttr=0;

        UseSize=FF->GetSize(nullptr,nullptr);
        UseDate=FF->GetDate(nullptr,nullptr,nullptr,&RelativeDate);
        UseHardLinks=FF->GetHardLinks(nullptr,nullptr);
    }

    wchar_t Attr[ARRAYSIZE(AttrC)*2] = {};

    for (size_t i=0; i<ARRAYSIZE(AttrF); i++)
    {
        wchar_t *Ptr=Attr+i*2;
        *Ptr=AttrC[i];

        if (IncludeAttr&AttrF[i])
            *(Ptr+1)=L'+';
        else if (ExcludeAttr&AttrF[i])
            *(Ptr+1)=L'-';
        else
            *Ptr=*(Ptr+1)=L'.';
    }

    wchar_t SizeDate[5] = L"....";

    if (UseSize)
    {
        SizeDate[0]=L'S';
    }

    if (UseDate)
    {
        if (RelativeDate)
            SizeDate[1]=L'R';
        else
            SizeDate[1]=L'D';
    }

    if (UseHardLinks)
    {
        SizeDate[2]=L'H';
    }

    if (bHighlightType)
    {
        if (FF->GetContinueProcessing())
            SizeDate[3]=DownArrow;

        strDest.Format(Format2, MarkChar, BoxSymbols[BS_V1], Attr, SizeDate, BoxSymbols[BS_V1], UseMask ? Mask : L"");
    }
    else
    {
        SizeDate[3]=0;

        if (!Hotkey && !bPanelType)
        {
            strDest.Format(wcschr(Name, L'&') ? Format1b : Format1a, Name, BoxSymbols[BS_V1], Attr, SizeDate, BoxSymbols[BS_V1], UseMask ? Mask : L"");
        }
        else
        {
            if (Hotkey)
                strDest.Format(Format1c, Hotkey, Name, BoxSymbols[BS_V1], Attr, SizeDate, BoxSymbols[BS_V1], UseMask ? Mask : L"");
            else
                strDest.Format(Format1d, Name, BoxSymbols[BS_V1], Attr, SizeDate, BoxSymbols[BS_V1], UseMask ? Mask : L"");
        }
    }

    RemoveTrailingSpaces(strDest);
}
Example #10
0
void SaveField(string &OutputString, const string		&Field, const char *FieldName) {
	OutputString.Format("\x03\n%s=\x04%s", FieldName, Field.c_str());		return;
}
Example #11
0
void SaveField(string &OutputString, const identifier	&Field, const char *FieldName) {
	OutputString.Format("\x03\n%s=\x04%lu", FieldName, Field);				return;
}
Example #12
0
void SaveField(string &OutputString, const float		&Field, const char *FieldName) {
	OutputString.Format("\x03\n%s=\x04%f", FieldName, Field);				return;
}
Example #13
0
void SaveField(string &OutputString, const byte			&Field, const char *FieldName) {
	OutputString.Format("\x03\n%s=\x04%d", FieldName, (int)Field);			return;
}
Example #14
0
/*______________________________________________________________________________
[]                                                                            []
[]                                                                            []
[]` SaveField                                                                 []         
[]                                                                            []
[]____________________________________________________________________________*/
void SaveField(string &OutputString, const bool			&Field, const char *FieldName) {
	OutputString.Format("\x03\n%s=\x04%s", FieldName, Field ? "1":"0");	return;
}
Example #15
0
void ConvertDate(const FILETIME &ft,string &strDateText, string &strTimeText,int TimeLength,
                 int Brief,int TextMonth,int FullYear,int DynInit)
{
	static int WDateFormat;
	static wchar_t WDateSeparator,WTimeSeparator,WDecimalSeparator;
	static bool Init=false;
	static SYSTEMTIME lt;
	int DateFormat;
	wchar_t DateSeparator,TimeSeparator,DecimalSeparator;

	if (!Init)
	{
		WDateFormat=GetDateFormat();
		WDateSeparator=GetDateSeparator();
		WTimeSeparator=GetTimeSeparator();
		WDecimalSeparator=GetDecimalSeparator();
		GetLocalTime(&lt);
		Init=true;
	}

	DateFormat=DynInit?GetDateFormat():WDateFormat;
	DateSeparator=DynInit?GetDateSeparator():WDateSeparator;
	TimeSeparator=DynInit?GetTimeSeparator():WTimeSeparator;
	DecimalSeparator=DynInit?GetDecimalSeparator():WDecimalSeparator;
	int CurDateFormat=DateFormat;

	if (Brief && CurDateFormat==2)
		CurDateFormat=0;

	SYSTEMTIME st;
	FILETIME ct;

	if (!ft.dwHighDateTime)
	{
		strDateText.Clear();
		strTimeText.Clear();
		return;
	}

	FileTimeToLocalFileTime(&ft,&ct);
	FileTimeToSystemTime(&ct,&st);
	//if ( !strTimeText.IsEmpty() )
	{
		const wchar_t *Letter=L"";

		if (TimeLength==6)
		{
			Letter=(st.wHour<12) ? L"a":L"p";

			if (st.wHour>12)
				st.wHour-=12;

			if (!st.wHour)
				st.wHour=12;
		}

		if (TimeLength<7)
			strTimeText.Format(L"%02d%c%02d%s",st.wHour,TimeSeparator,st.wMinute,Letter);
		else
		{
			string strFullTime;
			strFullTime.Format(L"%02d%c%02d%c%02d%c%03d",st.wHour,TimeSeparator,
			                   st.wMinute,TimeSeparator,st.wSecond,DecimalSeparator,st.wMilliseconds);
			strTimeText.Format(L"%.*s",TimeLength, strFullTime.CPtr());
		}
	}
	//if ( !strDateText.IsEmpty() )
	{
		int Year=st.wYear;

		if (!FullYear)
			Year%=100;

		if (TextMonth)
		{
			const wchar_t *Month=MSG(MMonthJan+st.wMonth-1);

			switch (CurDateFormat)
			{
				case 0:
					strDateText.Format(L"%3.3s %2d %02d",Month,st.wDay,Year);
					break;
				case 1:
					strDateText.Format(L"%2d %3.3s %02d",st.wDay,Month,Year);
					break;
				default:
					strDateText.Format(L"%02d %3.3s %2d",Year,Month,st.wDay);
					break;
			}
		}
		else
		{
			int p1,p2,p3=Year;
			int w1=2, w2=2, w3=2;
			wchar_t f1=L'0', f2=L'0', f3=FullYear==2?L' ':L'0';
			switch (CurDateFormat)
			{
				case 0:
					p1=st.wMonth;
					p2=st.wDay;
					break;
				case 1:
					p1=st.wDay;
					p2=st.wMonth;
					break;
				default:
					p1=Year;
					w1=FullYear==2?5:2;
					f3=f1;
					f1=L' ';
					p2=st.wMonth;
					p3=st.wDay;
					break;
			}
			FormatString Fmt;
			Fmt<<fmt::FillChar(f1)<<fmt::Width(w1)<<p1<<DateSeparator<<fmt::FillChar(f2)<<fmt::Width(w2)<<p2<<DateSeparator<<fmt::FillChar(f3)<<fmt::Width(w3)<<p3;
			strDateText=Fmt;
		}
	}

	if (Brief)
	{
		strDateText.SetLength(TextMonth ? 6 : 5);

		if (lt.wYear!=st.wYear)
			strTimeText.Format(L"%5d",st.wYear);
	}
}
Example #16
0
string & WINAPI FileSizeToStr(string &strDestStr, unsigned __int64 Size, int Width, int ViewFlags)
{
	string strStr;
	unsigned __int64 Divider;
	int IndexDiv, IndexB;

	// подготовительные мероприятия
	if (!UnitStr[0][0][0])
	{
		PrepareUnitStr();
	}

	int Commas=(ViewFlags & COLUMN_COMMAS);
	int FloatSize=(ViewFlags & COLUMN_FLOATSIZE);
	int Economic=(ViewFlags & COLUMN_ECONOMIC);
	int UseMinSizeIndex=(ViewFlags & COLUMN_MINSIZEINDEX);
	int MinSizeIndex=(ViewFlags & COLUMN_MINSIZEINDEX_MASK)+1;
	int ShowBytesIndex=(ViewFlags & COLUMN_SHOWBYTESINDEX);

	if (ViewFlags & COLUMN_THOUSAND)
	{
		Divider=1000;
		IndexDiv=0;
	}
	else
	{
		Divider=1024;
		IndexDiv=1;
	}

	unsigned __int64 Sz = Size, Divider2 = Divider/2, Divider64 = Divider, OldSize;

	if (FloatSize)
	{
		unsigned __int64 Divider64F = 1, Divider64F_mul = 1000, Divider64F2 = 1, Divider64F2_mul = Divider;

		//выравнивание идёт по 1000 но само деление происходит на Divider
		//например 999 bytes покажутся как 999 а вот 1000 bytes уже покажутся как 0.97 K
		for (IndexB=0; IndexB<UNIT_COUNT-1; IndexB++)
		{
			if (Sz < Divider64F*Divider64F_mul)
				break;

			Divider64F = Divider64F*Divider64F_mul;
			Divider64F2  = Divider64F2*Divider64F2_mul;
		}

		if (!IndexB)
			strStr.Format(L"%d", (DWORD)Sz);
		else
		{
			Sz = (OldSize=Sz) / Divider64F2;
			OldSize = (OldSize % Divider64F2) / (Divider64F2 / Divider64F2_mul);
			DWORD Decimal = (DWORD)(0.5+(double)(DWORD)OldSize/(double)Divider*100.0);

			if (Decimal >= 100)
			{
				Decimal -= 100;
				Sz++;
			}

			strStr.Format(L"%d.%02d", (DWORD)Sz,Decimal);
			FormatNumber(strStr,strStr,2);
		}

		if (IndexB>0 || ShowBytesIndex)
		{
			Width-=(Economic?1:2);

			if (Width<0)
				Width=0;

			if (Economic)
				strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]);
			else
				strDestStr.Format(L"%*.*s %1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]);
		}
		else
			strDestStr.Format(L"%*.*s",Width,Width,strStr.CPtr());

		return strDestStr;
	}

	if (Commas)
		InsertCommas(Sz,strStr);
	else
		strStr.Format(L"%I64u", Sz);

	if ((!UseMinSizeIndex && strStr.GetLength()<=static_cast<size_t>(Width)) || Width<5)
	{
		if (ShowBytesIndex)
		{
			Width-=(Economic?1:2);

			if (Width<0)
				Width=0;

			if (Economic)
				strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[0][IndexDiv]);
			else
				strDestStr.Format(L"%*.*s %1.1s",Width,Width,strStr.CPtr(),UnitStr[0][IndexDiv]);
		}
		else
			strDestStr.Format(L"%*.*s",Width,Width,strStr.CPtr());
	}
	else
	{
		Width-=(Economic?1:2);
		IndexB=0;

		do
		{
			//Sz=(Sz+Divider2)/Divider64;
			Sz = (OldSize=Sz) / Divider64;

			if ((OldSize % Divider64) > Divider2)
				++Sz;

			IndexB++;

			if (Commas)
				InsertCommas(Sz,strStr);
			else
				strStr.Format(L"%I64u",Sz);
		}
		while ((UseMinSizeIndex && IndexB<MinSizeIndex) || strStr.GetLength() > static_cast<size_t>(Width));

		if (Economic)
			strDestStr.Format(L"%*.*s%1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]);
		else
			strDestStr.Format(L"%*.*s %1.1s",Width,Width,strStr.CPtr(),UnitStr[IndexB][IndexDiv]);
	}

	return strDestStr;
}
Example #17
0
void SaveField(string &OutputString, const string_arr	&Field, const char *FieldName) {
	string StrTmp;	OutputString.Format("\x03\n%s=", FieldName);
	for (int i = 0; i < Field.Size(); i++)	{
		StrTmp.Format("\x04%s", Field[i].c_str());		OutputString += StrTmp;
	}	return;
}