예제 #1
0
        private void OpenTagReferenceRequested(object sender, TagReferenceEventArgs e)
        {
            //Get file name
            string fileName = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags", e.TagReference);

            try
            {
                //Load
                AbideTagGroupFile tagGroupFile = new AbideTagGroupFile();
                using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    tagGroupFile.Load(stream);

                //Create
                TagFileModel tagGroupFileViewModel = new TagFileModel(fileName, tagGroupFile);
                tagGroupFileViewModel.CloseCallback              = File_Close;
                tagGroupFileViewModel.OpenTagReferenceRequested += OpenTagReferenceRequested;
                Files.Add(tagGroupFileViewModel);

                //Set
                SelectedFile = tagGroupFileViewModel;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Unable to open the specified file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                throw ex;
            }
        }
예제 #2
0
 /// <summary>
 /// Loads the tag group from the file.
 /// </summary>
 public override void LoadFromFile()
 {
     //Check
     if (File.Exists(FileName))
     {
         tagGroupFile.Load(FileName);
     }
 }
예제 #3
0
        static void Main(string[] args)
        {
            var tagReferences = new List <string>();
            var file          = new AbideTagGroupFile();

            file.Load(args[0]);

            DiscoverReferences(tagReferences, file.TagGroup);
        }
예제 #4
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Prepare
            AbideTagGroupFile file = null;

            //Initialize
            using (OpenFileDialog openDlg = new OpenFileDialog())
            {
                //Setup
                openDlg.Filter = "All files (*.*)|*.*";
                openDlg.CustomPlaces.Add(new FileDialogCustomPlace(RegistrySettings.WorkspaceDirectory));

                //Show
                if (openDlg.ShowDialog() == DialogResult.OK)
                {
                    //Check
                    if (openEditors.ContainsKey(openDlg.FileName))
                    {
                        openEditors[openDlg.FileName].Show();
                    }
#if DEBUG
                    //Load file
                    file = new AbideTagGroupFile();
                    file.Load(openDlg.FileName);
#else
                    try
                    {
                        using (Stream stream = openDlg.OpenFile())
                        {
                            //Load file
                            file = new AbideTagGroupFile();
                            file.Load(stream);
                        }
                    }
                    catch { file = null; MessageBox.Show($"An error occured while opening {openDlg.FileName}.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); }
#endif

                    //Check
                    if (file != null)
                    {
                        //Create editor
                        TagGroupFileEditor editor = new TagGroupFileEditor(openDlg.FileName, file)
                        {
                            MdiParent = this
                        };
                        editor.FileNameChanged += Editor_FileNameChanged;
                        editor.FormClosed      += Editor_FormClosed;

                        //Show
                        editor.Show();
                    }
                }
            }
        }
예제 #5
0
        private void OpenFile()
        {
            //Prepare
            string tagsDirectory = Path.Combine(RegistrySettings.WorkspaceDirectory, "tags");

            //Create
            OpenFileDialog openDlg = new OpenFileDialog
            {
                InitialDirectory = tagsDirectory,
                Filter           = "All Files (*.*)|*.*"
            };

            //Add custom place
            openDlg.CustomPlaces.Add(new FileDialogCustomPlace(tagsDirectory));

            //Show
            if (openDlg.ShowDialog() ?? false)
            {
                if (!Files.Any(f => f.FileName == openDlg.FileName))
                {
                    try
                    {
                        //Load
                        AbideTagGroupFile tagGroupFile = new AbideTagGroupFile();
                        using (var stream = openDlg.OpenFile())
                            tagGroupFile.Load(stream);

                        //Create
                        TagFileModel tagGroupFileViewModel = new TagFileModel(openDlg.FileName, tagGroupFile);
                        tagGroupFileViewModel.CloseCallback              = File_Close;
                        tagGroupFileViewModel.OpenTagReferenceRequested += OpenTagReferenceRequested;
                        Files.Add(tagGroupFileViewModel);

                        //Set
                        SelectedFile = tagGroupFileViewModel;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Unable to open the specified file.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                        throw ex;
                    }
                }
            }
        }
예제 #6
0
        private static void DiscoverReferences(List <string> tagReferences, Block tagBlock)
        {
            foreach (var field in tagBlock)
            {
                switch (field)
                {
                case TagReferenceField tagReferenceField:
                    var tagString = tagReferenceField.String;
                    if (!string.IsNullOrEmpty(tagString))
                    {
                        if (!tagReferences.Contains(tagString))
                        {
                            string fileName = Path.Combine(TagsDirectory, tagString);
                            if (File.Exists(fileName))
                            {
                                tagReferences.Add(tagString);
                                var file = new AbideTagGroupFile();
                                file.Load(fileName);
                                DiscoverReferences(tagReferences, file.TagGroup);
                            }
                        }
                    }
                    break;

                case BlockField blockField:
                    foreach (var block in blockField.BlockList)
                    {
                        DiscoverReferences(tagReferences, block);
                    }
                    break;

                case StructField structField:
                    DiscoverReferences(tagReferences, structField.Block);
                    break;
                }
            }
        }
예제 #7
0
        private void Click(object obj)
        {
            List <string>       strings = new List <string>();
            List <TagReference> tags    = new List <TagReference>();
            List <IndexEntry>   entries = new List <IndexEntry>();
            TagId currentId             = TagId.Null;

            var openDlg = new OpenFileDialog()
            {
                Filter = "XML Files (*.xml)|*.xml"
            };

            if (openDlg.ShowDialog() ?? false)
            {
                XmlDocument document = new XmlDocument();
                document.Load(openDlg.FileName);

                var tagsRoot        = Path.GetDirectoryName(openDlg.FileName);
                var manifest        = document["AbideTagManifest"];
                var tagNameManifest = manifest["TagNames"];

                foreach (XmlNode node in tagNameManifest)
                {
                    var tagName  = node.Attributes["Name"].InnerText;
                    var groupTag = new TagFourCc(node.Attributes["GroupTag"].InnerText);
                    tags.Add(new TagReference()
                    {
                        TagName  = tagName,
                        GroupTag = groupTag
                    });
                }

                var globals = Map.GetTagById(Map.GlobalsTagId);
                using (var tagData = Map.ReadTagData(globals))
                {
                    _ = tagData.Stream.Seek(globals.MemoryAddress, SeekOrigin.Begin);
                    var globalsTagGroup = TagLookup.CreateTagGroup(globals.Tag);
                    globalsTagGroup.Read(tagData.Stream.CreateReader());

                    var soundGlobals = (BlockField)globalsTagGroup.TagBlocks[0].Fields[4];
                    if (soundGlobals.BlockList.Count == 1)
                    {
                        var soundGlobalsBlock = soundGlobals.BlockList[0];
                        currentId = (TagId)soundGlobalsBlock.Fields[4].Value;
                    }
                }

                using (var map = new HaloMap(Map.FileName))
                {
                    var soundCacheFileGestaltEntry = map.IndexEntries[currentId];

                    foreach (var tag in tags)
                    {
                        if (map.IndexEntries.Any(e => e.Filename == tag.TagName && e.Root == tag.GroupTag))
                        {
                            tag.Id = map.IndexEntries.First(e => e.Filename == tag.TagName && e.Root == tag.GroupTag).Id;
                        }
                        else
                        {
                            var tagGroup = TagLookup.CreateTagGroup(tag.GroupTag);
                            tag.FileName = Path.Combine(tagsRoot, $"{tag.TagName}.{tagGroup.Name}");

                            var tagGroupFile = new AbideTagGroupFile();
                            tagGroupFile.Load(tag.FileName);

                            var entry = new IndexEntry()
                            {
                                Filename = tag.TagName,
                                Id       = currentId++,
                                Tag      = map.Tags.First(t => t.Root == tag.GroupTag),
                            };

                            entries.Add(entry);
                            tag.TagGroup = tagGroupFile.TagGroup;
                            tag.Id       = entry.Id;

                            foreach (var offset in tagGroupFile.GetResourceAddresses())
                            {
                                var resource = tagGroupFile.GetResource(offset);
                                _ = entry.Resources.AddResource((int)offset, resource);
                            }
                        }
                    }

                    soundCacheFileGestaltEntry.Id = currentId;

                    int insertionIndex = map.IndexEntries.IndexOf(e => e == soundCacheFileGestaltEntry);
                    foreach (var tag in tags.Where(t => File.Exists(t.FileName)))
                    {
                        ConvertToCache(tag.TagGroup, map, tags);
                        var entry = entries.First(e => e.Id == tag.Id);

                        using (var stream = new MemoryStream())
                            using (var writer = new BinaryWriter(stream))
                            {
                                tag.TagGroup.Write(writer);
                                entry.Data.SetBuffer(stream.ToArray());
                                _ = map.IndexEntries.Insert(insertionIndex, entry);
                            }
                    }

                    map.Save(Path.Combine(tagsRoot, $"{map.Name}.map"));
                }
            }
        }