diff --git a/HeliosPlus/HeliosPlus.csproj b/HeliosPlus/HeliosPlus.csproj index 20697ae..452310f 100644 --- a/HeliosPlus/HeliosPlus.csproj +++ b/HeliosPlus/HeliosPlus.csproj @@ -88,6 +88,7 @@ + diff --git a/HeliosPlus/Program.cs b/HeliosPlus/Program.cs index 8b84b4c..0b697de 100644 --- a/HeliosPlus/Program.cs +++ b/HeliosPlus/Program.cs @@ -42,8 +42,8 @@ namespace HeliosPlus { public static string AppSteamIconFilename = Path.Combine(AppIconPath, @"Steam.ico"); public static string AppUplayIconFilename = Path.Combine(AppIconPath, @"Uplay.ico"); public static string AppEpicIconFilename = Path.Combine(AppIconPath, @"Epic.ico"); + public static ProgramSettings AppProgramSettings; - /// /// The main entry point for the application. /// @@ -65,7 +65,9 @@ namespace HeliosPlus { //Application.SetHighDpiMode(HighDpiMode.SystemAware); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); - + + // Load the program settings + AppProgramSettings = ProgramSettings.LoadSettings(); var app = new CommandLineApplication(); diff --git a/HeliosPlus/ProgramSettings.cs b/HeliosPlus/ProgramSettings.cs new file mode 100644 index 0000000..01b55f5 --- /dev/null +++ b/HeliosPlus/ProgramSettings.cs @@ -0,0 +1,123 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HeliosPlus +{ + public class ProgramSettings + { + #region Class Variables + // Common items to the class + private static bool _programSettingsLoaded = false; + // Other constants that are useful + private static string _programSettingsStorageJsonFileName = Path.Combine(Program.AppDataPath, $"Settings_{FileVersion.ToString(2)}.json"); + #endregion + + #region Instance Variables + private bool _minimiseOnStart = false; + #endregion + + #region Class Properties + public bool MinimiseOnStart { + get + { + return _minimiseOnStart; + } + set + { + _minimiseOnStart = value; + + // Because a value has changed, we need to save the setting + // to remember it for later. + if (_programSettingsLoaded) + SaveSettings(); + } + } + + public static Version FileVersion + { + get => new Version(1, 0, 0); + } + + #endregion + + #region Class Methods + public static ProgramSettings LoadSettings() + { + ProgramSettings programSettings = null; + + if (File.Exists(_programSettingsStorageJsonFileName)) + { + var json = File.ReadAllText(_programSettingsStorageJsonFileName, Encoding.Unicode); + + if (!string.IsNullOrWhiteSpace(json)) + { + try + { + programSettings = JsonConvert.DeserializeObject(json, new JsonSerializerSettings + { + MissingMemberHandling = MissingMemberHandling.Ignore, + NullValueHandling = NullValueHandling.Ignore, + DefaultValueHandling = DefaultValueHandling.Include, + TypeNameHandling = TypeNameHandling.Auto + }); + } + catch (FileNotFoundException ex) + { + Console.WriteLine($"ProgramSettings/LoadSettings exception 1: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + } + catch (Exception ex) + { + Console.WriteLine($"Unable to load Program Settings JSON file {_programSettingsStorageJsonFileName}: " + ex.Message); + } + } + } + + // If there isn't any settings in the file then create a new ProgramSettings object + if (programSettings == null) + programSettings = new ProgramSettings(); + _programSettingsLoaded = true; + return programSettings ; + } + + public bool SaveSettings() + { + + try + { + var json = JsonConvert.SerializeObject(this, Formatting.Indented, new JsonSerializerSettings + { + NullValueHandling = NullValueHandling.Include, + DefaultValueHandling = DefaultValueHandling.Populate, + TypeNameHandling = TypeNameHandling.Auto + + }); + + + if (!string.IsNullOrWhiteSpace(json)) + { + File.WriteAllText(_programSettingsStorageJsonFileName, json, Encoding.Unicode); + return true; + } + } + catch (FileNotFoundException ex) + { + Console.WriteLine($"ProgramSettings/SaveSettings exception 1: {ex.Message}: {ex.StackTrace} - {ex.InnerException}"); + } + catch (Exception ex) + { + Console.WriteLine($"Unable to save Program Settings JSON file {_programSettingsStorageJsonFileName}: " + ex.Message); + } + + return false; + } + + #endregion + } + + +} diff --git a/HeliosPlus/UIForms/MainForm.Designer.cs b/HeliosPlus/UIForms/MainForm.Designer.cs index 29de4ff..851efd0 100644 --- a/HeliosPlus/UIForms/MainForm.Designer.cs +++ b/HeliosPlus/UIForms/MainForm.Designer.cs @@ -50,6 +50,7 @@ this.shortcutToolStripSeparator = new System.Windows.Forms.ToolStripSeparator(); this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.cb_minimise_notification_area = new System.Windows.Forms.CheckBox(); ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit(); this.splitContainer1.Panel1.SuspendLayout(); this.splitContainer1.Panel2.SuspendLayout(); @@ -72,6 +73,7 @@ // // splitContainer1.Panel2 // + this.splitContainer1.Panel2.Controls.Add(this.cb_minimise_notification_area); this.splitContainer1.Panel2.Controls.Add(this.lbl_version); this.splitContainer1.Panel2.Controls.Add(this.btn_setup_game_shortcuts); this.splitContainer1.Panel2.Controls.Add(this.btn_exit); @@ -211,6 +213,14 @@ resources.ApplyResources(this.exitToolStripMenuItem, "exitToolStripMenuItem"); this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // + // cb_minimise_notification_area + // + resources.ApplyResources(this.cb_minimise_notification_area, "cb_minimise_notification_area"); + this.cb_minimise_notification_area.ForeColor = System.Drawing.Color.White; + this.cb_minimise_notification_area.Name = "cb_minimise_notification_area"; + this.cb_minimise_notification_area.UseVisualStyleBackColor = true; + this.cb_minimise_notification_area.CheckedChanged += new System.EventHandler(this.cb_minimise_notification_area_CheckedChanged); + // // MainForm // resources.ApplyResources(this, "$this"); @@ -255,5 +265,6 @@ private System.Windows.Forms.ToolStripSeparator shortcutToolStripSeparator; private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; + private System.Windows.Forms.CheckBox cb_minimise_notification_area; } } \ No newline at end of file diff --git a/HeliosPlus/UIForms/MainForm.cs b/HeliosPlus/UIForms/MainForm.cs index 549f549..ebc290b 100644 --- a/HeliosPlus/UIForms/MainForm.cs +++ b/HeliosPlus/UIForms/MainForm.cs @@ -27,11 +27,26 @@ namespace HeliosPlus.UIForms btn_setup_game_shortcuts.Parent = splitContainer1.Panel2; lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version); notifyIcon.Visible = true; - // Make the form show - allowVisible = true; - // Close the application when the form is closed - allowClose = true; RefreshNotifyIconMenus(); + + if (Program.AppProgramSettings.MinimiseOnStart) + { + // Make the form minimised on start + allowVisible = false; + // Hide the application to notification area when the form is closed + allowClose = false; + cb_minimise_notification_area.Checked = true; + } + else + { + // Make the form show to the user on startup + allowVisible = true; + // Really close the application when the form is closed + allowClose = true; + cb_minimise_notification_area.Checked = false; + } + + } protected override void SetVisibleCore(bool value) @@ -149,5 +164,27 @@ namespace HeliosPlus.UIForms allowClose = true; Application.Exit(); } + + private void cb_minimise_notification_area_CheckedChanged(object sender, EventArgs e) + { + if (cb_minimise_notification_area.Checked) + { + // Make the form minimised on start + allowVisible = false; + // Hide the application to notification area when the form is closed + allowClose = false; + // Enable the MinimiseOnStart setting + Program.AppProgramSettings.MinimiseOnStart = true; + } + else + { + // Make the form show to the user on startup + allowVisible = true; + // Really close the application when the form is closed + allowClose = true; + // Disable the MinimiseOnStart setting + Program.AppProgramSettings.MinimiseOnStart = false; + } + } } } diff --git a/HeliosPlus/UIForms/MainForm.resx b/HeliosPlus/UIForms/MainForm.resx index 0eb3c37..d49e5d1 100644 --- a/HeliosPlus/UIForms/MainForm.resx +++ b/HeliosPlus/UIForms/MainForm.resx @@ -10725,6 +10725,42 @@ 0 + + Bottom, Left, Right + + + True + + + Microsoft Sans Serif, 9.75pt + + + NoControl + + + 245, 352 + + + 296, 20 + + + 5 + + + Start HeliosPlus minimised in notification area + + + cb_minimise_notification_area + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + splitContainer1.Panel2 + + + 0 + True @@ -10732,7 +10768,7 @@ Microsoft Sans Serif, 9.75pt - 12, 355 + 12, 353 25, 16 @@ -10756,7 +10792,7 @@ splitContainer1.Panel2 - 0 + 1 None @@ -10768,7 +10804,7 @@ Microsoft Sans Serif, 21.75pt - 212, 180 + 212, 182 360, 50 @@ -10789,7 +10825,7 @@ splitContainer1.Panel2 - 1 + 2 Bottom, Right @@ -10797,8 +10833,11 @@ Flat + + NoControl + - 698, 347 + 698, 350 75, 23 @@ -10819,7 +10858,7 @@ splitContainer1.Panel2 - 2 + 3 Fill @@ -63104,7 +63143,7 @@ splitContainer1.Panel2 - 3 + 4 splitContainer1.Panel2 diff --git a/HeliosPlus/UIForms/ShortcutForm.Designer.cs b/HeliosPlus/UIForms/ShortcutForm.Designer.cs index daa2b39..707b944 100644 --- a/HeliosPlus/UIForms/ShortcutForm.Designer.cs +++ b/HeliosPlus/UIForms/ShortcutForm.Designer.cs @@ -42,7 +42,6 @@ namespace HeliosPlus.UIForms this.lbl_profile_shown_subtitle = new System.Windows.Forms.Label(); this.lbl_profile_shown = new System.Windows.Forms.Label(); this.ilv_saved_profiles = new Manina.Windows.Forms.ImageListView(); - this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView(); this.tabp_before = new System.Windows.Forms.TabPage(); this.pnl_start_program4 = new System.Windows.Forms.Panel(); this.cb_start_program4 = new System.Windows.Forms.CheckBox(); @@ -113,6 +112,7 @@ namespace HeliosPlus.UIForms this.lbl_title = new System.Windows.Forms.Label(); this.lbl_shortcut_name = new System.Windows.Forms.Label(); this.cb_autosuggest = new System.Windows.Forms.CheckBox(); + this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView(); this.tabc_shortcut.SuspendLayout(); this.tabp_display.SuspendLayout(); this.tabp_before.SuspendLayout(); @@ -253,21 +253,6 @@ namespace HeliosPlus.UIForms this.ilv_saved_profiles.View = Manina.Windows.Forms.View.HorizontalStrip; this.ilv_saved_profiles.ItemClick += new Manina.Windows.Forms.ItemClickEventHandler(this.ilv_saved_profiles_ItemClick); // - // dv_profile - // - this.dv_profile.BackColor = System.Drawing.Color.DimGray; - this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; - this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue; - this.dv_profile.Location = new System.Drawing.Point(0, 0); - this.dv_profile.Margin = new System.Windows.Forms.Padding(18); - this.dv_profile.Name = "dv_profile"; - this.dv_profile.PaddingX = 100; - this.dv_profile.PaddingY = 100; - this.dv_profile.Profile = null; - this.dv_profile.Size = new System.Drawing.Size(1082, 467); - this.dv_profile.TabIndex = 23; - // // tabp_before // this.tabp_before.BackColor = System.Drawing.Color.Black; @@ -1085,6 +1070,21 @@ namespace HeliosPlus.UIForms this.cb_autosuggest.UseVisualStyleBackColor = true; this.cb_autosuggest.CheckedChanged += new System.EventHandler(this.cb_autosuggest_CheckedChanged); // + // dv_profile + // + this.dv_profile.BackColor = System.Drawing.Color.DimGray; + this.dv_profile.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue; + this.dv_profile.Location = new System.Drawing.Point(0, 0); + this.dv_profile.Margin = new System.Windows.Forms.Padding(18); + this.dv_profile.Name = "dv_profile"; + this.dv_profile.PaddingX = 100; + this.dv_profile.PaddingY = 100; + this.dv_profile.Profile = null; + this.dv_profile.Size = new System.Drawing.Size(1082, 467); + this.dv_profile.TabIndex = 23; + // // ShortcutForm // this.AcceptButton = this.btn_save; diff --git a/HeliosPlus/UIForms/ShortcutForm.cs b/HeliosPlus/UIForms/ShortcutForm.cs index 92b982a..37d1782 100644 --- a/HeliosPlus/UIForms/ShortcutForm.cs +++ b/HeliosPlus/UIForms/ShortcutForm.cs @@ -1418,5 +1418,6 @@ namespace HeliosPlus.UIForms txt_start_program_args4.Visible = false; } } + } } \ No newline at end of file