Skip to content

Commit

Permalink
Code gardening
Browse files Browse the repository at this point in the history
  • Loading branch information
sailro committed Apr 22, 2024
1 parent 859d23a commit 5021d20
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 14 deletions.
16 changes: 11 additions & 5 deletions Installer/Compiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace Installer;

internal class Compiler
internal partial class Compiler
{
private ZipArchive ProjectArchive { get; }
private Installation Installation { get; }
Expand Down Expand Up @@ -42,9 +42,9 @@ public Compiler(ZipArchive projectArchive, CompilationContext context)

private IEnumerable<string> GetSourceFiles()
{
var matches = Regex.Matches(ProjectContent, "<Compile\\s+Include=\"(?<file>.*)\"\\s*/>");
var matches = CompileFileRegex().Matches(ProjectContent);

foreach (Match match in matches)
foreach (var match in matches.Cast<Match>())
{
if (!match.Success)
continue;
Expand Down Expand Up @@ -116,9 +116,9 @@ private IEnumerable<MetadataReference> GetReferences()
{
yield return MetadataReference.CreateFromFile(Path.Combine(Installation.Managed, "mscorlib.dll"));

var matches = Regex.Matches(ProjectContent, "<(Project)?Reference\\s+Include=\"(?<assemblyName>.*)\"\\s*/?>");
var matches = ProjectReferenceRegex().Matches(ProjectContent);

foreach (Match match in matches)
foreach (var match in matches.Cast<Match>())
{
if (!match.Success)
continue;
Expand Down Expand Up @@ -166,4 +166,10 @@ public CSharpCompilation Compile(string assemblyName)

return CSharpCompilation.Create(assemblyName, syntaxTrees, references, CompilationOptions);
}

[GeneratedRegex("<Compile\\s+Include=\"(?<file>.*)\"\\s*/>")]
private static partial Regex CompileFileRegex();

[GeneratedRegex("<(Project)?Reference\\s+Include=\"(?<assemblyName>.*)\"\\s*/?>")]
private static partial Regex ProjectReferenceRegex();
}
6 changes: 3 additions & 3 deletions Installer/InstallCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public override async Task<int> ExecuteAsync(CommandContext commandContext, Sett
}
}

if (compilation == null && files.Any() && files.All(f => f!.StartsWith(features)))
if (compilation == null && files.Length != 0 && files.All(f => f!.StartsWith(features)))
{
// Failure, retry by removing faulting features if possible
AnsiConsole.MarkupLine($"[yellow]Trying to disable faulting feature(s): [red]{GetFaultingFeatures(files)}[/].[/]");
Expand All @@ -163,7 +163,7 @@ public override async Task<int> ExecuteAsync(CommandContext commandContext, Sett

(compilation, archive, errors) = await GetCompilationAsync(context);

if (!errors.Any())
if (errors.Length == 0)
AnsiConsole.MarkupLine("[yellow]We found a fallback! But please file an issue here : https:/sailro/EscapeFromTarkov-Trainer/issues [/]");
}

Expand Down Expand Up @@ -241,7 +241,7 @@ private static void TryCreateGameDocumentFolder()
AnsiConsole.MarkupLine($"[grey]>> {error.Id} [[{error.Location.SourceTree?.FilePath.EscapeMarkup()}]]: {error.GetMessage().EscapeMarkup()}.[/]");
#endif
if (errors.Any())
if (errors.Length != 0)
{
AnsiConsole.MarkupLine($">> [blue]Try #{context.Try}[/] [yellow]Compilation failed for {context.Branch.EscapeMarkup()} branch.[/]");
compilation = null;
Expand Down
2 changes: 1 addition & 1 deletion Installer/Installation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal class Installation
private Installation(string location, Version version)
{
if (string.IsNullOrEmpty(location))
throw new ArgumentException(nameof(location));
throw new ArgumentException("empty location");

Location = location;
Version = version;
Expand Down
2 changes: 2 additions & 0 deletions Installer/Installer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<RepositoryUrl>https:/sailro/EscapeFromTarkov-Trainer</RepositoryUrl>
<Version>2.6.0.0</Version>
<Copyright>Sebastien Lebreton</Copyright>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NeutralLanguage>en-US</NeutralLanguage>
</PropertyGroup>

<ItemGroup>
Expand Down
8 changes: 4 additions & 4 deletions Installer/ParentProcessHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

namespace Installer;

[StructLayout(LayoutKind.Sequential)]
public struct ParentProcessHelper
[StructLayout(LayoutKind.Sequential), System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006")]
public partial struct ParentProcessHelper
{
// These members must match PROCESS_BASIC_INFORMATION
internal IntPtr Reserved1;
Expand All @@ -16,8 +16,8 @@ public struct ParentProcessHelper
internal IntPtr UniqueProcessId;
internal IntPtr InheritedFromUniqueProcessId;

[DllImport("ntdll.dll")]
private static extern int NtQueryInformationProcess(IntPtr processHandle, int processInformationClass, ref ParentProcessHelper processInformation, int processInformationLength, out int returnLength);
[LibraryImport("ntdll.dll")]
private static partial int NtQueryInformationProcess(IntPtr processHandle, int processInformationClass, ref ParentProcessHelper processInformation, int processInformationLength, out int returnLength);

public static Process? GetParentProcess()
{
Expand Down
2 changes: 1 addition & 1 deletion UI/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ColorPicker : Picker<Color>
private readonly Texture2D _rightArrow;
private readonly Texture2D _leftArrow;

const int HsvPickerSize = 120, HuePickerWidth = 16;
private const int HsvPickerSize = 120, HuePickerWidth = 16;

public ColorPicker(Color color) : base(color)
{
Expand Down
1 change: 1 addition & 0 deletions UI/Picker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public abstract class Picker<T>
public T Value => _value;
public abstract bool IsSelected { get; protected set; }

[System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE0290")]
protected Picker(T value)
{
_value = value;
Expand Down

0 comments on commit 5021d20

Please sign in to comment.