mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-29 08:00:19 +01:00
Massive sanity reorganization of project structure
Overall: - Removed all 'TG' prefixes on classes and enums Service: - TGStationServer => ServerInstance - TGServerService => Service - Moved all ServerInstance partial classes to a subfolder - Moved ChatProvider classes, delegate, and interface to a namespace - Moved EventID and ChatMessageType to their own .cs files - Moved SanitizeTopicString to Program - ServerService.cs => Service.cs - Fixed ProjectInstaller being in it's own namespace instead of TGServerService Interface: - Moved ExitCode enum to Command class - Moved all components to a namespace - Moved all component enums to Enumerations.cs - DDInteropCallHolder => DreamDaemonBridge - Move PullRequestInfo and DreamDaemonBridge to their own .cs files - Changes the type of ChannelFactory cache from Dictionary<Type, ChannelFactory> to IDictionary<Type, ChannelFactory>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace TGServerService
|
||||
{
|
||||
// Some useful functions for triggering pre action events
|
||||
partial class ServerInstance
|
||||
{
|
||||
const string EventFolder = "EventHandlers/";
|
||||
|
||||
string GetPath(string eventName)
|
||||
{
|
||||
return string.Format("{0}{1}.bat", EventFolder, eventName);
|
||||
}
|
||||
|
||||
bool EventHandlerExists(string eventName)
|
||||
{
|
||||
return File.Exists(GetPath(eventName));
|
||||
}
|
||||
|
||||
bool HandleEvent(string eventName)
|
||||
{
|
||||
if (!EventHandlerExists(eventName))
|
||||
{
|
||||
// We don't need a handler, so let's just fail silently.
|
||||
return true;
|
||||
}
|
||||
|
||||
var process = new Process
|
||||
{
|
||||
StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = GetPath(eventName),
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
RedirectStandardError = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
process.Start();
|
||||
process.WaitForExit();
|
||||
|
||||
var stdout = process.StandardOutput.ReadToEnd();
|
||||
var stderr = process.StandardError.ReadToEnd();
|
||||
|
||||
Service.WriteInfo(
|
||||
String.Format("Preaction Event: {0} @ {1} ran. Stdout:\n{2}\nStderr:\n{3}", eventName, GetPath(eventName), stdout, stderr),
|
||||
process.ExitCode == 0 ? EventID.PreactionEvent : EventID.PreactionFail
|
||||
);
|
||||
|
||||
return process.ExitCode == 0 ? true : false;
|
||||
}
|
||||
|
||||
public bool PrecompileHook()
|
||||
{
|
||||
return HandleEvent("precompile");
|
||||
}
|
||||
|
||||
public bool PostcompileHook()
|
||||
{
|
||||
return HandleEvent("postcompile");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user