private static bool DetermineIfShouldLoad(string projectFileName) { bool shouldLoad = true; // see if this project references any plugins that aren't installed: var glueFileName = FileManager.RemoveExtension(projectFileName) + ".glux"; if (System.IO.File.Exists(glueFileName)) { try { var tempGlux = GlueProjectSaveExtensions.Load(glueFileName); var requiredPlugins = tempGlux.PluginData.RequiredPlugins; List <string> individualPluginMessages = new List <string>(); foreach (var requiredPlugin in requiredPlugins) { var matchingPlugin = PluginManager.AllPluginContainers.FirstOrDefault(item => item.Name == requiredPlugin.Name); if (matchingPlugin == null) { individualPluginMessages.Add(requiredPlugin.Name); } else { switch (requiredPlugin.VersionRequirement) { case VersionRequirement.EqualToOrNewerThan: bool isNewerOrEqual = matchingPlugin.Plugin.Version >= new Version(requiredPlugin.Version); if (!isNewerOrEqual) { individualPluginMessages.Add($"{requiredPlugin.Name} must be updated\n\t{requiredPlugin.Version} required\n\t{matchingPlugin.Plugin.Version} installed"); } break; default: // eventually fill in the rest throw new NotImplementedException(); //break; } } } string missingPluginMessage = null; if (individualPluginMessages.Count != 0) { missingPluginMessage = $"The project {glueFileName} requires the following plugins:\n"; foreach (var item in individualPluginMessages) { missingPluginMessage += "\n" + item; } missingPluginMessage += "\n\nWould you like to load the project anyway? It may not run, or may run incorrectly until all plugins are installed/updated."; } if (!string.IsNullOrEmpty(missingPluginMessage)) { var result = MessageBox.Show(missingPluginMessage, "Missing Plugins", MessageBoxButtons.YesNo); shouldLoad = result == DialogResult.Yes; } } catch (Exception e) { GlueGui.ShowMessageBox($"Could not load .glux file {glueFileName}. Error:\n\n{e.ToString()}"); shouldLoad = false; } } return(shouldLoad); }
private bool DeserializeGluxXmlInternal(string projectFileName, string glueProjectFile) { bool succeeded = true; try { ProjectManager.GlueProjectSave = GlueProjectSaveExtensions.Load(glueProjectFile); string errors; ProjectManager.GlueProjectSave.PostLoadInitialize(out errors); if (errors != null) { GlueGui.ShowMessageBox(errors); } } catch (Exception e) { MultiButtonMessageBox mbmb = new MultiButtonMessageBox(); mbmb.MessageText = "There was an error loading the .glux file. What would you like to do?"; mbmb.AddButton("Nothing - Glue will abort loading the project.", DialogResult.None); mbmb.AddButton("See the Exception", DialogResult.OK); mbmb.AddButton("Try loading again", DialogResult.Retry); mbmb.AddButton("Test for conflicts", DialogResult.Yes); DialogResult result = mbmb.ShowDialog(MainGlueWindow.Self); mCurrentInitWindow.Close(); switch (result) { case DialogResult.None: // Do nothing; break; case DialogResult.OK: MessageBox.Show(e.ToString()); break; case DialogResult.Retry: LoadProject(projectFileName); break; case DialogResult.Yes: string text = FileManager.FromFileText(glueProjectFile); if (text.Contains("<<<")) { MessageBox.Show("There are conflicts in your GLUX file. You will need to use a merging " + "tool or text editor to resolve these conflicts."); } else { MessageBox.Show("No Subversion conflicts found in your GLUX."); } break; } succeeded = false; } return(succeeded); }
public void LoadProject(string projectFileName, InitializationWindow initializationWindow) { TimeManager.Initialize(); var topSection = Section.GetAndStartContextAndTime("All"); ////////////////// EARLY OUT!!!!!!!!! if (!File.Exists(projectFileName)) { GlueGui.ShowException("Could not find the project " + projectFileName + "\n\nOpening Glue without a project.", "Error Loading Project", null); return; } //////////////////// End EARLY OUT//////////////////////////////// FileWatchManager.PerformFlushing = false; bool closeInitWindow = PrepareInitializationWindow(initializationWindow); ClosePreviousProject(projectFileName); SetInitWindowText("Loading code project"); ProjectManager.ProjectBase = ProjectCreator.CreateProject(projectFileName); bool shouldLoad = true; if (ProjectManager.ProjectBase == null) { DialogResult result = MessageBox.Show( "The project\n\n" + projectFileName + "\n\nis an unknown project type. Would you like more " + "info on how to fix this problem?", "Unknown Project Type", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { System.Diagnostics.Process.Start("http://www.flatredball.com/frb/docs/index.php?title=Glue:Reference:Projects:csproj_File"); } shouldLoad = false; } // see if this project references any plugins that aren't installed: var glueFileName = FileManager.RemoveExtension(projectFileName) + ".glux"; if (System.IO.File.Exists(glueFileName)) { try { var tempGlux = GlueProjectSaveExtensions.Load(glueFileName); var requiredPlugins = tempGlux.PluginData.RequiredPlugins; List <string> missingPlugins = new List <string>(); foreach (var requiredPlugin in requiredPlugins) { if (PluginManager.AllPluginContainers.Any(item => item.Name == requiredPlugin) == false) { missingPlugins.Add(requiredPlugin); } } if (missingPlugins.Count != 0) { var message = $"The project {glueFileName} requires the following plugins:"; foreach (var item in missingPlugins) { message += "\n" + item; } message += "\nWould you like to load the project anyway? It may not run, or may run incorrectly until all plugins are installed."; var result = MessageBox.Show(message, "Missing Plugins", MessageBoxButtons.YesNo); shouldLoad = result == DialogResult.Yes; } } catch (Exception e) { GlueGui.ShowMessageBox($"Could not load .glux file {glueFileName}. Error:\n\n{e.ToString()}"); shouldLoad = false; } } if (shouldLoad) { ProjectManager.ProjectBase.Load(projectFileName); SetInitWindowText("Finding Game class"); FileWatchManager.UpdateToProjectDirectory(); FileManager.RelativeDirectory = FileManager.GetDirectory(projectFileName); // this will make other threads work properly: FileManager.DefaultRelativeDirectory = FileManager.RelativeDirectory; ElementViewWindow.AddDirectoryNodes(); #region Load the GlueProjectSave file if one exists string glueProjectFile = ProjectManager.GlueProjectFileName; bool shouldSaveGlux = false; if (!FileManager.FileExists(glueProjectFile)) { ProjectManager.GlueProjectSave = new GlueProjectSave(); // temporary - eventually this will just be done in the .glux itself Plugins.EmbeddedPlugins.CameraPlugin.CameraMainPlugin.CreateGlueProjectSettingsFor(ProjectManager.GlueProjectSave); ProjectManager.FindGameClass(); GluxCommands.Self.SaveGlux(); // no need to do this - will do it in PerformLoadGlux: //PluginManager.ReactToLoadedGlux(ProjectManager.GlueProjectSave, glueProjectFile); //shouldSaveGlux = true; //// There's not a lot of code to generate so we can do it on the main thread //// so we get the save to occur after //GlueCommands.Self.GenerateCodeCommands.GenerateAllCodeSync(); //ProjectManager.SaveProjects(); } PerformGluxLoad(projectFileName, glueProjectFile); #endregion SetInitWindowText("Cleaning extra Screens and Entities"); foreach (ScreenTreeNode screenNode in ElementViewWindow.AllScreens) { if (screenNode.ScreenSave == null) { ScreenSave screenSave = new ScreenSave(); screenSave.Name = screenNode.Text; ProjectManager.GlueProjectSave.Screens.Add(screenSave); screenNode.ScreenSave = screenSave; } } foreach (EntityTreeNode entityNode in ElementViewWindow.AllEntities) { if (entityNode.EntitySave == null) { EntitySave entitySave = new EntitySave(); entitySave.Name = entityNode.Text; entitySave.Tags.Add("GLUE"); entitySave.Source = "GLUE"; ProjectManager.GlueProjectSave.Entities.Add(entitySave); entityNode.EntitySave = entitySave; } } UnreferencedFilesManager.Self.RefreshUnreferencedFiles(true); MainGlueWindow.Self.Text = "FlatRedBall Glue - " + projectFileName; MainGlueWindow.Self.SaveRecentProject(projectFileName); if (shouldSaveGlux) { GluxCommands.Self.SaveGlux(); } TaskManager.Self.AddSync(GlueCommands.Self.ProjectCommands.SaveProjects, "Save all projects"); FileWatchManager.PerformFlushing = true; FileWatchManager.FlushAndClearIgnores(); } if (closeInitWindow) { mCurrentInitWindow.Close(); } Section.EndContextAndTime(); // If we ever want to make things go faster, turn this back on and let's see what's going on. //topSection.Save("Sections.xml"); }