private static void TryToRemoveInvalidState(this GlueProjectSave glueProjectSave, bool showPopupsOnFixedErrors, IElement containingElement, NamedObjectSave nos) { if (nos.SourceType == SourceType.Entity && !string.IsNullOrEmpty(nos.SourceClassType) && !string.IsNullOrEmpty(nos.CurrentState)) { EntitySave foundEntitySave = glueProjectSave.GetEntitySave(nos.SourceClassType); if (foundEntitySave != null) { bool hasFoundState = false; hasFoundState = foundEntitySave.GetStateRecursively(nos.CurrentState) != null; if (!hasFoundState) { if (showPopupsOnFixedErrors) { MessageBox.Show("The Object " + nos.InstanceName + " in " + containingElement.Name + " uses the invalid state " + nos.CurrentState + "\nRemoving this current State"); } nos.CurrentState = null; } } } }
public static void PostLoadInitialize(this GlueProjectSave glueProjectSave, out string errors) { errors = null; foreach (ScreenSave screenSave in glueProjectSave.Screens) { try { screenSave.PostLoadInitialize(); } catch (Exception e) { errors += "Error post-initialize in Screen " + screenSave.Name + ": " + e.Message; } } foreach (EntitySave entitySave in glueProjectSave.Entities) { try { entitySave.PostLoadInitialize(); } catch (Exception e) { errors += "Error post-initialize in Screen " + entitySave.Name + ": " + e.Message; } } }
private static void Merge(this GlueProjectSave origSave, GlueProjectSave newSave) { //Entities foreach (var entitySave in newSave.Entities) { var save = entitySave; if (origSave.Entities.All(t => t.Name != save.Name)) { origSave.Entities.Add(save); } else { //Do stuff for when it already exists } } //Screens foreach (var screenSave in newSave.Screens) { var save = screenSave; if (origSave.Screens.All(t => t.Name != save.Name)) { origSave.Screens.Add(save); } else { //Do stuff for when it already exists } } }
private static GlueProjectSave ConvertToPartial(this GlueProjectSave glueProjectSave, string tag) { GlueProjectSave returnValue; if (tag == "GLUE") { //Remove other elements returnValue = glueProjectSave.Clone(); //Entities returnValue.Entities.RemoveAll(t => !t.Tags.Contains(tag) && t.Tags.Count != 0); //Screens returnValue.Screens.RemoveAll(t => !t.Tags.Contains(tag) && t.Tags.Count != 0); } else { returnValue = new GlueProjectSave(); //Entities returnValue.Entities.RemoveAll(t => !t.Tags.Contains(tag)); //Screens returnValue.Screens.RemoveAll(t => !t.Tags.Contains(tag)); } return returnValue; }
private static void FixEmptyReferencedFileSaves(this GlueProjectSave instance, bool showPopupsOnFixedErrors) { Parallel.ForEach(instance.Entities, (entitySave) => //foreach (EntitySave entitySave in instance.Entities) { for (int i = entitySave.ReferencedFiles.Count - 1; i > -1; i--) { ReferencedFileSave rfs = entitySave.ReferencedFiles[i]; if (string.IsNullOrEmpty(rfs.Name)) { PluginManager.ReceiveOutput("Removing an empty file from " + entitySave.ToString()); entitySave.ReferencedFiles.RemoveAt(i); } } }); Parallel.ForEach(instance.Screens, (screen) => //foreach (ScreenSave screen in instance.Screens) { for (int i = screen.ReferencedFiles.Count - 1; i > -1; i--) { ReferencedFileSave rfs = screen.ReferencedFiles[i]; if (string.IsNullOrEmpty(rfs.Name)) { PluginManager.ReceiveOutput("Removing an empty file from " + screen.ToString()); screen.ReferencedFiles.RemoveAt(i); } } }); }
public static bool Save(this GlueProjectSave glueProjectSave, string tag, string fileName, out Exception lastException) { int failures = 0; // This gives Glue 2 chances to save....but not like weekend sales at RC Willey const int maxFailures = 3; bool succeeded = false; lastException = null; while (failures < maxFailures) { try { glueProjectSave.SaveToFile(fileName, tag); succeeded = true; break; } catch (IOException ioe) { lastException = ioe; System.Threading.Thread.Sleep(200); failures++; } catch (UnauthorizedAccessException uae) { lastException = uae; System.Threading.Thread.Sleep(200); failures++; } } return(succeeded); }
private static GlueProjectSave MarkTags(this GlueProjectSave origSave, string tag) { //Entities foreach (var entitySave in origSave.Entities) { entitySave.Source = tag; entitySave.Tags.Clear(); entitySave.Tags.Add(tag); // Eventually need to add this //foreach (var rfs in entitySave.ReferencedFiles) //{ // rfs.Tags.Clear(); // rfs.Tags.Add(tag); //} } //Screens foreach (var screenSave in origSave.Screens) { screenSave.Source = tag; screenSave.Tags.Clear(); screenSave.Tags.Add(tag); } return(origSave); }
public static void FixReferencedFileErrors(this GlueProjectSave instance, bool showPopupsOnFixedErrors) { List <ReferencedFileSave> rfsList = null; foreach (EntitySave entitySave in instance.Entities) { rfsList = entitySave.ReferencedFiles; instance.FixReferencedFileBackSlash(rfsList); } foreach (ScreenSave screenSave in instance.Screens) { rfsList = screenSave.ReferencedFiles; instance.FixReferencedFileBackSlash(rfsList); } rfsList = instance.GlobalFiles; instance.FixReferencedFileBackSlash(rfsList); //The methods below should be broken up and moved above //to improve performance. instance.FixEmptyReferencedFileSaves(showPopupsOnFixedErrors); instance.FixReferencedFileSaveContentPipelineSettings(); }
private static void SaveToFile(this GlueProjectSave glueProjectSave, string fileName, string tag) { var toSave = glueProjectSave.ConvertToPartial(tag); string convertedFileName = fileName.ConvertToPartialName(tag); FileManager.XmlSerialize(toSave, convertedFileName); }
public GlueProjectSave ToGlueProjectSave(ArrowProjectSave arrowProject) { GlueProjectSave toReturn = new GlueProjectSave(); ArrowElementToGlueConverter elementToElementConverter = new ArrowElementToGlueConverter(); foreach (var element in arrowProject.Elements) { IElement glueElement = elementToElementConverter.ToGlueIElement(element); if (glueElement is ScreenSave) { toReturn.Screens.Add(glueElement as ScreenSave); } else { toReturn.Entities.Add(glueElement as EntitySave); } } return toReturn; }
private static GlueProjectSave ConvertToPartial(this GlueProjectSave glueProjectSave, string tag) { GlueProjectSave returnValue; if (tag == "GLUE") { //Remove other elements returnValue = glueProjectSave.Clone(); //Entities returnValue.Entities.RemoveAll(t => !t.Tags.Contains(tag) && t.Tags.Count != 0); //Screens returnValue.Screens.RemoveAll(t => !t.Tags.Contains(tag) && t.Tags.Count != 0); } else { returnValue = new GlueProjectSave(); //Entities returnValue.Entities.RemoveAll(t => !t.Tags.Contains(tag)); //Screens returnValue.Screens.RemoveAll(t => !t.Tags.Contains(tag)); } return(returnValue); }
public static void TestSave(this GlueProjectSave glueProjectSave, string tag) { string serializedToString; var whatToSave = glueProjectSave.ConvertToPartial(tag); FileManager.XmlSerialize(whatToSave, out serializedToString); }
public static void FixNamedObjects(this GlueProjectSave instance) { instance.SearchForDuplicateNamedObjects(); instance.FixBackSlashSourcefiles(); instance.FixAttachmentProperties(); }
public static void FixAttachmentProperties(this GlueProjectSave instance) { foreach (EntitySave entitySave in instance.Entities) { foreach (var nos in entitySave.NamedObjects) { nos.AttachToCamera = false; } } }
static void VerifyAllElementsCustomCodeIsPartOfProject(this GlueProjectSave instance) { foreach (var screen in instance.Screens) { VerifyElementMembershipInProject(screen); } foreach (var entity in instance.Entities) { VerifyElementMembershipInProject(entity); } }
public static IEnumerable <IElement> AllElements(this GlueProjectSave instance) { foreach (ScreenSave screen in instance.Screens) { yield return(screen); } foreach (EntitySave entity in instance.Entities) { yield return(entity); } }
public static void FixEnumerationValues(this GlueProjectSave instance) { foreach (EntitySave entitySave in instance.Entities) { entitySave.FixEnumerationValues(); } foreach (ScreenSave screen in instance.Screens) { screen.FixEnumerationValues(); } }
public GlueProjectSave ToGlueProjectSave(GumProjectSave gumProjectSave, string gluxFolder) { mGluxFolder = gluxFolder; mGumProjectSave = gumProjectSave; mInstanceToNos.GumProjectSave = mGumProjectSave; GlueProjectSave toReturn = new GlueProjectSave(); mGlueProjectSave = toReturn; var copiedFiles = CopyExternalFilesToProjects(); AddScreensAndEntities(copiedFiles); return toReturn; }
public static void CleanUnusedVariablesFromStates(this GlueProjectSave instance) { Parallel.ForEach(instance.Entities, (entitySave) => { //foreach (EntitySave entitySave in instance.Entities) //{ entitySave.CleanUnusedVariablesFromStates(); }); Parallel.ForEach(instance.Screens, (screen) => //foreach (ScreenSave screen in instance.Screens) { screen.CleanUnusedVariablesFromStates(); }); }
public static void SearchForDuplicateEntities(this GlueProjectSave instance) { Dictionary <string, EntitySave> entitiesVisited = new Dictionary <string, EntitySave>(); foreach (EntitySave entitySave in instance.Entities) { if (entitiesVisited.ContainsKey(entitySave.Name)) { MessageBox.Show("The GLUX file contains duplicate entires for\n\n" + entitySave.Name + "\n\nYou should close Glue, open the GLUX in a text editor, remove one of the duplicates, then save the GLUX file"); } else { entitiesVisited.Add(entitySave.Name, entitySave); } } }
public static void FixErrors(this GlueProjectSave instance, bool showPopupsOnFixedErrors) { instance.SortScreens(); instance.CleanUnusedVariablesFromStates(); instance.FixReferencedFileErrors(showPopupsOnFixedErrors); // We do this in Glue in a separate step - do we want to do it here too? //instance.FixEnumerationValues(); instance.FixNamedObjects(); instance.SearchForDuplicateEntities(); instance.VerifyAllElementsCustomCodeIsPartOfProject(); }
public static void RemoveInvalidStatesFromNamedObjects(this GlueProjectSave glueProjectSave, bool showPopupsOnFixedErrors) { foreach (EntitySave entitySave in glueProjectSave.Entities) { foreach (NamedObjectSave nos in entitySave.NamedObjects) { glueProjectSave.TryToRemoveInvalidState(showPopupsOnFixedErrors, entitySave, nos); } } foreach (ScreenSave screenSave in glueProjectSave.Screens) { foreach (NamedObjectSave nos in screenSave.NamedObjects) { glueProjectSave.TryToRemoveInvalidState(showPopupsOnFixedErrors, screenSave, nos); } } }
public static void FixReferencedFileSaveContentPipelineSettings(this GlueProjectSave instance) { Parallel.ForEach(instance.Entities, (entitySave) => //foreach (EntitySave entitySave in instance.Entities) { List <ReferencedFileSave> rfsList = entitySave.ReferencedFiles; FixRfsListContentPipelineSetting(rfsList); }); Parallel.ForEach(instance.Screens, (screenSave) => //foreach (ScreenSave screenSave in instance.Screens) { List <ReferencedFileSave> rfsList = screenSave.ReferencedFiles; FixRfsListContentPipelineSetting(rfsList); }); FixRfsListContentPipelineSetting(instance.GlobalFiles); }
private static void SearchForDuplicateNamedObjects(this GlueProjectSave instance) { #if GLUE List <string> names = new List <string>(); foreach (EntitySave entitySave in instance.Entities) { names.Clear(); foreach (NamedObjectSave nos in entitySave.NamedObjects) { if (names.Contains(nos.InstanceName)) { MessageBox.Show("There are two objects named " + nos.InstanceName + " in the entity " + entitySave.ToString(), "Duplicate object name found"); } else { names.Add(nos.InstanceName); } } } foreach (ScreenSave screenSave in instance.Screens) { names.Clear(); foreach (NamedObjectSave nos in screenSave.NamedObjects) { if (names.Contains(nos.InstanceName)) { MessageBox.Show("There are two objects named " + nos.InstanceName + " in the entity " + screenSave.ToString(), "Duplicate object name found"); } else { names.Add(nos.InstanceName); } } } #endif }
public static CompareObjects ReloadUsingComparison(this GlueProjectSave instance, string fileName, out GlueProjectSave otherGlueProjectSave) { bool succeeded = true; // try loading multiple times just in case the file is being written by another application int timesTried = 0; int maxTries = 5; otherGlueProjectSave = null; while (timesTried < maxTries) { try { // When we load this thing, we need to have all of its variables // prepared for runtime. This means things like fixing enumerations, // which requires usage of the ObjectFinder. Therefore we need to tell // the ObjectFinder to use this GlueProjectSave, do the initializeation, then // go back to the old one. otherGlueProjectSave = GlueProjectSaveExtensions.Load(fileName); GlueProjectSave savedOld = ObjectFinder.Self.GlueProject; ObjectFinder.Self.GlueProject = otherGlueProjectSave; otherGlueProjectSave.FixEnumerationValues(); ObjectFinder.Self.GlueProject = savedOld; break; } catch (Exception e) { timesTried++; if (timesTried < maxTries) { System.Threading.Thread.Sleep(25); } else { MessageBox.Show("There was an error loading the .glux:\n\n" + e.ToString()); otherGlueProjectSave = null; succeeded = false; } } } if (succeeded) { CompareObjects compareObjects = new CompareObjects(); compareObjects.ElementsToIgnore.Add("TypedMembers"); compareObjects.ElementsToIgnore.Add("UsesTranslation"); compareObjects.ElementsToIgnore.Add("ContainerType"); compareObjects.ElementsToIgnore.Add("ImageWidth"); compareObjects.ElementsToIgnore.Add("ImageHeight"); compareObjects.ElementsToIgnore.Add("EquilibriumParticleCount"); compareObjects.ElementsToIgnore.Add("BurstParticleCount"); compareObjects.ElementsToIgnore.Add("RuntimeType"); compareObjects.ElementsToIgnore.Add("EventSave"); compareObjects.ElementsToIgnore.Add("SharedCodeFullFileName"); compareObjects.AttributesToIgnore.Add(typeof(XmlIgnoreAttribute)); compareObjects.MaxDifferences = int.MaxValue; if (!compareObjects.Compare(instance, otherGlueProjectSave)) { int m = 3; return(compareObjects); } else { return(null); } } else { return(null); } }
internal static void ReactToLoadedGluxEarly(GlueProjectSave glueProjectSave) { SaveRelativeDirectory(); foreach (PluginManager pluginManager in mInstances) { // Execute the new style plugins var plugins = pluginManager.ImportedPlugins.Where(x => x.ReactToLoadedGluxEarly != null); foreach (var plugin in plugins) { var container = pluginManager.mPluginContainers[plugin]; if (container.IsEnabled) { PluginBase plugin1 = plugin; PluginCommand(() => { plugin1.ReactToLoadedGluxEarly(); }, container, "Failed in ReactToLoadedGluxEarly"); } } } ResumeRelativeDirectory("ReactToLoadedGluxEarly"); }
private static IElement GetElementFromObjectString(string element, GlueProjectSave glueProjectSave, out int index) { Regex regex = new Regex(@"(Screens)\[[0-9]+\]"); Match match = regex.Match(element); if (match != Match.Empty && match.Groups.Count > 1 && match.Groups[1].Value == "Screens") { string matchRegex = @"Screens\[([0-9]+)\]"; string indexAsString = Regex.Match(element, matchRegex).Groups[1].Value; index = int.Parse(indexAsString); return glueProjectSave.Screens[index]; } //string screenOrEntity = regex = new Regex(@"(Entities)\[[0-9]+\]"); match = regex.Match(element); if (match != Match.Empty && match.Groups.Count > 1 && match.Groups[1].Value == "Entities") { string matchRegex = @"Entities\[([0-9]+)\]"; string indexAsString = Regex.Match(element, matchRegex).Groups[1].Value; index = int.Parse(indexAsString); return glueProjectSave.Entities[index]; } index = -1; return null; }
private static GlueProjectSave Clone(this GlueProjectSave obj) { var toReturn = FileManager.CloneObject(obj); return(toReturn); }
internal static void ReactToLoadedGlux(GlueProjectSave glueProjectSave, string fileName, Action<string> displayCurrentStatusMethod) { SaveRelativeDirectory(); foreach (PluginManager pluginManager in mInstances) { foreach (IGluxLoad plugin in pluginManager.GluxLoadPlugins) { PluginContainer container = pluginManager.mPluginContainers[plugin]; if (container.IsEnabled) { displayCurrentStatusMethod?.Invoke("Notifying " + container.Name + " of startup..."); IGluxLoad plugin1 = plugin; PluginCommand(() => { plugin1.ReactToGluxLoad(glueProjectSave, fileName); },container, "Failed in ReactToGluxLoad"); } } // Execute the new style plugins var plugins = pluginManager.ImportedPlugins.Where(x => x.ReactToLoadedGlux != null); foreach (var plugin in plugins) { var container = pluginManager.mPluginContainers[plugin]; if (container.IsEnabled) { displayCurrentStatusMethod?.Invoke("Notifying " + container.Name + " of startup..."); PluginBase plugin1 = plugin; PluginCommand(() => { plugin1.ReactToLoadedGlux(); }, container, "Failed in ReactToLoadedGlux"); } } } ResumeRelativeDirectory("ReactToLoadedGlux"); }
public static void Save(this GlueProjectSave glueprojectsave, string tag, string fileName) { glueprojectsave.SaveToFile(fileName, tag); }
public void ReactToGluxLoad(GlueProjectSave newGlux, string fileName) { //MessageBox.Show("Loaded " + fileName + " and it has this many Entities " + newGlux.Entities.Count); }
internal static void GenerateAllCustomClasses(GlueProjectSave glueProject) { foreach (var customClass in glueProject.CustomClasses) { GenerateCustomClass(customClass); } }
public static CompareObjects ReloadUsingComparison(this GlueProjectSave instance, string fileName, out GlueProjectSave otherGlueProjectSave) { bool succeeded = true; // try loading multiple times just in case the file is being written by another application int timesTried = 0; int maxTries = 5; otherGlueProjectSave = null; while (timesTried < maxTries) { try { // When we load this thing, we need to have all of its variables // prepared for runtime. This means things like fixing enumerations, // which requires usage of the ObjectFinder. Therefore we need to tell // the ObjectFinder to use this GlueProjectSave, do the initializeation, then // go back to the old one. otherGlueProjectSave = GlueProjectSaveExtensions.Load(fileName); GlueProjectSave savedOld = ObjectFinder.Self.GlueProject; ObjectFinder.Self.GlueProject = otherGlueProjectSave; otherGlueProjectSave.FixEnumerationValues(); ObjectFinder.Self.GlueProject = savedOld; break; } catch (Exception e) { timesTried++; if (timesTried < maxTries) { System.Threading.Thread.Sleep(25); } else { MessageBox.Show("There was an error loading the .glux:\n\n" + e.ToString()); otherGlueProjectSave = null; succeeded = false; } } } if (succeeded) { CompareObjects compareObjects = new CompareObjects(); compareObjects.ElementsToIgnore.Add("TypedMembers"); compareObjects.ElementsToIgnore.Add("UsesTranslation"); compareObjects.ElementsToIgnore.Add("ContainerType"); compareObjects.ElementsToIgnore.Add("ImageWidth"); compareObjects.ElementsToIgnore.Add("ImageHeight"); compareObjects.ElementsToIgnore.Add("EquilibriumParticleCount"); compareObjects.ElementsToIgnore.Add("BurstParticleCount"); compareObjects.ElementsToIgnore.Add("RuntimeType"); compareObjects.ElementsToIgnore.Add("EventSave"); compareObjects.ElementsToIgnore.Add("SharedCodeFullFileName"); compareObjects.AttributesToIgnore.Add(typeof(XmlIgnoreAttribute)); compareObjects.MaxDifferences = int.MaxValue; if (!compareObjects.Compare(instance, otherGlueProjectSave)) { int m = 3; return compareObjects; } else { return null; } } else { return null; } }