From 65af5354879467e250b4caf0a3840cd50ebda837 Mon Sep 17 00:00:00 2001 From: Timothy Baldridge Date: Wed, 16 Oct 2019 15:36:14 -0600 Subject: [PATCH] code cleanup --- Compression.BSA/BSABuilder.cs | 7 +----- VirtualFileSystem/VirtualFileSystem.cs | 2 +- Wabbajack.Common/FileExtractor.cs | 4 +-- Wabbajack.Common/Utils.cs | 18 +++++++++++++ Wabbajack.Common/Wabbajack.Common.csproj | 3 +++ Wabbajack.Common/packages.config | 1 + Wabbajack.Lib/Compiler.cs | 5 ---- Wabbajack.Lib/Data.cs | 5 +--- Wabbajack.Lib/Downloaders/HTTPDownloader.cs | 2 +- Wabbajack.Lib/Installer.cs | 9 +------ .../ModListRegistry/ModListMetadata.cs | 2 +- Wabbajack.Lib/Validation/ValidateModlist.cs | 25 +++++-------------- .../ContentRightsManagementTests.cs | 3 --- Wabbajack.WebAutomation/Extensions.cs | 2 +- 14 files changed, 37 insertions(+), 51 deletions(-) diff --git a/Compression.BSA/BSABuilder.cs b/Compression.BSA/BSABuilder.cs index 2d8d9a51..9025db0f 100644 --- a/Compression.BSA/BSABuilder.cs +++ b/Compression.BSA/BSABuilder.cs @@ -11,19 +11,16 @@ using Path = Alphaleonis.Win32.Filesystem.Path; namespace Compression.BSA { - public class BSABuilder : IDisposable, IBSABuilder + public class BSABuilder : IBSABuilder { internal uint _archiveFlags; - internal uint _fileCount; internal uint _fileFlags; internal byte[] _fileId; private List _files = new List(); - internal uint _folderCount; internal List _folders = new List(); internal uint _offset; internal uint _totalFileNameLength; - internal uint _totalFolderNameLength; internal uint _version; public BSABuilder() @@ -238,8 +235,6 @@ namespace Compression.BSA public class FileEntry { internal BSABuilder _bsa; - internal Stream _bytesSource; - internal string _filenameSource; internal bool _flipCompression; internal FolderRecordBuilder _folder; diff --git a/VirtualFileSystem/VirtualFileSystem.cs b/VirtualFileSystem/VirtualFileSystem.cs index 1f9346f2..27ba5e64 100644 --- a/VirtualFileSystem/VirtualFileSystem.cs +++ b/VirtualFileSystem/VirtualFileSystem.cs @@ -127,7 +127,7 @@ namespace VFS } } } - catch (EndOfStreamException ex) + catch (EndOfStreamException) { } diff --git a/Wabbajack.Common/FileExtractor.cs b/Wabbajack.Common/FileExtractor.cs index 02872f4a..c713f853 100644 --- a/Wabbajack.Common/FileExtractor.cs +++ b/Wabbajack.Common/FileExtractor.cs @@ -139,7 +139,7 @@ namespace Wabbajack.Common } } } - catch (Exception ex) + catch (Exception) { } @@ -197,7 +197,7 @@ namespace Wabbajack.Common } } } - catch (Exception ex) + catch (Exception) { } diff --git a/Wabbajack.Common/Utils.cs b/Wabbajack.Common/Utils.cs index ba911dc9..f6568d29 100644 --- a/Wabbajack.Common/Utils.cs +++ b/Wabbajack.Common/Utils.cs @@ -14,6 +14,8 @@ using ICSharpCode.SharpZipLib.BZip2; using IniParser; using Newtonsoft.Json; using Newtonsoft.Json.Bson; +using YamlDotNet.Serialization; +using YamlDotNet.Serialization.NamingConventions; using File = Alphaleonis.Win32.Filesystem.File; using FileInfo = Alphaleonis.Win32.Filesystem.FileInfo; using Path = Alphaleonis.Win32.Filesystem.Path; @@ -577,5 +579,21 @@ namespace Wabbajack.Common select assembly.GetManifestResourceStream(name)).First(); } + public static T FromYaml(this Stream s) + { + var d = new DeserializerBuilder() + .WithNamingConvention(PascalCaseNamingConvention.Instance) + .Build(); + return d.Deserialize(new StreamReader(s)); + } + + public static T FromYaml(this string s) + { + var d = new DeserializerBuilder() + .WithNamingConvention(PascalCaseNamingConvention.Instance) + .Build(); + return d.Deserialize(new StreamReader(s)); + } + } } \ No newline at end of file diff --git a/Wabbajack.Common/Wabbajack.Common.csproj b/Wabbajack.Common/Wabbajack.Common.csproj index 335221d8..bb6957b4 100644 --- a/Wabbajack.Common/Wabbajack.Common.csproj +++ b/Wabbajack.Common/Wabbajack.Common.csproj @@ -90,6 +90,9 @@ + + ..\packages\YamlDotNet.7.0.0\lib\net45\YamlDotNet.dll + diff --git a/Wabbajack.Common/packages.config b/Wabbajack.Common/packages.config index 1a9d10a9..0d61318f 100644 --- a/Wabbajack.Common/packages.config +++ b/Wabbajack.Common/packages.config @@ -10,4 +10,5 @@ + \ No newline at end of file diff --git a/Wabbajack.Lib/Compiler.cs b/Wabbajack.Lib/Compiler.cs index 9f4ed5f7..0627b69e 100644 --- a/Wabbajack.Lib/Compiler.cs +++ b/Wabbajack.Lib/Compiler.cs @@ -7,16 +7,11 @@ using System.Diagnostics; using System.IO; using System.IO.Compression; using System.Linq; -using System.Reflection; using System.Text; using System.Text.RegularExpressions; -using System.Web; using VFS; using Wabbajack.Common; using Wabbajack.Lib.Downloaders; -using Wabbajack.Lib.Downloaders; -using Wabbajack.Lib.NexusApi; -using Wabbajack.Lib.Validation; using Wabbajack.Lib.NexusApi; using Wabbajack.Lib.Validation; using Directory = Alphaleonis.Win32.Filesystem.Directory; diff --git a/Wabbajack.Lib/Data.cs b/Wabbajack.Lib/Data.cs index 43f45b99..7d1e4ea5 100644 --- a/Wabbajack.Lib/Data.cs +++ b/Wabbajack.Lib/Data.cs @@ -178,12 +178,10 @@ namespace Wabbajack.Lib [Serializable] public class PatchedFromArchive : FromArchive { - public string Hash; - /// /// The file to apply to the source file to patch it /// - public String PatchID; + public string PatchID; } [Serializable] @@ -197,7 +195,6 @@ namespace Wabbajack.Lib public class MergedPatch : Directive { public List Sources; - public string Hash; public string PatchID; } diff --git a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs index a2cd836f..e9e389a7 100644 --- a/Wabbajack.Lib/Downloaders/HTTPDownloader.cs +++ b/Wabbajack.Lib/Downloaders/HTTPDownloader.cs @@ -87,7 +87,7 @@ namespace Wabbajack.Lib.Downloaders { stream.Wait(); } - catch (Exception ex) + catch (Exception) { } diff --git a/Wabbajack.Lib/Installer.cs b/Wabbajack.Lib/Installer.cs index bddc0ee7..53bddbaf 100644 --- a/Wabbajack.Lib/Installer.cs +++ b/Wabbajack.Lib/Installer.cs @@ -1,20 +1,13 @@ -using CG.Web.MegaApiClient; -using Compression.BSA; -using System; +using System; using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; -using System.Net.Http; using System.Text; -using System.Text.RegularExpressions; using System.Windows; using VFS; using Wabbajack.Common; using Wabbajack.Lib.Downloaders; -using Wabbajack.Lib.Downloaders; -using Wabbajack.Lib.NexusApi; -using Wabbajack.Lib.Validation; using Wabbajack.Lib.NexusApi; using Wabbajack.Lib.Validation; using Directory = Alphaleonis.Win32.Filesystem.Directory; diff --git a/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs b/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs index dda8d0a1..9405a61a 100644 --- a/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs +++ b/Wabbajack.Lib/ModListRegistry/ModListMetadata.cs @@ -48,7 +48,7 @@ namespace Wabbajack.Lib.ModListRegistry public static List LoadFromGithub() { var d = new DeserializerBuilder() - .WithNamingConvention(new PascalCaseNamingConvention()) + .WithNamingConvention(PascalCaseNamingConvention.Instance) .Build(); var client = new HttpClient(); Utils.Log("Loading Modlists from Github"); diff --git a/Wabbajack.Lib/Validation/ValidateModlist.cs b/Wabbajack.Lib/Validation/ValidateModlist.cs index 005763c2..ca5fa4b9 100644 --- a/Wabbajack.Lib/Validation/ValidateModlist.cs +++ b/Wabbajack.Lib/Validation/ValidateModlist.cs @@ -1,14 +1,10 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Net.Http; using Wabbajack.Common; using Wabbajack.Lib.Downloaders; -using Wabbajack.Lib.Downloaders; -using YamlDotNet.Serialization; -using YamlDotNet.Serialization.NamingConventions; using Path = Alphaleonis.Win32.Filesystem.Path; namespace Wabbajack.Lib.Validation @@ -24,37 +20,28 @@ namespace Wabbajack.Lib.Validation public void LoadAuthorPermissionsFromString(string s) { - var d = new DeserializerBuilder() - .WithNamingConvention(new PascalCaseNamingConvention()) - .Build(); - AuthorPermissions = d.Deserialize>(s); + AuthorPermissions = s.FromYaml>(); } public void LoadServerWhitelist(string s) { - var d = new DeserializerBuilder() - .WithNamingConvention(new PascalCaseNamingConvention()) - .Build(); - ServerWhitelist = d.Deserialize(s); + ServerWhitelist = s.FromYaml(); } public void LoadListsFromGithub() { - var d = new DeserializerBuilder() - .WithNamingConvention(new PascalCaseNamingConvention()) - .Build(); var client = new HttpClient(); Utils.Log("Loading Nexus Mod Permissions"); - using (var result = new StringReader(client.GetStringSync(Consts.ModPermissionsURL))) + using (var result = client.GetStreamSync(Consts.ModPermissionsURL)) { - AuthorPermissions = d.Deserialize>(result); + AuthorPermissions = result.FromYaml>(); Utils.Log($"Loaded permissions for {AuthorPermissions.Count} authors"); } Utils.Log("Loading Server Whitelist"); - using (var result = new StringReader(client.GetStringSync(Consts.ServerWhitelistURL))) + using (var result = client.GetStreamSync(Consts.ServerWhitelistURL)) { - ServerWhitelist = d.Deserialize(result); + ServerWhitelist = result.FromYaml(); Utils.Log($"Loaded permissions for {ServerWhitelist.AllowedPrefixes.Count} servers and {ServerWhitelist.GoogleIDs.Count} GDrive files"); } diff --git a/Wabbajack.Test/ContentRightsManagementTests.cs b/Wabbajack.Test/ContentRightsManagementTests.cs index ecc02fe2..1eba31f6 100644 --- a/Wabbajack.Test/ContentRightsManagementTests.cs +++ b/Wabbajack.Test/ContentRightsManagementTests.cs @@ -1,13 +1,10 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Security.Policy; using Microsoft.VisualStudio.TestTools.UnitTesting; using Wabbajack.Common; using Wabbajack.Lib.Downloaders; using Wabbajack.Lib; -using Wabbajack.Lib.Downloaders; -using Wabbajack.Lib.Validation; using Wabbajack.Lib.Validation; using Game = Wabbajack.Common.Game; diff --git a/Wabbajack.WebAutomation/Extensions.cs b/Wabbajack.WebAutomation/Extensions.cs index bc9a808d..4a148665 100644 --- a/Wabbajack.WebAutomation/Extensions.cs +++ b/Wabbajack.WebAutomation/Extensions.cs @@ -46,7 +46,7 @@ namespace Wabbajack.WebAutomation { stream.Wait(); } - catch (Exception ex) + catch (Exception) { }