Save user settings

Closes #291

The following settings are saved:
Language, lastRunVersion, Unicode, SetDex, SetPKM

Appending a 2char language ID to the exe name no longer needed.

Changelog will be shown if an updated program is detected. First run
will not alert.

Fixes unintended Program Text clearing (PKHeX - Save name etc) when the
language is changed. Store, translate, restore.
This commit is contained in:
Kaphotics
2016-09-29 22:41:35 -07:00
parent 4784291ef8
commit edcb13e3b4
6 changed files with 178 additions and 17 deletions

View File

@@ -47,8 +47,6 @@ public Main()
}).Start();
CB_ExtraBytes.SelectedIndex = 0;
SaveFile.SetUpdateDex = Menu_ModifyDex.Checked;
SaveFile.SetUpdatePKM = Menu_ModifyPKM.Checked;
getFieldsfromPKM = populateFieldsPK6;
getPKMfromFields = preparePK6;
@@ -111,6 +109,13 @@ public Main()
if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
e.Cancel = true;
};
Menu_Options.DropDown.Closing += (sender, e) =>
{
if (!Menu_Unicode.Selected)
return;
if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked)
e.Cancel = true;
};
// Box to Tabs D&D
dragout.AllowDrop = true;
@@ -124,13 +129,32 @@ public Main()
#region Localize & Populate Fields
string[] args = Environment.GetCommandLineArgs();
string filename = args.Length > 0 ? Path.GetFileNameWithoutExtension(args[0])?.ToLower() : "";
HaX = filename.IndexOf("hax", StringComparison.Ordinal) >= 0;
HaX = filename?.IndexOf("hax", StringComparison.Ordinal) >= 0;
// Try and detect the language
string lastTwoChars = filename.Length > 2 ? filename.Substring(filename.Length - 2) : "";
if (lastTwoChars == "jp") lastTwoChars = "ja";
int lang = Array.IndexOf(lang_val, lastTwoChars);
CB_MainLanguage.SelectedIndex = lang < 0 ? 1 : lang;
bool showChangelog = false;
// Load User Settings
{
unicode = Menu_Unicode.Checked = Properties.Settings.Default.Unicode;
SaveFile.SetUpdateDex = Menu_ModifyDex.Checked = Properties.Settings.Default.SetUpdateDex;
SaveFile.SetUpdatePKM = Menu_ModifyPKM.Checked = Properties.Settings.Default.SetUpdatePKM;
// Select Language
string l = Properties.Settings.Default.Language;
if (l.Length != 2) l = "en";
int lang = Array.IndexOf(lang_val, l);
CB_MainLanguage.SelectedIndex = lang < 0 ? 1 : lang;
// Version Check
if (Properties.Settings.Default.Version.Length > 0) // already run on system
{
int lastrev; int.TryParse(Properties.Settings.Default.Version, out lastrev);
int currrev; int.TryParse(Properties.Resources.ProgramVersion, out currrev);
showChangelog = lastrev < currrev;
}
Properties.Settings.Default.Version = Properties.Resources.ProgramVersion;
Properties.Settings.Default.Save();
}
InitializeFields();
formInitialized = true;
@@ -166,6 +190,9 @@ public Main()
Show();
WindowState = FormWindowState.Normal;
if (HaX) Util.Alert("Illegal mode activated.", "Please behave.");
if (showChangelog)
new About().ShowDialog();
#endregion
}
@@ -348,16 +375,19 @@ private void mainMenuMysteryDM(object sender, EventArgs e)
}
private void mainMenuUnicode(object sender, EventArgs e)
{
unicode = Menu_Unicode.Checked;
Properties.Settings.Default.Unicode = unicode = Menu_Unicode.Checked;
Properties.Settings.Default.Save();
updateUnicode();
}
private void mainMenuModifyDex(object sender, EventArgs e)
{
SaveFile.SetUpdateDex = Menu_ModifyDex.Checked;
Properties.Settings.Default.SetUpdateDex = SaveFile.SetUpdateDex = Menu_ModifyDex.Checked;
Properties.Settings.Default.Save();
}
private void mainMenuModifyPKM(object sender, EventArgs e)
{
SaveFile.SetUpdatePKM = Menu_ModifyPKM.Checked;
Properties.Settings.Default.SetUpdatePKM = SaveFile.SetUpdatePKM = Menu_ModifyPKM.Checked;
Properties.Settings.Default.Save();
}
private void mainMenuBoxLoad(object sender, EventArgs e)
{
@@ -1177,14 +1207,18 @@ private void changeMainLanguage(object sender, EventArgs e)
Menu_Options.DropDown.Close();
InitializeStrings();
InitializeLanguage();
Util.TranslateInterface(this, lang_val[CB_MainLanguage.SelectedIndex]); // Translate the UI to language.
string ProgramTitle = Text;
Util.TranslateInterface(this, curlanguage); // Translate the UI to language.
Text = ProgramTitle;
// Recenter PKM SubEditors
FLP_PKMEditors.Location = new Point((Tab_OTMisc.Width - FLP_PKMEditors.Width)/2, FLP_PKMEditors.Location.Y);
populateFields(pk); // put data back in form
fieldsInitialized |= alreadyInit;
// Set the culture (makes it easy to pass language to other forms)
Thread.CurrentThread.CurrentCulture = new CultureInfo(lang_val[CB_MainLanguage.SelectedIndex]);
Properties.Settings.Default.Language = curlanguage;
Properties.Settings.Default.Save();
Thread.CurrentThread.CurrentCulture = new CultureInfo(curlanguage);
Thread.CurrentThread.CurrentUICulture = Thread.CurrentThread.CurrentCulture;
}
private void InitializeStrings()

View File

@@ -183,6 +183,7 @@
<Compile Include="Saves\SAV6.cs" />
<Compile Include="Saves\SaveFile.cs" />
<Compile Include="MysteryGifts\WC6.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Subforms\PKM Editors\BatchEditor.cs">
<SubType>Form</SubType>
</Compile>

View File

@@ -1,7 +1,7 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.17929
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
@@ -12,7 +12,7 @@ namespace PKHeX.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
@@ -22,5 +22,65 @@ internal sealed partial class Settings : global::System.Configuration.Applicatio
return defaultInstance;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Language {
get {
return ((string)(this["Language"]));
}
set {
this["Language"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("")]
public string Version {
get {
return ((string)(this["Version"]));
}
set {
this["Version"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool Unicode {
get {
return ((bool)(this["Unicode"]));
}
set {
this["Unicode"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool SetUpdateDex {
get {
return ((bool)(this["SetUpdateDex"]));
}
set {
this["SetUpdateDex"] = value;
}
}
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("True")]
public bool SetUpdatePKM {
get {
return ((bool)(this["SetUpdatePKM"]));
}
set {
this["SetUpdatePKM"] = value;
}
}
}
}

View File

@@ -1,5 +1,21 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="PKHeX.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings />
<Settings>
<Setting Name="Language" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="Version" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
<Setting Name="Unicode" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="SetUpdateDex" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="SetUpdatePKM" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>

28
PKHeX/Settings.cs Normal file
View File

@@ -0,0 +1,28 @@
namespace PKHeX.Properties {
// This class allows you to handle specific events on the settings class:
// The SettingChanging event is raised before a setting's value is changed.
// The PropertyChanged event is raised after a setting's value is changed.
// The SettingsLoaded event is raised after the setting values are loaded.
// The SettingsSaving event is raised before the setting values are saved.
internal sealed partial class Settings {
public Settings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
}
private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) {
// Add code to handle the SettingChangingEvent event here.
}
private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) {
// Add code to handle the SettingsSaving event here.
}
}
}

View File

@@ -1,8 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="PKHeX.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings/>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup>
<userSettings>
<PKHeX.Properties.Settings>
<setting name="Language" serializeAs="String">
<value />
</setting>
<setting name="Version" serializeAs="String">
<value />
</setting>
<setting name="Unicode" serializeAs="String">
<value>True</value>
</setting>
<setting name="SetUpdateDex" serializeAs="String">
<value>True</value>
</setting>
<setting name="SetUpdatePKM" serializeAs="String">
<value>True</value>
</setting>
</PKHeX.Properties.Settings>
</userSettings>
</configuration>