Skip to content

Commit

Permalink
-Fixed pathing bugs with loading assemblies
Browse files Browse the repository at this point in the history
-Added proper service support to SEServerExtender
-Added service installer to SEServerExtender
  • Loading branch information
chessmaster42 committed Sep 5, 2014
1 parent c17d650 commit ef3e4bb
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 5 deletions.
3 changes: 2 additions & 1 deletion SEModAPIInternal/API/Common/SandboxGameAssemblyWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ protected SandboxGameAssemblyWrapper()
m_isUsingCommonProgramData = false;
m_isInSafeMode = false;

m_assembly = Assembly.UnsafeLoadFrom("Sandbox.Game.dll");
string assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sandbox.Game.dll");
m_assembly = Assembly.UnsafeLoadFrom(assemblyPath);

m_lastProfilingOutput = DateTime.Now;
m_countQueuedActions = 0;
Expand Down
4 changes: 3 additions & 1 deletion SEModAPIInternal/API/Server/ServerAssemblyWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using System.Linq;
using System.Reflection;
Expand Down Expand Up @@ -43,7 +44,8 @@ protected ServerAssemblyWrapper()
{
m_instance = this;

m_assembly = Assembly.UnsafeLoadFrom("SpaceEngineersDedicated.exe");
string assemblyPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SpaceEngineersDedicated.exe");
m_assembly = Assembly.UnsafeLoadFrom(assemblyPath);

Console.WriteLine("Finished loading ServerAssemblyWrapper");
}
Expand Down
54 changes: 53 additions & 1 deletion SEServerExtender/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.ServiceProcess;

using SEModAPI.Support;

Expand All @@ -18,19 +19,61 @@ namespace SEServerExtender
{
public static class Program
{
public class WindowsService : ServiceBase
{
public WindowsService()
{
this.ServiceName = "SEServerExtender";
this.CanPauseAndContinue = false;
this.CanStop = true;
this.AutoLog = true;
}

protected override void OnStart(string[] args)
{
LogManager.APILog.WriteLine("Starting SEServerExtender Service with " + args.Length.ToString() + " arguments ...");

Program.Start(args);
}

protected override void OnStop()
{
LogManager.APILog.WriteLine("Stopping SEServerExtender Service ser...");

Program.Stop();
}
}

static SEServerExtender m_serverExtenderForm;
static Server m_server;

/// <summary>
/// Main entry point of the application
/// </summary>
static void Main(string[] args)
{
if (!Environment.UserInteractive)
{
using (var service = new WindowsService())
{
ServiceBase.Run(service);
}
}
else
{
Start(args);
}
}

private static void Start(string[] args)
{
//Setup error handling for unmanaged exceptions
AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException;
Application.ThreadException += Application_ThreadException;
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);

LogManager.APILog.WriteLine("Starting SEServerExtender with " + args.Length.ToString() + " arguments ...");

CommandLineArgs extenderArgs = new CommandLineArgs();

//Setup the default args
Expand Down Expand Up @@ -139,6 +182,7 @@ static void Main(string[] args)
{
extenderArgs.noConsole = true;
extenderArgs.noGUI = true;
extenderArgs.autoStart = true;
}

if (extenderArgs.debug)
Expand Down Expand Up @@ -175,7 +219,7 @@ static void Main(string[] args)
}
catch (AutoException eEx)
{
if(!extenderArgs.noConsole)
if (!extenderArgs.noConsole)
Console.WriteLine("AutoException - " + eEx.AdditionnalInfo + "\n\r" + eEx.GetDebugString());
if (!extenderArgs.noGUI)
MessageBox.Show(eEx.AdditionnalInfo + "\n\r" + eEx.GetDebugString(), @"SEServerExtender", MessageBoxButtons.OK, MessageBoxIcon.Error);
Expand Down Expand Up @@ -205,6 +249,14 @@ static void Main(string[] args)
}
}

private static void Stop()
{
if(m_server != null && m_server.IsRunning)
m_server.StopServer();
if (m_serverExtenderForm != null && m_serverExtenderForm.Visible == true)
m_serverExtenderForm.Close();
}

static void Application_ThreadException(Object sender, ThreadExceptionEventArgs e)
{
Console.WriteLine("Application.ThreadException - " + e.Exception.ToString());
Expand Down
4 changes: 2 additions & 2 deletions SEServerExtender/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("0.2.10.5")]
[assembly: AssemblyFileVersion("0.2.10.5")]
[assembly: AssemblyVersion("0.2.10.6")]
[assembly: AssemblyFileVersion("0.2.10.6")]
5 changes: 5 additions & 0 deletions SEServerExtender/SEServerExtender.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand Down Expand Up @@ -95,6 +97,9 @@
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Service.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="SEServerExtender.cs">
<SubType>Form</SubType>
</Compile>
Expand Down
31 changes: 31 additions & 0 deletions SEServerExtender/Service.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.ServiceProcess;
using System.Text;

namespace SEServerExtender
{
[RunInstaller(true)]
public class WindowsServiceInstaller : Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;

public WindowsServiceInstaller()
{
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();

processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.StartType = ServiceStartMode.Manual;
serviceInstaller.ServiceName = "SEServerExtender";
serviceInstaller.Description = "Service for running SEServerExtender";

Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
}

0 comments on commit ef3e4bb

Please sign in to comment.