void AddAnimationOK(Window callingWindow) { #if !FRB_MDX string sourceFile = ((FileWindow)callingWindow).Results[0]; string destinationFile = ""; string extension = FileManager.GetExtension(sourceFile); BuildToolAssociation toolForExtension = GetToolForExtension(extension); if (toolForExtension != null) { destinationFile = FileManager.UserApplicationDataForThisApplication + FileManager.RemovePath(FileManager.RemoveExtension(sourceFile)) + "." + toolForExtension.DestinationFileType; toolForExtension.PerformBuildOn(sourceFile, destinationFile, null, null, null); } else { destinationFile = sourceFile; } mAnimationListDisplayWindow.UpdateToList(); #endif }
void LoadSkeleton(Window callingWindow) { #if !FRB_MDX FileTextBox fileTextBox = callingWindow as FileTextBox; string sourceFile = fileTextBox.Text; string destinationFile = ""; string extension = FileManager.GetExtension(sourceFile); BuildToolAssociation toolForExtension = GetToolForExtension(extension); if (toolForExtension != null) { destinationFile = FileManager.UserApplicationDataForThisApplication + FileManager.RemovePath(FileManager.RemoveExtension(sourceFile)) + "." + toolForExtension.DestinationFileType; toolForExtension.PerformBuildOn(sourceFile, destinationFile, null, null, null); } else { destinationFile = sourceFile; } #endif }
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); }
private static string PerformBuildOnFile(this ReferencedFileSave instance, string absoluteSourceName, string absoluteDestinationName, bool runAsync) { bool doesFileExist = FileManager.FileExists(absoluteSourceName); string error = ""; if (!doesFileExist) { MessageBox.Show("Could not find the following source file:\n\n" + absoluteSourceName); } else { #region Find the BuildToolAssociation BuildToolAssociation buildToolAssociation = GetBuildToolAssociation(instance); #endregion string destinationExtension = FileManager.GetExtension(instance.Name); #region If there is no BuildToolAssociation, tell the user that's the case if (buildToolAssociation == null) { error = "Could not find the build tool for the source file\n" + absoluteSourceName + "\nwith destination extension\n" + destinationExtension; error += "\nThere are " + BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList.Count + " build tools registered with Glue"; foreach (BuildToolAssociation bta in BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList) { error += "\n\"" + bta.SourceFileType + "\" -> " + bta.BuildToolProcessed + " -> \"" + bta.DestinationFileType + "\""; } System.Windows.Forms.MessageBox.Show(error); } #endregion #region else, there is one, so let's do the build else { #region Call the process (the build tool) try { // Something could have screwed up the relative directory, so let's reset it here FileManager.RelativeDirectory = ProjectManager.ProjectBase.Directory; error = buildToolAssociation.PerformBuildOn(absoluteSourceName, absoluteDestinationName, instance.AdditionalArguments, PluginManager.ReceiveOutput, PluginManager.ReceiveError, runAsync); } catch (FileNotFoundException fnfe) { System.Windows.Forms.MessageBox.Show("Can't find the file:\n" + fnfe.FileName); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("There was an error building the file\n" + absoluteSourceName + "\n\n" + e.Message); } #endregion } #endregion } return(error); }