Skip to content

Commit

Permalink
Merge pull request #34 from powerlord/fixnav
Browse files Browse the repository at this point in the history
Fix Nav compilation issues and add textmode option to NAV process
  • Loading branch information
ruarai committed Oct 25, 2017
2 parents 6525107 + b94693f commit ac72ca7
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 21 deletions.
59 changes: 38 additions & 21 deletions CompilePalX/Compilers/NavProcess.cs
Expand Up @@ -20,6 +20,7 @@ class NavProcess : CompileProcess
static string mapnav;
static string mapcfg;
static string mapCFGBackup;
private string mapLogPath;

bool hidden;

Expand All @@ -39,16 +40,22 @@ public override void Run(CompileContext context)
mapnav = context.CopyLocation.Replace(".bsp", ".nav");
mapcfg = context.Configuration.GameFolder + "/cfg/" + mapname + ".cfg";
mapCFGBackup = context.Configuration.GameFolder + "/cfg/" + mapname + "_cpalbackup.cfg";
string mapLog = mapname + "_nav.log";
mapLogPath = Path.Combine(context.Configuration.GameFolder, mapLog);

deleteNav(mapname, context.Configuration.GameFolder);

hidden = GetParameterString().Contains("-hidden");
bool textmode = GetParameterString().Contains("-textmode");

string args = "-game \"" + context.Configuration.GameFolder + "\" -windowed -novid -nosound +sv_cheats 1 +map " + mapname;
string args = "-game \"" + context.Configuration.GameFolder + "\" -windowed -novid -nosound +log 0 +sv_logflush 1 +sv_cheats 1 +map " + mapname;

if (hidden)
args += " -noborder -x 4000 -y 2000";

if (textmode)
args += " -textmode";

var startInfo = new ProcessStartInfo(context.Configuration.GameEXE, args);
startInfo.UseShellExecute = false;
startInfo.CreateNoWindow = false;
Expand All @@ -61,28 +68,34 @@ public override void Run(CompileContext context)
System.IO.File.Move(mapcfg, mapCFGBackup);
}

if (File.Exists(mapLogPath))
File.Delete(mapLogPath);

System.IO.File.Create(mapcfg).Dispose();
TextWriter tw = new StreamWriter(mapcfg);
tw.WriteLine("con_logfile " + mapLog);
tw.WriteLine("nav_generate");
tw.Close();

Process = new Process { StartInfo = startInfo };
Process.Start();

FileSystemWatcher fw = new FileSystemWatcher();
fw.Path = System.IO.Path.GetDirectoryName(mapnav);
fw.Filter = "*.nav";
fw.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
fw.Changed += new FileSystemEventHandler(fileSystemWatcher_NavCreated);
fw.Created += new FileSystemEventHandler(fileSystemWatcher_NavCreated);
fw.EnableRaisingEvents = true;

Process.WaitForExit();
fw.Dispose();
using (TextReader tr = new StreamReader(File.Open(mapLogPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite)))
{
Process = new Process { StartInfo = startInfo };
Process.Exited += new EventHandler(Process_Exited);
Process.EnableRaisingEvents = true;
Process.Start();

string line;
do
{
Thread.Sleep(100);
line = tr.ReadLine();
} while (line == null || !line.Contains(".nav' saved."));

exitClient();
}

cleanUp();
CompilePalLogger.LogLine("nav file complete!");
}
CompilePalLogger.LogLine("nav file complete!");
}
catch (FileNotFoundException)
{
CompilePalLogger.LogLine("FAILED - Could not find " + context.CopyLocation);
Expand Down Expand Up @@ -111,29 +124,33 @@ private void deleteNav(string mapname, string gamefolder)

private void exitClient()
{
if (Process != null)
if (Process != null && !Process.HasExited)
try
{
this.Process.Kill();
}
catch (Win32Exception) { }
else
cleanUp();
}
private void cleanUp()
{
if (File.Exists(mapcfg))
File.Delete(mapcfg);
if (File.Exists(mapCFGBackup))
System.IO.File.Move(mapCFGBackup, mapcfg);
if (File.Exists(mapLogPath))
File.Delete(mapLogPath);
}

public override void Cancel()
{
cleanUp();
exitClient();
}

void fileSystemWatcher_NavCreated(object sender, FileSystemEventArgs e)
void Process_Exited(object sender, EventArgs e)
{
exitClient();
cleanUp();
}
}
}
8 changes: 8 additions & 0 deletions CompilePalX/Parameters/NAV/parameters.json
Expand Up @@ -6,5 +6,13 @@
"Value": null,
"CanHaveValue": false,
"Warning": ""
},
{
"Name": "Text Mode",
"Parameter": " -textmode",
"Description": "Runs the game client in text mode only.",
"Value": null,
"CanHaveValue": false,
"Warning": ""
}
]

0 comments on commit ac72ca7

Please sign in to comment.