diff --git a/src/addoncreator/Addon/AddonFileInfo.cs b/src/addoncreator/Addon/AddonFileInfo.cs index d14d26d..757e655 100644 --- a/src/addoncreator/Addon/AddonFileInfo.cs +++ b/src/addoncreator/Addon/AddonFileInfo.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using GarrysMod.AddonCreator.Hashing; namespace GarrysMod.AddonCreator.Addon @@ -8,23 +9,47 @@ namespace GarrysMod.AddonCreator.Addon private long? _size; /// - /// The file size. + /// The file size. /// public virtual long Size { - get { lock(this) return _size.HasValue ? _size.Value : (_size = GetContents().Length).Value; } + get + { + lock (this) + { + if (_size != null) + return _size.Value; + + var contents = GetContents(); + Debug.Assert(contents != null, "Contents are NULL"); + + return (_size = contents.Length).Value; + } + } } /// - /// The CRC32 hash of this file. + /// The CRC32 hash of this file. /// public virtual int Crc32Hash { - get { lock (this) return _hash.HasValue ? _hash.Value : (_hash = Crc32.Compute(GetContents())).Value; } + get + { + lock (this) + { + if (_hash != null) + return _hash.Value; + + var contents = GetContents(); + Debug.Assert(contents != null, "Contents are NULL"); + + return (_hash = Crc32.Compute(GetContents())).Value; + } + } } /// - /// Reads all contents of this file and returns it as a byte array. + /// Reads all contents of this file and returns it as a byte array. /// /// Byte array of the file content public abstract byte[] GetContents(); diff --git a/src/addoncreator/Addon/LuaAddonFileInfo.cs b/src/addoncreator/Addon/LuaAddonFileInfo.cs index b39cc06..23d50dd 100644 --- a/src/addoncreator/Addon/LuaAddonFileInfo.cs +++ b/src/addoncreator/Addon/LuaAddonFileInfo.cs @@ -42,6 +42,7 @@ namespace GarrysMod.AddonCreator.Addon _luaCode = Encoding.UTF8.GetString(_fi.GetContents()); _luaCode = Regex.Replace(_luaCode, _stripCommentsRegex, m => m.Groups["linebreak"] != null ? m.Groups["linebreak"].Value : ""); + _content = Encoding.UTF8.GetBytes(_luaCode); return _content; }