From a50ae062d863bb4a14c9625779c918b33a74aeb2 Mon Sep 17 00:00:00 2001 From: sardelka9515 Date: Wed, 19 Oct 2022 19:07:29 +0800 Subject: [PATCH] Fix resource loading --- Client/Scripts/Scripting/Resources.cs | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Client/Scripts/Scripting/Resources.cs b/Client/Scripts/Scripting/Resources.cs index f219a43..c6a111c 100644 --- a/Client/Scripts/Scripting/Resources.cs +++ b/Client/Scripts/Scripting/Resources.cs @@ -44,8 +44,16 @@ namespace RageCoop.Client.Scripting } internal class Resources { + public static string TempPath; internal readonly ConcurrentDictionary LoadedResources = new ConcurrentDictionary(); private Logger Logger { get; set; } + static Resources() + { + TempPath = Path.Combine(Path.GetTempPath(), "RageCoop"); + if (Directory.Exists(TempPath)) { try { Directory.Delete(TempPath, true); } catch { } } + TempPath = CoreUtils.GetTempDirectory(TempPath); + Directory.CreateDirectory(TempPath); + } public Resources() { Logger = Main.Logger; @@ -66,7 +74,10 @@ namespace RageCoop.Client.Scripting { Main.QueueToMainThreadAndWait(() => { - Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories).ForEach(x => ScriptDomain.CurrentDomain.StartScripts(x)); + foreach (var res in LoadedResources) + { + Directory.GetFiles(res.Value.ScriptsDirectory, "*.dll", SearchOption.AllDirectories).ForEach(x => ScriptDomain.CurrentDomain.StartScripts(x)); + } SetupScripts(); }); }); @@ -79,7 +90,7 @@ namespace RageCoop.Client.Scripting Loader.LoaderContext.RequestUnload(); } - private void Unpack(string zipPath, string dataFolderRoot) + private ClientResource Unpack(string zipPath, string dataFolderRoot) { var r = new ClientResource() { @@ -87,7 +98,7 @@ namespace RageCoop.Client.Scripting Scripts = new List(), Name = Path.GetFileNameWithoutExtension(zipPath), DataFolder = Path.Combine(dataFolderRoot, Path.GetFileNameWithoutExtension(zipPath)), - ScriptsDirectory = Path.Combine(Directory.GetParent(zipPath).FullName, Path.GetFileNameWithoutExtension(zipPath)) + ScriptsDirectory = Path.Combine(TempPath, Path.GetFileNameWithoutExtension(zipPath)), }; Directory.CreateDirectory(r.DataFolder); var scriptsDir = r.ScriptsDirectory; @@ -96,7 +107,7 @@ namespace RageCoop.Client.Scripting Directory.CreateDirectory(scriptsDir); new FastZip().ExtractZip(zipPath, scriptsDir, null); - + foreach (var dir in Directory.GetDirectories(scriptsDir, "*", SearchOption.AllDirectories)) { @@ -132,6 +143,7 @@ namespace RageCoop.Client.Scripting } LoadedResources.TryAdd(r.Name, r); + return r; } private void SetupScripts()