Skip to content
This repository has been archived by the owner on Jun 23, 2021. It is now read-only.

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
Allen Byron Penner committed Sep 5, 2015
1 parent b146c02 commit d3c13ba
Show file tree
Hide file tree
Showing 11 changed files with 1,145 additions and 1 deletion.
84 changes: 84 additions & 0 deletions FileHasher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{F1E12A66-BE62-4D56-B171-0B987488AB83}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>FileHasher</RootNamespace>
<AssemblyName>FileHasher</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
308 changes: 308 additions & 0 deletions Form1.Designer.cs

Large diffs are not rendered by default.

166 changes: 166 additions & 0 deletions Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Security.Cryptography;
using System.Windows.Forms;

namespace FileHasher
{
public partial class Form1 : Form
{
public int HashType = 0;
public Form1()
{
InitializeComponent();
}

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
if (string.IsNullOrEmpty((string)e.Argument))
{
e.Result = Properties.Resources.InvalidFilenameErrorText;
return;
}

byte[] buffer = new byte[] { };
using (var stream = File.OpenRead((string)e.Argument))
{
switch (HashType)
{
case 0:
buffer = MD5.Create().ComputeHash(stream);
break;
case 1:
buffer = SHA1.Create().ComputeHash(stream);
break;
case 2:
buffer = SHA256.Create().ComputeHash(stream);
break;
}
}
e.Result = GetHashStringFromArray(buffer);
}

private string GetHashStringFromArray(byte[] data)
{
return BitConverter.ToString(data).Replace("-", "");
}

private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if ((string)e.Result == Properties.Resources.InvalidFilenameErrorText)
{
progressBar1.Maximum = 100;
progressBar1.Value = 0;
progressBar1.Style = ProgressBarStyle.Continuous;
this.filenameTextBox.Text = (string)e.Result;
MessageBox.Show((string)e.Result, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
groupBox3.Enabled = false;
}
else
{
progressBar1.Maximum = 100;
progressBar1.Value = 100;
progressBar1.Style = ProgressBarStyle.Continuous;
resultTextBox.Text = (string)e.Result;
groupBox3.Enabled = true;
}

openFileButton.Enabled = true;
computeButton.Enabled = true;
}

private void openFileButton_Click(object sender, EventArgs e)
{
var ofdresult = openFileDialog1.ShowDialog();
if (ofdresult == DialogResult.OK && !string.IsNullOrEmpty(openFileDialog1.FileName))
{
filenameTextBox.Text = openFileDialog1.FileName;
}
}

private void computeButton_Click(object sender, EventArgs e)
{
openFileButton.Enabled = false;
computeButton.Enabled = false;
progressBar1.Style = ProgressBarStyle.Marquee;
backgroundWorker1.RunWorkerAsync(filenameTextBox.Text);
}

private void filenameTextBox_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(filenameTextBox.Text) || filenameTextBox.Text == "" || filenameTextBox.Text == Properties.Resources.FilenameTextBoxDefaultText)
{
groupBox2.Enabled = false;
groupBox3.Enabled = false;
}
else
{
groupBox2.Enabled = true;
groupBox3.Enabled = false;
}
}

private void Form1_Load(object sender, EventArgs e)
{
groupBox1.Text = Properties.Resources.Group1Header;
group1Label.Text = Properties.Resources.Group1Label;
openFileButton.Text = Properties.Resources.BrowseButtonDefaultText;
filenameTextBox.Text = Properties.Resources.FilenameTextBoxDefaultText;

groupBox2.Text = Properties.Resources.Group2Header;
group2Label.Text = Properties.Resources.Group2Label;
computeButton.Text = Properties.Resources.ComputeButtonDefaultText;
progressBar1.Style = ProgressBarStyle.Blocks;

groupBox3.Text = Properties.Resources.Group3Header;
group3Label.Text = Properties.Resources.Group3Label;
copyButton.Text = Properties.Resources.CopyButtonDefaultText;
compareButton.Text = Properties.Resources.CompareButtonDefaultText;
saveButton.Text = Properties.Resources.SaveButtonDefaultText;

saveFileDialog1.Filter = "Text|*.txt";
saveFileDialog1.Title = Properties.Resources.SaveDialogTitle;

openFileDialog1.FileName = "";
}

private void copyButton_Click(object sender, EventArgs e)
{
Clipboard.SetText(this.resultTextBox.Text);
}

private void saveButton_Click(object sender, EventArgs e)
{
RETRY:
var dialogresult = saveFileDialog1.ShowDialog(this);
if (!string.IsNullOrEmpty(saveFileDialog1.FileName) && dialogresult != DialogResult.Cancel)
{
try
{
File.WriteAllText(saveFileDialog1.FileName, this.resultTextBox.Text);
}
catch (Exception ex)
{
if (MessageBox.Show(this, Properties.Resources.FileSaveErrorText + " \r\n" + ex.Message, Properties.Resources.SaveDialogTitle, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button2) == DialogResult.Retry)
goto RETRY;
}
}

saveFileDialog1.FileName = "";
}

private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked)
HashType = 0;
if (radioButton2.Checked)
HashType = 1;
if (radioButton3.Checked)
HashType = 2;

resultTextBox.Text = "";
groupBox3.Enabled = false;
}
}
}
129 changes: 129 additions & 0 deletions Form1.resx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="openFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>181, 17</value>
</metadata>
<metadata name="saveFileDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>321, 17</value>
</metadata>
</root>
Loading

0 comments on commit d3c13ba

Please sign in to comment.