Remove use of CRCs to bypass bullshit.
This commit is contained in:
@@ -25,7 +25,7 @@ namespace Content.Client.Parallax
|
|||||||
|
|
||||||
// Both of these below are in the user directory.
|
// Both of these below are in the user directory.
|
||||||
private static readonly ResourcePath ParallaxPath = new ResourcePath("/parallax_cache.png");
|
private static readonly ResourcePath ParallaxPath = new ResourcePath("/parallax_cache.png");
|
||||||
private static readonly ResourcePath ParallaxConfigCrcPath = new ResourcePath("/parallax_config_crc");
|
private static readonly ResourcePath ParallaxConfigOld = new ResourcePath("/parallax_config_old");
|
||||||
|
|
||||||
public event Action<Texture> OnTextureLoaded;
|
public event Action<Texture> OnTextureLoaded;
|
||||||
public Texture ParallaxTexture { get; private set; }
|
public Texture ParallaxTexture { get; private set; }
|
||||||
@@ -34,6 +34,7 @@ namespace Content.Client.Parallax
|
|||||||
{
|
{
|
||||||
MemoryStream configStream = null;
|
MemoryStream configStream = null;
|
||||||
long crcValue;
|
long crcValue;
|
||||||
|
string contents;
|
||||||
TomlTable table;
|
TomlTable table;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -44,22 +45,20 @@ namespace Content.Client.Parallax
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate CRC32 of the config file.
|
using (var reader = new StreamReader(configStream, Encoding.UTF8))
|
||||||
var crc = new Crc32();
|
{
|
||||||
crc.Update(configStream.ToArray());
|
contents = reader.ReadToEnd();
|
||||||
crcValue = crc.Value;
|
}
|
||||||
|
|
||||||
// See if we we have a previous CRC stored.
|
if (_resourceCache.UserData.Exists(ParallaxConfigOld))
|
||||||
if (_resourceCache.UserData.Exists(ParallaxConfigCrcPath))
|
|
||||||
{
|
{
|
||||||
bool match;
|
bool match;
|
||||||
using (var data = _resourceCache.UserData.Open(ParallaxConfigCrcPath, FileMode.Open))
|
using (var data = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Open))
|
||||||
using (var binaryReader = new BinaryReader(data))
|
using (var reader = new StreamReader(data, Encoding.UTF8))
|
||||||
{
|
{
|
||||||
match = binaryReader.ReadInt64() == crcValue;
|
match = reader.ReadToEnd() == contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the previous CRC matches, just load the old texture.
|
|
||||||
if (match)
|
if (match)
|
||||||
{
|
{
|
||||||
using (var stream = _resourceCache.UserData.Open(ParallaxPath, FileMode.Open))
|
using (var stream = _resourceCache.UserData.Open(ParallaxPath, FileMode.Open))
|
||||||
@@ -72,12 +71,7 @@ namespace Content.Client.Parallax
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Well turns out the CRC does not match so the config changed.
|
table = Toml.ReadString(contents);
|
||||||
// Read the new config and get rid of the config memory stream.
|
|
||||||
using (var reader = new StreamReader(configStream, Encoding.UTF8))
|
|
||||||
{
|
|
||||||
table = Toml.ReadString(reader.ReadToEnd());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
@@ -95,10 +89,10 @@ namespace Content.Client.Parallax
|
|||||||
image.SaveAsPng(stream);
|
image.SaveAsPng(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var stream = _resourceCache.UserData.Open(ParallaxConfigCrcPath, FileMode.Create))
|
using (var stream = _resourceCache.UserData.Open(ParallaxConfigOld, FileMode.Create))
|
||||||
using (var writer = new BinaryWriter(stream))
|
using (var writer = new StreamWriter(stream, Encoding.UTF8))
|
||||||
{
|
{
|
||||||
writer.Write(crcValue);
|
writer.Write(contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnTextureLoaded?.Invoke(ParallaxTexture);
|
OnTextureLoaded?.Invoke(ParallaxTexture);
|
||||||
|
|||||||
Reference in New Issue
Block a user