Faction Test v1.0.1.0

This commit is contained in:
Regalis11
2023-02-16 15:01:28 +02:00
parent caa5a2f762
commit 2c5a7923b0
309 changed files with 7502 additions and 4335 deletions
@@ -1,9 +1,7 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
using Barotrauma.IO;
using System;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
@@ -12,52 +10,6 @@ namespace Barotrauma
{
public class Md5Hash
{
public static class Cache
{
private const string cachePath = "Data/hashcache.txt";
private readonly static List<(string Path, Md5Hash Hash, DateTime DateTime)> Entries
= new List<(string Path, Md5Hash Hash, DateTime DateTime)>();
public static void Load()
{
if (!File.Exists(cachePath)) { return; }
var lines = File.ReadAllLines(cachePath);
if (Version.TryParse(lines[0], out var cacheVersion) && cacheVersion == GameMain.Version)
{
for (int i = 1; i < lines.Length; i++)
{
string[] split = lines[i].Split('|');
string path = split[0].CleanUpPathCrossPlatform();
Md5Hash hash = Md5Hash.StringAsHash(split[1]);
DateTime? dateTime = null;
if (long.TryParse(split[2], out long dateTimeUlong))
{
dateTime = DateTime.FromBinary(dateTimeUlong);
}
if (File.Exists(path) && dateTime.HasValue && dateTime >= File.GetLastWriteTime(path))
{
Entries.Add((path, hash, dateTime.Value));
}
}
}
}
public static void Add(string path, Md5Hash hash, DateTime dateTime)
{
path = path.CleanUpPathCrossPlatform();
Remove(path);
Entries.Add((path, hash, dateTime));
}
public static void Remove(string path)
{
path = path.CleanUpPathCrossPlatform();
Entries.RemoveAll(e => e.Path == path);
}
}
public static readonly Md5Hash Blank = new Md5Hash(new string('0', 32));
private static string RemoveWhitespace(string s)
@@ -212,8 +164,13 @@ namespace Barotrauma
return false;
}
public override int GetHashCode()
{
return ShortRepresentation.GetHashCode(StringComparison.OrdinalIgnoreCase);
}
public static bool operator ==(Md5Hash? a, Md5Hash? b)
=> (a is null == b is null) && (a?.Equals(b) ?? true);
=> Equals(a, b);
public static bool operator !=(Md5Hash? a, Md5Hash? b) => !(a == b);
}