Skip to content

Commit

Permalink
Hotfix to 2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hellzerg committed Nov 21, 2019
1 parent e0a1b4c commit 2476d10
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 35 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to this project will be documented in this file.

## [2.5] - 2019-11-21
- Bugfix when restoring state

## [2.4] - 2019-11-15
- New: Choose font size
- New: Hide passwords from list
Expand Down
20 changes: 13 additions & 7 deletions Lain/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ public MainForm(SecureString key)

private void RestoreWindowState()
{
if (Options.CurrentOptions.WindowSize.IsEmpty && Options.CurrentOptions.WindowLocation == null)
{
return;
}

this.WindowState = Options.CurrentOptions.WindowState;
this.Size = Options.CurrentOptions.WindowSize;

if (Options.CurrentOptions.WindowLocation != null)
Expand All @@ -71,8 +67,18 @@ private void RestoreWindowState()

private void SaveWindowState()
{
Options.CurrentOptions.WindowLocation = this.Location;
Options.CurrentOptions.WindowSize = this.Size;
Options.CurrentOptions.WindowState = this.WindowState;

if (this.WindowState == FormWindowState.Normal)
{
Options.CurrentOptions.WindowLocation = this.Location;
Options.CurrentOptions.WindowSize = this.Size;
}
else
{
Options.CurrentOptions.WindowLocation = this.RestoreBounds.Location;
Options.CurrentOptions.WindowSize = this.RestoreBounds.Size;
}
}

private string NewVersionMessage(string latest)
Expand Down
39 changes: 15 additions & 24 deletions Lain/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SettingsJson
public int FontSize { get; set; }
public Size WindowSize { get; set; }
public Point? WindowLocation { get; set; }
public FormWindowState WindowState { get; set; }
}

internal static class Options
Expand All @@ -30,9 +31,6 @@ internal static class Options

internal static SettingsJson CurrentOptions = new SettingsJson();

// use this to determine if changes have been made
static SettingsJson _flag = new SettingsJson();

internal static void ApplyTheme(Form f)
{
switch (CurrentOptions.Color)
Expand Down Expand Up @@ -97,19 +95,16 @@ internal static void SaveSettings()
{
if (File.Exists(_settingsFile))
{
if ((_flag.HidePasswords != CurrentOptions.HidePasswords) || (_flag.WindowLocation != CurrentOptions.WindowLocation) || (_flag.WindowSize != CurrentOptions.WindowSize) || (_flag.FontSize != CurrentOptions.FontSize) || (_flag.Color != CurrentOptions.Color) || (_flag.Authorize != CurrentOptions.Authorize) || (_flag.AutoLock != CurrentOptions.AutoLock) || (_flag.AutoStart != CurrentOptions.AutoStart) || (_flag.Minutes != CurrentOptions.Minutes))
{
File.Delete(_settingsFile);
File.WriteAllText(_settingsFile, string.Empty);

using (FileStream fs = File.Open(_settingsFile, FileMode.OpenOrCreate))
using (StreamWriter sw = new StreamWriter(fs))
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
using (FileStream fs = File.Open(_settingsFile, FileMode.OpenOrCreate))
using (StreamWriter sw = new StreamWriter(fs))
using (JsonWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;

JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(jw, CurrentOptions);
}
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(jw, CurrentOptions);
}
}
}
Expand All @@ -127,6 +122,7 @@ internal static void LoadSettings()
CurrentOptions.WindowLocation = null;
CurrentOptions.WindowSize = new Size(907, 681);
CurrentOptions.FontSize = 1;
CurrentOptions.WindowState = FormWindowState.Normal;

using (FileStream fs = File.Open(_settingsFile, FileMode.CreateNew))
using (StreamWriter sw = new StreamWriter(fs))
Expand All @@ -142,16 +138,11 @@ internal static void LoadSettings()
{
CurrentOptions = JsonConvert.DeserializeObject<SettingsJson>(File.ReadAllText(_settingsFile));

// initialize flag
_flag.Color = CurrentOptions.Color;
_flag.Authorize = CurrentOptions.Authorize;
_flag.AutoLock = CurrentOptions.AutoLock;
_flag.AutoStart = CurrentOptions.AutoStart;
_flag.Minutes = CurrentOptions.Minutes;
_flag.WindowLocation = CurrentOptions.WindowLocation;
_flag.WindowSize = CurrentOptions.WindowSize;
_flag.FontSize = CurrentOptions.FontSize;
_flag.HidePasswords = CurrentOptions.HidePasswords;
if (CurrentOptions.WindowSize.IsEmpty)
{
CurrentOptions.WindowSize = new Size(907, 681);
SaveSettings();
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Lain/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ static class Program

// Enter current version here
internal readonly static float Major = 2;
internal readonly static float Minor = 4;
internal readonly static float Minor = 5;

/* END OF VERSION PROPERTIES */

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ https://github.com/hellzerg/lain/blob/master/IMAGES.md

## Details: ##

* Latest version: 2.4
* Released: November 15, 2019
* Latest version: 2.5
* Released: November 21, 2019
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.4
2.5

0 comments on commit 2476d10

Please sign in to comment.