2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2015-08-13 13:07:38 +12:00
|
|
|
|
Copyright (c) 2007-2015 ShareX Team
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
using ShareX.HelpersLib.Properties;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
using System;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2014-12-11 09:25:20 +13:00
|
|
|
|
namespace ShareX.HelpersLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2015-09-01 06:36:50 +12:00
|
|
|
|
public partial class HashCheckForm : BaseForm
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
private HashCheck hashCheck;
|
2015-12-29 14:36:10 +13:00
|
|
|
|
private Translator translator;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
public HashCheckForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
cbHashType.Items.AddRange(Helpers.GetEnumDescriptions<HashType>());
|
|
|
|
|
cbHashType.SelectedIndex = (int)HashType.SHA1;
|
|
|
|
|
|
|
|
|
|
hashCheck = new HashCheck();
|
|
|
|
|
hashCheck.FileCheckProgressChanged += fileCheck_FileCheckProgressChanged;
|
|
|
|
|
hashCheck.FileCheckCompleted += fileCheck_FileCheckCompleted;
|
2015-12-29 14:36:10 +13:00
|
|
|
|
|
|
|
|
|
translator = new Translator();
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
if (!Translator.Test()) MessageBox.Show("Text conversion failed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
#endif
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2015-12-29 14:36:10 +13:00
|
|
|
|
#region File hash check
|
|
|
|
|
|
2013-11-03 23:53:49 +13:00
|
|
|
|
private void btnFilePathBrowse_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2014-10-18 00:08:33 +13:00
|
|
|
|
Helpers.BrowseFile("ShareX - " + Resources.HashCheckForm_btnFilePathBrowse_Click_Choose_file_path, txtFilePath);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnStartHashCheck_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (hashCheck.IsWorking)
|
|
|
|
|
{
|
|
|
|
|
hashCheck.Stop();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
HashType hashType = (HashType)cbHashType.SelectedIndex;
|
|
|
|
|
|
|
|
|
|
if (hashCheck.Start(txtFilePath.Text, hashType))
|
|
|
|
|
{
|
2015-02-17 23:46:00 +13:00
|
|
|
|
btnStartHashCheck.Text = Resources.Stop;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
txtResult.Text = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fileCheck_FileCheckProgressChanged(float progress)
|
|
|
|
|
{
|
|
|
|
|
pbProgress.Value = (int)progress;
|
2015-12-29 14:36:10 +13:00
|
|
|
|
lblProgressPercentage.Text = (int)progress + "%";
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void fileCheck_FileCheckCompleted(string result, bool cancelled)
|
|
|
|
|
{
|
2015-02-17 23:46:00 +13:00
|
|
|
|
btnStartHashCheck.Text = Resources.Start;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
txtResult.Text = result.ToUpperInvariant();
|
2014-04-30 14:46:00 +12:00
|
|
|
|
if (!string.IsNullOrEmpty(txtTarget.Text))
|
|
|
|
|
{
|
|
|
|
|
txtTarget.Text = txtTarget.Text.ToUpperInvariant();
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtResult_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrEmpty(txtResult.Text) && !string.IsNullOrEmpty(txtTarget.Text))
|
|
|
|
|
{
|
|
|
|
|
if (txtResult.Text.Equals(txtTarget.Text, StringComparison.InvariantCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
txtTarget.BackColor = Color.FromArgb(200, 255, 200);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
txtTarget.BackColor = Color.FromArgb(255, 200, 200);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
txtTarget.BackColor = Color.White;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtFilePath_DragEnter(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.Copy;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
e.Effect = DragDropEffects.None;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void txtFilePath_DragDrop(object sender, DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
|
|
|
|
|
{
|
|
|
|
|
string[] files = e.Data.GetData(DataFormats.FileDrop, false) as string[];
|
|
|
|
|
|
|
|
|
|
if (files != null && files.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
txtFilePath.Text = files[0];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-29 14:36:10 +13:00
|
|
|
|
|
|
|
|
|
#endregion File hash check
|
|
|
|
|
|
|
|
|
|
#region Text conversions
|
|
|
|
|
|
|
|
|
|
private void FillConversionInfo()
|
|
|
|
|
{
|
|
|
|
|
if (translator != null)
|
|
|
|
|
{
|
|
|
|
|
txtHashCheckText.Text = translator.Text;
|
|
|
|
|
txtHashCheckBinary.Text = translator.BinaryText;
|
|
|
|
|
txtHashCheckHex.Text = translator.HexadecimalText;
|
|
|
|
|
txtHashCheckASCII.Text = translator.ASCIIText;
|
|
|
|
|
txtHashCheckBase64.Text = translator.Base64;
|
|
|
|
|
txtHashCheckHash.Text = translator.HashToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnHashCheckCopyAll_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (translator != null && !string.IsNullOrEmpty(translator.Text))
|
|
|
|
|
{
|
|
|
|
|
string text = translator.ToString();
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(text))
|
|
|
|
|
{
|
|
|
|
|
ClipboardHelpers.CopyText(text);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnHashCheckEncodeText_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (translator.EncodeText(txtHashCheckText.Text))
|
|
|
|
|
{
|
|
|
|
|
FillConversionInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnHashCheckDecodeBinary_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (translator.DecodeBinary(txtHashCheckBinary.Text))
|
|
|
|
|
{
|
|
|
|
|
FillConversionInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnHashCheckDecodeHex_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (translator.DecodeHex(txtHashCheckHex.Text))
|
|
|
|
|
{
|
|
|
|
|
FillConversionInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnHashCheckDecodeASCII_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (translator.DecodeASCII(txtHashCheckASCII.Text))
|
|
|
|
|
{
|
|
|
|
|
FillConversionInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnHashCheckDecodeBase64_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (translator.DecodeBase64(txtHashCheckBase64.Text))
|
|
|
|
|
{
|
|
|
|
|
FillConversionInfo();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion Text conversions
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
}
|