Added prototype ZuneHost console app

This commit is contained in:
Yoshi Askharoun
2022-06-03 01:24:53 -05:00
parent 321e353ef8
commit ef5de4ca94
5 changed files with 154 additions and 9 deletions
+76
View File
@@ -0,0 +1,76 @@
using Silk.NET.Windowing;
using System;
using System.IO;
using System.Reflection;
using System.Threading;
namespace ZuneHost
{
internal class Program
{
static string? _zuneProgramFolder;
static void Main(string[] args)
{
Console.WriteLine("Creating splash window...");
string strArgs = string.Join(' ', args);
// Make sure that ZuneDBApi can find all the Zune native libraries
Console.WriteLine("Setting up dependency resolver...");
_zuneProgramFolder = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
"Zune");
foreach (string file in Directory.GetFiles(_zuneProgramFolder))
{
string fileName = Path.GetFileName(file);
if ((fileName.StartsWith("Zune") || fileName.StartsWith("UIX"))
&& file.EndsWith(".dll")
&& fileName != "ZuneDbApi.dll")
{
string targetPath = Path.Combine(Environment.CurrentDirectory, fileName);
if (!File.Exists(targetPath))
File.Copy(file, targetPath);
}
}
//AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
Console.WriteLine("Starting Zune...");
Thread zuneThread = new Thread(new ThreadStart(() =>
{
Microsoft.Zune.Shell.ZuneApplication.Launch(strArgs, IntPtr.Zero);
}));
zuneThread.SetApartmentState(ApartmentState.STA);
zuneThread.Start();
//Thread t = new(() =>
// Microsoft.Zune.Shell.ZuneApplication.Launch(strArgs, IntPtr.Zero));
//t.SetApartmentState(ApartmentState.STA);
//t.Start();
}
private static Assembly? CurrentDomain_AssemblyResolve(object? sender, ResolveEventArgs args)
{
string fileName = args.Name[..args.Name.IndexOf(",")];
if (fileName == "ZuneDBApi")
{
string assemblyPath = Path.Combine(Directory.GetCurrentDirectory(), "ZuneDBApi.dll");
bool exists = File.Exists(assemblyPath);
return Assembly.LoadFrom(assemblyPath);
}
else if (!fileName.StartsWith("Zune"))
{
return null;
}
else
{
string assemblyPath = Path.Combine(
_zuneProgramFolder ?? throw new ArgumentNullException(),
fileName + ".dll");
return Assembly.Load(assemblyPath);
}
}
}
}
+17
View File
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Platforms>AnyCPU;x64;x86;ARM32</Platforms>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Silk.NET.Windowing" Version="2.15.0" />
<ProjectReference Include="..\ZuneShell\ZuneShell.csproj" />
</ItemGroup>
</Project>