public static void AdjustDataFilesIfIsCsv(string oldName, ReferencedFileSave rfs) { // We'll remove the old file from the project, delete it, then have the RFS regenerate/add the new one to the project //////////////Early Out/////////////////// if (!rfs.IsCsvOrTreatedAsCsv || UsesAlterntaiveClass(rfs)) { return; } ////////////End Early Out///////////////// string className = rfs.GetTypeForCsvFile(oldName); string whatToRemove = "DataTypes/" + className + ".Generated.cs"; ProjectManager.ProjectBase.RemoveItem(whatToRemove); string fileToDelete = whatToRemove; fileToDelete = ProjectManager.MakeAbsolute(fileToDelete); if (System.IO.File.Exists(fileToDelete)) { try { FileHelper.DeleteFile(fileToDelete); } catch (Exception e) { GlueGui.ShowMessageBox("Could not delete the file " + fileToDelete + "\n\nThe file is no longer referneced by the project so it is not necessary to delete this file manually."); } } CsvCodeGenerator.GenerateAndSaveDataClass(rfs, rfs.CsvDelimiter); }
internal static List<string> GetMemberNamesFrom(ReferencedFileSave rfs) { List<string> toReturn = new List<string>(); string fileName = rfs.Name; fileName = ProjectManager.MakeAbsolute(fileName); RuntimeCsvRepresentation rcr = CsvFileManager.CsvDeserializeToRuntime( fileName); for (int i = 0; i < rcr.Headers.Length; i++) { string memberName = rcr.Headers[i].Name; if (memberName.Trim().StartsWith("//")) { continue; } memberName = StringFunctions.RemoveWhitespace(memberName); if (memberName.Contains("(")) { memberName = memberName.Substring(0, memberName.IndexOfAny(new char[] { '(' })); } toReturn.Add(memberName); } return toReturn; }
private TreeNode GetTreeNodeFor(ReferencedFileSave referencedFileSave, string currentPath, TreeNode treeNode) { return null; }
public static string CreateZip(ReferencedFileSave rfs) { string absoluteFile = ProjectManager.MakeAbsolute(rfs.Name, true); List<string> allFiles = FileReferenceManager.Self.GetFilesReferencedBy( absoluteFile, TopLevelOrRecursive.Recursive); #region Check for relative files string directoryOfMainFile = FileManager.GetDirectory(absoluteFile); bool areAnyFilesOutsideOfMainDirectory = false; foreach (string referencedFile in allFiles) { if (!FileManager.IsRelativeTo(referencedFile, directoryOfMainFile)) { areAnyFilesOutsideOfMainDirectory = true; break; } } #endregion string outputFile; if (areAnyFilesOutsideOfMainDirectory) { outputFile = null; } else { allFiles.Add(absoluteFile); string extension = FileManager.GetExtension(rfs.Name); string newExtension = "zip"; if (extension.Length == 4 && extension[3] == 'x') { newExtension = extension.Substring(0, 3) + 'z'; } outputFile = FileManager.RemoveExtension(absoluteFile) + "." + newExtension; using (ZipFile zip = new ZipFile()) { foreach (string fileToAdd in allFiles) { string directory = FileManager.MakeRelative(FileManager.GetDirectory(fileToAdd), directoryOfMainFile); if (directory.EndsWith("/")) { directory = directory.Substring(0, directory.Length - 1); } zip.AddFile(fileToAdd, directory); } zip.Save(outputFile); } } return outputFile; }
public static void GenerateTimedEmit(ICodeBlock codeBlock, ReferencedFileSave rfs, IElement element) { if (rfs.LoadedAtRuntime && !rfs.LoadedOnlyWhenReferenced && (element is ScreenSave || rfs.IsSharedStatic == false) && !string.IsNullOrEmpty(rfs.Name) && FileManager.GetExtension(rfs.Name) == "emix") { codeBlock.Line(rfs.GetInstanceName() + ".TimedEmit();"); } }
public TreeNode GetTreeNodeFor(ReferencedFileSave referencedFileSave) { try { // the directory may be like Entities/Something but the ReferencedFileSave might be Content/Entities/Something // so if the RFS starts with Content, then get rid of it string rfsName = referencedFileSave.Name; if (rfsName.StartsWith("Content/")) { rfsName = rfsName.Substring("Content/".Length); } string thisRelativePath = FileManager.GetDirectoryKeepRelative(rfsName); string parentText = this.Parent.Text.Replace("\\", "/"); // Not sure why this is a .Contains... // If we're going to do a substring shouldn't // it be a .StartsWith? //if (thisRelativePath.Contains(parentText)) if (thisRelativePath.StartsWith(parentText)) { thisRelativePath = thisRelativePath.Substring(parentText.Length + 1); // add one for the slash '/' } //this.GetRelativePath().Replace("\\", "/"); //if (referencedFileSave.Name.Contains(thisRelativePath)) //{ // thisRelativePath = referencedFileSave.Name.Substring(thisRelativePath.Length); //} TreeNode treeNodeToSearch = GetNodeForDirectory(thisRelativePath, this); if (treeNodeToSearch == null) { treeNodeToSearch = this; } for (int i = 0; i < treeNodeToSearch.Nodes.Count; i++) { TreeNode node = treeNodeToSearch.Nodes[i]; if (node.Tag == referencedFileSave) { return node; } } } catch (Exception e) { int m = 3; } return null; }
private void CreateCsvContainerEntitySave() { mCsvContainerEntitySave = new EntitySave(); mCsvContainerEntitySave.Name = "CsvContainerEntityInExposedVariableTests"; ObjectFinder.Self.GlueProject.Entities.Add(mCsvContainerEntitySave); ReferencedFileSave rfs = new ReferencedFileSave(); rfs.SourceFile = "Whatever.csv"; rfs.Name = "Whatever.csv"; mCsvContainerEntitySave.ReferencedFiles.Add(rfs); }
public void Select(ReferencedFileSave referencedFile, string objectInFile = null) { // first let's select it: GlueState.Self.CurrentReferencedFileSave = referencedFile; // Next lets tell the plugin manager to try to find this object: if( string.IsNullOrEmpty(objectInFile) == false) { PluginManager.SelectItemInCurrentFile(objectInFile); } }
public static void RenameReferencedFile(string oldName, string newName, ReferencedFileSave rfs, IElement container) { string oldDirectory = FileManager.GetDirectory(oldName); string newDirectory = FileManager.GetDirectory(newName); string newFileNameAbsolute = ProjectManager.MakeAbsolute(newName); string instanceName = FileManager.RemovePath(FileManager.RemoveExtension(newName)); string whyIsntValid; if (oldDirectory != newDirectory) { MessageBox.Show("The old file was located in \n" + oldDirectory + "\n" + "The new file is located in \n" + newDirectory + "\n" + "Currently Glue does not support changing directories.", "Warning"); rfs.SetNameNoCall(oldName); } else if (NameVerifier.IsReferencedFileNameValid(instanceName, rfs.GetAssetTypeInfo(), rfs, container, out whyIsntValid) == false) { MessageBox.Show(whyIsntValid); rfs.SetNameNoCall(oldName); } else { bool shouldMove = true; bool shouldContinue = true; CheckForExistingFileOfSameName(oldName, rfs, newFileNameAbsolute, ref shouldMove, ref shouldContinue); if (shouldContinue) { MoveFileIfNecessary(oldName, newName, shouldMove); string rfsType = rfs.RuntimeType; if (rfsType != null && rfsType.Contains(".")) { // We dont want the fully qualified type. rfsType = FileManager.GetExtension(rfsType); } UpdateObjectsUsingFile(container, oldName, rfs, rfsType); RegenerateCodeAndUpdateUiAccordingToRfsRename(oldName, newName, rfs); UpdateBuildItemsForRenamedRfs(oldName, newName); AdjustDataFilesIfIsCsv(oldName, rfs); GluxCommands.Self.SaveGlux(); ProjectManager.SaveProjects(); } } }
public static void GetDictionaryTypes(ReferencedFileSave referencedFileSave, out string keyType, out string valueType) { valueType = referencedFileSave.GetTypeForCsvFile(); // To know the value type, we gotta pop this bad boy open and find the first requied type keyType = null; char oldDelimiter = CsvFileManager.Delimiter; switch (referencedFileSave.CsvDelimiter) { case AvailableDelimiters.Comma: CsvFileManager.Delimiter = ','; break; case AvailableDelimiters.Tab: CsvFileManager.Delimiter = '\t'; break; case AvailableDelimiters.Pipe: CsvFileManager.Delimiter = '|'; break; } string absoluteFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name); // If the file doesn't exist this will generate bad code. But this isn't // considered a silent failure because Glue will raise flags about missing // files earlier (like when it first starts up). We don't want to crash the // entire application in this case. if (System.IO.File.Exists(absoluteFileName)) { RuntimeCsvRepresentation rcr = CsvFileManager.CsvDeserializeToRuntime(absoluteFileName); // See if any of the headers are required foreach (CsvHeader header in rcr.Headers) { int indexOfOpeningParen = header.Name.IndexOf("("); if (indexOfOpeningParen != -1) { if (header.Name.IndexOf("required", indexOfOpeningParen) != -1) { keyType = CsvHeader.GetClassNameFromHeader(header.Name); break; } } } } CsvFileManager.Delimiter = oldDelimiter; }
private static void ExcludeFileFromProject(string projectName, ReferencedFileSave rfs) { rfs.ProjectsToExcludeFrom.Add(projectName); var syncedProject = GlueState.Self.GetProjects().FirstOrDefault(item => item.Name == projectName); if(syncedProject != null) { string absolute = GlueCommands.Self.GetAbsoluteFileName(rfs); syncedProject.RemoveItem(absolute); if (syncedProject.ContentProject != null) { syncedProject.ContentProject.RemoveItem(absolute); } } }
public void SetFrom(ReferencedFileSave rfs) { backingData = rfs; foreach(var project in GlueState.Self.GetProjects()) { var projectName = project.Name; var settings = new IndividualProjectSetting(); settings.ProjectName = projectName; settings.IsEnabled = backingData.ProjectsToExcludeFrom.Contains(projectName) == false; settings.PropertyChanged += HandlePropertyChanged; ProjectSettings.Add(settings); } }
public void PopulateWithReferencesTo(ReferencedFileSave rfs) { List<IElement> elements = ObjectFinder.Self.GetAllElementsReferencingFile(rfs.Name); foreach (IElement element in elements) { var rfsInThisElement = element.GetReferencedFileSave(rfs.Name); listBox1.Items.Add(rfsInThisElement); foreach(var namedObject in element.AllNamedObjects) { if(namedObject.SourceType == SourceType.File && namedObject.SourceFile == rfsInThisElement.Name) { listBox1.Items.Add(namedObject); } } } // If this is a CSV, then loop through all of the variables and see if any of them use this type if (rfs.IsCsvOrTreatedAsCsv) { string className = rfs.Name; CustomClassSave customClass = ObjectFinder.Self.GlueProject.GetCustomClassReferencingFile(rfs.Name); if (customClass != null) { className = customClass.Name; } foreach (IElement element in ObjectFinder.Self.GlueProject.Screens) { foreach (CustomVariable customVariable in element.CustomVariables.Where(customVariable => customVariable.Type == className)) { listBox1.Items.Add(customVariable); } } foreach (IElement element in ObjectFinder.Self.GlueProject.Entities) { foreach (CustomVariable customVariable in element.CustomVariables.Where(customVariable => customVariable.Type == className)) { listBox1.Items.Add(customVariable); } } } }
public void Initialize() { // Couldn't run tests here because it requires FRB to be initialized. OverallInitializer.Initialize(); mBaseEntity = new EntitySave(); mBaseEntity.Name = "ReferencedFileSaveTestsBaseEntity"; ReferencedFileSave rfs = new ReferencedFileSave(); ObjectFinder.Self.GlueProject.Entities.Add(mBaseEntity); mDerivedEntity = new EntitySave(); mDerivedEntity.Name = "ReferencedFileSaveTestsDerivedEntity"; mDerivedEntity.BaseEntity = mBaseEntity.Name; ObjectFinder.Self.GlueProject.Entities.Add(mDerivedEntity); }
public void CopyToBuildFolder(ReferencedFileSave rfs) { string projectName = FileManager.RemovePath(FileManager.RemoveExtension(GlueState.Self.CurrentGlueProjectFileName)); string buildFolder = FileManager.GetDirectory(GlueState.Self.CurrentGlueProjectFileName) + "bin/x86/debug/Content/"; string destination = buildFolder + rfs.Name; string source = ProjectManager.ContentDirectory + rfs.Name; try { System.IO.File.Copy(source, destination, true); PluginManager.ReceiveOutput("Copied " + source + " ==> " + destination); } catch (Exception e) { System.Windows.Forms.MessageBox.Show("Error copying file:\n\n" + e.ToString()); } }
public static bool ContainsRecursively(this IElement element, ReferencedFileSave whatToLookFor) { foreach (ReferencedFileSave rfs in element.ReferencedFiles) { if (rfs == whatToLookFor) { return true; } } if (!string.IsNullOrEmpty(element.BaseElement)) { IElement baseElement = ObjectFinder.Self.GetIElement(element.BaseElement); if (baseElement != null) { return baseElement.ContainsRecursively(whatToLookFor); } } return false; }
public void TestReferencedFileSave() { EntitySave entitySave = new EntitySave(); ReferencedFileSave rfs = new ReferencedFileSave(); rfs.Name = "File.png"; entitySave.ReferencedFiles.Add(rfs); string whyNot; NameVerifier.IsReferencedFileNameValid("File", null, null, entitySave, out whyNot); if(string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("File.wav", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("Folder/File.wav", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("Folder/File", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("Same-named files shouldn't be allowed, but the NameVerifier allows it."); } NameVerifier.IsReferencedFileNameValid("if", null, null, entitySave, out whyNot); if (string.IsNullOrEmpty(whyNot)) { throw new Exception("'if' is a reserved keyword and should not be allowed as a file name"); } }
public void SelectFile(ReferencedFileSave rfs) { // see if this has a created class var customClass = ObjectFinder.Self.GetCustomClassFor(rfs); TreeNode treeNodeToSelect = null; if(customClass != null) { var treeNode = this.TreeView.Nodes .FirstOrDefault(item => item.Tag == customClass); if(treeNode != null) { var subnode = treeNode.Nodes .FirstOrDefault(item => item.Text == rfs.Name); treeNodeToSelect = subnode; } } TreeView.SelectedNode = treeNodeToSelect; }
static Scene LoadScnx(ReferencedFileSave r, IElement container) { Scene newScene = null; try { newScene = FlatRedBallServices.Load<Scene>(ElementRuntime.ContentDirectory + r.Name, GluxManager.ContentManagerName); foreach (Text text in newScene.Texts) { text.AdjustPositionForPixelPerfectDrawing = true; if (ObjectFinder.Self.GlueProject.UsesTranslation) { text.DisplayText = LocalizationManager.Translate(text.DisplayText); } } if (!r.IsSharedStatic || container is ScreenSave) { newScene.AddToManagers(); } } catch (Exception e) { throw new Exception("Error loading Scene file " + ElementRuntime.ContentDirectory + r.Name + e.ToString()); } return newScene; }
static AnimationChainList LoadAchx(ReferencedFileSave r) { AnimationChainList newAnimationChainList; string fileToLoad = ElementRuntime.ContentDirectory + r.Name; newAnimationChainList = FlatRedBallServices.Load<AnimationChainList>(fileToLoad, GluxManager.ContentManagerName); return newAnimationChainList; }
static ShapeCollection LoadShcx(ReferencedFileSave r, IElement container) { ShapeCollection newShapeCollection; newShapeCollection = FlatRedBallServices.Load<ShapeCollection>(ElementRuntime.ContentDirectory + r.Name, GluxManager.ContentManagerName); if (!r.IsSharedStatic || container is ScreenSave) { newShapeCollection.AddToManagers(); } return newShapeCollection; }
static EmitterList LoadEmix(ReferencedFileSave r) { return FlatRedBallServices.Load<EmitterList>(ElementRuntime.ContentDirectory + r.Name, GluxManager.ContentManagerName); }
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 static string GetRelativePath(this ReferencedFileSave referencedFileSave) { return(ProjectManager.ContentDirectoryRelative + referencedFileSave.Name); }
private static void ApplyOptions(ReferencedFileSave toReturn, string options) { if (toReturn.IsCsvOrTreatedAsCsv) { toReturn.CreatesDictionary = options == "Dictionary"; } }
public static void RefreshSourceFileCache(this ReferencedFileSave instance, bool buildOnMissingFile, out string error) { error = null; string verboseError = ""; string fullName = ProjectManager.MakeAbsolute(instance.Name, true); try { // If it has a SourceFile, then no need to throw an error here, it will be built if (!FileManager.FileExists(fullName) && string.IsNullOrEmpty(instance.SourceFile)) { } else { instance.SourceFileCache = ContentParser.GetSourceReferencingFilesReferencedByAsset(fullName, TopLevelOrRecursive.Recursive, ErrorBehavior.ContinueSilently, ref error, ref verboseError); bool hasErrorOccurred = !string.IsNullOrEmpty(error); if (!string.IsNullOrEmpty(verboseError)) { int m = 3; } // If the file doesn't exist, no reason to do this, just build it if (hasErrorOccurred) { bool forceError = false; if (buildOnMissingFile && (!string.IsNullOrEmpty(instance.SourceFile) || instance.SourceFileCache.Count != 0)) { string subError = instance.PerformExternalBuild(runAsync: false); if (!string.IsNullOrEmpty(subError)) { error += "\nTried to build the file, but also got this error:\n" + subError; // This will be returned through the "out" //ErrorReporter.ReportError(fullName, error, forceError); } else if (System.IO.File.Exists(fullName)) { } } else { string message = ""; if (!FileManager.FileExists(fullName)) { message = "Could not find the file\n\n" + fullName + "\n\n" + "Glue will not be able to properly track dependencies and add the necessary files " + "to your project until this file is added.\n\nThis often happens if someone forgot to " + "check something in to Subversion."; } else { message = "Error tracking dependencies for\n\n" + fullName + "\n\nError details:\n\n" + error; } error = message; } } } ContentParser.EliminateDuplicateSourceReferencingFiles(instance.SourceFileCache); } catch (Exception e) { error = "Error getting referenced files for\n\n" + fullName + "\n\nError:\n\n" + e.ToString(); } }
public static void ResetVariablesReferencing(this NamedObjectSave namedObject, ReferencedFileSave rfs) { for (int i = namedObject.InstructionSaves.Count - 1; i > -1; i--) { var variable = namedObject.InstructionSaves[i]; if (CustomVariableExtensionMethods.GetIsFile(variable.Type) && (string)(variable.Value) == rfs.GetInstanceName()) { // We're going to make it null, but // we don't save null instructions in // NOS's so that our .glux stays small // and so there's less chances of conflicts // occurring because of undefined sorting behavior. namedObject.InstructionSaves.RemoveAt(i); } } }
public static bool IsReferencedFileNameValid(string name, AssetTypeInfo ati, ReferencedFileSave rfs, IElement container, out string whyItIsntValid) { whyItIsntValid = ""; CheckForCommonImproperNames(name, ref whyItIsntValid); // CheckForExistingEntity checks if the name is already used, but we can be more specific if it's part of this entity if (container != null) { string unqualifiedContainerName = FileManager.RemovePath(container.Name); if (unqualifiedContainerName.ToLowerInvariant() == FileManager.RemovePath(FileManager.RemoveExtension(name))) { string containerType = "Entity"; if (container is ScreenSave) { containerType = "Screen"; } else if (container is EntitySave) { containerType = "Entity"; } else { containerType = "Container"; } whyItIsntValid = "The " + containerType + " that you are adding the file to has the same name as the file. This is not allowed in Glue. Please rename the file"; } } if (string.IsNullOrEmpty(whyItIsntValid)) { CheckForExistingEntity(name, ref whyItIsntValid); } if (string.IsNullOrEmpty(whyItIsntValid)) { CheckForRfsWithMatchingFileName(container, name, rfs, ref whyItIsntValid); } if (string.IsNullOrEmpty(whyItIsntValid)) { if (ati != null && ati.Extension == "csv") { // Let's see if there is already a spreadsheet by this name and if so, let's warn the user // But we only want a spreadsheet that isn't using a created class: var existing = ObjectFinder.Self.GetAllReferencedFiles().Where(item => // Is the item a CSV... item.IsCsvOrTreatedAsCsv && // And is the item different than the rfs we're checking item != rfs && // And do the names match? FileManager.RemovePath(FileManager.RemoveExtension(item.Name)) == name && // And does it not use a custom class? ObjectFinder.Self.GlueProject.CustomClasses.Any(customClass => customClass.CsvFilesUsingThis.Contains(item.Name)) == false) .ToList(); if (existing.Count != 0) { whyItIsntValid = "There is already a CSV file using the name " + name + ". This CSV is not using a custom class: " + existing[0].ToString(); } } } bool returnValue = string.IsNullOrEmpty(whyItIsntValid); return(returnValue); }
public static ReferencedFileSave AddReferencedFileSave(IElement element, string directoryPath, string fileName, AssetTypeInfo resultAssetTypeInfo, string option, out string errorMessage) { char invalidCharacter; ReferencedFileSave rfs = null; errorMessage = null; #region Get directory string directoryRelativeToContent = ""; if (!String.IsNullOrEmpty(directoryPath)) { //string directory = directoryTreeNode.GetRelativePath().Replace("/", "\\"); directoryRelativeToContent = directoryPath; } else if (element != null) { //string directory = elementToAddTo.GetRelativePath().Replace("/", "\\"); directoryRelativeToContent = element.Name.Replace(@"/", @"\") + "\\"; } else { directoryRelativeToContent = "GlobalContent/"; } #endregion bool userCancelled = false; #region If there is some reason why the file name won't, then work show a message box string whyIsntValid; if (!NameVerifier.IsReferencedFileNameValid(fileName, resultAssetTypeInfo, rfs, element, out whyIsntValid)) { errorMessage = "Invalid file name:\n" + fileName + "\n" + whyIsntValid; } else if (resultAssetTypeInfo == null) { errorMessage = "You must select a valid type for your new file."; } else if (ObjectFinder.Self.GetReferencedFileSaveFromFile(directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension) != null) { errorMessage = "There is already a file named\n\n" + directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension; } // TODO: This currently checks for an exact match, but we should prevent different files (like a .emix and .scnx) from having the same name else if (EditorLogic.CurrentElement != null && EditorLogic.CurrentElement.GetReferencedFileSaveRecursively(directoryRelativeToContent + fileName + "." + resultAssetTypeInfo.Extension) != null) { errorMessage = "There is already a file named " + fileName; } // need to check global content for duplicates. This is not implemented yet. #endregion #region Else, create the file else { string createdFile = PluginManager.CreateNewFile(resultAssetTypeInfo, option == "2D", directoryRelativeToContent, fileName); // let's just re-route this // to the code that adds existing // files now that we have a file and // that's exactly what we're doing. rfs = RightClickHelper.AddSingleFile(createdFile, ref userCancelled, option); if (rfs == null && !userCancelled) { throw new NullReferenceException("The RFS shouldn't be null"); } } #endregion return(rfs); }
private static void CheckForRfsWithMatchingFileName(IElement container, string name, ReferencedFileSave rfsToSkip, ref string whyItIsntValid) { if (container == null) { // We need to see if there is already a file with the same name in Global Content ReferencedFileSave existingRfs = ObjectFinder.Self.GlueProject.GlobalFiles.FirstOrDefault( rfs => (FileManager.RemovePath(rfs.Name) == name || rfs.GetInstanceName() == name) && rfs != rfsToSkip ); if (existingRfs != null) { whyItIsntValid += "There is already a file in GlobalContent using the name " + name; } } else { // We need to see if there is already a file with the same name in Global Content ReferencedFileSave existingRfs = container.ReferencedFiles.FirstOrDefault( rfs => { return((FileManager.RemovePath(rfs.Name) == name || FileManager.RemoveExtension(FileManager.RemovePath(rfs.Name)) == name) && rfs != rfsToSkip ); }); if (existingRfs != null) { whyItIsntValid += "There is already a file in " + container.Name + " using the name " + name; } } }
public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List<string> additionalFilesToRemove, bool regenerateCode) { // 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. #region Remove the file from the current Screen or Entity if there is a current Screen or Entity IElement container = referencedFileToRemove.GetContainer(); 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(false); } 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.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(); } ); ContentLoadWriter.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.GetRelativePath())) { UnreferencedFilesManager.Self.RefreshUnreferencedFiles(false); foreach (var file in UnreferencedFilesManager.LastAddedUnreferencedFiles) { additionalFilesToRemove.Add(file.FilePath); } } ReactToRemovalIfCsv(referencedFileToRemove, additionalFilesToRemove); GluxCommands.Self.SaveGlux(); }
public object LoadReferencedFileSave(ReferencedFileSave r, IElement container) { return LoadReferencedFileSave(r, false, container); }
public static string PerformExternalBuild(this ReferencedFileSave instance) { return(PerformExternalBuild(instance, false)); }
public object LoadReferencedFileSave(ReferencedFileSave r, bool isBeingAccessed, IElement container) { //////////////////EARLY OUT/////////////////// if (r.LoadedAtRuntime == false) { return null; } if (mLoadedRfses.ContainsKey(r.Name.ToLower())) { // do nothing, it's already been loaded) return mLoadedRfses[r.Name.ToLower()]; } /////////////END EARLY OUT////////////////////// object runtimeObject = LoadRfsAndAddToLists(r, isBeingAccessed, container); if (isBeingAccessed || runtimeObject != null) { mLoadedRfses.Add(r.Name.ToLower(), runtimeObject); return mLoadedRfses[r.Name.ToLower()]; } else { // It's null, but not being accessed so that's okay return null; } }
void HandleNewFile(ReferencedFileSave rfs) { HandleBuiltFileChange(ProjectManager.MakeAbsolute(rfs.Name)); }
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; }
public static string GetTypeForCsvFile(this ReferencedFileSave referencedFileSave, string alternativeFileName = null)//string fileName) { if (referencedFileSave == null) { throw new ArgumentNullException("ReferencedFileSave is null - it can't be."); } string fileName = referencedFileSave.Name; if (!string.IsNullOrEmpty(alternativeFileName)) { fileName = alternativeFileName; } if (!string.IsNullOrEmpty(referencedFileSave.UniformRowType)) { return(referencedFileSave.UniformRowType); } else { string className = null; // Make sure that the fileName is relative: // Wait! There's no reason to do this. The // RFS's Name property will always be relative // to the content project. This is a must to make // projects portable so we don't have to do any processing // on the file name. //if (!FileManager.IsRelative(fileName)) //{ // if (ProjectManager.ContentProject.Directory != null && // !FileManager.IsRelativeTo(ProjectManager.ContentProject.Directory, FileManager.RelativeDirectory)) // { // fileName = FileManager.MakeRelative(fileName, ProjectManager.ContentProject.Directory); // } // else // { // fileName = FileManager.MakeRelative(fileName); // } //} // Is this file using a custom class? CustomClassSave ccs = ObjectFinder.Self.GlueProject.GetCustomClassReferencingFile(fileName); if (ccs == null) { className = FileManager.RemovePath(FileManager.RemoveExtension(fileName)); if (className.EndsWith("File")) { className = className.Substring(0, className.Length - "File".Length); } className = EditorObjects.IoC.Container.Get <IVsProjectState>().DefaultNamespace + ".DataTypes." + className; } else { if (!string.IsNullOrEmpty(ccs.CustomNamespace)) { className = ccs.CustomNamespace + "." + ccs.Name; } else { className = EditorObjects.IoC.Container.Get <IVsProjectState>().DefaultNamespace + ".DataTypes." + ccs.Name; } } return(className); } }
public void RemoveReferencedFile(ReferencedFileSave referencedFileToRemove, List<string> additionalFilesToRemove) { RemoveReferencedFile(referencedFileToRemove, additionalFilesToRemove, true); }
private static int CompareReferencedFiles(ReferencedFileSave rfs1, ReferencedFileSave rfs2) { return(rfs1.Name.CompareTo(rfs2.Name)); }
private static void ReactToRemovalIfCsv(ReferencedFileSave referencedFileToRemove, List<string> additionalFilesToRemove) { if (referencedFileToRemove.IsCsvOrTreatedAsCsv) { string name = referencedFileToRemove.GetTypeForCsvFile(); // If the CSV uses a custom class then the user should not // be asked if the file for that class should be removed. That // class was created independent of any CSV (perhaps by hand, perhaps // by plugin), so the user should have to explicitly remove the class. var customClass = ObjectFinder.Self.GlueProject.GetCustomClassReferencingFile(referencedFileToRemove.Name); if (customClass == null) { var first = ObjectFinder.Self.GetAllReferencedFiles().FirstOrDefault(item => item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == name); if (first == null) { // Remove the class string whatToRemove = "DataTypes/" + name + ".Generated.cs"; additionalFilesToRemove.Add(whatToRemove); } } // See if this uses a custom class. If so, remove the CSV from // the class' list. if (customClass != null) { customClass.CsvFilesUsingThis.Remove(referencedFileToRemove.Name); } } }
public static TypeConverter GetTypeConverter(this CustomVariable customVariable, IElement containingElement, StateSave stateSave, FlatRedBall.Glue.Plugins.ExportedInterfaces.IGlueState glueState) { TypeConverter typeConverter = null; if (customVariable.GetIsVariableState()) { typeConverter = new AvailableStates( FacadeContainer.Self.GlueState.CurrentNamedObjectSave, FacadeContainer.Self.GlueState.CurrentElement, FacadeContainer.Self.GlueState.CurrentCustomVariable, FacadeContainer.Self.GlueState.CurrentStateSave ); } else { Type runtimeType = customVariable.GetRuntimeType(); if (runtimeType != null) { if (runtimeType.IsEnum) { typeConverter = new EnumConverter(runtimeType); } else if (runtimeType == typeof(Color)) { return(new AvailableColorTypeConverter()); } else if ((runtimeType == typeof(string) || runtimeType == typeof(AnimationChainList)) && customVariable.SourceObjectProperty == "CurrentChainName") { typeConverter = new AvailableAnimationChainsStringConverter(customVariable, stateSave); } else if (customVariable.GetIsFile()) { AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement); converter.QualifiedRuntimeTypeName = runtimeType.FullName; converter.ShowNewFileOption = false; converter.RemovePathAndExtension = true; typeConverter = converter; } } else if (customVariable.GetIsCsv()) { if (FacadeContainer.Self.ProjectValues == null) { throw new NullReferenceException("The ProjectValues property in FAcadeContainer.Self.ProjectValues must be set before trying to get the CSV type converter for the variable " + customVariable.ToString()); } ReferencedFileSave rfs = ObjectFinder.Self.GetAllReferencedFiles().FirstOrDefault(item => item.IsCsvOrTreatedAsCsv && item.GetTypeForCsvFile() == customVariable.Type); AvailableSpreadsheetValueTypeConverter converter = null; if (rfs != null) { converter = new AvailableSpreadsheetValueTypeConverter( FacadeContainer.Self.ProjectValues.ContentDirectory + rfs.Name, containingElement); } else { converter = new AvailableSpreadsheetValueTypeConverter( FacadeContainer.Self.ProjectValues.ContentDirectory + customVariable.Type, containingElement); } converter.ShouldAppendFileName = true; typeConverter = converter; } else if (customVariable.GetIsFile()) { // If we got here, that means that the // CustomVariable is a file, but it doesn't // have a System.Type, so it only knows its runtime // type; AvailableFileStringConverter converter = new AvailableFileStringConverter(containingElement); converter.UnqualifiedRuntimeTypeName = customVariable.Type; converter.ShowNewFileOption = false; converter.RemovePathAndExtension = true; typeConverter = converter; } } return(typeConverter); }