Skip to content

Commit

Permalink
Make quick tests more accurate and code/UI cleanup PR #2
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrahmer authored Jan 8, 2020
2 parents 49e1257 + 30d2e09 commit 96b94d8
Show file tree
Hide file tree
Showing 21 changed files with 307 additions and 221 deletions.
64 changes: 64 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# EditorConfig: https://EditorConfig.org
# Visual Studio settings: https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-code-style-settings-reference?view=vs-2017

# top-most EditorConfig file
root = true

[*]
indent_style = tab
trim_trailing_whitespace = true

[*.{cs,vb}]
indent_size = 4
dotnet_style_qualification_for_field = false:suggestion
dotnet_style_qualification_for_property = false:suggestion
dotnet_style_qualification_for_method = false:suggestion
dotnet_style_qualification_for_event = false:suggestion
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
dotnet_style_predefined_type_for_member_access = true:suggestion
dotnet_style_require_accessibility_modifiers = always:suggestion
dotnet_style_readonly_field = true:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:none
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
dotnet_style_object_initializer = true:suggestion
dotnet_style_collection_initializer = true:suggestion
dotnet_style_explicit_tuple_names = true:suggestion
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_auto_properties = true:none
dotnet_style_prefer_conditional_expression_over_assignment = true:none
dotnet_style_prefer_conditional_expression_over_return = false
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_sort_system_directives_first = true:suggestion

[*.cs]
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
csharp_style_throw_expression = true:suggestion
csharp_style_conditional_delegate_call = false:suggestion
csharp_new_line_before_open_brace = all
csharp_new_line_before_else = true
csharp_new_line_before_catch = true
csharp_new_line_before_finally = true
csharp_new_line_before_members_in_object_initializers = true
csharp_new_line_before_members_in_anonymous_types = true
csharp_new_line_between_query_expression_clauses = true
csharp_style_inlined_variable_declaration = true:suggestion
csharp_preserve_single_line_statements = false
csharp_preserve_single_line_blocks = true
csharp_indent_case_contents = true
csharp_indent_switch_labels = true

csharp_space_after_cast = true
csharp_space_after_keywords_in_control_flow_statements = true
csharp_space_between_method_declaration_parameter_list_parentheses = false
csharp_space_between_method_call_parameter_list_parentheses = false
csharp_space_between_parentheses = false
csharp_space_before_colon_in_inheritance_clause = true
csharp_space_after_colon_in_inheritance_clause = true
csharp_space_around_binary_operators = before_and_after
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
csharp_space_between_method_call_name_and_opening_parenthesis = false
csharp_space_between_method_call_empty_parameter_list_parentheses = false
2 changes: 2 additions & 0 deletions MediaTester.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MediaTester", "MediaTester\
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{65E9EA9D-88EF-42A3-8771-64D5465655E0}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
.gitattributes = .gitattributes
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
Global
Expand Down
6 changes: 3 additions & 3 deletions MediaTester/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
230 changes: 136 additions & 94 deletions MediaTester/Main.Designer.cs

Large diffs are not rendered by default.

81 changes: 40 additions & 41 deletions MediaTester/Main.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
using MediaTesterLib;
using KrahmerSoft.MediaTesterLib;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;

namespace MediaTester
namespace KrahmerSoft.MediaTester
{
public partial class Main : Form
{
MediaTesterLib.Options _mediaTesterOptions = Options.Deserialize();
MediaTesterLib.MediaTester _mediaTester;
private Options _mediaTesterOptions = Options.Deserialize();
private KrahmerSoft.MediaTesterLib.MediaTester _mediaTester;
private Thread _mediaTesterThread;
const string PALCEHOLDER_VALUE = "---";
const string BYTES = " Bytes";
const string BYTES_PER_SECOND = BYTES + "/sec";
const string TEST_RESULTS_FILENAME_TEMPLATE = "MediaTesterResults_{0}_{1}.txt";
const string TEST_RESULTS_FILENAME_DATETIME_FORMAT = "yyyy-MM-dd_HH-mm-ss";

DateTime? _startDateTime;
private const string PALCEHOLDER_VALUE = "---";
private const string BYTES = " Bytes";
private const string BYTES_PER_SECOND = BYTES + "/sec";
private const string TEST_RESULTS_FILENAME_TEMPLATE = "MediaTesterResults_{0}_{1}.txt";
private const string TEST_RESULTS_FILENAME_DATETIME_FORMAT = "yyyy-MM-dd_HH-mm-ss";
private DateTime? _startDateTime;

public Main()
{
Expand Down Expand Up @@ -56,8 +55,7 @@ private void UpdateOptionsFromUi()
_mediaTesterOptions.RemoveTempDataFilesUponCompletion = RemoveTempDataFilesUponCompletionCheckBox.Checked;
_mediaTesterOptions.SaveTestResultsFileToMedia = SaveTestResultsFileToMediaCheckBox.Checked;

long lMaxBytesToTest;
if (long.TryParse(MaxBytesToTestComboBox.Text.Replace(",", string.Empty).Replace(".", string.Empty), out lMaxBytesToTest))
if (long.TryParse(MaxBytesToTestComboBox.Text.Replace(",", string.Empty).Replace(".", string.Empty), out long lMaxBytesToTest))
{
_mediaTesterOptions.MaxBytesToTest = lMaxBytesToTest;
}
Expand Down Expand Up @@ -97,8 +95,7 @@ private void UpdateTargetInformation()
{
if (Directory.Exists(targetDirectory))
{
long lTargetTotalBytes;
long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(targetDirectory, out lTargetTotalBytes, actual: true);
long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(targetDirectory, out long lTargetTotalBytes, actual: true);
targetTotalBytes = $"{lTargetTotalBytes.ToString("#,##0")}{BYTES}";
targetAvailableBytes = $"{lTargetAvailableBytes.ToString("#,##0")}{BYTES}";
}
Expand Down Expand Up @@ -131,7 +128,7 @@ private void EnableControls(bool enable = true)
if (TestOptionsGgroupBox.InvokeRequired)
{
EnableControlsDelegate d = new EnableControlsDelegate(EnableControls);
this.Invoke(d, new object[] { enable });
Invoke(d, new object[] { enable });
return;
}

Expand Down Expand Up @@ -269,8 +266,7 @@ private void LogTestCompletion(bool success)

if (success)
{
long lTargetTotalBytes;
long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out lTargetTotalBytes, actual: true);
long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out long lTargetTotalBytes, actual: true);
WriteLog(_mediaTester, $"Verified {_mediaTester.TotalBytesVerified.ToString("#,##0")}{BYTES} of {lTargetTotalBytes.ToString("#,##0")}{BYTES} total.");
WriteLog(_mediaTester, $"Media test PASSED!");
// WriteLog(_mediaTester, $"Information: Not all bytes are directly testable because directory and filenames take up additional space on the media.");
Expand All @@ -290,10 +286,9 @@ private void LogTestCompletion(bool success)
string dateTime = DateTime.Now.ToString(TEST_RESULTS_FILENAME_DATETIME_FORMAT);
string testResultsFilePath = Path.Combine(_mediaTester.Options.TestDirectory, string.Format(TEST_RESULTS_FILENAME_TEMPLATE, dateTime, success ? "PASS" : "FAIL"));
string testResultsLog = ActivityLogTextBox.Text;
long lTargetTotalBytes;
long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out lTargetTotalBytes, actual: true);
long lTargetAvailableBytes = MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out long lTargetTotalBytes, actual: true);

int spaceNeeded = testResultsLog.Length + (int)Math.Pow(2, 16);
int spaceNeeded = testResultsLog.Length + (int) Math.Pow(2, 16);
bool enoughSpace = true;
while (spaceNeeded > MediaTesterLib.MediaTester.GetAvailableBytes(_mediaTester.GetTestDirectory(), out lTargetTotalBytes, actual: true))
{
Expand Down Expand Up @@ -376,6 +371,10 @@ private void AfterVerifyBlock(MediaTesterLib.MediaTester mediaTester, long absol
else
{
WriteLog(mediaTester, $"{(isQuickTest ? "Quick test: " : string.Empty)}FAILED block {absoluteDataBlockIndex.ToString("#,##0")}! Byte index: {absoluteDataByteIndex.ToString("#,##0")}");
if (isQuickTest)
{
WriteLog(mediaTester, "Identifying first failing byte...");
}
}
}

Expand All @@ -399,7 +398,7 @@ private void WriteLog(MediaTesterLib.MediaTester mediaTester, string message)
if (ActivityLogTextBox.InvokeRequired)
{
WriteLogDelegate d = new WriteLogDelegate(WriteLog);
this.Invoke(d, new object[] { mediaTester, message });
Invoke(d, new object[] { mediaTester, message });
return;
}

Expand All @@ -424,7 +423,7 @@ private void UpdateStatus(long readBytesPerSecond = -1, long writeBytesPerSecond
if (ActivityLogTextBox.InvokeRequired)
{
UpdateStatusDelegate d = new UpdateStatusDelegate(UpdateStatus);
this.Invoke(d, new object[] { readBytesPerSecond, writeBytesPerSecond, writeBytesRemaining, readBytesRemaining, verifyBytesPerSecond });
Invoke(d, new object[] { readBytesPerSecond, writeBytesPerSecond, writeBytesRemaining, readBytesRemaining, verifyBytesPerSecond });
return;
}

Expand All @@ -448,23 +447,23 @@ private void UpdateStatus(long readBytesPerSecond = -1, long writeBytesPerSecond

if (_startDateTime != null)
{
elapsedTime = new TimeSpan(0, 0, (int)((DateTime.Now - _startDateTime.Value).TotalSeconds));
writeTimeRemaining = new TimeSpan(0, 0, bytesPerSecond < .01M ? 0 : (int)((decimal)writeBytesRemaining / bytesPerSecond));
elapsedTime = new TimeSpan(0, 0, (int) (DateTime.Now - _startDateTime.Value).TotalSeconds);
writeTimeRemaining = new TimeSpan(0, 0, bytesPerSecond < .01M ? 0 : (int) ((decimal) writeBytesRemaining / bytesPerSecond));
if (verifyBytesPerSecond > 1000)
{
readTimeRemaining = new TimeSpan(0, 0, bytesPerSecond < .01M ? 0 : (int)((decimal)readBytesRemaining / verifyBytesPerSecond)); // Assume read speed is the same as write speed since we do not know for sure.
readTimeRemaining = new TimeSpan(0, 0, bytesPerSecond < .01M ? 0 : (int) ((decimal) readBytesRemaining / verifyBytesPerSecond)); // Assume read speed is the same as write speed since we do not know for sure.
}
else
{
readTimeRemaining = new TimeSpan(0, 0, bytesPerSecond < .01M ? 0 : (int)((writeBytesPerSecond > 0 ? EstimatedReadVsWriteSpeedRatio : 1M)
* (decimal)readBytesRemaining / bytesPerSecond)); // Assume read speed is the same as write speed since we do not know for sure.
readTimeRemaining = new TimeSpan(0, 0, bytesPerSecond < .01M ? 0 : (int) ((writeBytesPerSecond > 0 ? EstimatedReadVsWriteSpeedRatio : 1M)
* (decimal) readBytesRemaining / bytesPerSecond)); // Assume read speed is the same as write speed since we do not know for sure.
}
totalTimeRemaining = writeTimeRemaining + readTimeRemaining;
}

// Display to the user...
ElapsedTimeLabel.Text = (elapsedTime?.ToString() ?? PALCEHOLDER_VALUE);
TotalTimeRemainingLabel.Text = (totalTimeRemaining?.ToString() ?? PALCEHOLDER_VALUE);
ElapsedTimeLabel.Text = elapsedTime?.ToString() ?? PALCEHOLDER_VALUE;
TotalTimeRemainingLabel.Text = totalTimeRemaining?.ToString() ?? PALCEHOLDER_VALUE;

if (_mediaTester != null)
{
Expand All @@ -473,13 +472,13 @@ private void UpdateStatus(long readBytesPerSecond = -1, long writeBytesPerSecond
FailedBytesLabel.Text = (_mediaTester?.TotalBytesFailed.ToString("#,##0") ?? PALCEHOLDER_VALUE) + BYTES;
}

ProgressBar.Value = _mediaTester == null ? 0 : (int)(10M * _mediaTester.ProgressPercent);
ProgressBar.Value = _mediaTester == null ? 0 : (int) (10M * _mediaTester.ProgressPercent);
}

long _totalReadSpeedSamples = 0;
long _totalWriteSpeedSamples = 0;
decimal _averageReadBytesPerSecond = 0;
decimal _averageWriteBytesPerSecond = 0;
private long _totalReadSpeedSamples = 0;
private long _totalWriteSpeedSamples = 0;
private decimal _averageReadBytesPerSecond = 0;
private decimal _averageWriteBytesPerSecond = 0;

private void UpdateSpeedAverage(long readBytesPerSecond = -1, long writeBytesPerSecond = -1)
{
Expand Down Expand Up @@ -515,17 +514,17 @@ private void AbortButton_Click(object sender, EventArgs e)
_mediaTesterThread?.Abort();
_startDateTime = null;
}
catch (Exception ex)
catch //(Exception ex)
{
}
}

private void AboutLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
string aboutMessage = $"MediaTester will test any media, such as SD cards, \n"
+ $"and verify that the media stores the expected number \n"
+ $"of bytes. If you buy any storage media, you should \n"
+ $"use MediaTested to verify it or risk losing your data.\n"
string aboutMessage = $"MediaTester can test any media (SD, microSD, thumb, etc) \n"
+ $"and verify it stores the expected number of bytes. \n"
+ $"If you buy any storage media, you should use MediaTester \n"
+ $"to verify it or risk losing your data.\n"
+ $"\n"
+ $"Written by Doug Krahmer\n"
+ $"Released as plublic domain open source.\n"
Expand All @@ -538,7 +537,7 @@ private void AboutLinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEvent

private void Main_Load(object sender, EventArgs e)
{
this.Text += $" v{Assembly.GetEntryAssembly().GetName().Version}";
Text += $" v{Assembly.GetEntryAssembly().GetName().Version}";
}
}
}
3 changes: 3 additions & 0 deletions MediaTester/Main.resx
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,7 @@
<metadata name="StatusStrip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>147, 17</value>
</metadata>
</root>
2 changes: 1 addition & 1 deletion MediaTester/MediaTester.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<ProjectGuid>{CBC3129F-F13E-4BAD-BEFE-00EBF57D2C09}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MediaTester</RootNamespace>
<RootNamespace>KrahmerSoft.MediaTester</RootNamespace>
<AssemblyName>MediaTester</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
Expand Down
6 changes: 3 additions & 3 deletions MediaTester/Program.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
using System;
using System.Windows.Forms;

namespace MediaTester
namespace KrahmerSoft.MediaTester
{
static class Program
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
private static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Expand Down
10 changes: 3 additions & 7 deletions MediaTester/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("KrahmerSoft")]
[assembly: AssemblyProduct("MediaTester")]
[assembly: AssemblyCopyright("Public Domain, KrahmerSoft 2018")]
[assembly: AssemblyCopyright("Public Domain, Copyright KrahmerSoft 2020")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

Expand All @@ -27,9 +27,5 @@
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.3.2.0")]
[assembly: AssemblyFileVersion("0.3.2.0")]
[assembly: AssemblyVersion("0.4.1.0")]
[assembly: AssemblyFileVersion("0.4.1.0")]
4 changes: 2 additions & 2 deletions MediaTester/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions MediaTester/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions MediaTesterCli/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
4 changes: 2 additions & 2 deletions MediaTesterCli/MediaTesterCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<ProjectGuid>{82DBB478-8EF7-45B1-8200-F28BEF178019}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MediaTesterCli</RootNamespace>
<AssemblyName>MediaTester</AssemblyName>
<RootNamespace>KrahmerSoft.MediaTesterCli</RootNamespace>
<AssemblyName>MediaTesterCli</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<NuGetPackageImportStamp>
Expand Down
Loading

0 comments on commit 96b94d8

Please sign in to comment.