Fix LuaAddonFileInfo returning NULL content.

master
Icedream 2014-12-11 04:07:13 +01:00
parent 6b89b38b96
commit eb36e6013c
2 changed files with 31 additions and 5 deletions

View File

@ -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;
/// <summary>
/// The file size.
/// The file size.
/// </summary>
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;
}
}
}
/// <summary>
/// The CRC32 hash of this file.
/// The CRC32 hash of this file.
/// </summary>
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;
}
}
}
/// <summary>
/// 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.
/// </summary>
/// <returns>Byte array of the file content</returns>
public abstract byte[] GetContents();

View File

@ -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;
}