Skip to content

Commit

Permalink
Support for making native linux binary
Browse files Browse the repository at this point in the history
  • Loading branch information
ementalo committed Aug 24, 2012
1 parent 90ef7c9 commit 260ce18
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChraftServer/ChraftServer.csproj
Expand Up @@ -67,6 +67,9 @@
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Posix">
<HintPath>.\Mono.Posix.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<Reference Include="System.Core" />
Expand Down
2 changes: 1 addition & 1 deletion ChraftServer/MainService.cs
Expand Up @@ -80,7 +80,7 @@ protected override void OnStop()

private void UnhandledException_Handler(object sender, UnhandledExceptionEventArgs e)
{
Server.Logger.Log((Exception)e.ExceptionObject);
Server.Logger.Log(LogLevel.Debug, ((Exception)e.ExceptionObject).StackTrace);
}

public void Run(string[] args)
Expand Down
Binary file added ChraftServer/Mono.Posix.dll
Binary file not shown.
14 changes: 12 additions & 2 deletions ChraftServer/Program.cs
Expand Up @@ -21,6 +21,8 @@
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using Mono.Unix.Native;

namespace ChraftServer
{
Expand All @@ -31,8 +33,7 @@ internal static class Program
/// </summary>
private static void Main(string[] args)
{
Environment.CurrentDirectory = Path.GetDirectoryName(typeof(Program).Assembly.Location);

Environment.CurrentDirectory = Path.GetDirectoryName(MainService.IsRunningInMono ? GetExecutablePath() : typeof (Program).Assembly.Location);
//Install command-line argument
if (args.Any(a => a.Equals("-install", StringComparison.InvariantCultureIgnoreCase)))
{
Expand Down Expand Up @@ -91,6 +92,15 @@ private static void ShowUsage()
Console.WriteLine("\tChraftServer -uninstall\r\n\t\tUninstall Chraft Windows Service");
Console.WriteLine("\tChraftServer\r\n\t\tRun Chraft from the console");
}

public static string GetExecutablePath()
{
var builder = new StringBuilder(8192);
if (Syscall.readlink("/proc/self/exe", builder) >= 0)
return builder.ToString();
else
return null;
}
}

}

0 comments on commit 260ce18

Please sign in to comment.