private void LoadModuleNames(string Location, bool Load_Externals = true) { string Folder = Path.GetDirectoryName(Location); if (Directory.Exists(Folder)) { Module_Names = new Dictionary <uint, string>(); External_Sections = new Dictionary <uint, Section_Entry[]>(); string[] Files = Directory.GetFiles(Folder); for (int i = 0; i < Files.Length; i++) { string Extension = Path.GetExtension(Files[i]); string File_Name = Path.GetFileNameWithoutExtension(Files[i]); byte[] Buff; if (Extension == ".rel" && !Files[i].Equals(Location)) { //Debug.WriteLine("Loading rel: " + File_Name); Buff = File.ReadAllBytes(Files[i]); uint Id = BitConverter.ToUInt32(Buff.Take(4).Reverse().ToArray(), 0); // Don't Load a REL file with the same id as the current one if (Id == Header.Id) { Debug.WriteLine(string.Format("Skipping loading {0} - the id was the same as the current rel!", File_Name)); continue; } if (Id == 0) { Debug.WriteLine(string.Format("Module Loading Error: A REL file has an ID of 0! File Name: {0}", File_Name)); continue; } else if (Module_Names.ContainsKey(Id)) { Debug.WriteLine(string.Format("Module Loading Error: A REL file has an ID that was previously found! File Name: {0}", File_Name)); continue; } Module_Names.Add(Id, File_Name); if (Load_Externals) { REL External_Rel = new REL(Buff, Files[i], false); External_Sections.Add(Id, External_Rel.Section_Entries); } } else if (Extension == ".dol" && !Module_Names.ContainsKey(0)) { Module_Names.Add(0, File_Name); } } } }
private void Open_Click(object sender, RoutedEventArgs e) { openFileDialog.Filter = "Relocatable Module|*.rel|Binary File|*.bin|All Files|*.*"; openFileDialog.DefaultExt = ".rel"; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fileLocation = openFileDialog.FileName; if (File.Exists(fileLocation)) { //HexEditor.FileName = fileLocation; File_Buffer = File.ReadAllBytes(fileLocation); Title = "Nintendo Reloctable Module Editor - " + Path.GetFileName(fileLocation); HexEditor.Stream = new MemoryStream(File_Buffer); Module = new REL(File_Buffer, fileLocation); progressLabel.Content = "REL Loaded"; } } }