Hash checker UI improvements

This commit is contained in:
Jaex 2023-12-23 10:36:49 +03:00
parent d6a5568068
commit 4443b103de
3 changed files with 217 additions and 1013 deletions

View file

@ -39,36 +39,11 @@ private void InitializeComponent()
this.txtResult = new System.Windows.Forms.TextBox();
this.txtTarget = new System.Windows.Forms.TextBox();
this.lblFilePath = new System.Windows.Forms.Label();
this.tcMain = new System.Windows.Forms.TabControl();
this.tpFileHashCheck = new System.Windows.Forms.TabPage();
this.lblFilePath2 = new System.Windows.Forms.Label();
this.txtFilePath2 = new System.Windows.Forms.TextBox();
this.btnFilePathBrowse2 = new System.Windows.Forms.Button();
this.cbCompareTwoFiles = new System.Windows.Forms.CheckBox();
this.pbProgress = new System.Windows.Forms.ProgressBar();
this.lblProgressPercentage = new System.Windows.Forms.Label();
this.tpTextConversions = new System.Windows.Forms.TabPage();
this.btnHashCheckCopyAll = new System.Windows.Forms.Button();
this.txtHashCheckHash = new System.Windows.Forms.TextBox();
this.lblHashCheckHash = new System.Windows.Forms.Label();
this.btnHashCheckDecodeBase64 = new System.Windows.Forms.Button();
this.txtHashCheckBase64 = new System.Windows.Forms.TextBox();
this.lblHashCheckBase64 = new System.Windows.Forms.Label();
this.btnHashCheckDecodeASCII = new System.Windows.Forms.Button();
this.txtHashCheckASCII = new System.Windows.Forms.TextBox();
this.lblHashCheckASCII = new System.Windows.Forms.Label();
this.btnHashCheckDecodeHex = new System.Windows.Forms.Button();
this.txtHashCheckHex = new System.Windows.Forms.TextBox();
this.lblHashCheckHex = new System.Windows.Forms.Label();
this.btnHashCheckDecodeBinary = new System.Windows.Forms.Button();
this.txtHashCheckBinary = new System.Windows.Forms.TextBox();
this.lblHashCheckBinary = new System.Windows.Forms.Label();
this.btnHashCheckEncodeText = new System.Windows.Forms.Button();
this.txtHashCheckText = new System.Windows.Forms.TextBox();
this.lblHashCheckText = new System.Windows.Forms.Label();
this.tcMain.SuspendLayout();
this.tpFileHashCheck.SuspendLayout();
this.tpTextConversions.SuspendLayout();
this.pbProgress = new ShareX.HelpersLib.BlackStyleProgressBar();
this.SuspendLayout();
//
// txtFilePath
@ -133,39 +108,6 @@ private void InitializeComponent()
resources.ApplyResources(this.lblFilePath, "lblFilePath");
this.lblFilePath.Name = "lblFilePath";
//
// tcMain
//
this.tcMain.Controls.Add(this.tpFileHashCheck);
this.tcMain.Controls.Add(this.tpTextConversions);
resources.ApplyResources(this.tcMain, "tcMain");
this.tcMain.Name = "tcMain";
this.tcMain.SelectedIndex = 0;
//
// tpFileHashCheck
//
this.tpFileHashCheck.AllowDrop = true;
this.tpFileHashCheck.BackColor = System.Drawing.SystemColors.Window;
this.tpFileHashCheck.Controls.Add(this.lblFilePath2);
this.tpFileHashCheck.Controls.Add(this.txtFilePath2);
this.tpFileHashCheck.Controls.Add(this.btnFilePathBrowse2);
this.tpFileHashCheck.Controls.Add(this.cbCompareTwoFiles);
this.tpFileHashCheck.Controls.Add(this.lblFilePath);
this.tpFileHashCheck.Controls.Add(this.txtFilePath);
this.tpFileHashCheck.Controls.Add(this.txtTarget);
this.tpFileHashCheck.Controls.Add(this.btnFilePathBrowse);
this.tpFileHashCheck.Controls.Add(this.txtResult);
this.tpFileHashCheck.Controls.Add(this.lblHashType);
this.tpFileHashCheck.Controls.Add(this.pbProgress);
this.tpFileHashCheck.Controls.Add(this.cbHashType);
this.tpFileHashCheck.Controls.Add(this.lblResult);
this.tpFileHashCheck.Controls.Add(this.btnStartHashCheck);
this.tpFileHashCheck.Controls.Add(this.lblTarget);
this.tpFileHashCheck.Controls.Add(this.lblProgressPercentage);
resources.ApplyResources(this.tpFileHashCheck, "tpFileHashCheck");
this.tpFileHashCheck.Name = "tpFileHashCheck";
this.tpFileHashCheck.DragDrop += new System.Windows.Forms.DragEventHandler(this.tpFileHashCheck_DragDrop);
this.tpFileHashCheck.DragEnter += new System.Windows.Forms.DragEventHandler(this.tpFileHashCheck_DragEnter);
//
// lblFilePath2
//
resources.ApplyResources(this.lblFilePath2, "lblFilePath2");
@ -198,153 +140,36 @@ private void InitializeComponent()
//
resources.ApplyResources(this.pbProgress, "pbProgress");
this.pbProgress.Name = "pbProgress";
//
// lblProgressPercentage
//
resources.ApplyResources(this.lblProgressPercentage, "lblProgressPercentage");
this.lblProgressPercentage.Name = "lblProgressPercentage";
//
// tpTextConversions
//
this.tpTextConversions.BackColor = System.Drawing.SystemColors.Window;
this.tpTextConversions.Controls.Add(this.btnHashCheckCopyAll);
this.tpTextConversions.Controls.Add(this.txtHashCheckHash);
this.tpTextConversions.Controls.Add(this.lblHashCheckHash);
this.tpTextConversions.Controls.Add(this.btnHashCheckDecodeBase64);
this.tpTextConversions.Controls.Add(this.txtHashCheckBase64);
this.tpTextConversions.Controls.Add(this.lblHashCheckBase64);
this.tpTextConversions.Controls.Add(this.btnHashCheckDecodeASCII);
this.tpTextConversions.Controls.Add(this.txtHashCheckASCII);
this.tpTextConversions.Controls.Add(this.lblHashCheckASCII);
this.tpTextConversions.Controls.Add(this.btnHashCheckDecodeHex);
this.tpTextConversions.Controls.Add(this.txtHashCheckHex);
this.tpTextConversions.Controls.Add(this.lblHashCheckHex);
this.tpTextConversions.Controls.Add(this.btnHashCheckDecodeBinary);
this.tpTextConversions.Controls.Add(this.txtHashCheckBinary);
this.tpTextConversions.Controls.Add(this.lblHashCheckBinary);
this.tpTextConversions.Controls.Add(this.btnHashCheckEncodeText);
this.tpTextConversions.Controls.Add(this.txtHashCheckText);
this.tpTextConversions.Controls.Add(this.lblHashCheckText);
resources.ApplyResources(this.tpTextConversions, "tpTextConversions");
this.tpTextConversions.Name = "tpTextConversions";
//
// btnHashCheckCopyAll
//
resources.ApplyResources(this.btnHashCheckCopyAll, "btnHashCheckCopyAll");
this.btnHashCheckCopyAll.Name = "btnHashCheckCopyAll";
this.btnHashCheckCopyAll.UseVisualStyleBackColor = true;
this.btnHashCheckCopyAll.Click += new System.EventHandler(this.btnHashCheckCopyAll_Click);
//
// txtHashCheckHash
//
resources.ApplyResources(this.txtHashCheckHash, "txtHashCheckHash");
this.txtHashCheckHash.Name = "txtHashCheckHash";
//
// lblHashCheckHash
//
resources.ApplyResources(this.lblHashCheckHash, "lblHashCheckHash");
this.lblHashCheckHash.Name = "lblHashCheckHash";
//
// btnHashCheckDecodeBase64
//
resources.ApplyResources(this.btnHashCheckDecodeBase64, "btnHashCheckDecodeBase64");
this.btnHashCheckDecodeBase64.Name = "btnHashCheckDecodeBase64";
this.btnHashCheckDecodeBase64.UseVisualStyleBackColor = true;
this.btnHashCheckDecodeBase64.Click += new System.EventHandler(this.btnHashCheckDecodeBase64_Click);
//
// txtHashCheckBase64
//
resources.ApplyResources(this.txtHashCheckBase64, "txtHashCheckBase64");
this.txtHashCheckBase64.Name = "txtHashCheckBase64";
//
// lblHashCheckBase64
//
resources.ApplyResources(this.lblHashCheckBase64, "lblHashCheckBase64");
this.lblHashCheckBase64.Name = "lblHashCheckBase64";
//
// btnHashCheckDecodeASCII
//
resources.ApplyResources(this.btnHashCheckDecodeASCII, "btnHashCheckDecodeASCII");
this.btnHashCheckDecodeASCII.Name = "btnHashCheckDecodeASCII";
this.btnHashCheckDecodeASCII.UseVisualStyleBackColor = true;
this.btnHashCheckDecodeASCII.Click += new System.EventHandler(this.btnHashCheckDecodeASCII_Click);
//
// txtHashCheckASCII
//
resources.ApplyResources(this.txtHashCheckASCII, "txtHashCheckASCII");
this.txtHashCheckASCII.Name = "txtHashCheckASCII";
//
// lblHashCheckASCII
//
resources.ApplyResources(this.lblHashCheckASCII, "lblHashCheckASCII");
this.lblHashCheckASCII.Name = "lblHashCheckASCII";
//
// btnHashCheckDecodeHex
//
resources.ApplyResources(this.btnHashCheckDecodeHex, "btnHashCheckDecodeHex");
this.btnHashCheckDecodeHex.Name = "btnHashCheckDecodeHex";
this.btnHashCheckDecodeHex.UseVisualStyleBackColor = true;
this.btnHashCheckDecodeHex.Click += new System.EventHandler(this.btnHashCheckDecodeHex_Click);
//
// txtHashCheckHex
//
resources.ApplyResources(this.txtHashCheckHex, "txtHashCheckHex");
this.txtHashCheckHex.Name = "txtHashCheckHex";
//
// lblHashCheckHex
//
resources.ApplyResources(this.lblHashCheckHex, "lblHashCheckHex");
this.lblHashCheckHex.Name = "lblHashCheckHex";
//
// btnHashCheckDecodeBinary
//
resources.ApplyResources(this.btnHashCheckDecodeBinary, "btnHashCheckDecodeBinary");
this.btnHashCheckDecodeBinary.Name = "btnHashCheckDecodeBinary";
this.btnHashCheckDecodeBinary.UseVisualStyleBackColor = true;
this.btnHashCheckDecodeBinary.Click += new System.EventHandler(this.btnHashCheckDecodeBinary_Click);
//
// txtHashCheckBinary
//
resources.ApplyResources(this.txtHashCheckBinary, "txtHashCheckBinary");
this.txtHashCheckBinary.Name = "txtHashCheckBinary";
//
// lblHashCheckBinary
//
resources.ApplyResources(this.lblHashCheckBinary, "lblHashCheckBinary");
this.lblHashCheckBinary.Name = "lblHashCheckBinary";
//
// btnHashCheckEncodeText
//
resources.ApplyResources(this.btnHashCheckEncodeText, "btnHashCheckEncodeText");
this.btnHashCheckEncodeText.Name = "btnHashCheckEncodeText";
this.btnHashCheckEncodeText.UseVisualStyleBackColor = true;
this.btnHashCheckEncodeText.Click += new System.EventHandler(this.btnHashCheckEncodeText_Click);
//
// txtHashCheckText
//
resources.ApplyResources(this.txtHashCheckText, "txtHashCheckText");
this.txtHashCheckText.Name = "txtHashCheckText";
//
// lblHashCheckText
//
resources.ApplyResources(this.lblHashCheckText, "lblHashCheckText");
this.lblHashCheckText.Name = "lblHashCheckText";
this.pbProgress.ShowPercentageText = true;
//
// HashCheckerForm
//
this.AllowDrop = true;
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.SystemColors.Window;
this.Controls.Add(this.tcMain);
this.Controls.Add(this.pbProgress);
this.Controls.Add(this.lblFilePath2);
this.Controls.Add(this.txtFilePath2);
this.Controls.Add(this.txtFilePath);
this.Controls.Add(this.btnFilePathBrowse2);
this.Controls.Add(this.cbCompareTwoFiles);
this.Controls.Add(this.lblTarget);
this.Controls.Add(this.lblFilePath);
this.Controls.Add(this.btnStartHashCheck);
this.Controls.Add(this.lblResult);
this.Controls.Add(this.txtTarget);
this.Controls.Add(this.cbHashType);
this.Controls.Add(this.btnFilePathBrowse);
this.Controls.Add(this.txtResult);
this.Controls.Add(this.lblHashType);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "HashCheckerForm";
this.tcMain.ResumeLayout(false);
this.tpFileHashCheck.ResumeLayout(false);
this.tpFileHashCheck.PerformLayout();
this.tpTextConversions.ResumeLayout(false);
this.tpTextConversions.PerformLayout();
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.HashCheckerForm_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.HashCheckerForm_DragEnter);
this.ResumeLayout(false);
this.PerformLayout();
}
@ -360,32 +185,10 @@ private void InitializeComponent()
private System.Windows.Forms.TextBox txtResult;
private System.Windows.Forms.TextBox txtTarget;
private System.Windows.Forms.Label lblFilePath;
private System.Windows.Forms.TabControl tcMain;
private System.Windows.Forms.TabPage tpFileHashCheck;
private System.Windows.Forms.TabPage tpTextConversions;
private System.Windows.Forms.Button btnHashCheckEncodeText;
private System.Windows.Forms.TextBox txtHashCheckText;
private System.Windows.Forms.Label lblHashCheckText;
private System.Windows.Forms.Button btnHashCheckCopyAll;
private System.Windows.Forms.TextBox txtHashCheckHash;
private System.Windows.Forms.Label lblHashCheckHash;
private System.Windows.Forms.Button btnHashCheckDecodeBase64;
private System.Windows.Forms.TextBox txtHashCheckBase64;
private System.Windows.Forms.Label lblHashCheckBase64;
private System.Windows.Forms.Button btnHashCheckDecodeASCII;
private System.Windows.Forms.TextBox txtHashCheckASCII;
private System.Windows.Forms.Label lblHashCheckASCII;
private System.Windows.Forms.Button btnHashCheckDecodeHex;
private System.Windows.Forms.TextBox txtHashCheckHex;
private System.Windows.Forms.Label lblHashCheckHex;
private System.Windows.Forms.Button btnHashCheckDecodeBinary;
private System.Windows.Forms.TextBox txtHashCheckBinary;
private System.Windows.Forms.Label lblHashCheckBinary;
private System.Windows.Forms.Label lblFilePath2;
private System.Windows.Forms.TextBox txtFilePath2;
private System.Windows.Forms.Button btnFilePathBrowse2;
private System.Windows.Forms.CheckBox cbCompareTwoFiles;
private System.Windows.Forms.ProgressBar pbProgress;
private System.Windows.Forms.Label lblProgressPercentage;
private BlackStyleProgressBar pbProgress;
}
}

View file

@ -35,7 +35,6 @@ public partial class HashCheckerForm : Form
public bool CompareTwoFiles { get; private set; }
private HashChecker hashChecker;
private Translator translator;
public HashCheckerForm()
{
@ -49,13 +48,27 @@ public HashCheckerForm()
hashChecker = new HashChecker();
hashChecker.FileCheckProgressChanged += fileCheck_FileCheckProgressChanged;
translator = new Translator();
txtResult.SupportSelectAll();
txtTarget.SupportSelectAll();
}
#region File hash check
private void UpdateCompareControls()
{
lblFilePath2.Enabled = txtFilePath2.Enabled = btnFilePathBrowse2.Enabled = CompareTwoFiles;
if (CompareTwoFiles)
{
lblResult.Text = Resources.ResultOfFirstFile;
lblTarget.Text = Resources.ResultOfSecondFile;
}
else
{
lblResult.Text = Resources.Result;
lblTarget.Text = Resources.Target;
}
txtTarget.ReadOnly = CompareTwoFiles;
}
private void UpdateResult()
{
@ -79,22 +92,24 @@ private void UpdateResult()
}
}
private void UpdateCompareControls()
private void HashCheckerForm_DragEnter(object sender, DragEventArgs e)
{
lblFilePath2.Enabled = txtFilePath2.Enabled = btnFilePathBrowse2.Enabled = CompareTwoFiles;
if (CompareTwoFiles)
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
lblResult.Text = Resources.ResultOfFirstFile;
lblTarget.Text = Resources.ResultOfSecondFile;
e.Effect = DragDropEffects.Copy;
}
else
{
lblResult.Text = Resources.Result;
lblTarget.Text = Resources.Target;
e.Effect = DragDropEffects.None;
}
}
txtTarget.ReadOnly = CompareTwoFiles;
private void HashCheckerForm_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && e.Data.GetData(DataFormats.FileDrop, false) is string[] files && files.Length > 0)
{
txtFilePath.Text = files[0];
}
}
private void btnFilePathBrowse_Click(object sender, EventArgs e)
@ -102,17 +117,37 @@ private void btnFilePathBrowse_Click(object sender, EventArgs e)
FileHelpers.BrowseFile(txtFilePath);
}
private void btnFilePathBrowse2_Click(object sender, EventArgs e)
{
FileHelpers.BrowseFile(txtFilePath2);
}
private void cbCompareTwoFiles_CheckedChanged(object sender, EventArgs e)
{
CompareTwoFiles = cbCompareTwoFiles.Checked;
UpdateCompareControls();
}
private void txtFilePath2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void txtFilePath2_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && e.Data.GetData(DataFormats.FileDrop, false) is string[] files && files.Length > 0)
{
txtFilePath2.Text = files[0];
}
}
private void btnFilePathBrowse2_Click(object sender, EventArgs e)
{
FileHelpers.BrowseFile(txtFilePath2);
}
private async void btnStartHashCheck_Click(object sender, EventArgs e)
{
if (hashChecker.IsWorking)
@ -157,8 +192,7 @@ private async void btnStartHashCheck_Click(object sender, EventArgs e)
private void fileCheck_FileCheckProgressChanged(float progress)
{
pbProgress.Value = (int)progress;
lblProgressPercentage.Text = (int)progress + "%";
pbProgress.Value = (int)Math.Round(progress);
}
private void txtResult_TextChanged(object sender, EventArgs e)
@ -170,128 +204,5 @@ private void txtTarget_TextChanged(object sender, EventArgs e)
{
UpdateResult();
}
private void tpFileHashCheck_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void tpFileHashCheck_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && e.Data.GetData(DataFormats.FileDrop, false) is string[] files && files.Length > 0)
{
txtFilePath.Text = files[0];
}
}
private void txtFilePath2_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void txtFilePath2_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop, false) && e.Data.GetData(DataFormats.FileDrop, false) is string[] files && files.Length > 0)
{
txtFilePath2.Text = files[0];
}
}
#endregion File hash check
#region Text conversions
private void FillConversionInfo()
{
FillConversionInfo(translator.Text);
}
private void FillConversionInfo(string text)
{
if (translator != null)
{
if (!string.IsNullOrEmpty(text))
{
translator.EncodeText(text);
txtHashCheckText.Text = translator.Text;
txtHashCheckBinary.Text = translator.BinaryText;
txtHashCheckHex.Text = translator.HexadecimalText;
txtHashCheckASCII.Text = translator.ASCIIText;
txtHashCheckBase64.Text = translator.Base64;
txtHashCheckHash.Text = translator.HashToString();
}
else
{
translator.Clear();
txtHashCheckText.Text = txtHashCheckBinary.Text = txtHashCheckHex.Text = txtHashCheckASCII.Text = txtHashCheckBase64.Text = txtHashCheckHash.Text = "";
}
}
}
private void btnHashCheckCopyAll_Click(object sender, EventArgs e)
{
if (translator != null)
{
string text = translator.ToString();
if (!string.IsNullOrEmpty(text))
{
ClipboardHelpers.CopyText(text);
}
}
}
private void btnHashCheckEncodeText_Click(object sender, EventArgs e)
{
FillConversionInfo(txtHashCheckText.Text);
}
private void btnHashCheckDecodeBinary_Click(object sender, EventArgs e)
{
string binary = txtHashCheckBinary.Text;
translator.DecodeBinary(binary);
FillConversionInfo();
txtHashCheckBinary.Text = binary;
}
private void btnHashCheckDecodeHex_Click(object sender, EventArgs e)
{
string hex = txtHashCheckHex.Text;
translator.DecodeHex(hex);
FillConversionInfo();
txtHashCheckHex.Text = hex;
}
private void btnHashCheckDecodeASCII_Click(object sender, EventArgs e)
{
string ascii = txtHashCheckASCII.Text;
translator.DecodeASCII(ascii);
FillConversionInfo();
txtHashCheckASCII.Text = ascii;
}
private void btnHashCheckDecodeBase64_Click(object sender, EventArgs e)
{
string base64 = txtHashCheckBase64.Text;
translator.DecodeBase64(base64);
FillConversionInfo();
txtHashCheckBase64.Text = base64;
}
#endregion Text conversions
}
}

File diff suppressed because it is too large Load diff