Exemplo n.º 1
0
        public override bool GetIfIsFixed()
        {
            var isFixed = false;

            if (AbsoluteMissingFile.Exists())
            {
                isFixed = true;
            }

            if (!isFixed)
            {
                bool isReferencedByElement = ReferencedFileSave.GetContainer() != null;
                bool isGlobalContent       = false;

                if (!isReferencedByElement)
                {
                    isGlobalContent = GlueState.Self.CurrentGlueProject.GetAllReferencedFiles().Contains(ReferencedFileSave);
                }

                if (!isReferencedByElement && !isGlobalContent)
                {
                    // the RFS has been removed
                    isFixed = true;
                }
            }

            return(isFixed);
        }
Exemplo n.º 2
0
        public bool IfReferencedFileSaveIsReferenced(ReferencedFileSave referencedFileSave)
        {
            IElement container = referencedFileSave.GetContainer();

            bool isContained = false;

            if (container != null)
            {
                isContained = container.GetAllReferencedFileSavesRecursively().Contains(referencedFileSave);
            }
            else
            {
                isContained = ProjectManager.GlueProjectSave.GlobalFiles.Contains(referencedFileSave);
            }

            return(isContained);
        }
Exemplo n.º 3
0
        public TreeNode ReferencedFileSaveTreeNode(ReferencedFileSave referencedFileSave)
        {
            IElement container = referencedFileSave.GetContainer();

            if (container == null)
            {
                return(TreeNodeByTagIn(referencedFileSave, ElementViewWindow.GlobalContentFileNode.Nodes));
            }
            else if (container is ScreenSave)
            {
                ScreenTreeNode screenTreeNode = GlueState.Self.Find.ScreenTreeNode((ScreenSave)container);
                return(screenTreeNode.GetTreeNodeFor(referencedFileSave));
            }
            else if (container is EntitySave)
            {
                EntityTreeNode entityTreeNode = GlueState.Self.Find.EntityTreeNode((EntitySave)container);
                return(entityTreeNode.GetTreeNodeFor(referencedFileSave));
            }

            return(null);
        }
Exemplo n.º 4
0
        public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List <string> additionalFilesToRemove, bool regenerateCode)
        {
            var isContained = GlueState.Self.Find.IfReferencedFileSaveIsReferenced(referencedFileToRemove);

            /////////////////////////Early Out//////////////////////////////
            if (!isContained)
            {
                return;
            }
            ////////////////////////End Early Out/////////////////////////////



            // There are some things that need to happen:
            // 1.  Remove the ReferencedFileSave from the Glue project (GLUX)
            // 2.  Remove the GUI item
            // 3.  Remove the item from the Visual Studio project.
            IElement container = referencedFileToRemove.GetContainer();

            #region Remove the file from the current Screen or Entity if there is a current Screen or Entity

            if (container != null)
            {
                // The referenced file better be a globally referenced file


                if (!container.ReferencedFiles.Contains(referencedFileToRemove))
                {
                    throw new ArgumentException();
                }
                else
                {
                    container.ReferencedFiles.Remove(referencedFileToRemove);
                }
                // Ask about any NamedObjects that reference this file.
                for (int i = container.NamedObjects.Count - 1; i > -1; i--)
                {
                    var nos = container.NamedObjects[i];
                    if (nos.SourceType == SourceType.File && nos.SourceFile == referencedFileToRemove.Name)
                    {
                        MainGlueWindow.Self.Invoke(() =>
                        {
                            // Ask the user what to do here - remove it?  Keep it and not compile?
                            MultiButtonMessageBox mbmb = new MultiButtonMessageBox();
                            mbmb.MessageText           = "The object\n" + nos.ToString() + "\nreferences the file\n" + referencedFileToRemove.Name +
                                                         "\nWhat would you like to do?";
                            mbmb.AddButton("Remove this object", DialogResult.Yes);
                            mbmb.AddButton("Keep it (object will not be valid until changed)", DialogResult.No);

                            var result = mbmb.ShowDialog();

                            if (result == DialogResult.Yes)
                            {
                                container.NamedObjects.RemoveAt(i);
                            }
                        });
                    }
                    nos.ResetVariablesReferencing(referencedFileToRemove);
                }

                MainGlueWindow.Self.Invoke(() =>
                {
                    if (EditorLogic.CurrentScreenTreeNode != null)
                    {
                        EditorLogic.CurrentScreenTreeNode.UpdateReferencedTreeNodes();
                    }
                    else if (EditorLogic.CurrentEntityTreeNode != null)
                    {
                        EditorLogic.CurrentEntityTreeNode.UpdateReferencedTreeNodes();
                    }
                    if (regenerateCode)
                    {
                        ElementViewWindow.GenerateSelectedElementCode();
                    }
                });
            }
            #endregion

            #region else, the file is likely part of the GlobalContentFile

            else
            {
                ProjectManager.GlueProjectSave.GlobalFiles.Remove(referencedFileToRemove);
                ProjectManager.GlueProjectSave.GlobalContentHasChanged = true;

                // Much faster to just remove the tree node.  This was done
                // to reuse code and make things reactive, but this has gotten
                // slow on bigger projects.
                //ElementViewWindow.UpdateGlobalContentTreeNodes(false); // don't save here because projects will get saved below

                Action refreshUiAction = () =>
                {
                    TreeNode treeNode = GlueState.Self.Find.ReferencedFileSaveTreeNode(referencedFileToRemove);
                    if (treeNode != null)
                    {
                        // treeNode can be null if the user presses delete + enter really really fast, stacking 2 remove
                        // actions
                        if (treeNode.Tag != referencedFileToRemove)
                        {
                            throw new Exception("Error removing the tree node - the selected tree node doesn't reference the file being removed");
                        }

                        treeNode.Parent.Nodes.Remove(treeNode);
                    }
                };

                MainGlueWindow.Self.Invoke((MethodInvoker) delegate
                {
                    refreshUiAction();
                }
                                           );


                GlobalContentCodeGenerator.UpdateLoadGlobalContentCode();

                List <IElement> elements = ObjectFinder.Self.GetAllElementsReferencingFile(referencedFileToRemove.Name);

                foreach (IElement element in elements)
                {
                    if (regenerateCode)
                    {
                        CodeWriter.GenerateCode(element);
                    }
                }
            }

            #endregion


            // November 10, 2015
            // I feel like this may
            // have been old code before
            // we had full dependency tracking
            // in Glue. This file should only be
            // removed from the project if nothing
            // else references it, including no entities.
            // This code does just entities/screens/global
            // content, but doesn't check the full dependency
            // tree. I think we can just remove it and depend on
            // the code below.
            // Actually, removing this seems to cause problems - files
            // that should be removed aren't. So instead we'll chnage the
            // call to use the dependency tree:
            // replace:

            List <string> referencedFiles =
                GlueCommands.Self.FileCommands.GetAllReferencedFileNames().Select(item => item.ToLowerInvariant()).ToList();

            string absoluteToLower   = GlueCommands.Self.GetAbsoluteFileName(referencedFileToRemove).ToLowerInvariant();
            string relativeToProject = FileManager.MakeRelative(absoluteToLower, GlueState.Self.ContentDirectory);

            bool isReferencedByOtherContent = referencedFiles.Contains(relativeToProject);

            if (isReferencedByOtherContent == false)
            {
                additionalFilesToRemove.Add(referencedFileToRemove.GetRelativePath());

                string itemName     = referencedFileToRemove.GetRelativePath();
                string absoluteName = ProjectManager.MakeAbsolute(referencedFileToRemove.Name, true);

                // I don't know why we were removing the file from the ProjectBase - it should
                // be from the Content project
                //ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase, itemName);
                ProjectManager.RemoveItemFromProject(ProjectManager.ProjectBase.ContentProject, itemName, performSave: false);

                foreach (ProjectBase syncedProject in ProjectManager.SyncedProjects)
                {
                    ProjectManager.RemoveItemFromProject(syncedProject.ContentProject, absoluteName);
                }
            }



            if (ProjectManager.IsContent(referencedFileToRemove.Name))
            {
                UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false);
                foreach (var file in UnreferencedFilesManager.LastAddedUnreferencedFiles)
                {
                    additionalFilesToRemove.Add(file.FilePath);
                }
            }

            ReactToRemovalIfCsv(referencedFileToRemove, additionalFilesToRemove);

            GluxCommands.Self.SaveGlux();
        }
Exemplo n.º 5
0
        private static void DragAddFileToGlobalContent(TreeNode treeNodeMoving, ReferencedFileSave referencedFileSave)
        {
            if (referencedFileSave.GetContainerType() == ContainerType.None)
            {
                // This means the user dragged a file from global content onto the global content tree node -
                // we shouldn't do anything here.  It's not a valid operation, but at the same time, it may have
                // happened accidentally and we don't want to burden the user with popups.
            }
            else
            {
                bool isAlreadyPartOfReferencedFiles = false;
                // If the file is already part of GlobalContent, then warn the user and do nothing
                foreach (ReferencedFileSave fileInGlobalContent in ObjectFinder.Self.GlueProject.GlobalFiles)
                {
                    if (fileInGlobalContent.Name == referencedFileSave.Name)
                    {
                        isAlreadyPartOfReferencedFiles = true;
                        break;
                    }
                }


                if (isAlreadyPartOfReferencedFiles)
                {
                    MessageBox.Show("The file\n\n" + referencedFileSave.Name + "\n\nis already a Global Content File");
                }
                else
                {
                    // If we got here, that means that the file that
                    // the user is dragging in to Global Content Files
                    // can be added to Global Content Files; however, the
                    // owner of the file may not be using global content.  We
                    // should ask the user if the containing IElement should use
                    // global content
                    IElement container = referencedFileSave.GetContainer();



                    if (!container.UseGlobalContent)
                    {
                        string screenOrEntity = "Screen";

                        if (container is EntitySave)
                        {
                            screenOrEntity = "Entity";
                        }

                        DialogResult result = MessageBox.Show("The " + screenOrEntity + " " + container.ToString() +
                                                              "does not UseGlobalContent.  Would you like " +
                                                              " to set UseGlobalContent to true?", "Set UseGlobalContent to true?", MessageBoxButtons.YesNo);

                        if (result == DialogResult.Yes)
                        {
                            container.UseGlobalContent = true;
                        }
                    }

                    bool useFullPathAsName = true;
                    ElementCommands.Self.AddReferencedFileToGlobalContent(referencedFileSave.Name, useFullPathAsName);

                    GlobalContentCodeGenerator.UpdateLoadGlobalContentCode();

                    ProjectManager.SaveProjects();
                    GluxCommands.Self.SaveGlux();
                }
            }
        }
Exemplo n.º 6
0
        public static bool UpdateFile(string changedFile)
        {
            bool shouldSave = false;
            bool handled    = false;

            lock (mUpdateFileLock)
            {
                if (ProjectManager.ProjectBase != null)
                {
                    handled = TryHandleProjectFileChanges(changedFile);

                    string projectFileName = ProjectManager.ProjectBase.FullFileName;

                    var standardizedGlux = FileManager.RemoveExtension(FileManager.Standardize(projectFileName).ToLower()) + ".glux";
                    var partialGlux      = FileManager.RemoveExtension(FileManager.Standardize(projectFileName).ToLower()) + @"\..*\.generated\.glux";
                    var partialGluxRegex = new Regex(partialGlux);
                    if (!handled && ((changedFile.ToLower() == standardizedGlux) || partialGluxRegex.IsMatch(changedFile.ToLower())))
                    {
                        TaskManager.Self.OnUiThread(ReloadGlux);
                        handled = true;
                    }

                    if (ProjectManager.IsContent(changedFile))
                    {
                        PluginManager.ReactToChangedFile(changedFile);
                    }

                    #region If it's a CSV, then re-generate the code for the objects

                    string extension = FileManager.GetExtension(changedFile);

                    if (extension == "csv" ||
                        extension == "txt")
                    {
                        ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(changedFile);

                        bool shouldGenerate = rfs != null &&
                                              (extension == "csv" || rfs.TreatAsCsv) &&
                                              rfs.IsDatabaseForLocalizing == false;

                        if (shouldGenerate)
                        {
                            try
                            {
                                CsvCodeGenerator.GenerateAndSaveDataClass(rfs, rfs.CsvDelimiter);

                                shouldSave = true;
                            }
                            catch (Exception e)
                            {
                                GlueCommands.Self.PrintError("Error saving Class from CSV " + rfs.Name +
                                                             "\n" + e.ToString());
                            }
                        }
                    }


                    #endregion

                    #region If it's a file that references other content we may need to update the project

                    if (FileHelper.DoesFileReferenceContent(changedFile))
                    {
                        ReferencedFileSave rfs = ObjectFinder.Self.GetReferencedFileSaveFromFile(changedFile);


                        if (rfs != null)
                        {
                            string error;
                            rfs.RefreshSourceFileCache(false, out error);

                            if (!string.IsNullOrEmpty(error))
                            {
                                ErrorReporter.ReportError(rfs.Name, error, false);
                            }
                            else
                            {
                                handled = true;
                            }

                            handled   |= GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject(rfs);
                            shouldSave = true;

                            MainGlueWindow.Self.Invoke((MethodInvoker) delegate
                            {
                                if (rfs.GetContainerType() == ContainerType.Entity)
                                {
                                    if (EditorLogic.CurrentEntityTreeNode != null)
                                    {
                                        if (EditorLogic.CurrentEntitySave == rfs.GetContainer())
                                        {
                                            PluginManager.RefreshCurrentElement();
                                        }
                                    }
                                }
                                else if (rfs.GetContainerType() == ContainerType.Screen)
                                {
                                    if (EditorLogic.CurrentScreenTreeNode != null)
                                    {
                                        if (EditorLogic.CurrentScreenSave == rfs.GetContainer())
                                        {
                                            PluginManager.RefreshCurrentElement();
                                        }
                                    }
                                }
                            });
                        }
                        else
                        {
                            // There may not be a RFS for this in Glue, but even if there's not,
                            // this file may be referenced by other RFS's.  I don't want to do a full
                            // project scan, so we'll just see if this file is part of Visual Studio.  If so
                            // then let's add its children

                            if (ProjectManager.ContentProject.IsFilePartOfProject(changedFile))
                            {
                                string relativePath = ProjectManager.MakeRelativeContent(changedFile);

                                shouldSave |= GlueCommands.Self.ProjectCommands.UpdateFileMembershipInProject(
                                    ProjectManager.ProjectBase, relativePath, false, false);
                                handled |= shouldSave;
                            }
                        }
                    }

                    #endregion

                    #region If it's a .cs file, we should see if we've added a new .cs file, and if so refresh the Element for it
                    if (extension == "cs")
                    {
                        TaskManager.Self.OnUiThread(() => ReactToChangedCodeFile(changedFile));
                    }


                    #endregion

                    #region Maybe it's a directory that was added or removed

                    if (FileManager.GetExtension(changedFile) == "")
                    {
                        ElementViewWindow.Invoke((MethodInvoker) delegate
                        {
                            try
                            {
                                // It's a directory, so let's just rebuild our directory TreeNodes
                                ElementViewWindow.AddDirectoryNodes();
                            }
                            catch (System.IO.IOException)
                            {
                                // this could be because something else is accessing the directory, so sleep, try again
                                System.Threading.Thread.Sleep(100);
                                ElementViewWindow.AddDirectoryNodes();
                            }
                        });
                    }

                    #endregion


                    #region Check for broken references to objects in file - like an Entity may reference an object in a file but it may have been removed

                    if (ObjectFinder.Self.GetReferencedFileSaveFromFile(changedFile) != null)
                    {
                        // This is a file that is part of the project, so let's see if any named objects are missing references
                        CheckForBrokenReferencesToObjectsInFile(changedFile);
                    }

                    #endregion

                    // This could be an externally built file:

                    ProjectManager.UpdateExternallyBuiltFile(changedFile);

                    if (handled)
                    {
                        PluginManager.ReceiveOutput("Handled changed file: " + changedFile);
                    }

                    if (shouldSave)
                    {
                        ProjectManager.SaveProjects();
                    }
                }
            }

            return(handled);
        }
        public override bool GetIfIsFixed()
        {
            // This is fixed if:
            //  1: AbsoluteMissingFile is now on disk
            //  2: Any file in the stack no longer exists
            //  3: Any file in the stack no longer references the next file in the stack
            //  4: The ReferencedFileSave has been removed from the project

            bool isFixed = false;

            if (AbsoluteMissingFile.Exists())
            {
                isFixed = true;
            }

            if (!isFixed)
            {
                foreach (var file in ReferenceStack)
                {
                    // 2:
                    if (file.Exists() == false)
                    {
                        isFixed = true;
                        break;
                    }
                }
            }

            if (!isFixed)
            {
                // 3:
                for (int i = 0; i < ReferenceStack.Count; i++)
                {
                    var      current = ReferenceStack[i];
                    FilePath next;
                    if (i + 1 < ReferenceStack.Count)
                    {
                        next = ReferenceStack[i + 1];
                    }
                    else
                    {
                        next = AbsoluteMissingFile;
                    }

                    var referencedFiles =
                        GlueCommands.Self.FileCommands.GetFilePathsReferencedBy(current.Standardized, EditorObjects.Parsing.TopLevelOrRecursive.TopLevel);

                    var stillReferences = referencedFiles.Any(item => item == next);

                    if (!stillReferences)
                    {
                        isFixed = true;
                        break;
                    }
                }
            }

            if (!isFixed)
            {
                bool isReferencedByElement = ReferencedFileSave.GetContainer() != null;
                bool isGlobalContent       = false;

                if (!isReferencedByElement)
                {
                    isGlobalContent = GlueState.Self.CurrentGlueProject.GetAllReferencedFiles().Contains(ReferencedFileSave);
                }

                if (!isReferencedByElement && !isGlobalContent)
                {
                    // the root RFS has been removed
                    isFixed = true;
                }
            }

            return(isFixed);
        }