Skip to content

Commit

Permalink
Add "Scanning..." message, add "Failed" message, clean up Codacy warn…
Browse files Browse the repository at this point in the history
…ings, and set project to treat warnings as errors
  • Loading branch information
CorruptComputer committed Nov 26, 2023
1 parent 576f119 commit 8e04a81
Show file tree
Hide file tree
Showing 65 changed files with 760 additions and 639 deletions.
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"ms-dotnettools.csharp",
"ms-dotnettools.csdevkit",
"ms-dotnettools.vscodeintellicode-csharp",
"avaloniateam.vscode-avalonia"
]
}
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": "0.2.0",
"configurations": [
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/dotnet/vscode-csharp/blob/main/debugger-launchjson.md
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/UnitystationLauncher/bin/Debug/net7.0/StationHub.dll",
"args": [],
"cwd": "${workspaceFolder}/UnitystationLauncher",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach"
}
]
}
41 changes: 41 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/UnitystationLauncher.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "publish",
"command": "dotnet",
"type": "process",
"args": [
"publish",
"${workspaceFolder}/UnitystationLauncher.sln",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
"problemMatcher": "$msCompile"
},
{
"label": "watch",
"command": "dotnet",
"type": "process",
"args": [
"watch",
"run",
"--project",
"${workspaceFolder}/UnitystationLauncher.sln"
],
"problemMatcher": "$msCompile"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using System.Collections.Generic;
using UnitystationLauncher.Models.Api.Changelog;
using UnitystationLauncher.Services.Interface;
Expand Down
7 changes: 3 additions & 4 deletions UnitystationLauncher.Tests/MocksRepository/MockPingService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Threading.Tasks;
using UnitystationLauncher.Models.Api;
using UnitystationLauncher.Services.Interface;

Expand All @@ -9,23 +8,23 @@ public static class MockPingService
public static IPingService StaticPingTime(int pingTime)
{
Mock<IPingService> mock = new();
mock.Setup(x => x.GetPing(It.IsAny<Server>()))
mock.Setup(x => x.GetPingAsync(It.IsAny<Server>()))
.ReturnsAsync($"{pingTime}ms");
return mock.Object;
}

public static IPingService NullPingTime()
{
Mock<IPingService> mock = new();
mock.Setup(x => x.GetPing(It.IsAny<Server>()))
mock.Setup(x => x.GetPingAsync(It.IsAny<Server>()))
!.ReturnsAsync(null as string);
return mock.Object;
}

public static IPingService ThrowsException()
{
Mock<IPingService> mock = new();
mock.Setup(x => x.GetPing(It.IsAny<Server>()))
mock.Setup(x => x.GetPingAsync(It.IsAny<Server>()))
.Throws<Exception>();
return mock.Object;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using UnitystationLauncher.Services.Interface;
using UnitystationLauncher.Tests.MocksRepository;
using UnitystationLauncher.ViewModels;
using Xunit.Sdk;

namespace UnitystationLauncher.Tests.ViewModels;

Expand Down
11 changes: 9 additions & 2 deletions UnitystationLauncher/Constants/ApiUrls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ namespace UnitystationLauncher.Constants;

public static class ApiUrls
{
public const string ApiBaseUrl = "https://api.unitystation.org";
private const string ApiBaseUrl = "https://api.unitystation.org";
public const string ServerListUrl = $"{ApiBaseUrl}/serverlist";
public const string ValidateUrl = $"{ApiBaseUrl}/validatehubclient";
public const string ValidateTokenUrl = $"{ApiBaseUrl}/validatetoken?data=";
public const string SignOutUrl = $"{ApiBaseUrl}/signout?data=";

public const string ChangelogBaseUrl = "https://changelog.unitystation.org";
private const string ChangelogBaseUrl = "https://changelog.unitystation.org";
public const string Latest10VersionsUrl = $"{ChangelogBaseUrl}/all-changes?format=json&limit=10";
public const string LatestBlogPosts = $"{ChangelogBaseUrl}/posts/?format=json";

private const string CdnBaseUrl = "https://unitystationfile.b-cdn.net";
public const string GoodFilesBaseUrl = $"{CdnBaseUrl}/GoodFiles/";
public const string AllowedGoodFilesUrl = $"{GoodFilesBaseUrl}/AllowGoodFiles.json";

private const string RawGitHubFileBaseUrl = "https://raw.githubusercontent.com/unitystation/unitystation/develop";
public const string CodeScanListUrl = $"{RawGitHubFileBaseUrl}/CodeScanList.json";
}
6 changes: 6 additions & 0 deletions UnitystationLauncher/Constants/AssemblyNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace UnitystationLauncher.Constants;

public static class AssemblyNames
{
public const string SystemAssemblyName = "mscorlib";
}
8 changes: 8 additions & 0 deletions UnitystationLauncher/Constants/FolderNames.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace UnitystationLauncher.Constants;

public static class FolderNames
{
public const string Managed = "Managed";
public const string Plugins = "Plugins";
public const string UnitystationData = "Unitystation_Data";
}
55 changes: 25 additions & 30 deletions UnitystationLauncher/ContentScanning/AssemblyTypeCheckerHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ namespace UnitystationLauncher.ContentScanning;
/// </summary>
internal static class AssemblyTypeCheckerHelpers
{
// Used to be in Sandbox.yml, moved out of there to facilitate faster loading.
internal const string SystemAssemblyName = "mscorlib"; //TODO check security
//UnityEngine.dll
//mscorlib
//System.Runtime
private static readonly bool _parallelReferencedMembersScanning = true;

internal static Resolver CreateResolver(DirectoryInfo ManagedPath)
internal static Resolver CreateResolver(DirectoryInfo managedPath)
{
return new Resolver(ManagedPath);
return new(managedPath);
}

internal static string FormatMethodName(MetadataReader reader, MethodDefinition method)
Expand All @@ -57,13 +53,13 @@ internal static void CheckNoUnmanagedMethodDefs(MetadataReader reader, Concurren
or MethodImplAttributes.Runtime))
{
string err = $"Method has illegal MethodImplAttributes: {FormatMethodName(reader, methodDef)}";
errors.Add(new SandboxError(err));
errors.Add(new(err));
}

if ((attr & (MethodAttributes.PinvokeImpl | MethodAttributes.UnmanagedExport)) != 0)
{
string err = $"Method has illegal MethodAttributes: {FormatMethodName(reader, methodDef)}";
errors.Add(new SandboxError(err));
errors.Add(new(err));
}
}
}
Expand All @@ -83,7 +79,7 @@ internal static void CheckNoTypeAbuse(MetadataReader reader, ConcurrentBag<Sandb
if (typeDef.GetFields().Count > 0)
{
string err = $"Explicit layout type {type} may not have fields.";
errors.Add(new SandboxError(err));
errors.Add(new(err));
}
}
}
Expand All @@ -99,7 +95,7 @@ internal static List<MTypeReferenced> GetReferencedTypes(MetadataReader reader,
}
catch (UnsupportedMetadataException e)
{
errors.Add(new SandboxError(e));
errors.Add(new(e));
return null;
}
})
Expand All @@ -109,8 +105,7 @@ internal static List<MTypeReferenced> GetReferencedTypes(MetadataReader reader,

internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, ConcurrentBag<SandboxError> errors)
{
bool Parallel = true;
if (Parallel)
if (_parallelReferencedMembersScanning)
{
return reader.MemberReferences.AsParallel()
.Select(memRefHandle =>
Expand All @@ -130,7 +125,7 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
}
catch (UnsupportedMetadataException u)
{
errors.Add(new SandboxError(u));
errors.Add(new(u));
return null;
}

Expand All @@ -144,7 +139,7 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
}
catch (UnsupportedMetadataException u)
{
errors.Add(new SandboxError(u));
errors.Add(new(u));
return null;
}

Expand All @@ -154,7 +149,7 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
{
TypeSpecification typeSpec = reader.GetTypeSpecification((TypeSpecificationHandle)memRef.Parent);
// Generic type reference.
TypeProvider provider = new TypeProvider();
TypeProvider provider = new();
parent = typeSpec.DecodeSignature(provider, 0);

if (parent.IsCoreTypeDefined())
Expand All @@ -168,18 +163,18 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
}
case HandleKind.ModuleReference:
{
errors.Add(new SandboxError(
errors.Add(new(
$"Module global variables and methods are unsupported. Name: {memName}"));
return null;
}
case HandleKind.MethodDefinition:
{
errors.Add(new SandboxError($"Vararg calls are unsupported. Name: {memName}"));
errors.Add(new($"Vararg calls are unsupported. Name: {memName}"));
return null;
}
default:
{
errors.Add(new SandboxError(
errors.Add(new(
$"Unsupported member ref parent type: {memRef.Parent.Kind}. Name: {memName}"));
return null;
}
Expand Down Expand Up @@ -236,7 +231,7 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
}
catch (UnsupportedMetadataException u)
{
errors.Add(new SandboxError(u));
errors.Add(new(u));
return null;
}

Expand All @@ -250,7 +245,7 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
}
catch (UnsupportedMetadataException u)
{
errors.Add(new SandboxError(u));
errors.Add(new(u));
return null;
}

Expand All @@ -260,7 +255,7 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
{
TypeSpecification typeSpec = reader.GetTypeSpecification((TypeSpecificationHandle)memRef.Parent);
// Generic type reference.
TypeProvider provider = new TypeProvider();
TypeProvider provider = new();
parent = typeSpec.DecodeSignature(provider, 0);

if (parent.IsCoreTypeDefined())
Expand All @@ -274,18 +269,18 @@ internal static List<MMemberRef> GetReferencedMembers(MetadataReader reader, Con
}
case HandleKind.ModuleReference:
{
errors.Add(new SandboxError(
errors.Add(new(
$"Module global variables and methods are unsupported. Name: {memName}"));
return null;
}
case HandleKind.MethodDefinition:
{
errors.Add(new SandboxError($"Vararg calls are unsupported. Name: {memName}"));
errors.Add(new($"Vararg calls are unsupported. Name: {memName}"));
return null;
}
default:
{
errors.Add(new SandboxError(
errors.Add(new(
$"Unsupported member ref parent type: {memRef.Parent.Kind}. Name: {memName}"));
return null;
}
Expand Down Expand Up @@ -344,14 +339,14 @@ internal static bool ParseInheritType(MType ownerType, EntityHandle handle, [Not
}
catch (UnsupportedMetadataException u)
{
errors.Add(new SandboxError(u));
errors.Add(new(u));
return false;
}

case HandleKind.TypeSpecification:
TypeSpecification typeSpec = reader.GetTypeSpecification((TypeSpecificationHandle)handle);
// Generic type reference.
TypeProvider provider = new TypeProvider();
TypeProvider provider = new();
type = typeSpec.DecodeSignature(provider, 0);

if (type.IsCoreTypeDefined())
Expand All @@ -364,7 +359,7 @@ internal static bool ParseInheritType(MType ownerType, EntityHandle handle, [Not
break;

default:
errors.Add(new SandboxError(
errors.Add(new(
$"Unsupported BaseType of kind {handle.Kind} on type {ownerType}"));
return false;
}
Expand Down Expand Up @@ -421,7 +416,7 @@ internal static MTypeReferenced ParseTypeReference(MetadataReader reader, TypeRe
$"TypeRef to {typeRef.ResolutionScope.Kind} for type {nameSpace}.{name}");
}

return new MTypeReferenced(resScope, name, nameSpace);
return new(resScope, name, nameSpace);
}

internal static string? NilNullString(MetadataReader reader, StringHandle handle)
Expand All @@ -442,6 +437,6 @@ internal static MTypeDefined GetTypeFromDefinition(MetadataReader reader, TypeDe
enclosing = GetTypeFromDefinition(reader, typeDef.GetDeclaringType());
}

return new MTypeDefined(name, ns, enclosing);
return new(name, ns, enclosing);
}
}
19 changes: 0 additions & 19 deletions UnitystationLauncher/ContentScanning/FileInfoComparer.cs

This file was deleted.

Loading

0 comments on commit 8e04a81

Please sign in to comment.