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

0.4.4-alpha #29

Merged
merged 10 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
33 changes: 28 additions & 5 deletions Horizon.Installer/Package.wxs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs" xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package Name="Horizon" Compressed="yes" Scope="perMachine" Manufacturer="The Headmaster" Version="0.4.2" UpgradeCode="f629909a-bc3c-4e54-a352-c3fcd75c44f6">
<Package Name="Horizon" Compressed="yes" Scope="perMachine" Manufacturer="The Headmaster" Version="0.4.4" UpgradeCode="f629909a-bc3c-4e54-a352-c3fcd75c44f6">
<?define Horizon_TargetDir=$(var.Horizon.TargetDir)?>
<MediaTemplate EmbedCab="yes" />
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />

<ui:WixUI Id="WixUI_InstallDir" InstallDirectory="INSTALLFOLDER" />
<ui:WixUI Id="WixUI_FeatureTree" InstallDirectory="INSTALLFOLDER" />
<WixVariable Id="WixUILicenseRtf" Value="license.rtf" />
<Icon Id="Horizon.ico" SourceFile="$(var.Horizon_TargetDir)Horizon.ico" />
<Property Id="ARPPRODUCTICON" Value="Horizon.ico" />
Expand All @@ -19,8 +19,22 @@
<Directory Id="ApplicationProgramsFolder" Name="Horizon" />
</StandardDirectory>
<StandardDirectory Id="ProgramFiles6432Folder">
<Directory Id="INSTALLFOLDER" Name="!(bind.Property.ProductName)" />
<Directory Id="INSTALLFOLDER" Name="!(bind.Property.ProductName)">
<Directory Id="Plugins" Name="Plugins">
<Directory Id="StarboundPluginFolder" Name="Horizon.Starbound" />
</Directory>
<Directory Id="LogsFolder" Name="Logs">
</Directory>
</Directory>
</StandardDirectory>

<DirectoryRef Id="LogsFolder">
<Component Id="LogsCleanup" Guid="9bd5259c-7d66-42a3-b395-6f4fa0c7772a">
<RemoveFile Id="PurgeLogsFolder" Directory="LogsFolder" Name="*.*" On="uninstall" />
<RemoveFolder Id="CleanupLogs" Directory="LogsFolder" On="uninstall" />
</Component>
</DirectoryRef>

<DirectoryRef Id="ApplicationProgramsFolder">
<Component Id="ApplicationShortcut">
<Shortcut Id="ApplicationStartMenuShortcut" Icon="Horizon.ico" Name="Horizon" Description="Horizon IDE" Target="[INSTALLFOLDER]Horizon.exe" WorkingDirectory="INSTALLFOLDER" />
Expand All @@ -30,15 +44,24 @@
</Component>
</DirectoryRef>

<Feature Id="Complete" Title="Horizon" Display="expand" Level="1" ConfigurableDirectory="INSTALLFOLDER">
<Feature Id="ProductFeature" Title="Horizon" Level="1">
<Feature Id="Complete" Title="Horizon" Display="expand" Description="Installs everything in Horizon." AllowAbsent="false" Level="1" ConfigurableDirectory="INSTALLFOLDER">
<Feature Id="ProductFeature" Title="Core Executable" Description="Installs the Horizon executable and all of its dependencies." Display="expand" AllowAbsent="false" Level="1">
<ComponentRef Id="ApplicationShortcut" />
<ComponentRef Id="ApplicationShortcutDesktop" />
<ComponentRef Id="LogsCleanup" />
<Files Include="$(var.Horizon_TargetDir)**" Directory="INSTALLFOLDER">
<!-- Don't harvest PDB files because we don't want to ship them. -->
<Exclude Files="$(var.Horizon_TargetDir)**\*.pdb" />
<!-- Don't harvest Log files because we don't want to ship them. -->
<Exclude Files="$(var.Horizon_TargetDir)Logs\**\*.log" />
<!-- Don't harvest plugin files because we are installing them in separate features. -->
<Exclude Files="$(var.Horizon_TargetDir)Plugins\**\*.*" />
</Files>
</Feature>

<Feature Id="PluginStarbound" Title="Starbound Plugin" Description="This plugin adds support for Starbound mod projects to Horizon." Level="2" AllowAbsent="true">
<Files Include="$(var.Horizon_TargetDir)Plugins\Horizon.Starbound\**\*.*" Directory="StarboundPluginFolder" />
</Feature>
</Feature>
</Package>
</Wix>
22 changes: 22 additions & 0 deletions Horizon.Starbound/Horizon.Starbound.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Horizon\Horizon.csproj">
<Private>false</Private>
<ExcludeAssets>runtime</ExcludeAssets>
</ProjectReference>
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo f | xcopy /v /Y &quot;$(OutDir)$(TargetName).dll&quot; &quot;$(SolutionDir)Horizon\bin\Debug\net8.0-windows\Plugins\Horizon.Starbound\$(TargetName).dll&quot;" />
</Target>

</Project>
7 changes: 7 additions & 0 deletions Horizon.Starbound/Modules/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Horizon.API;

namespace Horizon.Starbound.Modules;

public class Item : AssetFile
{
}
8 changes: 8 additions & 0 deletions Horizon.Starbound/Plugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Horizon.API;

namespace Horizon.Starbound;

public class Plugin : IPlugin
{
public string ID { get; set; }
}
10 changes: 10 additions & 0 deletions Horizon.Starbound/Projects/StarboundModProject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using Horizon.ObjectModel;

namespace Horizon.Starbound.Templates;

public class StarboundModProject : ProjectFile
{
public override List<string> Tags { get; } = ["Starbound", "Mod"];
public override string TemplateName { get; } = "Starbound Mod Project";
public override string TemplateDescription { get; } = "A mod project for the game Starbound.";
}
54 changes: 36 additions & 18 deletions Horizon.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Horizon", "Horizon\Horizon.csproj", "{83A33026-94B7-4C90-A7D5-C42A25E7D105}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Horizon.Testing", "Horizon.Testing\Horizon.Testing.csproj", "{23F3058E-5053-4EBC-B701-35B0A444CDE2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{66E3A57B-1FEA-48C2-B925-6E622922CB67}"
ProjectSection(SolutionItems) = preProject
.editorconfig = .editorconfig
Expand All @@ -31,6 +29,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEM
EndProject
Project("{B7DD6F7E-DEF8-4E67-B5B7-07EF123DB6F0}") = "Horizon.Installer", "Horizon.Installer\Horizon.Installer.wixproj", "{C7407183-3A01-46FC-AC57-1FAEF9318BDC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Horizon.Starbound", "Horizon.Starbound\Horizon.Starbound.csproj", "{234B5F50-6F04-471D-AF3D-5A620B56A260}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Horizon.Testing", "Horizon.Testing\Horizon.Testing.csproj", "{7A543094-A54A-4E5D-A54F-DAFB17F0034F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -59,22 +61,6 @@ Global
{83A33026-94B7-4C90-A7D5-C42A25E7D105}.Release|x64.Build.0 = Release|Any CPU
{83A33026-94B7-4C90-A7D5-C42A25E7D105}.Release|x86.ActiveCfg = Release|Any CPU
{83A33026-94B7-4C90-A7D5-C42A25E7D105}.Release|x86.Build.0 = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|ARM64.Build.0 = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|x64.ActiveCfg = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|x64.Build.0 = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|x86.ActiveCfg = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Debug|x86.Build.0 = Debug|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|Any CPU.Build.0 = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|ARM64.ActiveCfg = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|ARM64.Build.0 = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|x64.ActiveCfg = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|x64.Build.0 = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|x86.ActiveCfg = Release|Any CPU
{23F3058E-5053-4EBC-B701-35B0A444CDE2}.Release|x86.Build.0 = Release|Any CPU
{C7407183-3A01-46FC-AC57-1FAEF9318BDC}.Debug|Any CPU.ActiveCfg = Debug|x64
{C7407183-3A01-46FC-AC57-1FAEF9318BDC}.Debug|Any CPU.Build.0 = Debug|x64
{C7407183-3A01-46FC-AC57-1FAEF9318BDC}.Debug|ARM64.ActiveCfg = Debug|ARM64
Expand All @@ -91,6 +77,38 @@ Global
{C7407183-3A01-46FC-AC57-1FAEF9318BDC}.Release|x64.Build.0 = Release|x64
{C7407183-3A01-46FC-AC57-1FAEF9318BDC}.Release|x86.ActiveCfg = Release|x86
{C7407183-3A01-46FC-AC57-1FAEF9318BDC}.Release|x86.Build.0 = Release|x86
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|Any CPU.Build.0 = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|ARM64.Build.0 = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|x64.ActiveCfg = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|x64.Build.0 = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|x86.ActiveCfg = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Debug|x86.Build.0 = Debug|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|Any CPU.ActiveCfg = Release|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|Any CPU.Build.0 = Release|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|ARM64.ActiveCfg = Release|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|ARM64.Build.0 = Release|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|x64.ActiveCfg = Release|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|x64.Build.0 = Release|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|x86.ActiveCfg = Release|Any CPU
{234B5F50-6F04-471D-AF3D-5A620B56A260}.Release|x86.Build.0 = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|ARM64.ActiveCfg = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|ARM64.Build.0 = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|x64.ActiveCfg = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|x64.Build.0 = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|x86.ActiveCfg = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Debug|x86.Build.0 = Debug|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|Any CPU.Build.0 = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|ARM64.ActiveCfg = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|ARM64.Build.0 = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|x64.ActiveCfg = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|x64.Build.0 = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|x86.ActiveCfg = Release|Any CPU
{7A543094-A54A-4E5D-A54F-DAFB17F0034F}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
16 changes: 16 additions & 0 deletions Horizon/API/AssetFile.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Horizon.ObjectModel;

namespace Horizon.API;

public class AssetFile : UniqueJsonFile
{
public override Task Load()
{
throw new NotImplementedException();
}

public override Task Unload()
{
throw new NotImplementedException();
}
}
6 changes: 6 additions & 0 deletions Horizon/API/IPlugin.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Horizon.API;

public interface IPlugin
{
public string ID { get; set; }
}
21 changes: 21 additions & 0 deletions Horizon/API/PluginLoadContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Reflection;
using System.Runtime.Loader;

namespace Horizon.API;

public class PluginLoadContext(string pluginPath) : AssemblyLoadContext
{
private readonly AssemblyDependencyResolver resolver = new(pluginPath);

protected override Assembly? Load(AssemblyName assemblyName)
{
string? assemblyPath = this.resolver.ResolveAssemblyToPath(assemblyName);
return assemblyPath is not null ? this.LoadFromAssemblyPath(assemblyPath) : null;
}

protected override nint LoadUnmanagedDll(string unmanagedDllName)
{
string? libraryPath = this.resolver.ResolveUnmanagedDllToPath(unmanagedDllName);
return libraryPath is not null ? this.LoadUnmanagedDllFromPath(libraryPath) : IntPtr.Zero;
}
}
73 changes: 73 additions & 0 deletions Horizon/API/PluginLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections.ObjectModel;
using System.IO;
using System.Reflection;

namespace Horizon.API;

internal static class PluginLoader
{
internal static Task InitializePlugins()
{
List<string> pluginPaths = [];

foreach (string folder in Directory.GetDirectories(App.PluginDirectory))
{
string? folderName = new DirectoryInfo(folder).Name;

if (string.IsNullOrWhiteSpace(folderName))
{
continue;
}

if (!File.Exists(Path.Combine(folder, $"{folderName}.dll")))
{
continue;
}

pluginPaths.Add(Path.Combine(folder, $"{folderName}.dll"));
}

List<IPlugin> plugins = pluginPaths
.SelectMany(pluginPath =>
{
Assembly pluginAssembly = LoadPlugin(pluginPath);
return CreatePlugins(pluginAssembly);
}).ToList();

App.ViewModel.Plugins = new ObservableCollection<IPlugin>(plugins);

return Task.CompletedTask;
}

internal static Assembly LoadPlugin(string pluginPath)
{
PluginLoadContext loadContext = new(pluginPath);
return loadContext.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(pluginPath)));
}

internal static IEnumerable<IPlugin> CreatePlugins(Assembly assembly)
{
int count = 0;

foreach (Type type in assembly.GetTypes())
{
if (typeof(IPlugin).IsAssignableFrom(type))
{
IPlugin? result = Activator.CreateInstance(type) as IPlugin;
if (result is not null)
{
count++;
yield return result;
}
}
}

if (count == 0)
{
string availableTypes = string.Join(",", assembly.GetTypes().Select(t => t.FullName));
throw new ApplicationException(
$"Can't find any type which implements IPlugin in {assembly} from {assembly.Location}.\n" +
$"Available types: {availableTypes}");
}
}
}
Loading
Loading