diff --git a/EduNetworkBuilder/NB.cs b/EduNetworkBuilder/NB.cs index 34caea2..963bf60 100644 --- a/EduNetworkBuilder/NB.cs +++ b/EduNetworkBuilder/NB.cs @@ -1372,6 +1372,43 @@ namespace EduNetworkBuilder reader.Close(); } } + + /// + /// Reads an object instance from an XML resource. + /// Object type must have a parameterless constructor. + /// + /// The type of object to read from the file. + /// The name of the resource to use. + /// Returns a new instance of the object read from the XML resource. + public static T ReadFromXmlResource(string resource) where T : new() + { + System.Reflection.Assembly MyAssembly; + BuilderWindow tWin = GetBuilderWin(); + MyAssembly = tWin.GetType().Assembly; + + // Creates the ResourceManager. + System.Resources.ResourceManager myManager = new + System.Resources.ResourceManager("EduNetworkBuilder.Properties.Resources", + MyAssembly); + + // Retrieves String and Image resources. + //System.String myString; + byte[] item = Encoding.UTF8.GetBytes((string)myManager.GetObject(resource)); + // myString = new StreamReader(new MemoryStream(item), true).ReadToEnd(*/); + //myString = System.Text.Encoding.Default.GetString(item); + + //TextReader reader = null; + try + { + var serializer = new XmlSerializer(typeof(T)); + return (T)serializer.Deserialize(new MemoryStream(item)); + } + catch(Exception e) + { + MessageBox.Show(e.ToString()); + } + return default(T); + } #endregion #region ActionFunctions diff --git a/EduNetworkBuilder/NBSettings.cs b/EduNetworkBuilder/NBSettings.cs index 183e545..d48a808 100644 --- a/EduNetworkBuilder/NBSettings.cs +++ b/EduNetworkBuilder/NBSettings.cs @@ -38,7 +38,7 @@ namespace EduNetworkBuilder public string FormLastTransDir = ""; protected ActionCollection UserActions = new ActionCollection(); [XmlIgnore] - public bool ReplayMode = true; //Whether or not we are able to do replays + public bool ReplayMode = false; //Whether or not we are able to do replays public NBSettings() { @@ -96,7 +96,6 @@ namespace EduNetworkBuilder if (!ToClass.RecentFiles.Contains(one)) ToClass.RecentFiles.Add(one); } - } public NBSettings(bool UsingMono) @@ -159,6 +158,12 @@ namespace EduNetworkBuilder } } + public void LoadReplays() + { + ReplayMode = true; + UserActions = NB.ReadFromXmlResource("EduNetworkReplay"); + } + public bool CheckIfDone(string PuzzleName) { //we just mark it in the settings class diff --git a/EduNetworkBuilder/NetworkBuilder.cs b/EduNetworkBuilder/NetworkBuilder.cs index a5a130b..915a6f5 100644 --- a/EduNetworkBuilder/NetworkBuilder.cs +++ b/EduNetworkBuilder/NetworkBuilder.cs @@ -2856,6 +2856,8 @@ namespace EduNetworkBuilder replayToolStripMenuItem.Visible = false; storeReplayToolStripMenuItem.Visible = false; saveReplayToolStripMenuItem.Visible = false; + if (OurSettings.ReplayMode == false && ModifierKeys == Keys.Control) + OurSettings.LoadReplays(); if (OurSettings != null && OurSettings.ReplayMode) {