Skip to content

Commit

Permalink
fix #16
Browse files Browse the repository at this point in the history
handle negative values for speed
  • Loading branch information
SIRprise committed Apr 5, 2023
1 parent a8a9696 commit 3a4b2d2
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
31 changes: 28 additions & 3 deletions SSD-LED/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ public void SSDActivityWMI()

public bool SSDActivityPerfCount()
{
float bytesPSRead;
float bytesPSWrite;
float bytesPSRead=0f;
float bytesPSWrite=0f;

if (!checkBox1.Checked || (diskSelectionPFCStr == null))
{
Expand All @@ -277,7 +277,7 @@ public bool SSDActivityPerfCount()
}
catch (Exception ex)
{
Log.Error("PhysicalDisk->_Total could not captured - Exception here: {exc}", ex);
Log.Error("PhysicalDisk->_Total could not be captured - Exception here: {exc}", ex);
return false;
}
}
Expand All @@ -295,6 +295,19 @@ public bool SSDActivityPerfCount()
}
}

//this cases should never happen (but happened probably caused by uninitialized floats bytesPSRead/Write - fixed now)
if (bytesPSRead<0)
{
Log.Error("PhysicalDisk _diskReadCounter was negative:{numb}", bytesPSRead);
return false;
}

if (bytesPSWrite < 0)
{
Log.Error("PhysicalDisk _diskWriteCounter was negative:{numb}", bytesPSWrite);
return false;
}

//notifyIcon.Text = Math.Round(bytesPSRead / 1024, 2).ToString() + " KB/s read / " + Math.Round(bytesPSWrite / 1024, 2).ToString() + " KB/s write";

Color newColor = CalculateColor(bytesPSRead, bytesPSWrite);
Expand Down Expand Up @@ -343,6 +356,18 @@ private Color CalculateColor(float bytesPSRead, float bytesPSWrite)
scaledKBSRead = scaledKBSRead > 255 ? 255 : scaledKBSRead;
scaledKBSWrite = scaledKBSWrite > 255 ? 255 : scaledKBSWrite;

if(scaledKBSRead < 0)
{
scaledKBSRead = 0;
Log.Error("scaledKBSRead < 0 --> {numb}",scaledKBSRead);
}

if(scaledKBSWrite < 0)
{
scaledKBSWrite = 0;
Log.Error("scaledKBSWrite < 0 --> {numb}", scaledKBSWrite);
}


int R = (int)(((readColor.R / 255f) * scaledKBSRead + (writeColor.R / 255f) * scaledKBSWrite));// / 2);
int G = (int)(((readColor.G / 255f) * scaledKBSRead + (writeColor.G / 255f) * scaledKBSWrite));// / 2);
Expand Down
6 changes: 3 additions & 3 deletions SSD-LED/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SSD-LED")]
[assembly: AssemblyCopyright("Copyright © 2022")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.7.1")]
[assembly: AssemblyFileVersion("1.0.7.1")]
[assembly: AssemblyVersion("1.0.7.5")]
[assembly: AssemblyFileVersion("1.0.7.5")]
4 changes: 2 additions & 2 deletions SSD-LED/SSD-LED.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<AutorunEnabled>true</AutorunEnabled>
<ApplicationRevision>4</ApplicationRevision>
<ApplicationVersion>1.0.7.4</ApplicationVersion>
<ApplicationRevision>5</ApplicationRevision>
<ApplicationVersion>1.0.7.5</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<PublishWizardCompleted>true</PublishWizardCompleted>
<BootstrapperEnabled>true</BootstrapperEnabled>
Expand Down
Binary file modified SSD-LED/bin/Release/SSD-LED.exe
Binary file not shown.

0 comments on commit 3a4b2d2

Please sign in to comment.