From d9230c09a5bca3a582c1c45df46c83a44abf1a23 Mon Sep 17 00:00:00 2001 From: TSR Berry <20988865+TSRBerry@users.noreply.github.com> Date: Sat, 17 Dec 2022 20:14:06 +0100 Subject: [PATCH] Address gdkchan's review comments --- Ryujinx.CustomTasks/GenerateArrays.cs | 24 ++++++++----------- .../SyntaxWalker/ArraySizeCollector.cs | 5 ++-- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Ryujinx.CustomTasks/GenerateArrays.cs b/Ryujinx.CustomTasks/GenerateArrays.cs index 267b7ad..440f284 100644 --- a/Ryujinx.CustomTasks/GenerateArrays.cs +++ b/Ryujinx.CustomTasks/GenerateArrays.cs @@ -1,13 +1,13 @@ -using Microsoft.CodeAnalysis; +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.Build.Framework; +using Ryujinx.CustomTasks.Helper; +using Ryujinx.CustomTasks.SyntaxWalker; using System.Collections.Generic; using System.IO; -using Ryujinx.CustomTasks.SyntaxWalker; -using Ryujinx.CustomTasks.Helper; using System.Linq; -using Task = Microsoft.Build.Utilities.Task; namespace Ryujinx.CustomTasks { @@ -16,7 +16,7 @@ namespace Ryujinx.CustomTasks private const string InterfaceFileName = "IArray.g.cs"; private const string ArraysFileName = "Arrays.g.cs"; - private readonly HashSet _outputFiles = new HashSet(); + private readonly List _outputFiles = new List(); [Required] public string ArrayNamespace { get; set; } @@ -55,23 +55,19 @@ namespace Ryujinx.CustomTasks private void AddGeneratedSource(string filePath, string content) { - bool addToOutputFiles = true; - if (File.Exists(filePath)) { File.Delete(filePath); - addToOutputFiles = false; } - - File.WriteAllText(filePath, content); - - if (addToOutputFiles) + else { _outputFiles.Add(filePath); } + + File.WriteAllText(filePath, content); } - private HashSet GetArraySizes(string itemPath) + private ICollection GetArraySizes(string itemPath) { Log.LogMessage(MessageImportance.Low, $"Searching for StructArray types in: {itemPath}"); diff --git a/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs b/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs index 832caaf..1205c61 100644 --- a/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs +++ b/Ryujinx.CustomTasks/SyntaxWalker/ArraySizeCollector.cs @@ -6,7 +6,8 @@ namespace Ryujinx.CustomTasks.SyntaxWalker { class ArraySizeCollector : CSharpSyntaxWalker { - public HashSet ArraySizes { get; } = new HashSet(); + private readonly HashSet _arraySizes = new HashSet(); + public ICollection ArraySizes => _arraySizes; private void AddArrayString(string name) { @@ -19,7 +20,7 @@ namespace Ryujinx.CustomTasks.SyntaxWalker if (int.TryParse(rawArrayType.Substring(5), out int size)) { - ArraySizes.Add(size); + _arraySizes.Add(size); } }