Faction Test v1.0.1.0
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user