This commit is contained in:
LDj3SNuD 2019-09-15 14:13:40 +02:00 committed by GitHub
commit b48b542c06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -35,6 +35,7 @@ namespace ARMeilleure.Translation.AOT
public static string TitleId { get; private set; } public static string TitleId { get; private set; }
public static bool Enabled { get; private set; } public static bool Enabled { get; private set; }
public static bool ReadOnlyMode { get; private set; }
static Aot() static Aot()
{ {
@ -52,6 +53,7 @@ namespace ARMeilleure.Translation.AOT
TitleId = String.Empty; TitleId = String.Empty;
Enabled = false; Enabled = false;
ReadOnlyMode = true;
_infosStream = new MemoryStream(); _infosStream = new MemoryStream();
_codesStream = new MemoryStream(); _codesStream = new MemoryStream();
@ -75,6 +77,7 @@ namespace ARMeilleure.Translation.AOT
} }
Enabled = enabled; Enabled = enabled;
ReadOnlyMode = readOnlyMode;
if (enabled) if (enabled)
{ {
@ -97,6 +100,8 @@ namespace ARMeilleure.Translation.AOT
{ {
using (FileStream compressedCacheStream = new FileStream(cachePath, FileMode.Open)) using (FileStream compressedCacheStream = new FileStream(cachePath, FileMode.Open))
{ {
DeflateStream deflateStream = new DeflateStream(compressedCacheStream, CompressionMode.Decompress, true);
MemoryStream cacheStream = new MemoryStream(); MemoryStream cacheStream = new MemoryStream();
MD5 md5 = MD5.Create(); MD5 md5 = MD5.Create();
@ -105,7 +110,7 @@ namespace ARMeilleure.Translation.AOT
try try
{ {
using (DeflateStream deflateStream = new DeflateStream(compressedCacheStream, CompressionMode.Decompress, true)) using (deflateStream)
{ {
deflateStream.CopyTo(cacheStream); deflateStream.CopyTo(cacheStream);
} }
@ -150,22 +155,22 @@ namespace ARMeilleure.Translation.AOT
} }
else else
{ {
compressedCacheStream.SetLength(0L); InvalidateCompressedCacheStream(compressedCacheStream);
} }
} }
else else
{ {
compressedCacheStream.SetLength(0L); InvalidateCompressedCacheStream(compressedCacheStream);
} }
} }
else else
{ {
compressedCacheStream.SetLength(0L); InvalidateCompressedCacheStream(compressedCacheStream);
} }
} }
catch catch
{ {
compressedCacheStream.SetLength(0L); InvalidateCompressedCacheStream(compressedCacheStream);
} }
md5.Dispose(); md5.Dispose();
@ -208,6 +213,14 @@ namespace ARMeilleure.Translation.AOT
headerReader.Dispose(); headerReader.Dispose();
} }
private static void InvalidateCompressedCacheStream(FileStream compressedCacheStream)
{
if (!ReadOnlyMode)
{
compressedCacheStream.SetLength(0L);
}
}
private static void MergeAndSave(Object source, ElapsedEventArgs e) private static void MergeAndSave(Object source, ElapsedEventArgs e)
{ {
string cachePath = Path.Combine(WorkPath, TitleId); string cachePath = Path.Combine(WorkPath, TitleId);