Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
imp - Actually resolve dependencies
Browse files Browse the repository at this point in the history
We need to actually resolve dependencies during boot.

---

When we need to boot to a .NET Framework 4.8 app, like Nitrocid KS
0.0.24.x, we need to resolve all dependencies using the resolver.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Aug 8, 2023
1 parent 13e653e commit be55dc5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
38 changes: 32 additions & 6 deletions GRILO.Bootloader/BootApps/BootLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,24 @@
* SOFTWARE.
*/

#if !NETCOREAPP
using GRILO.Boot;
using GRILO.Bootloader.Diagnostics;
using System;
using System.IO;
using System.Reflection;

namespace GRILO.Bootloader.BootApps
{
#if !NETCOREAPP
public class BootLoader : MarshalByRefObject
{
internal byte[] bytes = Array.Empty<byte>();
internal string lookupPath = "";
internal bool shutting = false;

public void ProxyExecuteBootable(params string[] args)
{
AppDomain.CurrentDomain.AssemblyResolve += this.ResolveDependency;
var asm = Assembly.Load(bytes);
IBootable proxy = null;
foreach (Type t in asm.GetTypes())
Expand All @@ -47,19 +51,41 @@ public void ProxyExecuteBootable(params string[] args)
}
}
proxy.Boot(args);
AppDomain.CurrentDomain.AssemblyResolve -= this.ResolveDependency;
shutting = proxy.ShutdownRequested;
}

public bool VerifyBoot()
public bool VerifyBoot(byte[] bootBytes)
{
var asm = Assembly.Load(bytes);
AppDomain.CurrentDomain.AssemblyResolve += this.ResolveDependency;
var asm = Assembly.Load(bootBytes);
bool validBoot = false;
foreach (Type t in asm.GetTypes())
{
if (t.GetInterface(typeof(IBootable).Name) != null)
return true;
validBoot = true;
}
if (validBoot)
bytes = bootBytes;
AppDomain.CurrentDomain.AssemblyResolve -= this.ResolveDependency;
return validBoot;
}

internal Assembly ResolveDependency(object sender, ResolveEventArgs args)
{
string depAssemblyName = new AssemblyName(args.Name).Name;
string depAssemblyFilePath = Path.Combine(lookupPath, depAssemblyName + ".dll");
try
{
DiagnosticsWriter.WriteDiag(DiagnosticsLevel.Info, "Loading {0}", depAssemblyFilePath);
return Assembly.LoadFrom(depAssemblyFilePath);
}
catch (Exception ex)
{
DiagnosticsWriter.WriteDiag(DiagnosticsLevel.Error, "{0}: {1}", ex.GetType().Name, ex.Message);
return null;
}
return false;
}
}
#endif
}
#endif
7 changes: 4 additions & 3 deletions GRILO.Bootloader/BootApps/BootManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Linq;
using GRILO.Bootloader.Diagnostics;
using GRILO.Bootloader.Configuration;
Expand Down Expand Up @@ -142,6 +141,7 @@ public static void PopulateBootApps()
bootArgs = metadata["Arguments"]?.ToObject<string[]>() ?? Array.Empty<string>();
bootApp = new(bootFile, bootOverrideTitle, bootArgs, bootable);
bootApps.Add(bootOverrideTitle, bootApp);
loads.Add(bootContext);
}
}
else
Expand All @@ -157,10 +157,10 @@ public static void PopulateBootApps()
continue;
}
#else
assemblyLoader.bytes = File.ReadAllBytes(bootFile);
assemblyLoader.lookupPath = bootDir;

// Now, check the metadata
if (assemblyLoader.VerifyBoot())
if (assemblyLoader.VerifyBoot(File.ReadAllBytes(bootFile)))
{
// We found it! Now, populate info from the metadata file
string metadataFile = Path.Combine(GRILOPaths.GRILOBootablesPath, bootId, "BootMetadata.json");
Expand Down Expand Up @@ -189,6 +189,7 @@ public static void PopulateBootApps()
bootArgs = metadata["Arguments"]?.ToObject<string[]>() ?? Array.Empty<string>();
bootApp = new(bootFile, bootOverrideTitle, bootArgs, proxy);
bootApps.Add(bootOverrideTitle, bootApp);
loads.Add(assemblyLoader);
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions GRILO.Bootloader/BootApps/BootProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
* SOFTWARE.
*/

#if !NETCOREAPP
using GRILO.Boot;
using System;

namespace GRILO.Bootloader.BootApps
{
#if !NETCOREAPP
public class BootProxy : IBootable
{
internal BootLoader loader = null;
Expand All @@ -43,5 +43,5 @@ public void Boot(string[] args)
ShutdownRequested = loader.shutting;
}
}
#endif
}
#endif

0 comments on commit be55dc5

Please sign in to comment.