void documentManager_DocumentRenamed(IDocument document, string oldPath) { Output.Write(OutputTypes.Debug, "Document renamed from " + oldPath + " to " + document.DocumentFilename); TagPath oldTagPath = new TagPath(oldPath); string testPath; if (oldTagPath.Location == TagLocation.Archive) { testPath = oldTagPath.ToPath(PathFormat.Relative); } else { testPath = oldTagPath.ToPath(PathFormat.ExplicitLocation); } foreach (ProjectTag tag in projectManager.Project.Templates.GetTemplateList()) { if (tag.Path == testPath) { projectManager.Project.Templates.UpdateElementPath( tag.TemplateElement, document.DocumentFilename); return; } } foreach (TemplateTag tag in projectManager.Project.Template.TagSet) { if (tag.DefaultFile + "." + tag.FileType == testPath) { projectManager.Project.Templates.Add(tag.Name, new TagPath(document.DocumentFilename)); return; } } }
/// <summary> /// Adds the the specified template element/path combination to the list. /// </summary> public void Add(string templateElement, TagPath tagPath) { // Make sure that the template element that is attempting to be added exists in // the related Template for this list. bool validTemplate = false; foreach (TemplateTag templateTag in baseTemplate.TagSet) { if (templateTag.Name == templateElement) { validTemplate = true; break; } } if (validTemplate) { // Get the explicit location and add that path to the elements // (Or update an existing path if the named element already exists.) string path = tagPath.ToPath(PathFormat.ExplicitLocation); ProjectTag tag = new ProjectTag(templateElement, path); if (!templateTags.ContainsKey(templateElement)) { templateTags.Add(templateElement, tag); } else { templateTags[templateElement].Path = path; } // If the tag is from the project, store the relative path // (no "p:\" prefix) to the templateTagHierarchy. if (tagPath.Location == TagLocation.Project) { templateTagHierarchy.Add(tagPath.ToPath(PathFormat.Relative)); // We added a new file yar!! OnFileAdded(path, templateElement); TemplateTag templateTag = GetTemplateTag(templateElement); if (templateTag != null) { // Again, haxzorzz!! TagPath lePath = new TagPath(templateTag.DefaultFile + "." + templateTag.FileType, "", TagLocation.Archive); OnFileRemoved(lePath.ToPath(PathFormat.ExplicitLocation), templateTag.Name); } } } else { throw new Exception("The specified element '" + templateElement + "' does not exist in the template '" + baseTemplate.Name + "'"); } }
/// <summary> /// Retreive the TagFile object from the specified TagPath. /// </summary> public TagFile GetTagFile(TagPath path) { // Qualify the scope if necessary. if (path.Location == TagLocation.Auto) { string qualifiedPath = QualifyScope(path.Game, path.Path); TagPath newPath = new TagPath(qualifiedPath); path.Location = newPath.Location; } byte[] bin = null; if (path.Location == TagLocation.Archive) { bin = archives[path.Game].ReadFile(path.Path + "." + path.Extension); } else if (path.Location == TagLocation.Project) { if (library != null) { bin = library.ReadFile(path.Path + "." + path.Extension); } } if (bin == null) { throw new Exception("The specified tag was not found: " + path.ToPath()); } MemoryStream stream = new MemoryStream(bin); TagFile file = new TagFile(stream); return(file); }
/// <summary> /// Adds a format-specific archive to the list of available archives. /// </summary> /// <param name="gameFormat">game that the archive supports</param> /// <param name="library">archive to add</param> public void RegisterGame(string gameFormat, string globalsTagName, TypeTable types, ILibrary library) { if (archives.ContainsKey(gameFormat)) // halo pc and halo ce, for instance, use the same library. { return; } archives.Add(gameFormat, library); tables.Add(gameFormat, types); if (library == null) { return; } if (!String.IsNullOrEmpty(globalsTagName)) { TagPath path = new TagPath(globalsTagName, gameFormat, TagLocation.Archive); if (library.FileExists(globalsTagName)) { globals.Add(gameFormat, Open(path.ToPath(), types.LocateEntryByName(path.Extension).TagType, true, true)); } } }
public void RemoveByElementName(string elementName) { ProjectTag[] values = new ProjectTag[templateTags.Values.Count]; templateTags.Values.CopyTo(values, 0); foreach (ProjectTag tag in values) { if (tag.TemplateElement == elementName) { templateTags.Remove(tag.TemplateElement); TagPath basePath = new TagPath(tag.Path); if (basePath.Location == TagLocation.Project) { string relativePath = basePath.ToPath(PathFormat.Relative); templateTagHierarchy.RemoveFile(relativePath); } OnFileRemoved(tag.Path, elementName); TemplateTag templateTag = GetTemplateTag(elementName); if (templateTag != null) { // Generate the FileAdded event with the default filename - this is so that the // ProjectExplorer can update it's Essential Tags list. // This is kind of hackish, because the ProjectFile shouldn't be worrying // about the PE at all. A more appropriate place to put this functionality would // be in the ProjectNodeSource, but that would complicate some things and would // force me to write additional code. And we all know how lazy I am! :D TagPath path = new TagPath(templateTag.DefaultFile + "." + templateTag.FileType, "", TagLocation.Archive); OnFileAdded(path.ToPath(PathFormat.ExplicitLocation), templateTag.Name); } } } }
/// <summary> /// Determines the initial state that subscribers of this state will be in. /// </summary> protected override bool DetermineState(NodeInfo info) { // Look up the document in the DocumentManager TagPath path = new TagPath(info.Identifier, gameID, tagLocation); return(manager.DocumentExists(path.ToPath())); }
void Templates_FileAdded(object sender, TemplateTagActionArgs e) { TagPath path = new TagPath(e.Filename); NodeInfo info; if (path.Location == TagLocation.Project) { info = new NodeInfo(GetNodeType <ProjectTemplateTagNodeType>(), path.ToPath(PathFormat.ExplicitLocation)); } else { info = new NodeInfo(GetNodeType <GlobalTemplateTagNodeType>(), path.ToPath(PathFormat.Relative)); } info.Tag = e.TemplateElement; OnItemAdded(info); }
private bool previewTest(MultiSourceTreeNode node, NodeInfo info) { // Check to see if the tag is previewable and isn't already open. if (game.TypeTable.Previewable(Path.GetExtension(info.Identifier).TrimStart('.'))) { TagPath path = new TagPath(info.Identifier, game.GameID, TagLocation.Project); return(!RenderCore.ContainsScene(path.ToPath())); } return(false); }
/// <summary> /// Takes a non-qualified path and creates a fully-qualified path based on tag scope. /// This method takes into account scope priority rules. /// </summary> private string QualifyScope(string gameID, string path) { // TODO: Eventually, when we supoprt a shared folder and prefabs, we will need to look through them. // Check the Project folder first. TagPath tagPath = new TagPath(path, gameID, TagLocation.Project); if (TagExists(tagPath)) { return(tagPath.ToPath()); } // Next check the game archive. tagPath.Location = TagLocation.Archive; if (TagExists(tagPath)) { return(tagPath.ToPath()); } return(""); }
public void PerformTest() { Interfaces.Games.GameDefinition def = Core.Prometheus.Instance.GetGameDefinitionByGameID("halopc"); Core.Libraries.TagArchive tagArchive = (Core.Libraries.TagArchive)def.GlobalTagLibrary; string[] files = tagArchive.GetFileList("", "*", true); ProgressDialog pd = new ProgressDialog(); pd.Show(); pd.SuspendLayout(); pd.Maximum = files.Length; List <string> classes = new List <string>(100); for (int x = 0; x < files.Length; x++) { pd.Info2 = files[x]; pd.Value = x; pd.Refresh(); string fileExt = files[x].Substring(files[x].LastIndexOf('.')).ToLower(); if (classes.Contains(fileExt)) { continue; } // Open the tag. TagPath path = new TagPath(files[x], "halopc", TagLocation.Archive); Type type = Core.Prometheus.Instance.GetTypeFromTagPath(path); Tag tag = Core.Prometheus.Instance.Pool.Open(path.ToPath(), type, false); using (Prometheus.Controls.TagEditor.TagEditorControl tempTagEditorControl = new Prometheus.Controls.TagEditor.TagEditorControl()) { try { // Load the tag in the tag editor tempTagEditorControl.Create(def, def.TypeTable.LocateEntryByName(tag.FileExtension).FourCC, tag); } catch { Interfaces.Output.Write(Interfaces.OutputTypes.Error, "There was an error loading tag " + x + ": " + files[x]); } } classes.Add(fileExt); } System.Windows.Forms.MessageBox.Show("A total of " + classes.Count + " tags/classes were tested!"); }
public string OnAddScene(TagPath path) { GameDefinition game = instance.GetGameDefinitionByGameID(path.Game); string tagName = path.Path + "." + path.Extension; Type type = game.TypeTable.LocateEntryByName(path.Extension).TagType; if (!new List <Type>(type.GetInterfaces()).Contains(typeof(IInstanceable))) { throw new CoreException("Cannot preview tag; {0} does not implement {1}.", type.FullName, typeof(IInstanceable).Name); } Tag tag = pool.Open(path.ToPath(), type, true); string identifier = path.ToPath(); if (!scenes.ContainsKey(identifier)) { scenes.Add(identifier, tag); } Camera newCam = new Camera(); if (tag is ScenarioBase) { Interfaces.Rendering.Radiosity.WorldBounds totalBounds = (tag as ScenarioBase).BspList[0].WorldBounds; foreach (IBsp bsp in (tag as ScenarioBase).BspList) { totalBounds &= bsp.WorldBounds; } newCam.Position = new Vector3((totalBounds.X.Lower + totalBounds.X.Upper) / 2, (totalBounds.Y.Lower + totalBounds.Y.Upper) / 2, (totalBounds.Z.Lower + totalBounds.Z.Upper) / 2); } RenderCore.AddScene(identifier, tagName, newCam, ((IInstanceable)tag).Instance, RenderState.Textured, game.GetSceneType(tag)); // Temp using RenderState.Textured until we load the value from the project file. RenderCore.ActiveSceneName = identifier; //added this line to activate the latest Scene - gren return(identifier); }
/// <summary> /// Returns a standardized tooltip to represent a TagPath. /// </summary> public static string GetTagPathToolTip(TagPath path, bool abridged) { StringBuilder sb = new StringBuilder(); if (path.Location == TagLocation.Archive) { sb.Append("<img src=\"global::Prometheus.Properties.Resources.joystick16\"/>"); if (!abridged) { if (!String.IsNullOrEmpty(path.Game)) { GameDefinition gd = Core.Prometheus.Instance.GetGameDefinitionByGameID(path.Game); if (gd != null) { sb.Append(" <b>" + gd.LongName + "</b>"); } } } } else if (path.Location == TagLocation.Project) { sb.Append("<img src=\"global::Prometheus.Properties.Resources.application16\"/>"); if (!abridged) { if (Core.Prometheus.Instance.ProjectManager.ProjectLoaded) { sb.Append(" <b>" + Core.Prometheus.Instance.ProjectManager.Project.MapName + "</b>"); } } } else { sb.Append("<i>Unknown Location</i>"); } if (!abridged) { sb.Append("<br/>"); } else { sb.Append(" "); } sb.Append(path.ToPath(PathFormat.Relative)); return(sb.ToString()); }
/// <summary> /// Removes the specified tag from the list of tag references for this project. /// </summary> /// <param name="path">The path of the reference to remove.</param> /// <param name="autoRevertTemplateTag">If the reference points to an essential tag, specifies if it will automatically be reverted to its default tag. Normally, the user is prompted in this scenario.</param> /// <returns>A value indicating if the reference was removed.</returns> public bool RemoveTagReference(string path, bool autoRevertEssentialTag) { // In order to see if this is a referenced essential tag, we need to // create a project-scoped explicit path to check against. // TODO: After shared folder / prefabs are implemented, we will also need to check those. TagPath projectPath = new TagPath(path); projectPath.Location = TagLocation.Project; string projectPathString = projectPath.ToPath(PathFormat.ExplicitLocation); // Check the essential tags collection (templates), not the normal references table (projectReferencesTable). if (templates.ContainsPath(projectPathString)) { // This is an essential tag, so get it's corresponding template name. // Ex: 'levels\test\bloodgulch\bloodgulch.scenario' would be the 'Scenario' template element. string templateName = templates.GetTemplateNameBypath(projectPathString); // If we aren't auto-reverting, generate the TemplateReverting event to prompt the user. bool revertEssentialTag = autoRevertEssentialTag; if (!autoRevertEssentialTag) { // The value returned here indicates whether the event was cancelled, so we want the inverse of it. revertEssentialTag = !OnTemplateReverting(projectPathString, templateName); } if (revertEssentialTag) { templates.RemoveByTagPath(projectPathString); // User chose to remove, or auto-revert was set. } else { return(false); // Nothing was removed. } } else // This was not an essential tag. { if (FileExists(path)) { // Remove the reference from the references table and raise the corresponding event. projectReferencesTable.RemoveFile(path); OnFileRemoved(path); } } return(true); // References were removed. }
/// <summary> /// Returns an array of NodeInfo entries that exist beneath the specified NodeInfo. /// </summary> public override NodeInfo[] GetChildNodes(NodeInfo info) { List <NodeInfo> children = new List <NodeInfo>(); TagArchiveObjectViewNodeSource source = (TagArchiveObjectViewNodeSource)ParentSource; // Get a list of dependencies of the tag that matches the specified path. Pool pool = Core.Prometheus.Instance.Pool; string tagName = Path.GetExtension(info.Identifier).Trim('.'); Type tagType = source.Game.TypeTable.LocateEntryByName(tagName).TagType; TagPath poolPath = new TagPath(info.Identifier, source.Game.GameID, TagLocation.Archive); string[] references = new string[0]; try { references = pool.GetTagReferences(poolPath.ToPath(), tagType); } catch { //NodeInfo errorInfo = new NodeInfo("", "error", this); //MultiSourceTreeNode node = CreateNode("Error deserializing tag.", errorInfo); //children.Add(node); } foreach (string reference in references) { if (reference == "") { continue; } if (!source.Library.FileExists(reference)) { continue; } NodeInfo tagInfo = new NodeInfo(source.GetNodeType <TagNodeType>(), reference); children.Add(tagInfo); } return(children.ToArray()); }
private bool documentOpenedTest(MultiSourceTreeNode node, NodeInfo info) { TagPath path = new TagPath(info.Identifier, projectManager.GameID, TagLocation.Project); return(!Core.Prometheus.Instance.DocumentManager.DocumentExists(path.ToPath())); }
/// <summary> /// Checks to see if the tag at the specified path exists. /// </summary> public bool TagExists(TagPath path) { if (path.Location == TagLocation.Archive) { GameDefinition def = Core.Prometheus.Instance.GetGameDefinitionByGameID(path.Game); if (def == null) { Output.Write(OutputTypes.Debug, "A tag was passed to 'Pool.TagExists()' that references a game that was not found in the GameDefinition list: " + path.ToPath()); return(false); } return(def.GlobalTagLibrary.FileExists(path.Path + "." + path.Extension)); } else if (path.Location == TagLocation.Project) { // Make sure that a project is loaded. ProjectManager pm = Core.Prometheus.Instance.ProjectManager; if (pm != null) { if (pm.ProjectLoaded) { if (pm.GameID == path.Game) { return(pm.ProjectFolder.FileExists(path.Path + "." + path.Extension)); } } } return(false); } else { throw new Exception("The specified tag source is invalid or not supported."); } }
/// <summary> /// Update the path that corresponds to the specified element. /// </summary> public void UpdateElementPath(string element, TagPath newTagPath) { string newPath = newTagPath.ToPath(PathFormat.ExplicitLocation); UpdateElementPath(element, newPath); }
/// <summary> /// A nongeneric method used to create a tag and return a handle to the tag when the strong type of that tag is not available. /// </summary> /// <param name="name">tag path name of the tag to be created</param> /// <param name="type">type of the tag to be created</typeparam> /// <returns>the newly created tag or null if bad call</returns> public Tag Create(TagPath path, Type type, bool doPostProcessing) { return(GetTagInstance(PoolAction.CreateNew, path.ToPath(PathFormat.ExplicitLocation), type, doPostProcessing, false, false, true, path.Game)); }
private void Extract(TagArchive archive, bool recusive, params string[] files) { extractionActive = true; int totalFilesExtracted = 0, totalFilesToExtract = 0; List <TagSet> sets = archive.BuildTagLocationList(files, currentGame); // Setup the counts. foreach (TagSet set in sets) { totalFilesToExtract += set.Tags.Count; } progressPanel.TotalExtracted = 0; progressPanel.TagCount = totalFilesToExtract; UniqueStringCollection additionalFiles = new UniqueStringCollection(); try { foreach (TagSet set in sets) { string filename = currentGame.Maps[set.MapIndex].Filename; // UI Update progressPanel.CurrentMap = Path.GetFileName(filename); progressPanel.CurrentMap = filename; progressPanel.OpeningMap = true; IMapFile map = currentGame.CreateMapFileObject(); map.Load(currentGame.MapFilePath + "\\" + filename); progressPanel.ExtractingTags = true; // Sort alphabetically so that folders don't get extracted out of order. set.Tags.Sort(); // Extract the tags one by one. foreach (string tag in set.Tags) { // UI Update progressPanel.CurrentTag = tag; bool successful = true; try { // Check and see if we have attempted to cancel... if (!extractionActive) { return; } if (!archive.FileExists(tag)) { byte[] data = map.GetTag(tag); archive.AddFile(tag, data); } } catch (Exception ex) { successful = false; Output.Write(OutputTypes.Error, "Unable to extract tag '" + tag + ex.Message); } if (successful) { RemoveFromQueue(tag); } totalFilesExtracted++; // UI Update progressPanel.TotalExtracted = totalFilesExtracted; if (recusive) { // Attempt to deserialize the tag, and get its dependencies. string tagExtension = Path.GetExtension(tag).Trim('.'); Type tagType = currentGame.TypeTable.LocateEntryByName(tagExtension).TagType; TagPath poolPath = new TagPath(tag, currentGame.GameID, TagLocation.Archive); string[] dependencies = Core.Prometheus.Instance.Pool.GetTagReferences(poolPath.ToPath(), tagType); foreach (string dependency in dependencies) { if (!archive.FileExists(dependency)) { additionalFiles.Add(dependency); } } } } } if (additionalFiles.Count > 0) { progressPanel.Title = "Extracting dependencies..."; // Extract the additional files. Extract(archive, true, additionalFiles.ToArray()); } } finally { UpdateExtractionButton(); } }
public void PerformTest() { try { System.IO.StreamWriter sw = new System.IO.StreamWriter("C:\\tagerrors.txt"); Interfaces.Games.GameDefinition def = Core.Prometheus.Instance.GetGameDefinitionByGameID("halopc"); Core.Libraries.TagArchive tagArchive = (Core.Libraries.TagArchive)def.GlobalTagLibrary; string[] files = tagArchive.GetFileList("", "*", true); ProgressDialog pd = new ProgressDialog(); pd.Show(); pd.SuspendLayout(); pd.Maximum = files.Length; for (int x = 0; x < files.Length; x++) { try { string fileExt = files[x].Substring(files[x].LastIndexOf('.') + 1); // get the extension of the file. if (fileExt.ToLower() == "scenario") { continue; } if (fileExt.ToLower() == "scenario_structure_bsp") { continue; } if (fileExt.ToLower() == "unit_hud_interface") { continue; } using (Prometheus.Controls.TagEditor.TagEditorControl tempTagEditorControl = new Prometheus.Controls.TagEditor.TagEditorControl()) { // Setup the progress dialog. pd.Info1 = "Testing tags... (" + (x + 1) + " out of " + files.Length + ")"; pd.Info2 = files[x]; pd.Refresh(); // Open the tag. TagPath path = new TagPath(files[x], "halopc", TagLocation.Archive); Type type = Core.Prometheus.Instance.GetTypeFromTagPath(path); Tag tag = Core.Prometheus.Instance.Pool.Open(path.ToPath(), type, false); // Load the tag in the tag editor try { tempTagEditorControl.Create(def, def.TypeTable.LocateEntryByName(tag.FileExtension).FourCC, tag); sw.WriteLine("File: " + files[x] + "(" + x + ")"); Interfaces.Output.Write(Interfaces.OutputTypes.Information, "Tag completed sucessfully!"); } catch (Exception ex) { // Write any error data Interfaces.Output.Write(Interfaces.OutputTypes.Error, "There was an error loading tag " + x + " \"" + files[x] + "\": " + ex.Message, ""); sw.WriteLine("File: " + files[x] + "(" + x + ")"); sw.WriteLine("Error: " + ex.Message); sw.WriteLine("Trace: " + ex.StackTrace); sw.Flush(); } // refresh the tooltip //Interfaces.TagEditor.FieldControl.stFieldControl = new DevComponents.DotNetBar.SuperTooltip(); } pd.Value = x; } catch (Exception ex) { Interfaces.Output.Write(Interfaces.OutputTypes.Error, "There was an error loading tag " + x + " \"" + files[x] + "\":" + ex.Message, ""); sw.WriteLine("File: " + files[x]); sw.WriteLine("Error: " + ex.Message); sw.WriteLine("Trace: " + ex.StackTrace); sw.Flush(); } } pd.Close(); sw.Close(); } catch (Exception ex) { Interfaces.Output.Write(Interfaces.OutputTypes.Error, "There was an error performing the test: " + ex.Message, ""); } }