public void AddIfNecessary(BuildToolAssociation association)
        {
            var found = BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList.FirstOrDefault(
                possible => possible.ToString().ToLowerInvariant() == association.ToString().ToLowerInvariant());

            if (found == null)
            {
                BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList.Add(association);

                BuildToolAssociationManager.Self.SaveProjectSpecificBuildTools();
            }
        }
Пример #2
0
        void AddIfNecessary(BuildToolAssociation association)
        {
            if (System.IO.File.Exists(association.BuildToolProcessed))
            {
                var buildToolList = BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList;

                bool found = buildToolList.Any(
                    possible => possible.ToString().ToLowerInvariant() == association.ToString().ToLowerInvariant());

                if (!found)
                {
                    BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList.Add(association);

                    BuildToolAssociationManager.Self.SaveProjectSpecificBuildTools();
                }
            }
        }
Пример #3
0
        public ReferencedFileSave AddSingleFileTo(string fileName, string rfsName, string extraCommandLineArguments,
                                                  BuildToolAssociation buildToolAssociation, bool isBuiltFile, string options, IElement sourceElement, string directoryOfTreeNode)
        {
            ReferencedFileSave toReturn = null;

            //string directoryOfTreeNode = EditorLogic.CurrentTreeNode.GetRelativePath();

            string targetDirectory = FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.GetFullPathContentDirectory(sourceElement, directoryOfTreeNode);
            string targetFile      = fileName;

            string errorMessage = null;
            bool   failed       = false;

            if (isBuiltFile)
            {
                targetFile = targetDirectory + rfsName + "." + buildToolAssociation.DestinationFileType;
            }

            string targetFileWithOriginalExtension = FileManager.RemoveExtension(targetFile) + "." + FileManager.GetExtension(fileName);

            bool copied = false;

            var projectRootDirectory = ProjectManager.ProjectRootDirectory;

            if (!FileManager.IsRelativeTo(fileName, projectRootDirectory) && isBuiltFile)
            {
                copied = PluginManager.TryCopyFile(fileName, targetFileWithOriginalExtension);

                if (!copied)
                {
                    errorMessage = $"Could not add the file\n{fileName}\n\nBecause it is not relative to\n{ProjectManager.ProjectRootDirectory}\n\nPlease move this file to a folder inside your project and try again";
                    failed       = true;
                }
                else
                {
                    // the file was copied - from now on just use the copied file name:
                    fileName = targetFileWithOriginalExtension;
                }
            }

            if (!failed)
            {
                if (isBuiltFile)
                {
                    errorMessage = buildToolAssociation.PerformBuildOn(fileName, targetFile, extraCommandLineArguments, PluginManager.ReceiveOutput, PluginManager.ReceiveError);
                    failed       = true;
                }
            }

            if (!failed)
            {
                string creationReport;

                string directoryToUse = null;

                if (!isBuiltFile)
                {
                    directoryToUse = directoryOfTreeNode;
                }

                var assetTypeInfo = AvailableAssetTypes.Self.GetAssetTypeFromExtension(FileManager.GetExtension(targetFile));


                toReturn = CreateReferencedFileSaveForExistingFile(
                    sourceElement, directoryToUse, targetFile, PromptHandleEnum.Prompt,
                    assetTypeInfo,
                    out creationReport, out errorMessage);

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    failed = true;
                }
                else if (toReturn != null && string.IsNullOrEmpty(toReturn.Name))
                {
                    errorMessage = "There was an error creating the named object for\n" + fileName;
                    failed       = true;
                }
            }

            if (!failed)
            {
                if (isBuiltFile)
                {
                    toReturn.SourceFile          = ProjectManager.MakeRelativeContent(fileName);
                    toReturn.AdditionalArguments = extraCommandLineArguments;
                    toReturn.BuildTool           = buildToolAssociation.ToString();

                    // If a background sync is happening, this can lock the thread, so we want to
                    // make sure this doesn't happen at the same time as a background sync:
                    TaskManager.Self.AddAsyncTask(() =>
                    {
                        UpdateReactor.UpdateFile(ProjectManager.MakeAbsolute(toReturn.Name));
                    },
                                                  "Updating file " + toReturn.Name);
                    string directoryOfFile = FileManager.GetDirectory(ProjectManager.MakeAbsolute(fileName));

                    RightClickHelper.SetExternallyBuiltFileIfHigherThanCurrent(directoryOfFile, false);
                }
            }

            if (!failed)
            {
                TaskManager.Self.OnUiThread(() =>
                {
                    ElementViewWindow.UpdateChangedElements();
                });

                if (sourceElement == null)
                {
                    GlueCommands.Self.RefreshCommands.RefreshGlobalContent();
                }

                PluginManager.ReactToNewFile(toReturn);
                GluxCommands.Self.SaveGlux();
                TaskManager.Self.Add(GluxCommands.Self.ProjectCommands.SaveProjects, "Saving projects after adding file");
            }

            if (!string.IsNullOrWhiteSpace(errorMessage))
            {
                PluginManager.ReceiveError(errorMessage);
                // I think we should show an error message.  I had a user
                // try to add a file and no popup appeared telling them that
                // the entity was named that.
                //MessageBox.Show(errorMessage);
                GlueCommands.Self.DialogCommands.ShowMessageBox(errorMessage);
            }

            if (toReturn != null)
            {
                ApplyOptions(toReturn, options);

                TaskManager.Self.AddSync(() =>
                                         TaskManager.Self.OnUiThread(() =>
                                                                     GlueState.Self.CurrentReferencedFileSave = toReturn), "Select new file");
            }

            return(toReturn);
        }