Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Scanning..." and "Failed" messages to downloads and misc changes #222

Merged
merged 11 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,5 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using UnitystationLauncher.Models;
using UnitystationLauncher.Models.Api;
using UnitystationLauncher.Services.Interface;
Expand All @@ -22,7 +23,7 @@ public List<Installation> GetInstallations()
return null;
}

public (Download?, string) DownloadInstallation(Server server)
public Task<(Download?, string)> DownloadInstallationAsync(Server server)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace UnitystationLauncher.Tests.MocksRepository.PingService;

public class MockPingReturnsNull : IPingService
{
public Task<string> GetPing(Server server)
public Task<string> GetPingAsync(Server server)
{
return Task.FromResult(null as string)!;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public MockPingStaticPingTime(int pingInMilliseconds)
{
_pingTime = $"{pingInMilliseconds}ms";
}
public Task<string> GetPing(Server server)
public Task<string> GetPingAsync(Server server)
{
return Task.FromResult(_pingTime);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace UnitystationLauncher.Tests.MocksRepository.PingService;

public class MockPingThrowsException : IPingService
{
public Task<string> GetPing(Server server)
public Task<string> GetPingAsync(Server server)
{
throw new();
}
Expand Down
25 changes: 16 additions & 9 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";
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";
public const string Latest10VersionsUrl = $"{ChangelogBaseUrl}/all-changes?format=json&limit=10";
public const string LatestBlogPosts = $"{ChangelogBaseUrl}/posts/?format=json";
private static string ApiBaseUrl => "https://api.unitystation.org";
public static string ServerListUrl => $"{ApiBaseUrl}/serverlist";
public static string ValidateUrl => $"{ApiBaseUrl}/validatehubclient";
public static string ValidateTokenUrl => $"{ApiBaseUrl}/validatetoken?data=";
public static string SignOutUrl => $"{ApiBaseUrl}/signout?data=";

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

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

private static string RawGitHubFileBaseUrl => "https://raw.githubusercontent.com/unitystation/unitystation/develop";
public static 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