fix(core): Fixes errors from missing files (#511)

This commit is contained in:
Kamron Batman 2021-02-14 18:30:53 -08:00 • committed by GitHub
parent ea5d09a7d7
commit 8006fa20df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 54 additions and 14 deletions

View file

@ -10,41 +10,42 @@ namespace Server.Tests.Network
{
[Theory]
[InlineData("Test String", "us-ascii", false, -1, 1024, 1024, 0)]
[InlineData("Test String", "utf-u", false, -1, 1024, 1024, 0)]
[InlineData("Test String", "utf-8", false, -1, 1024, 1024, 0)]
[InlineData("Test String", "utf-16BE", false, -1, 1024, 1024, 0)]
[InlineData("Test String", "utf-16", false, -1, 1024, 1024, 0)]
[InlineData("Test String", "us-ascii", false, -1, 1024, 1024, 1030)]
[InlineData("Test String", "utf-u", false, -1, 1024, 1024, 1030)]
[InlineData("Test String", "utf-8", false, -1, 1024, 1024, 1030)]
[InlineData("Test String", "utf-16BE", false, -1, 1024, 1024, 1030)]
[InlineData("Test String", "utf-16", false, -1, 1024, 1024, 1030)]
[InlineData("Test String", "us-ascii", false, -1, 1024, 1024, 1020)]
[InlineData("Test String", "utf-u", false, -1, 1024, 1024, 1020)]
[InlineData("Test String", "utf-8", false, -1, 1024, 1024, 1020)]
[InlineData("Test String", "utf-16BE", false, -1, 1024, 1024, 1020)]
[InlineData("Test String", "utf-16", false, -1, 1024, 1024, 1020)]
[InlineData("Test String", "us-ascii", false, 8, 1024, 1024, 0)]
[InlineData("Test String", "utf-u", false, 8, 1024, 1024, 0)]
[InlineData("Test String", "utf-8", false, 8, 1024, 1024, 0)]
[InlineData("Test String", "utf-16BE", false, 8, 1024, 1024, 0)]
[InlineData("Test String", "utf-16", false, 8, 1024, 1024, 0)]
[InlineData("Test String", "us-ascii", false, 8, 1024, 1024, 1030)]
[InlineData("Test String", "utf-u", false, 8, 1024, 1024, 1030)]
[InlineData("Test String", "utf-8", false, 8, 1024, 1024, 1030)]
[InlineData("Test String", "utf-16BE", false, 8, 1024, 1024, 1030)]
[InlineData("Test String", "utf-16", false, 8, 1024, 1024, 1030)]
[InlineData("Test String", "us-ascii", false, 8, 1024, 1024, 1020)]
[InlineData("Test String", "utf-u", false, 8, 1024, 1024, 1020)]
[InlineData("Test String", "utf-8", false, 8, 1024, 1024, 1020)]
[InlineData("Test String", "utf-16BE", false, 8, 1024, 1024, 1020)]
[InlineData("Test String", "utf-16", false, 8, 1024, 1024, 1020)]
[InlineData("Test String", "us-ascii", false, 20, 1024, 1024, 0)]
[InlineData("Test String", "utf-u", false, 20, 1024, 1024, 0)]
[InlineData("Test String", "utf-8", false, 20, 1024, 1024, 0)]
[InlineData("Test String", "utf-16BE", false, 20, 1024, 1024, 0)]
[InlineData("Test String", "utf-16", false, 20, 1024, 1024, 0)]
[InlineData("Test String", "us-ascii", false, 20, 1024, 1024, 1030)]
[InlineData("Test String", "utf-u", false, 20, 1024, 1024, 1030)]
[InlineData("Test String", "utf-8", false, 20, 1024, 1024, 1030)]
[InlineData("Test String", "utf-16BE", false, 20, 1024, 1024, 1030)]
[InlineData("Test String", "utf-16", false, 20, 1024, 1024, 1030)]
[InlineData("Test String", "us-ascii", false, 20, 1024, 1024, 1020)]
[InlineData("Test String", "utf-u", false, 20, 1024, 1024, 1020)]
[InlineData("Test String", "utf-8", false, 20, 1024, 1024, 1020)]
[InlineData("Test String", "utf-16BE", false, 20, 1024, 1024, 1020)]
[InlineData("Test String", "utf-16", false, 20, 1024, 1024, 1020)]
[InlineData("测试", "utf-8", true, -1, 1024, 1024, 0)]
public void TestReadString(
string value,
string encodingStr,

View file

@ -176,7 +176,7 @@ namespace Server
Utility.PushColor(ConsoleColor.Red);
Console.WriteLine("failed");
Utility.PopColor();
throw new Exception("Core: Server configuration failed to deserialize.");
throw new FileNotFoundException($"Failed to deserialize {m_FilePath}.");
}
Console.WriteLine("done");

View file

@ -22,6 +22,7 @@ using System.Runtime;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Server.Json;
@ -445,7 +446,12 @@ namespace Server
var assemblyPath = Path.Join(BaseDirectory, AssembliesConfiguration);
// Load UOContent.dll
var assemblyFiles = JsonConfig.Deserialize<List<string>>(assemblyPath).ToArray();
var assemblyFiles = JsonConfig.Deserialize<List<string>>(assemblyPath)?.ToArray();
if (assemblyFiles == null)
{
throw new JsonException($"Failed to deserialize {assemblyPath}.");
}
for (var i = 0; i < assemblyFiles.Length; i++)
{
assemblyFiles[i] = Path.Join(BaseDirectory, "Assemblies", assemblyFiles[i]);

View file

@ -17,6 +17,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using Server.Json;
@ -51,6 +52,10 @@ namespace Server
var stopwatch = Stopwatch.StartNew();
var maps = JsonConfig.Deserialize<List<MapDefinition>>(path);
if (maps == null)
{
throw new JsonException($"Failed to deserialize {path}.");
}
foreach (var def in maps)
{

View file

@ -17,6 +17,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using Server.Json;
using Server.Utilities;
@ -35,6 +36,10 @@ namespace Server
var stopwatch = Stopwatch.StartNew();
var regions = JsonConfig.Deserialize<List<DynamicJson>>(path);
if (regions == null)
{
throw new JsonException($"Failed to deserialize {path}.");
}
foreach (var json in regions)
{

View file

@ -16,6 +16,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using Server.Items;
using Server.Json;
@ -31,6 +32,10 @@ namespace Server.Commands
var path = Path.Combine(Core.BaseDirectory, "Data/categorization.json");
var list = JsonConfig.Deserialize<List<CAGJson>>(path);
if (list == null)
{
throw new JsonException($"Failed to deserialize {path}.");
}
// Not an optimized solution
foreach (var cag in list)

View file

@ -15,6 +15,7 @@
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using MimeKit;
using Server.Json;
@ -52,7 +53,7 @@ namespace Server.Configurations
Utility.PushColor(ConsoleColor.Red);
Console.WriteLine("failed");
Utility.PopColor();
throw new Exception("Core: Email configuration failed to deserialize.");
throw new JsonException($"Failed to deserialize {path}.");
}
Console.WriteLine("done");

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Server.Json;
namespace Server.Gumps
@ -23,6 +24,10 @@ namespace Server.Gumps
try
{
Root = JsonConfig.Deserialize<GoCategory>(path);
if (Root == null)
{
throw new JsonException($"Failed to deserialize {path}.");
}
SetParents(Root);
}
catch (Exception e)

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using Server.Json;
@ -44,6 +45,12 @@ namespace Server
var filePath = Path.Combine(Core.BaseDirectory, "Data/names.json");
var nameLists = JsonConfig.Deserialize<List<NameList>>(filePath);
if (nameLists == null)
{
throw new JsonException($"Failed to deserialize {filePath}.");
}
foreach (var nameList in nameLists)
{
nameList.FixNames();

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text.Json;
using Server.Json;
namespace Server
@ -28,8 +29,12 @@ namespace Server
private static int[] Load()
{
var table = JsonConfig.Deserialize<Dictionary<string, string>>("Data/shrink.json")
?? new Dictionary<string, string>();
var path = "Data/shrink.json";
var table = JsonConfig.Deserialize<Dictionary<string, string>>(path);
if (table == null)
{
throw new JsonException($"Failed to deserialize {path}.");
}
int length = 0;