private void TextBox_WADFile_TextChanged(object sender, EventArgs e) { try { var tb = (TextBox)sender; var filePath = tb.Text; if (string.IsNullOrWhiteSpace(filePath)) { return; } var file = new FileInfo(filePath); if (!file.Exists) { return; } using (var fs = file.OpenRead()) { this.CurrentFile = WADFileFactory.FromStream(fs).FirstOrDefault(); } } catch (Exception ex) { this.ShowError(ex); } }
private void UpdateMapView(IWADFile file) { try { using (var oldMap = this.PictureBox_Map.Image) { if (file == null) { return; } var offsetX = (int)this.NumericUpDown_OffsetX.Value; var offsetY = (int)this.NumericUpDown_OffsetY.Value; var scale = (int)this.NumericUpDown_MapScale.Value; var newImage = new Bitmap(short.MaxValue / 10, short.MaxValue / 10, PixelFormat.Format32bppArgb); try { var whitePen = Pens.White; using (var g = Graphics.FromImage(newImage)) { g.FillRectangle(Brushes.Black, new Rectangle(0, 0, newImage.Width, newImage.Height)); foreach (var lump in file.EnumerateLumps().OfType <ILinedefsLump>()) { foreach (var linedef in lump.EnumerateLinedefs()) { var p1 = new Point((linedef.Start.X) / scale + offsetX, (linedef.Start.Y) / scale + offsetY); var p2 = new Point((linedef.End.X) / scale + offsetX, (linedef.End.Y) / scale + offsetY); g.DrawLine(whitePen, p1, p2); } } g.Flush(); g.Save(); } this.PictureBox_Map.Image = newImage; } catch (Exception ex) { newImage.Dispose(); throw ex; } } } catch (Exception ex) { this.ShowError(ex); } }
/// <summary> /// Enumerates over the DOOM 2 maps. /// </summary> /// <param name="wadFile">The IWAD file.</param> /// <returns>The list of maps.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="wadFile" /> is <see langword="null" />. /// </exception> /// <exception cref="FormatException"> /// <paramref name="wadFile" /> has an invalid value in <see cref="IWADFile.Format" />. /// </exception> public static IEnumerable <IWADFile> EnumerateDOOM2Maps(this IWADFile wadFile) { if (wadFile == null) { throw new ArgumentNullException("wadFile"); } if (wadFile.Format != WADFormat.Default) { throw new FormatException("wadFile"); } using (var stream = wadFile.GetStream()) { ILump mapLump = null; IList <ILump> lumpsOfMap = null; foreach (var lump in wadFile.EnumerateLumps()) { if ((lump.Name ?? string.Empty).ToUpper().Trim().StartsWith("MAP")) { if (lumpsOfMap != null) { using (var builder = new WADFileBuilder(true)) { builder.AddRange(lumpsOfMap); yield return(builder.Build(mapLump.Name, WADFormat.Default)); } } mapLump = lump; lumpsOfMap = new List <ILump>(); continue; } if (mapLump == null) { continue; } lumpsOfMap.Add(lump); } } }
private void UpdateView(IWADFile file) { try { try { // remove old lumps foreach (var lvi in this.ListView_Lumps.Items .Cast <ListViewItem>()) { using (var lump = (ILump)lvi.Tag) { lvi.Remove(); } } this.SplitContainer_LumpDetails.Visible = false; if (file == null) { return; } foreach (var lump in file.EnumerateLumps()) { var lvi = new ListViewItem(); lvi.Tag = lump; lvi.Text = lump.Name; this.ListView_Lumps.Items.Add(lvi); } this.SplitContainer_LumpDetails.Visible = true; } finally { this.ListView_Lumps_SelectedIndexChanged(this.ListView_Lumps, EventArgs.Empty); } } catch (Exception ex) { this.ShowError(ex); } }
/// <summary> /// Creates instances from a stream. /// </summary> /// <param name="format">The format.</param> /// <param name="stream">The stream.</param> /// <param name="bufferSize">The custom buffer size to use to read from <paramref name="stream" />.</param> /// <returns>The list of lazy loaded instances.</returns> /// <exception cref="ArgumentException"> /// <paramref name="stream" /> is not readable. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="stream" /> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="bufferSize" /> is less than 1. /// </exception> public static IEnumerable <IWADFile> FromStream(Stream stream, WADFormat format = WADFormat.Default, int?bufferSize = null) { if (stream == null) { throw new ArgumentNullException("stream"); } if (stream.CanRead == false) { throw new ArgumentException("stream"); } if (bufferSize < 1) { throw new ArgumentOutOfRangeException("bufferSize", bufferSize, "Is less than 1!"); } bool hasNext; do { hasNext = false; byte[] buffer; buffer = new byte[4]; if (stream.Read(buffer, 0, buffer.Length) != buffer.Length) { continue; } var header = Encoding.ASCII.GetString(buffer).ToUpper().Trim(); IWADFile result = null; var wadStream = new MemoryStream(); try { Action copyToWadStream = () => { if (!bufferSize.HasValue) { stream.CopyTo(wadStream); } else { stream.CopyTo(wadStream, bufferSize.Value); } wadStream.Position = 0; }; switch (header) { case "IWAD": copyToWadStream(); result = new IWAD(format, wadStream, true); break; case "PWAD": copyToWadStream(); result = new PWAD(format, wadStream, true); break; } } catch (Exception ex) { wadStream.Dispose(); throw ex; } if (result != null) { hasNext = true; yield return(result); } }while (hasNext); }
private void UpdateMapView(IWADFile file) { try { using (var oldMap = this.PictureBox_Map.Image) { if (file == null) { return; } var offsetX = (int)this.NumericUpDown_OffsetX.Value; var offsetY = (int)this.NumericUpDown_OffsetY.Value; var scale = (int)this.NumericUpDown_MapScale.Value; var newImage = new Bitmap(short.MaxValue / 10, short.MaxValue / 10, PixelFormat.Format32bppArgb); try { var whitePen = Pens.White; using (var g = Graphics.FromImage(newImage)) { g.FillRectangle(Brushes.Black, new Rectangle(0, 0, newImage.Width, newImage.Height)); foreach (var lump in file.EnumerateLumps().OfType<ILinedefsLump>()) { foreach (var linedef in lump.EnumerateLinedefs()) { var p1 = new Point((linedef.Start.X) / scale + offsetX, (linedef.Start.Y) / scale + offsetY); var p2 = new Point((linedef.End.X) / scale + offsetX, (linedef.End.Y) / scale + offsetY); g.DrawLine(whitePen, p1, p2); } } g.Flush(); g.Save(); } this.PictureBox_Map.Image = newImage; } catch (Exception ex) { newImage.Dispose(); throw ex; } } } catch (Exception ex) { this.ShowError(ex); } }
private void UpdateView(IWADFile file) { try { try { // remove old lumps foreach (var lvi in this.ListView_Lumps.Items .Cast<ListViewItem>()) { using (var lump = (ILump)lvi.Tag) { lvi.Remove(); } } this.SplitContainer_LumpDetails.Visible = false; if (file == null) { return; } foreach (var lump in file.EnumerateLumps()) { var lvi = new ListViewItem(); lvi.Tag = lump; lvi.Text = lump.Name; this.ListView_Lumps.Items.Add(lvi); } this.SplitContainer_LumpDetails.Visible = true; } finally { this.ListView_Lumps_SelectedIndexChanged(this.ListView_Lumps, EventArgs.Empty); } } catch (Exception ex) { this.ShowError(ex); } }