Basically working resource system

This commit is contained in:
Sardelka9515
2023-02-27 11:54:02 +08:00
parent 6e2b4aff2f
commit 0e5271b322
21 changed files with 332 additions and 95 deletions

View File

@ -15,7 +15,7 @@ using System.Resources;
[assembly: AssemblyCulture("")]
// Version information
[assembly: AssemblyVersion("1.6.0.33")]
[assembly: AssemblyFileVersion("1.6.0.33")]
[assembly: AssemblyVersion("1.6.0.45")]
[assembly: AssemblyFileVersion("1.6.0.45")]
[assembly: NeutralResourcesLanguageAttribute( "en-US" )]

View File

@ -22,6 +22,11 @@ internal class Resources
Logger = server.Logger;
}
static Resources()
{
CoreUtils.ForceLoadAllAssemblies();
}
public bool IsLoaded { get; private set; }
public void LoadAll()
@ -263,7 +268,7 @@ internal class Resources
}
if (Server.GetResponse<Packets.FileTransferResponse>(client, new Packets.AllResourcesSent(),
ConnectionChannel.RequestResponse, 30000)?.Response == FileResponse.Loaded)
ConnectionChannel.File, 30000)?.Response == FileResponse.Loaded)
{
client.IsReady = true;
Server.API.Events.InvokePlayerReady(client);

View File

@ -47,6 +47,10 @@ public class ServerResource : PluginLoader
internal static ServerResource LoadFrom(string resDir, string dataFolder, Logger logger = null)
{
string mainAssemblyPath = Path.Combine(resDir, Path.GetFileName(resDir) + ".dll");
if (!File.Exists(mainAssemblyPath))
throw new FileNotFoundException($"Main assemby not found: {mainAssemblyPath}");
var runtimeLibs = Path.Combine(resDir, "RuntimeLibs", CoreUtils.GetInvariantRID());
if (Directory.Exists(runtimeLibs))
{
@ -61,16 +65,18 @@ public class ServerResource : PluginLoader
CoreUtils.CopyFilesRecursively(new DirectoryInfo(runtimeLibs), new DirectoryInfo(resDir));
}
var conf = new PluginConfig(Path.GetFullPath(Path.Combine(resDir, Path.GetFileName(resDir) + ".dll")))
var conf = new PluginConfig(Path.GetFullPath(mainAssemblyPath))
{
PreferSharedTypes = true,
EnableHotReload = false,
IsUnloadable = false,
LoadInMemory = true
};
ServerResource r = new(conf);
r.Logger = logger;
r.Name = Path.GetFileName(resDir);
ServerResource r = new(conf)
{
Logger = logger,
Name = Path.GetFileName(resDir)
};
if (!File.Exists(conf.MainAssemblyPath))
{
r.Dispose();