From 22dbc8b5b02414cdd755a25e0311ebedad671a8e Mon Sep 17 00:00:00 2001 From: AraHaan Date: Thu, 8 Dec 2022 14:08:07 -0500 Subject: [PATCH] Use IDisposableGenerator in unluac for LuaDecompileStream. (#115) This is so that way the code becomes simpler and easier to maintain. --- src/UnluacNET/Directory.Build.targets | 1 + src/UnluacNET/Directory.Packages.props | 4 ++++ src/UnluacNET/LuaDecompileStream.cs | 32 ++++++++------------------ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/src/UnluacNET/Directory.Build.targets b/src/UnluacNET/Directory.Build.targets index e9e727f..99c13ec 100644 --- a/src/UnluacNET/Directory.Build.targets +++ b/src/UnluacNET/Directory.Build.targets @@ -9,6 +9,7 @@ + diff --git a/src/UnluacNET/Directory.Packages.props b/src/UnluacNET/Directory.Packages.props index 3dbd75c..98d6e98 100644 --- a/src/UnluacNET/Directory.Packages.props +++ b/src/UnluacNET/Directory.Packages.props @@ -2,6 +2,10 @@ + + all + runtime; build; native; contentfiles; compile; analyzers; buildtransitive + diff --git a/src/UnluacNET/LuaDecompileStream.cs b/src/UnluacNET/LuaDecompileStream.cs index a5e7b32..508e20f 100644 --- a/src/UnluacNET/LuaDecompileStream.cs +++ b/src/UnluacNET/LuaDecompileStream.cs @@ -5,7 +5,11 @@ namespace Elskom.Generic.Libs.UnluacNET; -public class LuaDecompileStream : Stream +/// +/// A stream that can decompile Lua files. +/// +[GenerateDispose(true)] +public partial class LuaDecompileStream : Stream { /// /// Initializes a new instance of the class. @@ -39,7 +43,7 @@ public LuaDecompileStream(Stream input, bool keepOpen) /// Initializes a new instance of the class. /// public LuaDecompileStream() - : this(new MemoryStream(), false) + : this(new MemoryStream()) => this.InputNoData = true; /// @@ -65,14 +69,11 @@ public override long Position set => throw new NotSupportedException(); } + [DisposeField(true)] private Stream BaseStream { get; set; } private bool InputNoData { get; } - private bool KeepOpen { get; } - - private bool IsDisposed { get; set; } - /// /// Decompiles Lua bytecode based on the data Read from the input stream. /// @@ -105,31 +106,18 @@ public override void Write(byte[] buffer, int offset, int count) _ = this.DecompileLuaWithStreamBuffer(); } + /// public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); + /// public override void SetLength(long value) => throw new NotSupportedException(); + /// public override void Flush() => throw new NotSupportedException(); - protected override void Dispose(bool disposing) - { - if (!this.IsDisposed && disposing) - { - if (!this.KeepOpen) - { - this.BaseStream.Dispose(); - this.BaseStream = null; - } - - this.IsDisposed = true; - } - - base.Dispose(disposing); - } - private int DecompileLuaWithStreamBuffer() { if (this.BaseStream is not MemoryStream baseMemStream)