diff --git a/MainForm.Designer.cs b/MainForm.Designer.cs index f46458e..ccb8ea5 100644 --- a/MainForm.Designer.cs +++ b/MainForm.Designer.cs @@ -67,6 +67,7 @@ private void InitializeComponent() this.buttonCustomInfo = new System.Windows.Forms.Button(); this.radioButtonUnicode = new System.Windows.Forms.RadioButton(); this.labelHexPrefix = new System.Windows.Forms.Label(); + this.labelVersion = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.nudDelay)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.nudDuration)).BeginInit(); this.statusStrip1.SuspendLayout(); @@ -502,6 +503,16 @@ private void InitializeComponent() this.labelHexPrefix.TabIndex = 31; this.labelHexPrefix.Text = "0x"; // + // labelVersion + // + this.labelVersion.AutoSize = true; + this.labelVersion.ForeColor = System.Drawing.SystemColors.ControlDark; + this.labelVersion.Location = new System.Drawing.Point(345, 447); + this.labelVersion.Name = "labelVersion"; + this.labelVersion.Size = new System.Drawing.Size(45, 13); + this.labelVersion.TabIndex = 32; + this.labelVersion.Text = "Version:"; + // // MainForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -534,6 +545,7 @@ private void InitializeComponent() this.Controls.Add(this.btnF23); this.Controls.Add(this.btnF24); this.Controls.Add(this.panelCustomOutline); + this.Controls.Add(this.labelVersion); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Name = "MainForm"; @@ -589,5 +601,6 @@ private void InitializeComponent() private System.Windows.Forms.Label labelHexPrefix; private System.Windows.Forms.RadioButton radioButtonUnicode; private System.Windows.Forms.Button buttonCustomInfo; + private System.Windows.Forms.Label labelVersion; } } \ No newline at end of file diff --git a/MainForm.cs b/MainForm.cs index 235100b..5c09ff6 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -5,6 +5,7 @@ using System.Diagnostics; using System.Drawing; using System.Linq; +using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading; @@ -15,6 +16,7 @@ namespace F_Key_Sender { public partial class MainForm : Form { + const string VERSION = "1.1.0"; // Dictionary to store virtual key codes and scan codes. Will want to use wscan codes for SendInput private static readonly Dictionary keyCodes = new Dictionary @@ -57,6 +59,11 @@ public MainForm() this.TopMost = true; stopwatch.Start(); dropdownMethod.SelectedIndex = 0; + + VerifyAssemblyVersion(); + + // Set Version Label + labelVersion.Text = $"Version: {VERSION}"; } // Using WaitHandle instead of Thread.Sleep to avoid wasting system resources and also more accurate @@ -1006,5 +1013,42 @@ private void buttonCustomInfo_Click(object sender, EventArgs e) MessageBoxIcon.None ); } + + // If in debug mode and the assembly version does not match the file version, display a warning message + private void VerifyAssemblyVersion() + { +#if DEBUG + var assembly = Assembly.GetExecutingAssembly(); + var assemblyVersion = assembly.GetName().Version.ToString(); + var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); + var fileVersion = new Version(fileVersionInfo.FileVersion).ToString(); + + // Ignore the last digit of the version number if it's 0 and the file version doesn't use it by counting periods in the file version + if (assemblyVersion.EndsWith(".0") && VERSION.Count(c => c == '.') < 3) + { + assemblyVersion = assemblyVersion.Substring(0, assemblyVersion.Length - 2); + } + if (fileVersion.EndsWith(".0") && VERSION.Count(c => c == '.') < 3) + { + fileVersion = fileVersion.Substring(0, fileVersion.Length - 2); + } + + if (assemblyVersion != VERSION || fileVersion != VERSION) + { + string warningMessage = $"WARNING: Version mismatch detected!\n" + + $"Expected version: {VERSION}\n" + + $"Assembly version: {assemblyVersion}\n" + + $"File version: {fileVersion}"; + + Debug.WriteLine(warningMessage); + MessageBox.Show(warningMessage, "Version Mismatch", + MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + else + { + Debug.WriteLine($"Version check passed. Current version: {VERSION}"); + } +#endif + } } } \ No newline at end of file