private void StartupDetermineType(string path) { try { if (File.Exists(path)) { // Magic Check var stream = new EndianStream(new FileStream(path, FileMode.Open), Endian.BigEndian); stream.SeekTo(0); switch (stream.ReadAscii(0x04)) { case "head": // Map File stream.Close(); AddCacheTabModule(path); return; case "_blf": // BLF Container, needs more checking stream.Close(); var blf = new PureBLF(path); blf.Close(); if (blf.BLFChunks.Count > 2) { switch (blf.BLFChunks[1].ChunkMagic) { case "levl": AddInfooTabModule(path); return; case "mapi": AddImageTabModule(path); return; } } MetroMessageBox.Show("Unsupported BLF Type", "The selected BLF file is not supported in assembly."); return; default: MetroMessageBox.Show("Unsupported file type", "The selected file is not supported in assembly."); return; } } MetroMessageBox.Show("Unable to find file", "The selected file could no longer be found"); } catch (Exception ex) { MetroException.Show(ex); } }
private void loadBLF() { try { _blf = new PureBLF(_blfLocation); List<byte> imgChunkData = new List<byte>(_blf.BLFChunks[1].ChunkData); imgChunkData.RemoveRange(0, 0x08); Dispatcher.Invoke(new Action(delegate { BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(imgChunkData.ToArray()); image.EndInit(); imgBLF.Source = image; // Add Image Info paneImageInfo.Children.Insert(0, new Components.MapHeaderEntry("Image Width:", image.PixelWidth + "px")); paneImageInfo.Children.Insert(1, new Components.MapHeaderEntry("Image Height", image.PixelHeight + "px")); // Add BLF Info paneBLFInfo.Children.Insert(0, new Components.MapHeaderEntry("BLF Length:", "0x" + _blf.BLFStream.Length.ToString("X"))); paneBLFInfo.Children.Insert(1, new Components.MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString())); if (Settings.startpageHideOnLaunch) Settings.homeWindow.ExternalTabClose(Windows.Home.TabGenre.StartPage); RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "BLF Image", Settings.RecentFileType.BLF); })); } catch (Exception ex) { Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open BLF", ex.Message.ToString()); Settings.homeWindow.ExternalTabClose((TabItem)this.Parent); })); } }
public void LoadMapInfo() { try { // Just a lazy way to validate the BLF file _blf = new PureBLF(_blfLocation); if (_blf.BLFChunks[1].ChunkMagic != "levl") throw new Exception("The selected Map Info BLF is not a valid Map Info BLF file."); _blf.Close(); _mapInfo = new MapInfo(_blfLocation); Dispatcher.Invoke(new Action(delegate { // Add BLF Info paneBLFInfo.Children.Insert(0, new Components.MapHeaderEntry("BLF Length:", "0x" + _mapInfo.Stream.Length.ToString("X8"))); paneBLFInfo.Children.Insert(1, new Components.MapHeaderEntry("BLF Chunks:", _blf.BLFChunks.Count.ToString())); // Load Languages LoadLanguages(_mapInfo.MapInformation.Game); // Add Map Info switch (_mapInfo.MapInformation.Game) { case MapInfo.GameIdentifier.Halo3: txtGameName.Text = "Halo 3"; break; case MapInfo.GameIdentifier.Halo3ODST: txtGameName.Text = "Halo 3: ODST"; break; case MapInfo.GameIdentifier.HaloReach: txtGameName.Text = "Halo Reach"; break; case MapInfo.GameIdentifier.Halo4: txtGameName.Text = "Halo 4"; break; } txtMapID.Text = _mapInfo.MapInformation.MapID.ToString(); lblBLFNameFooter.Text = lblBLFname.Text = txtMapInternalName.Text = _mapInfo.MapInformation.InternalName; txtMapPhysicalName.Text = _mapInfo.MapInformation.PhysicalName; // Update UI cbLanguages.SelectedIndex = 0; if (Settings.startpageHideOnLaunch) Settings.homeWindow.ExternalTabClose(Windows.Home.TabGenre.StartPage); RecentFiles.AddNewEntry(new FileInfo(_blfLocation).Name, _blfLocation, "Map Info", Settings.RecentFileType.MapInfo); _startEditing = true; })); } catch (Exception ex) { Dispatcher.Invoke(new Action(delegate { MetroMessageBox.Show("Unable to open MapInfo", ex.Message.ToString()); Settings.homeWindow.ExternalTabClose((TabItem)this.Parent); })); } }