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 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(); } }
private void AddButton_Click(object sender, EventArgs e) { BuildToolAssociation newItem = new BuildToolAssociation(); mBuildToolList.Add(newItem); listBox1.Items.Add(newItem); listBox1.SelectedItem = newItem; }
public void Initialize() { BuildToolAssociation bta = new BuildToolAssociation() { SourceFileType = "src", DestinationFileType = "dst", BuildTool = "c:\\WHATEVER.exe" }; BuildToolAssociationManager.Self.ProjectSpecificBuildTools = new BuildToolAssociationList(); BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList.Add(bta); }
internal BuildToolAssociation GetBuilderToolAssociationByName(string name) { BuildToolAssociation buildToolAssociation = null; foreach (BuildToolAssociation bta in ProjectSpecificBuildTools.BuildToolList) { if (bta.ToString().ToLower() == name.ToLower()) { buildToolAssociation = bta; break; } } return(buildToolAssociation); }
public BuildToolAssociation GetBuilderToolAssociationForDestinationExtension(string destinationExtension) { BuildToolAssociation buildToolAssociation = null; foreach (BuildToolAssociation bta in ProjectSpecificBuildTools.BuildToolList) { if (bta.DestinationFileType.ToLowerInvariant() == destinationExtension.ToLowerInvariant()) { buildToolAssociation = bta; break; } } return(buildToolAssociation); }
internal BuildToolAssociation GetBuilderToolAssociationForSourceExtension(string sourceExtension) { BuildToolAssociation buildToolAssociation = null; foreach (BuildToolAssociation bta in ProjectSpecificBuildTools.BuildToolList) { if (bta.SourceFileType != null && bta.SourceFileType.ToLowerInvariant() == sourceExtension.ToLowerInvariant()) { buildToolAssociation = bta; break; } } return(buildToolAssociation); }
BuildToolAssociation MakeBmfcBuildToolAssociation() { BuildToolAssociation toReturn = new BuildToolAssociation(); // relative to Glue: string relativePath = @"%Glue%Libraries\BMFont\bmfont.exe"; toReturn.BuildTool = relativePath; toReturn.SourceFileType = "bmfc"; toReturn.DestinationFileType = "fnt"; toReturn.SourceFileArgumentPrefix = "-c"; toReturn.DestinationFileArgumentPrefix = "-o"; return(toReturn); }
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(); } } }
public static BuildToolAssociation GetBuildToolAssociation(this ReferencedFileSave instance) { string destinationExtension = FileManager.GetExtension(instance.Name); // See if there is a tool that this is built with BuildToolAssociation buildToolAssociation = null; if (!string.IsNullOrEmpty(instance.BuildTool)) { buildToolAssociation = BuildToolAssociationManager.Self.GetBuilderToolAssociationByName(instance.BuildTool); } else { buildToolAssociation = BuildToolAssociationManager.Self.GetBuilderToolAssociationForDestinationExtension(destinationExtension); } return(buildToolAssociation); }
public ReferencedFileSave AddSingleFile(string fileName, ref bool userCancelled, IElement element, string directoryOfTreeNode, string options = null) { ReferencedFileSave toReturn = null; #region Find the BuildToolAssociation for the selected file string rfsName = FileManager.RemoveExtension(FileManager.RemovePath(fileName)); string extraCommandLineArguments = null; BuildToolAssociation buildToolAssociation = null; bool isBuiltFile = BuildToolAssociationManager.Self.GetIfIsBuiltFile(fileName); bool userPickedNone = false; if (isBuiltFile) { buildToolAssociation = BuildToolAssociationManager.Self.GetBuildToolAssocationAndNameFor(fileName, out userCancelled, out userPickedNone, out rfsName, out extraCommandLineArguments); } #endregion string sourceExtension = FileManager.GetExtension(fileName); if (userPickedNone) { isBuiltFile = false; } if (isBuiltFile && buildToolAssociation == null && !userPickedNone) { GlueCommands.Self.PrintOutput("Couldn't find a tool for the file extension " + sourceExtension); } else if (!userCancelled) { toReturn = GlueCommands.Self.GluxCommands.AddSingleFileTo(fileName, rfsName, extraCommandLineArguments, buildToolAssociation, isBuiltFile, options, element, directoryOfTreeNode); } return(toReturn); }
BuildToolAssociation MakeBmfcBuildToolAssociation() { BuildToolAssociation toReturn = new BuildToolAssociation(); string folder = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); if (!folder.EndsWith("\\") && !folder.EndsWith("/")) { folder += "\\"; } string bmFontAbsolutePath = folder + @"AngelCode\BMFont\bmfont.exe"; toReturn.BuildTool = bmFontAbsolutePath; toReturn.SourceFileType = "bmfc"; toReturn.DestinationFileType = "fnt"; toReturn.SourceFileArgumentPrefix = "-c"; toReturn.DestinationFileArgumentPrefix = "-o"; return(toReturn); }
public ReferencedFileSave CreateReferencedFileSaveForExistingFile(IElement containerForFile, string directoryInsideContainer, string absoluteFileName, PromptHandleEnum unknownTypeHandle, AssetTypeInfo ati, out string creationReport, out string errorMessage) { creationReport = ""; errorMessage = null; ReferencedFileSave referencedFileSaveToReturn = null; string whyItIsntValid; // Let's see if there is already an Entity with the same name string fileWithoutPath = FileManager.RemovePath(FileManager.RemoveExtension(absoluteFileName)); bool isValid = NameVerifier.IsReferencedFileNameValid(fileWithoutPath, ati, referencedFileSaveToReturn, containerForFile, out whyItIsntValid); if (!isValid) { errorMessage = "Invalid file name:\n" + fileWithoutPath + "\n" + whyItIsntValid; } else { Zipper.UnzipAndModifyFileIfZip(ref absoluteFileName); string extension = FileManager.GetExtension(absoluteFileName); bool isValidExtensionOrIsConfirmedByUser; bool isUnknownType; FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.CheckAndWarnAboutUnknownFileTypes(unknownTypeHandle, extension, out isValidExtensionOrIsConfirmedByUser, out isUnknownType); string fileToAdd = null; if (isValidExtensionOrIsConfirmedByUser) { string directoryThatFileShouldBeRelativeTo = FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.GetFullPathContentDirectory(containerForFile, directoryInsideContainer); string projectDirectory = ProjectManager.ContentProject.GetAbsoluteContentFolder(); bool needsToCopy = !FileManager.IsRelativeTo(absoluteFileName, projectDirectory); if (needsToCopy) { fileToAdd = directoryThatFileShouldBeRelativeTo + FileManager.RemovePath(absoluteFileName); fileToAdd = FileManager.MakeRelative(fileToAdd, ProjectManager.ContentProject.GetAbsoluteContentFolder()); try { FileHelper.RecursivelyCopyContentTo(absoluteFileName, FileManager.GetDirectory(absoluteFileName), directoryThatFileShouldBeRelativeTo); } catch (System.IO.FileNotFoundException fnfe) { errorMessage = "Could not copy the files because of a missing file: " + fnfe.Message; } } else { fileToAdd = FlatRedBall.Glue.Plugins.ExportedImplementations.CommandInterfaces.ElementCommands.GetNameOfFileRelativeToContentFolder(absoluteFileName, directoryThatFileShouldBeRelativeTo, projectDirectory); } } if (string.IsNullOrEmpty(errorMessage)) { BuildToolAssociation bta = null; if (ati != null && !string.IsNullOrEmpty(ati.CustomBuildToolName)) { bta = BuildToolAssociationManager.Self.GetBuilderToolAssociationByName(ati.CustomBuildToolName); } if (containerForFile != null) { referencedFileSaveToReturn = containerForFile.AddReferencedFile(fileToAdd, ati, bta); } else { bool useFullPathAsName = false; // todo - support built files here referencedFileSaveToReturn = AddReferencedFileToGlobalContent(fileToAdd, useFullPathAsName); } // This will be null if there was an error above in creating this file if (referencedFileSaveToReturn != null) { if (containerForFile != null) { containerForFile.HasChanged = true; } if (fileToAdd.EndsWith(".csv")) { string fileToAddAbsolute = ProjectManager.MakeAbsolute(fileToAdd); CsvCodeGenerator.GenerateAndSaveDataClass(referencedFileSaveToReturn, referencedFileSaveToReturn.CsvDelimiter); } if (isUnknownType) { referencedFileSaveToReturn.LoadedAtRuntime = false; } string error; referencedFileSaveToReturn.RefreshSourceFileCache(false, out error); if (!string.IsNullOrEmpty(error)) { ErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false); } } } } return(referencedFileSaveToReturn); }
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); }
public BuildToolAssociation GetBuildToolAssocationAndNameFor(string fileName, out bool userCancelled, out bool userPickedNone, out string rfsName, out string extraCommandLineArguments) { userCancelled = false; userPickedNone = false; rfsName = null; BuildToolAssociation buildToolAssociation = null; string sourceExtension = FileManager.GetExtension(fileName); List <BuildToolAssociation> btaList = new List <BuildToolAssociation>(); foreach (BuildToolAssociation bta in BuildToolAssociationManager.Self.ProjectSpecificBuildTools.BuildToolList) { if (bta.SourceFileType != null && bta.SourceFileType.ToLower() == sourceExtension.ToLower()) { btaList.Add(bta); } } NewFileWindow nfw = new NewFileWindow(); nfw.ComboBoxMessage = "Which builder would you like to use for this file?"; int commandLineArgumentsId = nfw.AddTextBox("Enter extra command line arguments:"); bool showNoneOption = Elements.AvailableAssetTypes.Self.AllAssetTypes .Any(item => item.Extension == sourceExtension && string.IsNullOrEmpty(item.CustomBuildToolName)); if (showNoneOption) { nfw.AddOption("<None>"); } foreach (BuildToolAssociation bta in btaList) { nfw.AddOption(bta); } if (btaList.Count != 0) { nfw.SelectedItem = btaList[0]; } nfw.ResultName = FileManager.RemoveExtension(FileManager.RemovePath(fileName)); //DialogResult result = cbmb.ShowDialog(); DialogResult result = nfw.ShowDialog(); extraCommandLineArguments = ""; if (result == DialogResult.OK) { buildToolAssociation = nfw.SelectedItem as BuildToolAssociation; if (buildToolAssociation != null) { rfsName = nfw.ResultName; extraCommandLineArguments = nfw.GetValueFromId(commandLineArgumentsId); } else { userPickedNone = nfw.SelectedItem is string && (nfw.SelectedItem as string) == "<None>"; } } else { userCancelled = true; } return(buildToolAssociation); }
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); }
public ReferencedFileSave CreateReferencedFileSaveForExistingFile(IElement containerForFile, string directoryInsideContainer, string absoluteFileName, PromptHandleEnum unknownTypeHandle, AssetTypeInfo ati, out string creationReport, out string errorMessage) { creationReport = ""; errorMessage = null; ReferencedFileSave referencedFileSaveToReturn = null; string whyItIsntValid; // Let's see if there is already an Entity with the same name string fileWithoutPath = FileManager.RemovePath(FileManager.RemoveExtension(absoluteFileName)); bool isValid = NameVerifier.IsReferencedFileNameValid(fileWithoutPath, ati, referencedFileSaveToReturn, containerForFile, out whyItIsntValid); if (!isValid) { errorMessage = "Invalid file name:\n" + fileWithoutPath + "\n" + whyItIsntValid; } else { Zipper.UnzipAndModifyFileIfZip(ref absoluteFileName); string extension = FileManager.GetExtension(absoluteFileName); bool isValidExtensionOrIsConfirmedByUser; bool isUnknownType; CheckAndWarnAboutUnknownFileTypes(unknownTypeHandle, extension, out isValidExtensionOrIsConfirmedByUser, out isUnknownType); if (isValidExtensionOrIsConfirmedByUser) { string directoryThatFileShouldBeRelativeTo = GetFullPathContentDirectory(containerForFile, directoryInsideContainer); string projectDirectory = ProjectManager.ContentProject.GetAbsoluteContentFolder(); string fileToAdd = GetNameOfFileRelativeToContentFolder(absoluteFileName, directoryThatFileShouldBeRelativeTo, projectDirectory); BuildToolAssociation bta = null; if (ati != null && !string.IsNullOrEmpty(ati.CustomBuildToolName)) { bta = BuildToolAssociationManager.Self.GetBuilderToolAssociationByName(ati.CustomBuildToolName); } if (containerForFile != null) { referencedFileSaveToReturn = containerForFile.AddReferencedFile(fileToAdd, ati, bta); } else { bool useFullPathAsName = false; // todo - support built files here referencedFileSaveToReturn = AddReferencedFileToGlobalContent(fileToAdd, useFullPathAsName); } // This will be null if there was an error above in creating this file if (referencedFileSaveToReturn != null) { if (containerForFile != null) { containerForFile.HasChanged = true; } if (fileToAdd.EndsWith(".csv")) { string fileToAddAbsolute = ProjectManager.MakeAbsolute(fileToAdd); CsvCodeGenerator.GenerateAndSaveDataClass(referencedFileSaveToReturn, referencedFileSaveToReturn.CsvDelimiter); } if (isUnknownType) { referencedFileSaveToReturn.LoadedAtRuntime = false; } ProjectManager.UpdateFileMembershipInProject(referencedFileSaveToReturn); PluginManager.ReactToNewFile(referencedFileSaveToReturn); GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false); string error; referencedFileSaveToReturn.RefreshSourceFileCache(false, out error); if (!string.IsNullOrEmpty(error)) { ErrorReporter.ReportError(referencedFileSaveToReturn.Name, error, false); } } } } return(referencedFileSaveToReturn); }