Cleaned up a bunch of warnings and errors

This commit is contained in:
Timothy Baldridge 2020-03-28 07:33:39 -06:00
parent c130106213
commit 129f6b4fc2
27 changed files with 111 additions and 89 deletions

View File

@ -55,7 +55,7 @@ namespace Wabbajack.Common.CSP
private static ManyToManyChannel<TIn, TOut> ChannelForRxBuf<TIn, TOut>(RxBuffer<TIn, TOut> buf)
{
return new ManyToManyChannel<TIn, TOut>(null, RxBuffer<TIn,TOut>.TransformAdd, RxBuffer<TIn, TOut>.Finalize, buf);
return new ManyToManyChannel<TIn, TOut>(null, RxBuffer<TIn,TOut>.TransformAdd, (final) => ((RxBuffer<TIn, TOut>)final).Dispose(), buf);
}
/// <summary>

View File

@ -151,9 +151,9 @@ namespace Wabbajack.Common.CSP
var putIsOpen = await to.Put(f(job));
if (!putIsOpen) return;
}
catch (Exception ex)
catch (Exception)
{
// ignored
}
}
}

View File

@ -33,19 +33,9 @@ namespace Wabbajack.Common.CSP
return ((RxBuffer<TIn, TOut>) buf).TransformAdd(itm);
}
public void Finalize()
{
_inputSubject.OnCompleted();
}
public void Dispose()
{
throw new NotImplementedException();
}
public static void Finalize(IBuffer<TOut> buf)
{
((RxBuffer<TIn, TOut>)buf).Finalize();
_inputSubject.OnCompleted();
}
public bool IsFull => Count >= _maxSize;

View File

@ -46,7 +46,7 @@ namespace Wabbajack.Common.Test
using (var queue = new WorkQueue(Observable.Empty<int>()))
{
Assert.Equal(0, queue.DesiredNumWorkers);
Assert.Equal(0, queue._tasks.Count);
Assert.Empty(queue._tasks);
}
}
@ -207,6 +207,7 @@ namespace Wabbajack.Common.Test
///
/// TLDR: Don't put the same work completion source to be done on the queue multiple times.
/// </summary>
[Fact]
public async Task ThreadCoalescenceExample()
{
var subj = new BehaviorSubject<int>(Large);
@ -260,7 +261,7 @@ namespace Wabbajack.Common.Test
// Show that only one job was started/worked on (by our one coalesced worker thread)
lock (lockObj)
{
Assert.Equal(1, secondWorkStartedArray.Where(i => i).Count());
Assert.Single(secondWorkStartedArray.Where(i => i));
}
}
}

View File

@ -1,4 +1,5 @@
using System;
#nullable enable
using System;
using System.Collections.Generic;
using System.Data.HashFunction.xxHash;
using System.IO;

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Collections.Generic;
namespace Wabbajack.Common.IO
{
@ -9,7 +10,7 @@ namespace Wabbajack.Common.IO
{
// ---- MEMBERS ------------------------------------------------------------------------------------------------
private static Dictionary<KnownFolderType, KnownFolder> _knownFolderInstances;
private static ConcurrentDictionary<KnownFolderType, KnownFolder> _knownFolderInstances;
// ---- PROPERTIES ---------------------------------------------------------------------------------------------
@ -660,18 +661,21 @@ namespace Wabbajack.Common.IO
public static KnownFolder Windows => GetInstance(KnownFolderType.Windows);
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
private static KnownFolder GetInstance(KnownFolderType type)
{
// Check if the caching directory exists yet.
if (_knownFolderInstances == null)
_knownFolderInstances = new Dictionary<KnownFolderType, KnownFolder>();
_knownFolderInstances = new ConcurrentDictionary<KnownFolderType, KnownFolder>();
// Get a KnownFolder instance out of the cache dictionary or create it when not cached yet.
if (!_knownFolderInstances.TryGetValue(type, out KnownFolder knownFolder))
{
knownFolder = new KnownFolder(type);
_knownFolderInstances.Add(type, knownFolder);
if (_knownFolderInstances.TryAdd(type, knownFolder))
return knownFolder;
return _knownFolderInstances[type];
}
return knownFolder;
}

View File

@ -35,9 +35,9 @@ namespace Wabbajack.Common
Utils.FromEncryptedJson<string>(Consts.MetricsKeyHeader));
await client.GetAsync($"http://build.wabbajack.org/metrics/{action}/{value}");
}
catch (Exception ex)
catch (Exception)
{
// ignored
}
}
}

View File

@ -142,13 +142,30 @@ namespace Wabbajack.Common
public long Size => new FileInfo(_path).Length;
public DateTime LastModified => File.GetLastWriteTime(_path);
public DateTime LastModified
{
get => File.GetLastWriteTime(_path);
set => File.SetLastWriteTime(_path, value);
}
public DateTime LastModifiedUtc => File.GetLastWriteTimeUtc(_path);
public AbsolutePath Parent => (AbsolutePath)Path.GetDirectoryName(_path);
public RelativePath FileName => (RelativePath)Path.GetFileName(_path);
public RelativePath FileNameWithoutExtension => (RelativePath)Path.GetFileNameWithoutExtension(_path);
public bool IsEmptyDirectory => IsDirectory && !EnumerateFiles().Any();
public bool IsReadOnly
{
get
{
return new FileInfo(_path).IsReadOnly;
}
set
{
new FileInfo(_path).IsReadOnly = value;
}
}
/// <summary>
/// Moves this file to the specified location
/// </summary>

View File

@ -47,24 +47,27 @@ namespace Wabbajack.Common
StartInfo = info,
EnableRaisingEvents = true
};
p.Exited += (sender, args) =>
EventHandler Exited = (sender, args) =>
{
finished.SetResult(p.ExitCode);
};
p.Exited += Exited;
p.OutputDataReceived += (sender, data) =>
DataReceivedEventHandler OutputDataReceived = (sender, data) =>
{
if (string.IsNullOrEmpty(data.Data)) return;
Output.OnNext((StreamType.Output, data.Data));
};
p.OutputDataReceived += OutputDataReceived;
p.ErrorDataReceived += (sender, data) =>
DataReceivedEventHandler ErrorEventHandler = (sender, data) =>
{
if (string.IsNullOrEmpty(data.Data)) return;
Output.OnNext((StreamType.Error, data.Data));
if (LogError)
Utils.Log($"{AlphaPath.GetFileName(Path)} ({p.Id}) StdErr: {data.Data}");
};
p.ErrorDataReceived += ErrorEventHandler;
p.Start();
p.BeginErrorReadLine();
@ -82,6 +85,12 @@ namespace Wabbajack.Common
var result = await finished.Task;
p.CancelErrorRead();
p.CancelOutputRead();
p.OutputDataReceived -= OutputDataReceived;
p.ErrorDataReceived -= ErrorEventHandler;
p.Exited -= Exited;
Output.OnCompleted();
return result;
}

View File

@ -10,11 +10,10 @@ namespace Wabbajack.Common
/// </summary>
public class DiskSlabAllocator : IDisposable
{
private TempFile _file;
private MemoryMappedFile _mmap;
private readonly TempFile _file;
private readonly MemoryMappedFile _mmap;
private long _head = 0;
private string _name;
private FileStream _fileStream;
private readonly FileStream _fileStream;
public DiskSlabAllocator(long size)
{

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Wabbajack.Common
{
public class TempFolder : IDisposable
public class TempFolder : IAsyncDisposable
{
public AbsolutePath Dir { get; }
public bool DeleteAfter = true;
@ -29,12 +29,11 @@ namespace Wabbajack.Common
}
DeleteAfter = deleteAfter;
}
public void Dispose()
public async ValueTask DisposeAsync()
{
if (DeleteAfter && Dir.Exists)
{
Utils.DeleteDirectory(Dir).Wait();
await Utils.DeleteDirectory(Dir);
}
}
}

View File

@ -61,7 +61,7 @@ namespace Wabbajack.Launcher
return new Version(0, 0, 0, 0);
}).FirstOrDefault();
}
catch (Exception ex)
catch (Exception)
{
FinishAndExit();
}

View File

@ -137,43 +137,41 @@ namespace Wabbajack.Lib
Status($"Copying files for {archive.Name}");
void CopyFile(string from, string to, bool useMove)
async ValueTask CopyFile(AbsolutePath from, AbsolutePath to, bool useMove)
{
if (File.Exists(to))
if (to.Exists)
{
var fi = new FileInfo(to);
if (fi.IsReadOnly)
fi.IsReadOnly = false;
File.Delete(to);
if (to.IsReadOnly)
to.IsReadOnly = false;
to.Delete();
}
if (File.Exists(from))
if (from.Exists)
{
var fi = new FileInfo(from);
if (fi.IsReadOnly)
fi.IsReadOnly = false;
if (from.IsReadOnly)
from.IsReadOnly = false;
}
if (useMove)
File.Move(from, to);
from.MoveTo(to);
else
File.Copy(from, to);
from.CopyTo(to);
// If we don't do this, the file will use the last-modified date of the file when it was compressed
// into an archive, which isn't really what we want in the case of files installed archives
File.SetLastWriteTime(to, DateTime.Now);
to.LastModified = DateTime.Now;
}
await vFiles.GroupBy(f => f.FromFile)
.PDoIndexed(queue, (idx, group) =>
.PDoIndexed(queue, async (idx, group) =>
{
Utils.Status("Installing files", Percent.FactoryPutInRange(idx, vFiles.Count));
var firstDest = OutputFolder.Combine(group.First().To);
group.Key.StagedPath.CopyTo(firstDest, true);
await CopyFile(group.Key.StagedPath, firstDest, true);
foreach (var copy in group.Skip(1))
{
firstDest.CopyTo(OutputFolder.Combine(copy.To));
await CopyFile(firstDest, OutputFolder.Combine(copy.To), false);
}
});

View File

@ -64,7 +64,7 @@ namespace Wabbajack.Lib.Downloaders
[MessagePackObject]
public class State<TDownloader> : AbstractDownloadState, IMetaState where TDownloader : IDownloader
public class State<TStateDownloader> : AbstractDownloadState, IMetaState where TStateDownloader : IDownloader
{
[Key(0)]
public string FileID { get; set; }

View File

@ -94,7 +94,7 @@ namespace Wabbajack.Lib.Downloaders
result.ToEcryptedJson(DataName);
return result;
}
catch (Exception _)
catch (Exception)
{
return null;
}
@ -105,7 +105,6 @@ namespace Wabbajack.Lib.Downloaders
return StateFromUrl(new Uri(url));
}
public event PropertyChangedEventHandler PropertyChanged;
public ReactiveCommand<Unit, Unit> TriggerLogin { get; }
public ReactiveCommand<Unit, Unit> ClearLogin { get; }
public IObservable<bool> IsLoggedIn => Utils.HaveEncryptedJsonObservable(DataName);

View File

@ -151,7 +151,7 @@ namespace Wabbajack.Lib.Downloaders
return false;
}
catch (Exception ex)
catch (Exception)
{
return false;
}

View File

@ -102,7 +102,7 @@ namespace Wabbajack.Lib.Downloaders
try
{
using var queue = new WorkQueue();
using var folder = new TempFolder();
await using var folder = new TempFolder();
folder.Dir.Combine("tracks").CreateDirectory();
var client = new YoutubeClient(Common.Http.ClientFactory.Client);
var meta = await client.GetVideoAsync(Key);
@ -143,7 +143,7 @@ namespace Wabbajack.Lib.Downloaders
return true;
}
catch (VideoUnavailableException ex)
catch (VideoUnavailableException)
{
return false;
}
@ -240,7 +240,7 @@ namespace Wabbajack.Lib.Downloaders
var video = await client.GetVideoAsync(Key);
return true;
}
catch (VideoUnavailableException ex)
catch (VideoUnavailableException)
{
return false;
}

View File

@ -68,8 +68,6 @@ namespace Wabbajack.Lib.FileUploader
Interlocked.Add(ref sent, block_size);
progressFn((double)sent / fsize);
int retries = 0;
await using var fs = filename.OpenRead();
fs.Position = block_offset;
var data = new byte[block_size];

View File

@ -363,10 +363,9 @@ namespace Wabbajack.Lib
if (modified)
parser.WriteFile((string)file, data);
}
catch (Exception ex)
catch (Exception)
{
Utils.Log($"Skipping screen size remap for {file} due to parse error.");
continue;
}
}
}

View File

@ -76,8 +76,9 @@ namespace Wabbajack.Lib.ModListRegistry
if (summaries.TryGetValue(data.Title, out var summary))
data.ValidationSummary = summary;
}
catch (Exception ex)
catch (Exception)
{
// ignored
}
return metadata.OrderBy(m => (m.ValidationSummary?.HasFailures ?? false ? 1 : 0, m.Title)).ToList();

View File

@ -22,7 +22,6 @@ namespace Wabbajack.Lib.NexusApi
public class NexusApiClient : ViewModel
{
private static readonly string API_KEY_CACHE_FILE = "nexus.key_cache";
private static string _additionalEntropy = "vtP2HF6ezg";
public Common.Http.Client HttpClient { get; } = new Common.Http.Client();
@ -331,7 +330,6 @@ namespace Wabbajack.Lib.NexusApi
public string URI { get; set; }
}
private static bool? _useLocalCache;
public static MethodInfo CacheMethod { get; set; }
private static string _localCacheDir;

View File

@ -43,7 +43,7 @@ namespace Wabbajack.Lib
public const string StagingMarkerName = "__vortex_staging_folder";
public const string DownloadMarkerName = "__vortex_downloads_folder";
private bool _isSteamGame;
//private bool _isSteamGame = true;
private SteamGame _steamGame;
private bool _hasSteamWorkshopItems;
@ -71,12 +71,14 @@ namespace Wabbajack.Lib
ActiveArchives = new List<string>();
// there can be max one game after filtering
/*
StoreHandler.Instance.StoreGames.Where(g => g.Game == game && g.Type == StoreType.STEAM).Do(g =>
{
_isSteamGame = true;
_steamGame = (SteamGame)g;
_hasSteamWorkshopItems = _steamGame.WorkshopItems.Count > 0;
});
*/
}
protected override async Task<bool> _Begin(CancellationToken cancel)

View File

@ -101,6 +101,12 @@
<None Update="concrt140.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<Compile Remove="VortexCompiler.cs" />
<None Include="VortexCompiler.cs" />
<Compile Remove="CompilationSteps\IgnoreDisabledVortexMods.cs" />
<None Include="CompilationSteps\IgnoreDisabledVortexMods.cs" />
<Compile Remove="CompilationSteps\IgnoreVortex.cs" />
<None Include="CompilationSteps\IgnoreVortex.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Downloaders\BethesdaNet" />

View File

@ -534,7 +534,7 @@ namespace Wabbajack.Test
[Fact]
public async Task TestUpgrading()
{
using var folder = new TempFolder();
await using var folder = new TempFolder();
var dest = folder.Dir.Combine("Cori.7z");
var archive = new Archive
{

View File

@ -25,7 +25,7 @@ namespace Wabbajack.Test
public static TempFolder CreateSetFolder(FilePickerVM vm)
{
var temp = new TempFolder();
await var temp = new TempFolder();
Directory.CreateDirectory(temp.Dir.FullName);
vm.TargetPath = temp.Dir.FullName;
return temp;

View File

@ -1,4 +1,5 @@
using System.IO;
using System.Threading.Tasks;
using Wabbajack.Common;
using Wabbajack.Lib;
using Xunit;
@ -9,53 +10,53 @@ namespace Wabbajack.Test
{
#region CheckValidInstallPath
[Fact]
public void CheckValidInstallPath_Empty()
public async Task CheckValidInstallPath_Empty()
{
using var tempDir = new TempFolder();
await using var tempDir = new TempFolder();
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
}
[Fact]
public void CheckValidInstallPath_DoesNotExist()
public async Task CheckValidInstallPath_DoesNotExist()
{
using var tempDir = new TempFolder();
await using var tempDir = new TempFolder();
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir.Combine("Subfolder"), downloadFolder: null).Succeeded);
}
[Fact]
public void CheckValidInstallPath_HasModlist()
public async Task CheckValidInstallPath_HasModlist()
{
using var tempDir = new TempFolder();
using var mo2 = tempDir.Dir.Combine("ModOrganizer.exe").Create();
using var molist = tempDir.Dir.Combine(((RelativePath)"modlist")).WithExtension(Consts.ModListExtension).Create();
await using var tempDir = new TempFolder();
await using var mo2 = tempDir.Dir.Combine("ModOrganizer.exe").Create();
await using var molist = tempDir.Dir.Combine(((RelativePath)"modlist")).WithExtension(Consts.ModListExtension).Create();
Assert.False(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
}
[Fact]
public void CheckValidInstallPath_ProperOverwrite()
public async Task CheckValidInstallPath_ProperOverwrite()
{
using var tempDir = new TempFolder();
using var tmp = tempDir.Dir.Combine(Consts.ModOrganizer2Exe).Create();
await using var tempDir = new TempFolder();
await using var tmp = tempDir.Dir.Combine(Consts.ModOrganizer2Exe).Create();
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
}
[Fact]
public void CheckValidInstallPath_ImproperOverwrite()
public async Task CheckValidInstallPath_ImproperOverwrite()
{
using var tempDir = new TempFolder();
tempDir.Dir.DeleteDirectory();
await using var tempDir = new TempFolder();
await tempDir.Dir.DeleteDirectory();
tempDir.Dir.CreateDirectory();
using var tmp = tempDir.Dir.Combine($"someFile.txt").Create();
await using var tmp = tempDir.Dir.Combine($"someFile.txt").Create();
Assert.False(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: null).Succeeded);
}
[Fact]
public void CheckValidInstallPath_OverwriteFilesInDownloads()
public async Task CheckValidInstallPath_OverwriteFilesInDownloads()
{
using var tempDir = new TempFolder();
await using var tempDir = new TempFolder();
var downloadsFolder = tempDir.Dir.Combine("downloads");
downloadsFolder.CreateDirectory();
using var tmp = tempDir.Dir.Combine($"downloads/someFile.txt").Create();
await using var tmp = tempDir.Dir.Combine($"downloads/someFile.txt").Create();
Assert.True(MO2Installer.CheckValidInstallPath(tempDir.Dir, downloadFolder: downloadsFolder).Succeeded);
}
#endregion

View File

@ -235,7 +235,7 @@ namespace Wabbajack.VirtualFileSystem
return stream.FromJSON<IndexedVirtualFile>();
}
}
catch (Exception ex)
catch (Exception)
{
return null;
}