fix some cross-platform issues on Windows
This commit is contained in:
parent
df25f1cac0
commit
c4ea69407b
@ -13,6 +13,7 @@ using System.Text.Json.Nodes;
|
||||
using Mocha.Core.UI;
|
||||
using Mocha.Core.Oop;
|
||||
using MBS.Core;
|
||||
|
||||
using MBS.Core.Collections.Generic;
|
||||
|
||||
using System.Collections.ObjectModel;
|
||||
@ -57,7 +58,7 @@ public class Program : WebApplication
|
||||
}
|
||||
|
||||
protected override void OnStartup(EventArgs e)
|
||||
{
|
||||
{
|
||||
string pidfile = "/var/run/mocha/mocha-oms.pid";
|
||||
try
|
||||
{
|
||||
@ -74,22 +75,39 @@ public class Program : WebApplication
|
||||
TenantHandle th = oms.CreateTenant("super");
|
||||
oms.SelectTenant(th);
|
||||
|
||||
string path = "/home/beckermj/Documents/Projects/mochapowered/mocha-dotnet/mocha-common/mocha-common/output";
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
string path;
|
||||
if (System.Environment.OSVersion.Platform == PlatformID.Win32NT)
|
||||
{
|
||||
path = "/usr/share/mocha/system";
|
||||
path = System.IO.Path.Combine(new string[]
|
||||
{
|
||||
System.Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
|
||||
"Mocha"
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
path = "/home/beckermj/Documents/Projects/mochapowered/mocha-dotnet/mocha-common/mocha-common/output";
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
Console.Error.WriteLine("path not found: " + path);
|
||||
path = "/usr/share/mocha/system";
|
||||
}
|
||||
}
|
||||
|
||||
LibraryHandle lh = oms.LoadLibrary(path + "/net.alcetech.Mocha.System.mcl");
|
||||
oms.AddLibraryReference(lh);
|
||||
|
||||
LibraryHandle lh2 = oms.LoadLibrary(path + "/net.alcetech.Mocha.Web.mcl");
|
||||
oms.AddLibraryReference(lh2);
|
||||
if (!System.IO.Directory.Exists(path))
|
||||
{
|
||||
Console.Error.WriteLine("path not found: " + path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryLoadLibrary(oms, path, "net.alcetech.Mocha.System.mcl"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!TryLoadLibrary(oms, path, "net.alcetech.Mocha.Web.mcl"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// implement functions to get user IP address
|
||||
oms.RegisterSystemAttributeRoutine<string>(KnownInstanceGuids.SystemAttributeRoutines.GetIPAddress, delegate (Oms oms2, OmsContext ctx2)
|
||||
{
|
||||
@ -100,7 +118,26 @@ public class Program : WebApplication
|
||||
|
||||
// now we can start the Web server
|
||||
base.OnStartup(e);
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryLoadLibrary(Oms oms, string path, string fileName)
|
||||
{
|
||||
string fullyQualifiedFileName = System.IO.Path.Combine(new string[] { path, fileName });
|
||||
if (!System.IO.File.Exists(fullyQualifiedFileName))
|
||||
{
|
||||
Console.WriteLine("file not found: {0}", fullyQualifiedFileName);
|
||||
return false;
|
||||
}
|
||||
|
||||
LibraryHandle lh = oms.LoadLibrary(fullyQualifiedFileName);
|
||||
if (lh == LibraryHandle.Empty)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
oms.AddLibraryReference(lh);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void oms_SystemRoutineExecuted(object? sender, SystemRoutineExecutedEventArgs e)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user