forked from SmartlyDressedGames/Legally-Distinct-Missile
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (45 loc) · 2.01 KB
/
Copy pathProgram.cs
File metadata and controls
53 lines (45 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Diagnostics;
using System.IO;
namespace Rocket.Unturned.Launcher
{
class RocketLauncher
{
private static TextReader consoleReader;
public static void Main(string[] args)
{
string instanceName = args.Length > 0 ? args[0] : "Rocket";
string executableName = "";
foreach (string s in new string[] { "Unturned_Headless.x86" , "Unturned.x86" , "Unturned.exe", "Unturned_Headless.x86_64", "Unturned.x86_64"})
{
if (File.Exists(s)) {
executableName = s;
break;
}
}
if (String.IsNullOrEmpty(executableName)) throw new FileNotFoundException("Could not locate Unturned executable");
string arguments = "-nographics -batchmode -logfile 'Servers/" + instanceName + "/unturned.log' +secureserver/" + instanceName;
string consoleOutput = instanceName + ".console";
FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(".", consoleOutput);
fileSystemWatcher.Changed += fileSystemWatcher_Changed;
consoleReader = new StreamReader(new FileStream(consoleOutput, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite));
fileSystemWatcher.EnableRaisingEvents = true;
Process p = new Process();
p.StartInfo = new ProcessStartInfo(executableName, arguments);
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardInput = false;
p.StartInfo.UseShellExecute = false;
p.Start();
p.WaitForExit();
}
private static void fileSystemWatcher_Changed(object sender, FileSystemEventArgs e)
{
if (e.ChangeType == WatcherChangeTypes.Changed)
{
string newline = consoleReader.ReadToEnd();
if (!String.IsNullOrEmpty(newline))
Console.Write(newline);
}
}
}
}