Latest work

This commit is contained in:
Timothy Baldridge 2022-06-29 07:18:04 -06:00
parent 609d473387
commit 1c0fec2d02
7 changed files with 50 additions and 15 deletions

View File

@ -1,5 +1,8 @@
### Changelog ### Changelog
#### Version - 2.5.3.25 - 6/29/2022
* Correctly modify Witcher 3 settings to the game accepts the values
#### Version - 2.5.3.23 - 6/24/2022 #### Version - 2.5.3.23 - 6/24/2022
* Automatically set the screen resolution on Witcher 3 installs * Automatically set the screen resolution on Witcher 3 installs
* Fix the launcher's error messages when run in bad folders * Fix the launcher's error messages when run in bad folders

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text.Json; using System.Text.Json;
@ -12,14 +13,15 @@ public static class StreamExtensions
{ {
public static async Task CopyToLimitAsync(this Stream frm, Stream tw, int limit, CancellationToken token) public static async Task CopyToLimitAsync(this Stream frm, Stream tw, int limit, CancellationToken token)
{ {
var buff = new byte[1024 * 128]; using var buff = MemoryPool<byte>.Shared.Rent(1024 * 128);
var buffMemory = buff.Memory;
while (limit > 0 && !token.IsCancellationRequested) while (limit > 0 && !token.IsCancellationRequested)
{ {
var toRead = Math.Min(buff.Length, limit); var toRead = Math.Min(buffMemory.Length, limit);
var read = await frm.ReadAsync(buff.AsMemory(0, toRead), token); var read = await frm.ReadAsync(buffMemory[..toRead], token);
if (read == 0) if (read == 0)
throw new Exception("End of stream before end of limit"); throw new Exception("End of stream before end of limit");
await tw.WriteAsync(buff.AsMemory(0, read), token); await tw.WriteAsync(buffMemory[..read], token);
limit -= read; limit -= read;
} }

View File

@ -68,6 +68,11 @@ public class FileExtractor
_limiter = limiter; _limiter = limiter;
} }
public FileExtractor WithTemporaryFileManager(TemporaryFileManager manager)
{
return new FileExtractor(_logger, _parallelOptions, manager, _limiter);
}
public async Task<IDictionary<RelativePath, T>> GatheringExtract<T>( public async Task<IDictionary<RelativePath, T>> GatheringExtract<T>(
IStreamFactory sFn, IStreamFactory sFn,
Predicate<RelativePath> shouldExtract, Predicate<RelativePath> shouldExtract,

View File

@ -82,7 +82,7 @@ public abstract class AInstaller<T>
_logger = logger; _logger = logger;
_extractor = extractor; _extractor = extractor;
_jsonSerializer = jsonSerializer; _jsonSerializer = jsonSerializer;
_vfs = vfs; _vfs = vfs.WithTemporaryFileManager(_manager);
FileHashCache = fileHashCache; FileHashCache = fileHashCache;
_downloadDispatcher = downloadDispatcher; _downloadDispatcher = downloadDispatcher;
_parallelOptions = parallelOptions; _parallelOptions = parallelOptions;

View File

@ -172,7 +172,28 @@ public static class AbsolutePathExtensions
CancellationToken token) CancellationToken token)
{ {
// TODO: Make this async // TODO: Make this async
File.Move(src.ToString(), dest.ToString(), overwrite); var srcStr = src.ToString();
var destStr = dest.ToString();
var fi = new FileInfo(srcStr);
if (fi.IsReadOnly)
fi.IsReadOnly = false;
var fid = new FileInfo(destStr);
if (dest.FileExists() && fid.IsReadOnly)
{
fid.IsReadOnly = false;
}
try
{
File.Move(srcStr, destStr, overwrite);
}
catch (Exception)
{
}
} }
public static async ValueTask CopyToAsync(this AbsolutePath src, AbsolutePath dest, bool overwrite, public static async ValueTask CopyToAsync(this AbsolutePath src, AbsolutePath dest, bool overwrite,
@ -217,15 +238,11 @@ public static class AbsolutePathExtensions
DeleteDirectory(directory.ToAbsolutePath(), dontDeleteIfNotEmpty); DeleteDirectory(directory.ToAbsolutePath(), dontDeleteIfNotEmpty);
} }
try try
{
Directory.Delete(path.ToString(), true);
}
catch (IOException)
{ {
var di = new DirectoryInfo(path.ToString()); var di = new DirectoryInfo(path.ToString());
if (di.Attributes.HasFlag(FileAttributes.ReadOnly)) if (di.Attributes.HasFlag(FileAttributes.ReadOnly))
di.Attributes &= ~FileAttributes.ReadOnly; di.Attributes &= ~FileAttributes.ReadOnly;
di.Delete(true); Directory.Delete(path.ToString(), true);
} }
catch (UnauthorizedAccessException) catch (UnauthorizedAccessException)
{ {

View File

@ -44,6 +44,12 @@ public class Context
_parallelOptions = parallelOptions; _parallelOptions = parallelOptions;
} }
public Context WithTemporaryFileManager(TemporaryFileManager manager)
{
return new Context(Logger, _parallelOptions, manager, VfsCache, HashCache, Limiter, HashLimiter,
Extractor.WithTemporaryFileManager(manager));
}
public IndexRoot Index { get; private set; } = IndexRoot.Empty; public IndexRoot Index { get; private set; } = IndexRoot.Empty;

View File

@ -17,14 +17,16 @@ public class FallthroughVFSCache : IVfsCache
public async Task<IndexedVirtualFile?> Get(Hash hash, CancellationToken token) public async Task<IndexedVirtualFile?> Get(Hash hash, CancellationToken token)
{ {
IndexedVirtualFile? result = null;
foreach (var cache in _caches) foreach (var cache in _caches)
{ {
var result = await cache.Get(hash, token); if (result == null)
if (result == null) continue; result = await cache.Get(hash, token);
return result; else
await cache.Put(result, token);
} }
return default; return result;
} }
public async Task Put(IndexedVirtualFile file, CancellationToken token) public async Task Put(IndexedVirtualFile file, CancellationToken token)