Skip to content

Commit

Permalink
feat: added ability to save and load app window size and location (#183)
Browse files Browse the repository at this point in the history
* added ability to save and load app window size and location

* chore: empty to commit to trigger ci

---------

Co-authored-by: Scott Willeke <[email protected]>
  • Loading branch information
mega5800 and activescott authored Apr 9, 2024
1 parent 309f163 commit 368c04f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/LessMsi.Gui/LessMsi.Gui.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
Expand Down
64 changes: 58 additions & 6 deletions src/LessMsi.Gui/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Drawing;
using System.Globalization;
using System.IO;
Expand All @@ -50,8 +51,15 @@ internal class MainForm : Form, IMainFormView
private ToolStripMenuItem searchFileToolStripMenuItem;
readonly static string[] AllowedDragDropExtensions = new[] { ".msi", ".msp" };

#region Form size and location members
private const string c_WindowWidthAttribute = "WindowWidth";
private const string c_WindowHeightAttribute = "WindowHeight";

public MainForm(string defaultInputFile)
private const string c_XPositionAttribute = "X_Position";
private const string c_YPositionAttribute = "Y_Position";
#endregion

public MainForm(string defaultInputFile)
{
InitializeComponent();
msiTableGrid.AutoGenerateColumns = false;
Expand Down Expand Up @@ -815,6 +823,8 @@ private void InitializeComponent()
this.Name = "MainForm";
this.Text = "Less MSIérables";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainForm_FormClosing);
this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.MainForm_FormClosed);
this.Load += new System.EventHandler(this.MainForm_Load);
this.DragDrop += new System.Windows.Forms.DragEventHandler(this.MainForm_DragDrop);
this.DragEnter += new System.Windows.Forms.DragEventHandler(this.MainForm_DragEnter);
this.tabs.ResumeLayout(false);
Expand Down Expand Up @@ -1073,9 +1083,52 @@ private void cboStream_SelectedValueChanged(object sender, EventArgs e)
this.Presenter.OnSelectedStreamChanged();
}

#endregion
private void MainForm_Load(object sender, EventArgs e)
{
int windowWidth = getIntValueFromConfiguration(c_WindowWidthAttribute, MinimumSize.Width);
int windowHeight = getIntValueFromConfiguration(c_WindowHeightAttribute, MinimumSize.Height);

int xPosition = getIntValueFromConfiguration(c_XPositionAttribute, 0);
int yPosition = getIntValueFromConfiguration(c_YPositionAttribute, 0);

Size = new Size(windowWidth, windowHeight);
Location = new Point(xPosition, yPosition);
}

private ExtractionProgressDialog BeginShowingProgressDialog()
private void MainForm_FormClosed(object sender, FormClosedEventArgs e)
{
updateConfiguration(c_WindowWidthAttribute, Size.Width.ToString());
updateConfiguration(c_WindowHeightAttribute, Size.Height.ToString());

updateConfiguration(c_XPositionAttribute, Location.X.ToString());
updateConfiguration(c_YPositionAttribute, Location.Y.ToString());
}
#endregion

#region Form size and location methods
private int getIntValueFromConfiguration(string i_SettingName, int i_MinValue)
{
int intValue = 0;
string rawValue = ConfigurationManager.AppSettings.Get(i_SettingName);

int.TryParse(rawValue, out intValue);
intValue = Math.Max(intValue, i_MinValue);

return intValue;
}

private void updateConfiguration(string i_SettingName, string i_SettingValue)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);

config.AppSettings.Settings.Remove(i_SettingName);
config.AppSettings.Settings.Add(i_SettingName, i_SettingValue);

config.Save(ConfigurationSaveMode.Minimal);
}
#endregion

private ExtractionProgressDialog BeginShowingProgressDialog()
{
var progressDialog = new ExtractionProgressDialog(this);
progressDialog.Show();
Expand All @@ -1101,6 +1154,5 @@ protected bool IsFileTabSelected
return tabs.SelectedTab == tabExtractFiles;
}
}

}
}
}
}
9 changes: 8 additions & 1 deletion src/LessMsi.Gui/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v4.5"/>
</startup>
</configuration>
<appSettings>
<add key="WindowWidth" value="0"/>
<add key="WindowHeight" value="0"/>

<add key="X_Position" value="10"/>
<add key="Y_Position" value="10"/>
</appSettings>
</configuration>

0 comments on commit 368c04f

Please sign in to comment.