📄 preferences.cpp
字号:
// Overall Run Time
ini.WriteInt(_T("ConnRunTime"), (GetTickCount() - theStats.starttime)/1000 + GetConnRunTime());
// Number of Reconnects
ini.WriteInt(_T("ConnNumReconnects"), (theStats.reconnects>0) ? (theStats.reconnects - 1 + GetConnNumReconnects()) : GetConnNumReconnects());
// Average Connections
if (theApp.serverconnect->IsConnected())
ini.WriteInt(_T("ConnAvgConnections"), (theApp.listensocket->GetAverageConnections() + cumConnAvgConnections)/2);
// Peak Connections
if (theApp.listensocket->GetPeakConnections() > cumConnPeakConnections)
cumConnPeakConnections = theApp.listensocket->GetPeakConnections();
ini.WriteInt(_T("ConnPeakConnections"), cumConnPeakConnections);
// Max Connection Limit Reached
if (theApp.listensocket->GetMaxConnectionReached() + cumConnMaxConnLimitReached > cumConnMaxConnLimitReached)
ini.WriteInt(_T("ConnMaxConnLimitReached"), theApp.listensocket->GetMaxConnectionReached() + cumConnMaxConnLimitReached);
// Time Stuff...
ini.WriteInt(_T("ConnTransferTime"), GetConnTransferTime() + theStats.GetTransferTime());
ini.WriteInt(_T("ConnUploadTime"), GetConnUploadTime() + theStats.GetUploadTime());
ini.WriteInt(_T("ConnDownloadTime"), GetConnDownloadTime() + theStats.GetDownloadTime());
ini.WriteInt(_T("ConnServerDuration"), GetConnServerDuration() + theStats.GetServerDuration());
// Compare and Save Server Records
uint32 servtotal, servfail, servuser, servfile, servlowiduser, servtuser, servtfile;
float servocc;
theApp.serverlist->GetStatus(servtotal, servfail, servuser, servfile, servlowiduser, servtuser, servtfile, servocc);
if (servtotal - servfail > cumSrvrsMostWorkingServers)
cumSrvrsMostWorkingServers = servtotal - servfail;
ini.WriteInt(_T("SrvrsMostWorkingServers"), cumSrvrsMostWorkingServers);
if (servtuser > cumSrvrsMostUsersOnline)
cumSrvrsMostUsersOnline = servtuser;
ini.WriteInt(_T("SrvrsMostUsersOnline"), cumSrvrsMostUsersOnline);
if (servtfile > cumSrvrsMostFilesAvail)
cumSrvrsMostFilesAvail = servtfile;
ini.WriteInt(_T("SrvrsMostFilesAvail"), cumSrvrsMostFilesAvail);
// Compare and Save Shared File Records
if (theApp.sharedfiles->GetCount() > cumSharedMostFilesShared)
cumSharedMostFilesShared = theApp.sharedfiles->GetCount();
ini.WriteInt(_T("SharedMostFilesShared"), cumSharedMostFilesShared);
uint64 bytesLargestFile = 0;
uint64 allsize = theApp.sharedfiles->GetDatasize(bytesLargestFile);
if (allsize > cumSharedLargestShareSize)
cumSharedLargestShareSize = allsize;
ini.WriteUInt64(_T("SharedLargestShareSize"), cumSharedLargestShareSize);
if (bytesLargestFile > cumSharedLargestFileSize)
cumSharedLargestFileSize = bytesLargestFile;
ini.WriteUInt64(_T("SharedLargestFileSize"), cumSharedLargestFileSize);
if (theApp.sharedfiles->GetCount() != 0) {
uint64 tempint = allsize/theApp.sharedfiles->GetCount();
if (tempint > cumSharedLargestAvgFileSize)
cumSharedLargestAvgFileSize = tempint;
}
ini.WriteUInt64(_T("SharedLargestAvgFileSize"), cumSharedLargestAvgFileSize);
ini.WriteUInt64(_T("statsDateTimeLastReset"), stat_datetimeLastReset);
// If we are saving a back-up or a temporary back-up, return now.
if (bBackUp != 0)
return;
}
void CPreferences::SetRecordStructMembers() {
// The purpose of this function is to be called from CStatisticsDlg::ShowStatistics()
// This was easier than making a bunch of functions to interface with the record
// members of the prefs struct from ShowStatistics.
// This function is going to compare current values with previously saved records, and if
// the current values are greater, the corresponding member of prefs will be updated.
// We will not write to INI here, because this code is going to be called a lot more often
// than SaveStats() - Khaos
CString buffer;
// Servers
uint32 servtotal, servfail, servuser, servfile, servlowiduser, servtuser, servtfile;
float servocc;
theApp.serverlist->GetStatus( servtotal, servfail, servuser, servfile, servlowiduser, servtuser, servtfile, servocc );
if ((servtotal-servfail)>cumSrvrsMostWorkingServers) cumSrvrsMostWorkingServers = (servtotal-servfail);
if (servtuser>cumSrvrsMostUsersOnline) cumSrvrsMostUsersOnline = servtuser;
if (servtfile>cumSrvrsMostFilesAvail) cumSrvrsMostFilesAvail = servtfile;
// Shared Files
if (theApp.sharedfiles->GetCount()>cumSharedMostFilesShared) cumSharedMostFilesShared = theApp.sharedfiles->GetCount();
uint64 bytesLargestFile = 0;
uint64 allsize=theApp.sharedfiles->GetDatasize(bytesLargestFile);
if (allsize>cumSharedLargestShareSize) cumSharedLargestShareSize = allsize;
if (bytesLargestFile>cumSharedLargestFileSize) cumSharedLargestFileSize = bytesLargestFile;
if (theApp.sharedfiles->GetCount() != 0) {
uint64 tempint = allsize/theApp.sharedfiles->GetCount();
if (tempint>cumSharedLargestAvgFileSize) cumSharedLargestAvgFileSize = tempint;
}
} // SetRecordStructMembers()
void CPreferences::SaveCompletedDownloadsStat(){
// This function saves the values for the completed
// download members to INI. It is called from
// CPartfile::PerformFileComplete ... - Khaos
TCHAR* fullpath = new TCHAR[_tcslen(configdir)+MAX_PATH]; // i_a
_stprintf(fullpath,_T("%sstatistics.ini"),configdir);
CIni ini( fullpath, _T("Statistics") );
delete[] fullpath;
ini.WriteInt(_T("DownCompletedFiles"), GetDownCompletedFiles());
ini.WriteInt(_T("DownSessionCompletedFiles"), GetDownSessionCompletedFiles());
} // SaveCompletedDownloadsStat()
void CPreferences::Add2SessionTransferData(uint8 uClientID, uint16 uClientPort, BOOL bFromPF,
BOOL bUpDown, uint32 bytes, bool sentToFriend)
{
// This function adds the transferred bytes to the appropriate variables,
// as well as to the totals for all clients. - Khaos
// PARAMETERS:
// uClientID - The identifier for which client software sent or received this data, eg SO_EMULE
// uClientPort - The remote port of the client that sent or received this data, eg 4662
// bFromPF - Applies only to uploads. True is from partfile, False is from non-partfile.
// bUpDown - True is Up, False is Down
// bytes - Number of bytes sent by the client. Subtract header before calling.
switch (bUpDown){
case true:
// Upline Data
switch (uClientID){
// Update session client breakdown stats for sent bytes...
case SO_EMULE:
case SO_OLDEMULE: sesUpData_EMULE+=bytes; break;
case SO_EDONKEYHYBRID: sesUpData_EDONKEYHYBRID+=bytes; break;
case SO_EDONKEY: sesUpData_EDONKEY+=bytes; break;
case SO_MLDONKEY: sesUpData_MLDONKEY+=bytes; break;
case SO_AMULE: sesUpData_AMULE+=bytes; break;
case SO_SHAREAZA: sesUpData_SHAREAZA+=bytes; break;
case SO_CDONKEY:
case SO_LPHANT:
case SO_XMULE: sesUpData_EMULECOMPAT+=bytes; break;
}
switch (uClientPort){
// Update session port breakdown stats for sent bytes...
case 4662: sesUpDataPort_4662+=bytes; break;
default: sesUpDataPort_OTHER+=bytes; break;
}
if (bFromPF) sesUpData_Partfile+=bytes;
else sesUpData_File+=bytes;
// Add to our total for sent bytes...
theApp.UpdateSentBytes(bytes, sentToFriend);
break;
case false:
// Downline Data
switch (uClientID){
// Update session client breakdown stats for received bytes...
case SO_EMULE:
case SO_OLDEMULE: sesDownData_EMULE+=bytes; break;
case SO_EDONKEYHYBRID: sesDownData_EDONKEYHYBRID+=bytes;break;
case SO_EDONKEY: sesDownData_EDONKEY+=bytes; break;
case SO_MLDONKEY: sesDownData_MLDONKEY+=bytes; break;
case SO_AMULE: sesDownData_AMULE+=bytes; break;
case SO_SHAREAZA: sesDownData_SHAREAZA+=bytes; break;
case SO_CDONKEY:
case SO_LPHANT:
case SO_XMULE: sesDownData_EMULECOMPAT+=bytes; break;
case SO_URL: sesDownData_URL+=bytes; break;
}
switch (uClientPort){
// Update session port breakdown stats for received bytes...
// For now we are only going to break it down by default and non-default.
// A statistical analysis of all data sent from every single port/domain is
// beyond the scope of this add-on.
case 4662: sesDownDataPort_4662+=bytes; break;
default: sesDownDataPort_OTHER+=bytes; break;
}
// Add to our total for received bytes...
theApp.UpdateReceivedBytes(bytes);
}
}
// Reset Statistics by Khaos
void CPreferences::ResetCumulativeStatistics(){
// Save a backup so that we can undo this action
SaveStats(1);
// SET ALL CUMULATIVE STAT VALUES TO 0 :'-(
totalDownloadedBytes=0;
totalUploadedBytes=0;
cumDownOverheadTotal=0;
cumDownOverheadFileReq=0;
cumDownOverheadSrcEx=0;
cumDownOverheadServer=0;
cumDownOverheadKad=0;
cumDownOverheadTotalPackets=0;
cumDownOverheadFileReqPackets=0;
cumDownOverheadSrcExPackets=0;
cumDownOverheadServerPackets=0;
cumDownOverheadKadPackets=0;
cumUpOverheadTotal=0;
cumUpOverheadFileReq=0;
cumUpOverheadSrcEx=0;
cumUpOverheadServer=0;
cumUpOverheadKad=0;
cumUpOverheadTotalPackets=0;
cumUpOverheadFileReqPackets=0;
cumUpOverheadSrcExPackets=0;
cumUpOverheadServerPackets=0;
cumUpOverheadKadPackets=0;
cumUpSuccessfulSessions=0;
cumUpFailedSessions=0;
cumUpAvgTime=0;
cumUpData_EDONKEY=0;
cumUpData_EDONKEYHYBRID=0;
cumUpData_EMULE=0;
cumUpData_MLDONKEY=0;
cumUpData_AMULE=0;
cumUpData_EMULECOMPAT=0;
cumUpData_SHAREAZA=0;
cumUpDataPort_4662=0;
cumUpDataPort_OTHER=0;
cumDownCompletedFiles=0;
cumDownSuccessfulSessions=0;
cumDownFailedSessions=0;
cumDownAvgTime=0;
cumLostFromCorruption=0;
cumSavedFromCompression=0;
cumPartsSavedByICH=0;
cumDownData_EDONKEY=0;
cumDownData_EDONKEYHYBRID=0;
cumDownData_EMULE=0;
cumDownData_MLDONKEY=0;
cumDownData_AMULE=0;
cumDownData_EMULECOMPAT=0;
cumDownData_SHAREAZA=0;
cumDownData_URL=0;
cumDownDataPort_4662=0;
cumDownDataPort_OTHER=0;
cumConnAvgDownRate=0;
cumConnMaxAvgDownRate=0;
cumConnMaxDownRate=0;
cumConnAvgUpRate=0;
cumConnRunTime=0;
cumConnNumReconnects=0;
cumConnAvgConnections=0;
cumConnMaxConnLimitReached=0;
cumConnPeakConnections=0;
cumConnDownloadTime=0;
cumConnUploadTime=0;
cumConnTransferTime=0;
cumConnServerDuration=0;
cumConnMaxAvgUpRate=0;
cumConnMaxUpRate=0;
cumSrvrsMostWorkingServers=0;
cumSrvrsMostUsersOnline=0;
cumSrvrsMostFilesAvail=0;
cumSharedMostFilesShared=0;
cumSharedLargestShareSize=0;
cumSharedLargestAvgFileSize=0;
// Set the time of last reset...
time_t timeNow;time(&timeNow);stat_datetimeLastReset = (__int64) timeNow;
// Save the reset stats
SaveStats();
theApp.emuledlg->statisticswnd->ShowStatistics(true);
// End Reset Statistics
}
// Load Statistics
// This used to be integrated in LoadPreferences, but it has been altered
// so that it can be used to load the backup created when the stats are reset.
// Last Modified: 2-22-03 by Khaos
bool CPreferences::LoadStats(int loadBackUp)
{
// loadBackUp is 0 by default
// loadBackUp = 0: Load the stats normally like we used to do in LoadPreferences
// loadBackUp = 1: Load the stats from statbkup.ini and create a backup of the current stats. Also, do not initialize session variables.
// loadBackUp = 2: Load the stats from preferences.ini.old because the version has changed.
CString sINI;
CFileFind findBackUp;
switch (loadBackUp) {
case 0:{
// for transition...
if(PathFileExists(configdir+_T("statistics.ini")))
sINI.Format(_T("%sstatistics.ini"), configdir);
else
sINI.Format(_T("%spreferences.ini"), configdir);
break;
}
case 1:
sINI.Format(_T("%sstatbkup.ini"), configdir);
if (!findBackUp.FindFile(sINI))
return false;
SaveStats(2); // Save our temp backup of current values to statbkuptmp.ini, we will be renaming it at the end of this function.
break;
case 2:
sINI.Format(_T("%spreferences.ini.old"),configdir);
break;
}
bool fileex = PathFileExists(sINI);
CIni ini(sINI, _T("Statistics"));
totalDownloadedBytes = ini.GetUInt64(_T("TotalDownloadedBytes"));
totalUploadedBytes = ini.GetUInt64(_T("TotalUploadedBytes"));
// Load stats for cumulative downline overhead
cumDownOverheadTotal = ini.GetUInt64(_T("DownOverheadTotal"));
cumDownOverheadFileReq = ini.GetUInt64(_T("DownOverheadFileReq"));
cumDownOverheadSrcEx = ini.GetUInt64(_T("DownOverheadSrcEx"));
cumDownOverheadServer = ini.GetUInt64(_T("DownOverheadServer"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -