private void AddProjectClick(object sender, RoutedEventArgs e) { var openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.Filter = "C# Project files (*.csproj)|*.csproj|VS Project files (*.vcproj)|*.vcproj|Android Project (*.project)|*.project"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var newProject = ProjectManager.AddSyncedProject(openFileDialog.FileName); // If newProject is null, then no project was added if (newProject != null) { ViewModel.Refresh(); } else { GlueGui.ShowMessageBox("The selected project is already a synced project."); } GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); } }
public static bool AddSyncedProjectToProjectManager(string absoluteFileName) { bool succeeded = false; if (!File.Exists(absoluteFileName)) { MessageBox.Show("Could not find the project" + absoluteFileName + ", removing project from synched project list."); } else if (FileManager.Standardize(absoluteFileName).ToLower() == FileManager.Standardize(ProjectManager.ProjectBase.FullFileName).ToLower()) { // Victor Chelaru // January 1, 2013 // One user had the // synced and main project // as the same. This screws // up Glue pretty badly. We need // to check for this and not allow // it. MessageBox.Show("A synced project is using the same file as the main project. This is not allowed. Glue will remove this synced project the synced project list."); } else { try { ProjectBase vsp = ProjectCreator.CreateProject(absoluteFileName).Project; vsp.OriginalProjectBaseIfSynced = ProjectManager.ProjectBase; vsp.Load(absoluteFileName); if (vsp.SaveAsRelativeSyncedProject == false && vsp.SaveAsAbsoluteSyncedProject == false) { vsp.SaveAsRelativeSyncedProject = true; vsp.SaveAsAbsoluteSyncedProject = false; } if (FileManager.GetDirectory(absoluteFileName).ToLower() == FileManager.GetDirectory(ProjectManager.ProjectBase.FullFileName).ToLower()) { vsp.SaveAsRelativeSyncedProject = false; vsp.SaveAsAbsoluteSyncedProject = false; } lock (ProjectManager.SyncedProjects) { ProjectManager.AddSyncedProject(vsp); } succeeded = true; } catch (Exception e) { GlueCommands.Self.PrintError($"Error loading sycned project. Glue will remove this synced project: {absoluteFileName}:\n{e.ToString()}"); } } return(succeeded); }
public static void CreateNewSyncedProject() { if (ProjectManager.ProjectBase == null) { MessageBox.Show(@"Can not create a new Synced Project because there is no open project."); return; } // Gotta find the .sln of this project so we can put the synced project in there var directory = GlueState.Self.CurrentSlnFileName?.GetDirectoryContainingThis(); Process process = NewProjectHelper.RunNewProjectCreator(directory, GlueState.Self.ProjectNamespace, creatingSyncedProject: true); if (process != null) { while (!process.HasExited) { Thread.Sleep(100); } string createdProject = GetCreatedProjectName(process); ProjectBase newProjectBase = null; if (!String.IsNullOrEmpty(createdProject)) { // The return value could be null if the project being added // already exists as a synced project, but this should never be // the case here. newProjectBase = ProjectManager.AddSyncedProject(createdProject); ProjectManager.SyncedProjects[ProjectManager.SyncedProjects.Count - 1].SaveAsRelativeSyncedProject = true; GluxCommands.Self.SaveGlux(); // These are now part of the engine, so don't do anything here. // Wait, these may be part of old templates, so let's keep this here. if (File.Exists(newProjectBase.Directory + "Screens/Screen.cs")) { newProjectBase.RemoveItem(newProjectBase.Directory + "Screens/Screen.cs"); File.Delete(newProjectBase.Directory + "Screens/Screen.cs"); } if (File.Exists(newProjectBase.Directory + "Screens/ScreenManager.cs")) { newProjectBase.RemoveItem(newProjectBase.Directory + "Screens/ScreenManager.cs"); File.Delete(newProjectBase.Directory + "Screens/ScreenManager.cs"); } // Remove Game1.cs so that it will just use the same Game1 of the master project. if (File.Exists(newProjectBase.Directory + "Game1.cs")) { newProjectBase.RemoveItem(newProjectBase.Directory + "Game1.cs"); File.Delete(newProjectBase.Directory + "Game1.cs"); } // This line is slow. Not sure why..maybe the project is saving after every file is added? // I could make it an async call but I want to figure out why it's slow at the core. newProjectBase.SyncTo(ProjectManager.ProjectBase, false); ProjectManager.SaveProjects(); } } }