Mono does not like my settings for some reason. Moved settings to my own class that loads from properties.settings. Will load/save to xml in another commit.

This commit is contained in:
Tim Young 2017-06-16 11:27:53 -05:00
parent b7bef436d2
commit 16f5c54ee9
7 changed files with 150 additions and 57 deletions

View File

@ -115,6 +115,7 @@
<DependentUpon>ListBoxWindow.cs</DependentUpon>
</Compile>
<Compile Include="NB.cs" />
<Compile Include="NBSettings.cs" />
<Compile Include="NetTest.cs" />
<Compile Include="NetTestEditor.cs">
<SubType>Form</SubType>

View File

@ -78,7 +78,8 @@ namespace EduNetworkBuilder
}
public void Add(string Text)
{
LanguageString oneString = new LanguageString(Properties.Settings.Default.ChosenLanguage,Text,tag);
NBSettings oursettings = NB.GetSettings();
LanguageString oneString = new LanguageString(oursettings.ChosenLanguage,Text,tag);
//remove duplicates
for (int i = TheStrings.Count - 1; i >= 0; i--)
{
@ -125,7 +126,8 @@ namespace EduNetworkBuilder
public string GetText()
{
return GetText(Properties.Settings.Default.ChosenLanguage);
NBSettings oursettings = NB.GetSettings();
return GetText(oursettings.ChosenLanguage);
}
}
}

View File

@ -43,6 +43,9 @@ namespace EduNetworkBuilder
tbSearchBox.Visible = true;
if (SelectedTag == NB.Translate("_All"))
Text = Text + NB.Translate("_AllS");
NBSettings oursettings = NB.GetSettings();
foreach (string str in NB.GetPuzzleTags())
{
newCB = AddCheckBox(count, str);
@ -60,7 +63,7 @@ namespace EduNetworkBuilder
btnOK.Text = NB.Translate("_Load");
btnAdd.Text = NB.Translate("_Cancel");
btnAdd.Visible = true;
cbLoadPuzzlesAtStart.Checked = Properties.Settings.Default.AutoStartPuzzles;
cbLoadPuzzlesAtStart.Checked = oursettings.AutoStartPuzzles;
UpdateForm();
}
@ -151,12 +154,11 @@ namespace EduNetworkBuilder
private string GetSelectedTag()
{
if (Properties.Settings.Default.ScoreList == null)
Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection();
PuzzleInfo PI;
string first = "";
NBSettings oursettings = NB.GetSettings();
string OriginalChoice = Properties.Settings.Default.ProcessingLevel;
string OriginalChoice = oursettings.ProcessingLevel;
if(OriginalChoice != null)
{
if (NB.PuzzleLevelHasUnsolved(OriginalChoice))
@ -165,7 +167,7 @@ namespace EduNetworkBuilder
foreach (string str in NB.GetPuzzleNames())
{
if(!Properties.Settings.Default.ScoreList.Contains(str))
if(!oursettings.ScoreList.Contains(str))
{
PI = NB.GetPuzzleInfoFromName(str);
first = "Level_" + PI.Level;
@ -222,10 +224,9 @@ namespace EduNetworkBuilder
cbLoadPuzzlesAtStart.Visible = true;
btnReset.Visible = true;
PuzzleInfo pi;
if (Properties.Settings.Default.ScoreList == null)
Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection();
string shown_name;
List<string> Puzzles = NB.GetPuzzleNames();
NBSettings oursettings = NB.GetSettings();
if (Puzzles == null) return;
foreach (string str in Puzzles)
{
@ -233,7 +234,7 @@ namespace EduNetworkBuilder
{
pi = NB.GetPuzzleInfoFromName(str);
shown_name = pi.PuzzleName;
if (Properties.Settings.Default.ScoreList.Contains(str))
if (oursettings.ScoreList.Contains(str))
shown_name = "* " + shown_name;
foreach (string tag in pi.PuzzleTags)
{
@ -250,7 +251,7 @@ namespace EduNetworkBuilder
shown_name = pi.PuzzleName;
bool added = false;
string localFilter = ".*" + FilterString + ".*";
if (Properties.Settings.Default.ScoreList.Contains(str))
if (oursettings.ScoreList.Contains(str))
shown_name = "* " + shown_name;
if (!added && pi.PuzzleName != null && Regex.IsMatch(pi.PuzzleName, localFilter, RegexOptions.IgnoreCase))
{
@ -295,6 +296,7 @@ namespace EduNetworkBuilder
private void btnOK_Click(object sender, EventArgs e)
{
NBSettings oursettings = NB.GetSettings();
if (MyMode == LBContents.puzzles && lbWindowData.SelectedItem != null)
{
string TheName = lbWindowData.SelectedItem.ToString();
@ -305,10 +307,10 @@ namespace EduNetworkBuilder
{
myWin.Activate();
}
if(Properties.Settings.Default.AutoStartPuzzles != cbLoadPuzzlesAtStart.Checked)
if(oursettings.AutoStartPuzzles != cbLoadPuzzlesAtStart.Checked)
{
Properties.Settings.Default.AutoStartPuzzles = cbLoadPuzzlesAtStart.Checked;
Properties.Settings.Default.Save();
oursettings.AutoStartPuzzles = cbLoadPuzzlesAtStart.Checked;
// oursettings.Save();
}
if (lbWindowData.SelectedItem != null)
NB.LoadNetworkFromResource(TheName);
@ -360,6 +362,7 @@ namespace EduNetworkBuilder
DebugLevel toFind;
int mycount = 0;
string labelname = "";
NBSettings oursettings = NB.GetSettings();
if (MyMode == LBContents.puzzles)
{
foreach (Control mycontrol in panelCheckboxes.Controls)
@ -376,8 +379,8 @@ namespace EduNetworkBuilder
if (mycount == 1)
{
//We only have one item checked. Store this value for later
Properties.Settings.Default.ProcessingLevel = labelname;
Properties.Settings.Default.Save();
oursettings.ProcessingLevel = labelname;
// oursettings.Save();
}
}
if (MyMode == LBContents.messages)
@ -406,16 +409,17 @@ namespace EduNetworkBuilder
private void btnAdd_Click(object sender, EventArgs e)
{
NBSettings oursettings = NB.GetSettings();
if (MyMode == LBContents.routes)
{
AddRoute();
}
if(MyMode == LBContents.puzzles)
{
if (Properties.Settings.Default.AutoStartPuzzles != cbLoadPuzzlesAtStart.Checked)
if (oursettings.AutoStartPuzzles != cbLoadPuzzlesAtStart.Checked)
{
Properties.Settings.Default.AutoStartPuzzles = cbLoadPuzzlesAtStart.Checked;
Properties.Settings.Default.Save();
oursettings.AutoStartPuzzles = cbLoadPuzzlesAtStart.Checked;
// oursettings.Save();
}
Close();
}
@ -499,13 +503,11 @@ namespace EduNetworkBuilder
private void btnReset_Click(object sender, EventArgs e)
{
if (Properties.Settings.Default.ScoreList == null)
Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection();
DialogResult answer = MessageBox.Show(NB.Translate("LBW_btnResetYouSure"), NB.Translate("LBW_btnResetForget"), MessageBoxButtons.YesNo);
if (answer == System.Windows.Forms.DialogResult.Yes)
{
Properties.Settings.Default.ScoreList.Clear();
Properties.Settings.Default.Save();
NBSettings oursettings = NB.GetSettings();
oursettings.ScoreList.Clear();
UpdateForm();
}
}

View File

@ -326,13 +326,14 @@ namespace EduNetworkBuilder
{
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
CultureInfo CI=null;
NBSettings oursettings = NB.GetSettings();
if (myWin != null)
{
CI = myWin.GetCulture();
}
if(CI == null || myWin == null)
{
string CL = Properties.Settings.Default.ChosenLanguage;
string CL = oursettings.ChosenLanguage;
CI = CultureInfo.CreateSpecificCulture(CL);
}
return CI;
@ -358,6 +359,16 @@ namespace EduNetworkBuilder
return myresource;
}
public static NBSettings GetSettings()
{
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
if (myWin != null)
{
return myWin.OurSettings;
}
return new NBSettings(); //This is only in case we are blowing up. Try to avoid that.
}
/// <summary>
/// Determine if we are using Mono or .Net. Some things get killed using Mono.
/// </summary>
@ -460,7 +471,8 @@ namespace EduNetworkBuilder
{
//Find the window. If it exists, use /set the language setting there. If not, use / set the default.
BuilderWindow myWin = (BuilderWindow)Application.OpenForms["BuilderWindow"];
string lang = Properties.Settings.Default.ChosenLanguage;
NBSettings oursettings = NB.GetSettings();
string lang = oursettings.ChosenLanguage;
if (lang == "") lang = "en";
string StartingItem = "";
@ -512,12 +524,12 @@ namespace EduNetworkBuilder
LanguageForm.ShowDialog();
if (cbQuestions.SelectedIndex >= 0)
{
Properties.Settings.Default.LanguageHasBeenChosen = true;
oursettings.LanguageHasBeenChosen = true;
string mychoice = LanguageChoices[cbQuestions.SelectedIndex, 1];
if (myWin == null)
{
Properties.Settings.Default.ChosenLanguage = mychoice;
//Properties.Settings.Default.Save(); //We do this when we exit. No need to save it right this instant.
oursettings.ChosenLanguage = mychoice;
//oursettings.Save(); //We do this when we exit. No need to save it right this instant.
}
else
{

View File

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EduNetworkBuilder
{
/// <summary>
/// We have settings that need to be loaded and saved. Mono has issues with
/// properties.settings.default stuff, so we need to load/save from an xml file
/// when we are using mono. So this class does that
/// </summary>
public class NBSettings
{
public string LastPath = "";
public List<string> ScoreList = new List<string>();
public bool AutoStartPuzzles = true;
public string ChosenLanguage = "en";
public bool LanguageHasBeenChosen = false;
public int MainWindowX = -1;
public int MainWindowY = -1;
public int MainWindowWidth = -1;
public int MainWindowHeight = -1;
public string ProcessingLevel = "none";
public NBSettings()
{
if(NB.IsRunningOnMono())
{
//Try loading from xml file
}
else
{
LastPath = Properties.Settings.Default.LastPath;
AutoStartPuzzles = Properties.Settings.Default.AutoStartPuzzles;
ChosenLanguage = Properties.Settings.Default.ChosenLanguage;
LanguageHasBeenChosen = Properties.Settings.Default.LanguageHasBeenChosen;
MainWindowX = Properties.Settings.Default.MainWindowX;
MainWindowY = Properties.Settings.Default.MainWindowY;
MainWindowHeight = Properties.Settings.Default.MainWindowHeight;
MainWindowWidth = Properties.Settings.Default.MainWindowWidth;
foreach(string one in Properties.Settings.Default.ScoreList)
{
if (!ScoreList.Contains(one))
ScoreList.Add(one);
}
}
}
public void Save()
{
if(NB.IsRunningOnMono())
{
//Save it to an XML file.
}
else
{
if (Properties.Settings.Default.ScoreList == null)
Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection();
Properties.Settings.Default.LastPath = LastPath;
Properties.Settings.Default.AutoStartPuzzles = AutoStartPuzzles;
Properties.Settings.Default.ChosenLanguage = ChosenLanguage;
Properties.Settings.Default.LanguageHasBeenChosen = LanguageHasBeenChosen;
Properties.Settings.Default.MainWindowX = MainWindowX;
Properties.Settings.Default.MainWindowY = MainWindowY;
Properties.Settings.Default.MainWindowHeight = MainWindowHeight;
Properties.Settings.Default.MainWindowWidth = MainWindowWidth;
Properties.Settings.Default.ScoreList.Clear();
foreach(string One in ScoreList)
{
Properties.Settings.Default.ScoreList.Add(One);
}
Properties.Settings.Default.Save();
}
}
}
}

View File

@ -809,12 +809,10 @@ namespace EduNetworkBuilder
PuzzleIsSolved = true;
if (PuzzleName != "" && PuzzleName != null)
{
if (Properties.Settings.Default.ScoreList == null)
Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection();
if (!Properties.Settings.Default.ScoreList.Contains(PuzzleName))
NBSettings oursettings = NB.GetSettings();
if (!oursettings.ScoreList.Contains(PuzzleName))
{
Properties.Settings.Default.ScoreList.Add(PuzzleName);
Properties.Settings.Default.Save();
oursettings.ScoreList.Add(PuzzleName);
}
}
//kill all extra windows that no longer need to be open.

View File

@ -19,6 +19,8 @@ namespace EduNetworkBuilder
public partial class BuilderWindow : Form
{
public Random GameRandomGen = new Random();
public NBSettings OurSettings = new NBSettings(); //This will auto-load the settings
private int LastPacketID=1;
public DebugPausePoint DebugSetting = DebugPausePoint.none;
// public DebugPausePoint DebugSetting = DebugPausePoint.all | DebugPausePoint.dump;
@ -30,7 +32,7 @@ namespace EduNetworkBuilder
private Point ClickedLocation;
private Point ClickedImageLocation;
DateTime LastClick = DateTime.Now;
private string LastPath = Properties.Settings.Default.LastPath;
private string LastPath = "";
private bool processing = false;
private List<PuzzleInfo> PuzzleList = new List<PuzzleInfo>();
private ResourceManager LanguageResources = null;
@ -52,7 +54,10 @@ namespace EduNetworkBuilder
public BuilderWindow()
{
InitializeComponent();
if(!Properties.Settings.Default.LanguageHasBeenChosen)
LastPath = OurSettings.LastPath;
if(!OurSettings.LanguageHasBeenChosen)
NB.ChangeLanguage();
LanguagifyComponents();
//I never implimented cut/copy/paste/undo. So we will remove them since they do nothing anyway
@ -164,7 +169,7 @@ namespace EduNetworkBuilder
{
if(LanguageCulture == null)
{
string CL = Properties.Settings.Default.ChosenLanguage;
string CL = OurSettings.ChosenLanguage;
if (CL != ChosenLanguage) ChosenLanguage = CL;
LanguageCulture = CultureInfo.CreateSpecificCulture(ChosenLanguage);
}
@ -495,14 +500,12 @@ namespace EduNetworkBuilder
public bool PuzzleLevelHasUnsolved(string LevelName)
{
if (Properties.Settings.Default.ScoreList == null)
Properties.Settings.Default.ScoreList = new System.Collections.Specialized.StringCollection();
foreach (PuzzleInfo pi in PuzzleList)
{
if ("Level_" + pi.Level.ToString() == LevelName)
{
if (!Properties.Settings.Default.ScoreList.Contains(pi.PuzzleName))
if (!OurSettings.ScoreList.Contains(pi.PuzzleName))
{
return true; //We have one puzzle in the level which has not been solved
}
@ -1430,16 +1433,8 @@ namespace EduNetworkBuilder
private void BuilderWindow_FormClosing(object sender, FormClosingEventArgs e)
{
Properties.Settings.Default.ChosenLanguage = ChosenLanguage;
Properties.Settings.Default.LastPath = LastPath;
if (WindowState == FormWindowState.Normal)
{
Properties.Settings.Default.MainWindowHeight = Height;
Properties.Settings.Default.MainWindowWidth = Width;
Properties.Settings.Default.MainWindowX = Location.X;
Properties.Settings.Default.MainWindowY = Location.Y;
}
Properties.Settings.Default.Save();
//The values in the settings are all up-to-date. Just tell them to save.
OurSettings.Save();
}
private void dHCPRequestToolStripMenuItem_Click(object sender, EventArgs e)
@ -1582,14 +1577,15 @@ namespace EduNetworkBuilder
private void BuilderWindow_Load(object sender, EventArgs e)
{
if (Properties.Settings.Default.MainWindowX != -1 && Properties.Settings.Default.MainWindowY != -1)
if (OurSettings.MainWindowX != -1 && OurSettings.MainWindowY != -1)
{
Location = new Point(Properties.Settings.Default.MainWindowX, Properties.Settings.Default.MainWindowY);
Location = new Point(OurSettings.MainWindowX, OurSettings.MainWindowY);
}
if (Properties.Settings.Default.MainWindowHeight != -1 && Properties.Settings.Default.MainWindowWidth != -1)
if (OurSettings.MainWindowHeight != -1 && OurSettings.MainWindowWidth != -1)
{
Height = Properties.Settings.Default.MainWindowHeight;
Width = Properties.Settings.Default.MainWindowWidth;
Height = OurSettings.MainWindowHeight;
Width = OurSettings.MainWindowWidth;
}
//If we started by clicking on a file, load that file
if (AppDomain.CurrentDomain.SetupInformation.ActivationArguments != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData != null && AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData.Any())
@ -1610,7 +1606,7 @@ namespace EduNetworkBuilder
}
else
{
if (Properties.Settings.Default.AutoStartPuzzles)
if (OurSettings.AutoStartPuzzles)
{
//We are supposed to start the puzzle-selection box
puzzlesToolStripMenuItem_Click(null, null);
@ -1702,7 +1698,7 @@ namespace EduNetworkBuilder
DialogResult answer = MessageBox.Show(NB.Translate("NB_ChngLngClose"),NB.Translate("NB_ChngLngSure"),MessageBoxButtons.YesNoCancel);
if (answer == System.Windows.Forms.DialogResult.Yes)
{
Properties.Settings.Default.LanguageHasBeenChosen = false; //So we choose the language on restart
OurSettings.LanguageHasBeenChosen = false; //So we choose the language on restart
//System.Diagnostics.Process.Start(Application.ExecutablePath); // to start new instance of application
this.Close(); //to turn off current app
}