/// <summary> /// Opens Frostbite binary file in <see cref="treeViewBinaryFile"/> based on given file path and hexadecimal offset in <see cref="textBoxOffset"/>. /// </summary> /// <param name="filePath">File path to load in tool.</param> private void OpenBinaryFile(string filePath) { uint offset = Convert.ToUInt32(textBoxOffset.Text, 16); treeViewBinaryFile.Nodes.Clear(); // Clears any potentially previously-loaded nodes // Tool tries its best not to overwrite user's custom-inputted offset // So it checks that the offset is 0 or 556 (header size) before doing header checks and changing offset if (offset == 0 || offset == 556) { if (SurfaceFile.IsHeaderPresent(filePath)) { checkBoxHeader.Checked = true; offset = 556; } else { checkBoxHeader.Checked = false; offset = 0; } } treeViewBinaryFile.OpenFrostbiteBinaryFile(filePath, offset); this.Text = $"{this.formText} - {Path.GetFileName(filePath)}"; }
/// <summary> /// Helper method for opening Frostbite binary file data inside of <see cref="TreeView"/>. /// </summary> /// <param name="treeView">The <see cref="TreeView"/> object to open data in.</param> /// <param name="path">The file to open for reading.</param> /// <param name="offset">Position to start reading in file.</param> public static void OpenFrostbiteBinaryFile(this TreeView treeView, string path, uint offset) { Entry mainEntry = SurfaceFile.CreateEntry(path, offset); TreeNode mainEntryNode = mainEntry.CreateTreeNode(); // After adding mainEntryNode expands it to reveal data quicker treeView.Nodes.Add(mainEntryNode); treeView.Nodes[0].Expand(); }
/// <summary> /// Reads data from file to put into current <see cref="InitFS"/> object. /// </summary> /// <param name="path">The file to read from.</param> /// <exception cref="ArgumentException">Thrown if file does not exist in <paramref name="path"/>.</exception> private void ReadFromFile(string path) { if (!File.Exists(path)) { throw new ArgumentException("Data does not point to valid file on system.", "path"); } using var reader = new BinaryReader(File.OpenRead(path)); this.Name = Path.GetFileName(path); this.IsWin32 = SurfaceFile.IsHeaderPresent(reader); this.Keys = this.IsWin32 ? reader.ReadBytes(SurfaceConstants.KeysLength) : SurfaceFile.GetBlankKeys; this.FileEntryList = (List <Entry>)SurfaceFile.CreateEntry(path, this.IsWin32).Data; }