Skip to content

Commit

Permalink
Fix settings not upgrading properly
Browse files Browse the repository at this point in the history
  • Loading branch information
JungleDruid committed Aug 30, 2023
1 parent b43e663 commit b8e9797
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
3 changes: 3 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@
<setting name="CultureName" serializeAs="String">
<value />
</setting>
<setting name="SettingsVersion" serializeAs="String">
<value />
</setting>
</BG3LocalizationMerger.Properties.Settings>
</userSettings>
</configuration>
1 change: 1 addition & 0 deletions BG3LocalizationMerger.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PlatformTarget>x64</PlatformTarget>
<NeutralLanguage>en</NeutralLanguage>
<Version>$(VersionPrefix)1.0.1</Version>
<SignAssembly>False</SignAssembly>
</PropertyGroup>

<ItemGroup>
Expand Down
30 changes: 23 additions & 7 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BG3LocalizationMerger.Resources.Strings;
using BG3LocalizationMerger.Properties;
using BG3LocalizationMerger.Resources.Strings;
using ModernWpf.Controls.Primitives;
using Ookii.Dialogs.Wpf;
using System;
Expand All @@ -7,6 +8,7 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -27,10 +29,10 @@ public partial class MainWindow
public MainWindow()
{
s_instance = this;
Properties.Settings.Default.Upgrade();
var props = Properties.Settings.Default;
UpgradeSettings();
InitializeComponent();

var props = Settings.Default;
UnpackedDataTextBox.Text = props.UnpackedDataPath;
LanguagePackTextBox.Text = props.LanguagePackPath;
ReferencePackTextBox.Text = props.ReferencePackPath;
Expand All @@ -39,11 +41,25 @@ public MainWindow()
InitCulture();
}

private static void UpgradeSettings()
{
var version = Assembly.GetEntryAssembly()?.GetName().Version;
if (version != null)
{
if (Settings.Default.SettingsVersion != version.ToString())
{
Settings.Default.Upgrade();
Settings.Default.SettingsVersion = version.ToString();
Settings.Default.Save();
}
}
}

private void InitCulture()
{
LanguageComboBox.ItemsSource = TranslationSource.GetAllCultures();

string defaultCultureName = Properties.Settings.Default.CultureName;
string defaultCultureName = Settings.Default.CultureName;
var defaultCulture = string.IsNullOrEmpty(defaultCultureName)
? CultureInfo.CurrentUICulture
: new CultureInfo(defaultCultureName);
Expand Down Expand Up @@ -205,7 +221,7 @@ private async void Window_Closing(object sender, System.ComponentModel.CancelEve

private void SaveSettings()
{
var props = Properties.Settings.Default;
var props = Settings.Default;
props.UnpackedDataPath = UnpackedDataTextBox.Text;
props.LanguagePackPath = LanguagePackTextBox.Text;
props.ReferencePackPath = ReferencePackTextBox.Text;
Expand Down Expand Up @@ -334,8 +350,8 @@ private void LanguageComboBox_SelectionChanged(object sender, SelectionChangedEv
if (LanguageComboBox.SelectedItem is CultureInfo culture)
{
TranslationSource.Instance.Culture = culture;
Properties.Settings.Default.CultureName = culture.Name;
Properties.Settings.Default.Save();
Settings.Default.CultureName = culture.Name;
Settings.Default.Save();
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,8 @@
<Setting Name="CultureName" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="SettingsVersion" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>

0 comments on commit b8e9797

Please sign in to comment.