Skip to content

Commit

Permalink
Merge #3878 Restore window position without default instance
Browse files Browse the repository at this point in the history
  • Loading branch information
HebaruSan committed Aug 11, 2023
2 parents b0f8601 + 10a43c9 commit 399d82f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file.
- [Build] Add missing dependency to .deb package (#3872 by: HebaruSan; reviewed: erkinalp)
- [Core] Add missing resource string for upgrading (#3873 by: HebaruSan; reviewed: techman83)
- [Multiple] Repository management fixes (#3876 by: HebaruSan; reviewed: techman83)
- [GUI] Restore window position without default instance (#3878 by: HebaruSan; reviewed: techman83)

### Internal

Expand Down
29 changes: 20 additions & 9 deletions GUI/Main/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,9 @@ protected override void OnLoad(EventArgs e)
}

// We need a config object to get the window geometry, but we don't need the registry lock yet
configuration = CurrentInstance != null
? GUIConfiguration.LoadOrCreateConfiguration(
Path.Combine(CurrentInstance.CkanDir(), "GUIConfig.xml"),
CurrentInstance.game)
// No instance, just get the defaults
: new GUIConfiguration();
configuration = GUIConfigForInstance(
// Find the most recently used instance if no default instance
CurrentInstance ?? InstanceWithNewestGUIConfig(manager.Instances.Values));

// This must happen before Shown, and it depends on the configuration
SetStartPosition();
Expand All @@ -182,6 +179,22 @@ protected override void OnLoad(EventArgs e)
base.OnLoad(e);
}

private const string GUIConfigFilename = "GUIConfig.xml";

private static string GUIConfigPath(GameInstance inst)
=> Path.Combine(inst.CkanDir(), GUIConfigFilename);

private static GUIConfiguration GUIConfigForInstance(GameInstance inst)
=> inst == null ? new GUIConfiguration()
: GUIConfiguration.LoadOrCreateConfiguration(GUIConfigPath(inst),
inst.game);

private static GameInstance InstanceWithNewestGUIConfig(IEnumerable<GameInstance> instances)
=> instances.Where(inst => inst.Valid)
.OrderByDescending(inst => File.GetLastWriteTime(GUIConfigPath(inst)))
.ThenBy(inst => inst.Name)
.FirstOrDefault();

/// <summary>
/// Form.Visible says true even when the form hasn't shown yet.
/// This value will tell the truth.
Expand Down Expand Up @@ -379,9 +392,7 @@ private void CurrentInstanceUpdated(bool allowRepoUpdate)
registry.BuildTagIndex(ManageMods.mainModList.ModuleTags);

configuration?.Save();
configuration = GUIConfiguration.LoadOrCreateConfiguration(
Path.Combine(CurrentInstance.CkanDir(), "GUIConfig.xml"),
CurrentInstance.game);
configuration = GUIConfigForInstance(CurrentInstance);

if (!configuration.CheckForUpdatesOnLaunchNoNag && AutoUpdate.CanUpdate)
{
Expand Down

0 comments on commit 399d82f

Please sign in to comment.