private void updateCounters(TorrentInfo torrentInfo)
{
try
{
// Random random = new Random();
// modify Upload Rate
uploadCount.Text = FormatFileSize((ulong)torrentInfo.uploaded);
Int64 uploadedR = torrentInfo.uploadRate + RandomSP(txtRandUpMin.Text, txtRandUpMax.Text, chkRandUP.Checked);
// Int64 uploadedR = torrentInfo.uploadRate + (Int64)random.Next(10 * 1024) - 5 * 1024;
if (uploadedR < 0) { uploadedR = 0; }
torrentInfo.uploaded += uploadedR;
// modify Download Rate
downloadCount.Text = FormatFileSize((ulong)torrentInfo.downloaded);
if (!seedMode && torrentInfo.downloadRate > 0) // dont update download stats
{
Int64 downloadedR = torrentInfo.downloadRate + RandomSP(txtRandDownMin.Text, txtRandDownMax.Text, chkRandDown.Checked);
// Int64 downloadedR = torrentInfo.downloadRate + (Int64)random.Next(10 * 1024) - 5 * 1024;
if (downloadedR < 0) { downloadedR = 0; }
torrentInfo.downloaded += downloadedR;
torrentInfo.left = torrentInfo.totalsize - torrentInfo.downloaded;
}
if (torrentInfo.left <= 0) // either seedMode or start seed mode
{
torrentInfo.downloaded = torrentInfo.totalsize;
torrentInfo.left = 0;
torrentInfo.downloadRate = 0;
if (!seedMode)
{
currentTorrent = torrentInfo;
seedMode = true;
temporaryIntervalCounter = 0;
Thread myThread = new Thread(completedProcess);
myThread.Name = "completedProcess() Thread";
myThread.Start();
}
}
torrentInfo.interval = int.Parse(interval.Text);
currentTorrent = torrentInfo;
double finishedPercent;
if (torrentInfo.totalsize == 0)
{
fileSize.Text = "100";
}
else
{
// finishedPercent = (((((float)currentTorrentFile.totalLength - (float)torrentInfo.totalsize) + (float)torrentInfo.downloaded) / (float)currentTorrentFile.totalLength) * 100);
finishedPercent = (((currentTorrentFile.totalLength - (float)torrentInfo.left)) / ((float)currentTorrentFile.totalLength)) * 100.0;
fileSize.Text = (finishedPercent >= 100) ? "100" : SetPrecision(finishedPercent.ToString(), 2);
}
downloadCount.Text = FormatFileSize((ulong)torrentInfo.downloaded);
// modify Ratio Lable
if (torrentInfo.downloaded / 1024 < 100)
{
lblTorrentRatio.Text = "NaN";
}
else
{
float data = torrentInfo.uploaded / (float)torrentInfo.downloaded;
lblTorrentRatio.Text = SetPrecision(data.ToString(), 2);
}
}
catch (Exception e)
{
AddLogLine(e.Message);
SetCountersCallback d = updateCounters;
Invoke(d, new object[] { torrentInfo });
}
}