示例#1
0
        public static void UpdateLoadGlobalContentCode()
        {
            //////////////////////Early Out////////////////////////
            if (GlueState.Self.CurrentGlueProject == null)
            {
                // early out in case Glue is closing:
                return;
            }
            ///////////////////End Early Out//////////////////////

            var classContent = GetLoadGlobalContentCode();



            string absoluteFileName = FileManager.RelativeDirectory + "GlobalContent.Generated.cs";

            bool failedSaving = false;

            try
            {
                FileWatchManager.IgnoreNextChangeOnFile(absoluteFileName);
                GlueCommands.Self.TryMultipleTimes(() =>
                                                   FileManager.SaveText(classContent.ToString(), absoluteFileName));
            }
            catch
            {
                failedSaving = true;
            }

            if (failedSaving)
            {
                Plugins.ExportedImplementations.GlueCommands.Self.PrintError("Could not save the file\n\n" + absoluteFileName);
            }

            if (ProjectManager.ProjectBase.GetItem(absoluteFileName) == null)
            {
                ProjectManager.ProjectBase.AddCodeBuildItem(absoluteFileName);
            }

            try
            {
                CodeWriter.InitializeStaticData(ProjectManager.GameClassFileName, true);
            }
            catch (CodeParseException exception)
            {
                GlueCommands.Self.PrintError(
                    "Could not add GlobalContent.Initialize to your Game class because of an error:\n\n" +
                    exception.Message);
            }
        }
示例#2
0
        public static void UnloadProject(bool isExiting)
        {
            PluginManager.ReactToGluxUnload(isExiting);

            if (!isExiting)
            {
                PluginManager.ReactToGluxClose();
            }

            if (mProjectBase != null)
            {
                mProjectBase.Unload();
            }
            mProjectBase = null;

            GlueProjectSave = null;


            foreach (var syncedProject in mSyncedProjects)
            {
                syncedProject.Unload();
            }

            mSyncedProjects.Clear();

            if (isExiting)
            {
                // If we're exiting we don't care about crashes here...especially
                // since we may have gotten here because of a missing XNA so we can't
                // initialize plugins anyway

                try
                {
                    PluginManager.Initialize(false);
                }
                catch
                {
                    // do nothing
                }
            }
            else
            {
                PluginManager.Initialize(false);
            }

            FileWatchManager.UpdateToProjectDirectory();
        }
示例#3
0
        public static void UpdateLoadGlobalContentCode()
        {
            var classContent = GetLoadGlobalContentCode();



            string absoluteFileName = FileManager.RelativeDirectory + "GlobalContent.Generated.cs";

            bool failedSaving = false;

            try
            {
                FileWatchManager.IgnoreNextChangeOnFile(absoluteFileName);
                FileManager.SaveText(classContent.ToString(), absoluteFileName);
            }
            catch
            {
                failedSaving = true;
            }


            if (failedSaving)
            {
                System.Windows.Forms.MessageBox.Show("Could not save the file\n\n" + absoluteFileName);
            }

            if (ProjectManager.ProjectBase.GetItem(absoluteFileName) == null)
            {
                ProjectManager.ProjectBase.AddCodeBuildItem(absoluteFileName);
            }

            try
            {
                CodeWriter.InitializeStaticData(ProjectManager.GameClassFileName, true);
            }
            catch (CodeParseException exception)
            {
                GlueGui.ShowMessageBox("Could not add GlobalContent.Initialize to your Game class because of an error:\n\n" + exception.Message);
            }
        }
示例#4
0
        public static void GenerateEventGeneratedFile(IElement element)
        {
            //string fileName = EventManager.GetEventFileNameForElement(element);
            //string fullCustomFileName = ProjectManager.ProjectBase.Directory + fileName;

            ////////////////// Early Out //////////////////////

            ///////////////// End Early Out////////////////////

            string projectDirectory = ProjectManager.ProjectBase.Directory;


            string fullGeneratedFileName = projectDirectory + EventManager.GetGeneratedEventFileNameForElement(element);

            ////////////////EARLY OUT///////////////
            if (element.Events.Count == 0)
            {
                // The file may exist.  If it does, we want to make sure it's empty:
                if (File.Exists(fullGeneratedFileName))
                {
                    FileWatchManager.IgnoreNextChangeOnFile(fullGeneratedFileName);
                    FileManager.SaveText("", fullGeneratedFileName);
                }


                return;
            }
            ///////////////END EARLY OUT///////////

            if (!File.Exists(fullGeneratedFileName))
            {
                CodeWriter.AddEventGeneratedCodeFileForElement(element);
            }
            else
            {
                // Make sure the file is part of the project
                GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject(ProjectManager.ProjectBase, fullGeneratedFileName, false, false);
            }

            ICodeBlock codeBlock = GenerateEventGeneratedCodeFile(element);

            // Let's try this a few times:
            int  numberOfFailures = 0;
            bool succeeded        = false;

            FileWatchManager.IgnoreNextChangeOnFile(fullGeneratedFileName);

            while (numberOfFailures < 3)
            {
                try
                {
                    FileManager.SaveText(codeBlock.ToString(), fullGeneratedFileName);
                    succeeded = true;
                    break;
                }
                catch
                {
                    numberOfFailures++;
                    System.Threading.Thread.Sleep(30);
                }
            }

            if (!succeeded)
            {
                GlueGui.ShowMessageBox("Could not save " + fullGeneratedFileName);
            }
        }
示例#5
0
        static void SaveGluxSync(bool sendMessageToRefresh)
        {
            if (ProjectManager.GlueProjectSave != null)
            {
                if (MainGlueWindow.Self.HasErrorOccurred)
                {
                    string projectName = FileManager.RemovePath(FileManager.RemoveExtension(ProjectManager.GlueProjectFileName));

                    MessageBox.Show("STOP RIGHT THERE!!!!  There was an error in Glue at some point.  To prevent " +
                                    "corruption in the GLUX file, Glue will no longer save any changes that you make to the project.  " +
                                    "You should exit out of Glue immediately and attempt to solve the problem.\n\n" +
                                    "Glue has saved your work in a temporary file called " + projectName + ".gluxERROR"
                                    );


                    ProjectManager.GlueProjectSave.Save("GLUE", ProjectManager.GlueProjectFileName + "ERROR");
                }
                else
                {
                    ProjectSyncer.SyncGlux();


                    // October 27, 2011
                    // Instead of saving
                    // directly to disk we're
                    // going to serialize to a
                    // string.  If the serialization
                    // fails, we won't try to save the
                    // file to disk.
                    try
                    {
                        ProjectManager.GlueProjectSave.TestSave("GLUE");
                    }
                    catch (Exception e)
                    {
                        string errorLogLocation = FileManager.UserApplicationDataForThisApplication + "ExceptionInGlue.txt";

                        MessageBox.Show("Error trying to save your .glux file.  Because of this error, Glue did not make any changes to the .glux file on disk.\n\nAn error log has been saved here:\n" + errorLogLocation);
                        try
                        {
                            FileManager.SaveText(e.ToString(), errorLogLocation);
                        }
                        catch
                        {
                            // If this fails that's okay, we're already in a failed state.
                        }
                        PluginManager.ReceiveError("Error saving glux:\n\n" + e.ToString());

                        MainGlueWindow.Self.HasErrorOccurred = true;
                    }

                    if (!MainGlueWindow.Self.HasErrorOccurred)
                    {
                        FileWatchManager.IgnoreNextChangeOnFile(GlueState.Self.GlueProjectFileName);

                        Exception lastException;
                        var       succeeded = ProjectManager.GlueProjectSave.Save("GLUE", GlueState.Self.GlueProjectFileName, out lastException);

                        if (!succeeded)
                        {
                            MessageBox.Show("Error saving the .glux:\n" + lastException);
                        }
                        else
                        {
                            if (sendMessageToRefresh)
                            {
                                PluginManager.ReactToGluxSave();
                            }
                        }
                    }
                }
            }
        }