Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Zt-freak committed Sep 28, 2021
1 parent 6effa8b commit e851b11
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
3 changes: 0 additions & 3 deletions Castor/Castor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
</ItemGroup>

<ItemGroup>
<None Update="castor-serve-mod.z2f">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="castor-serve-save.z2s">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
6 changes: 2 additions & 4 deletions Castor/Interfaces/ICommandService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System.Diagnostics;

namespace Castor.Interfaces
namespace Castor.Interfaces
{
interface ICommandService
{
Expand All @@ -10,6 +8,6 @@ interface ICommandService
void Install(string[] args);
void Version();
void Serve(string[] args);
Process ConsoleCommand(string arg);
void ConsoleCommand(string program, string arg);
}
}
5 changes: 0 additions & 5 deletions Castor/Interfaces/IFileService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
using Castor.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Castor.Interfaces
{
Expand Down
48 changes: 27 additions & 21 deletions Castor/Services/CommandService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Castor.Interfaces;
using Castor.Models;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Reflection;
using System.Text.Json;

namespace Castor.Services
Expand Down Expand Up @@ -173,34 +170,43 @@ public void Serve(string[] args)

string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;

File.Copy($"{baseDirectory}\\castor-serve-mod.z2f", "castor-serve-mod.z2f");

string command = $"\"{castorConfig.ZT2loc}\\zt.exe\" {baseDirectory}castor-serve-save.z2s";
Console.WriteLine("preparing serve");
Console.WriteLine("loading Tiny Test Map...");
using (ConsoleCommand(command))
{

}
Console.WriteLine("loading Tiny Test Map");
string ZTprogram = $"\"{castorConfig.ZT2loc}\\zt.exe\"";
string ZTarg = $"{baseDirectory}castor-serve-save.z2s";

File.Delete("castor-serve-mod.z2f");
Console.WriteLine("watching Zoo Tycoon 2...");
ConsoleCommand(ZTprogram, ZTarg);
}

public void Version()
{
Console.WriteLine("Castor v3.0.0-beta");
}

public Process ConsoleCommand(string arg)
public void ConsoleCommand(string program, string arg)
{
using (var process = new Process())
{
process.StartInfo.FileName = program;
process.StartInfo.Arguments = arg;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.Start();

while (!process.StandardOutput.EndOfStream)
{
string line = process.StandardOutput.ReadLine();
Console.WriteLine(line);
// do something with line
}
process.WaitForExit();
}
}

void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
Process process = new();
ProcessStartInfo startInfo = new();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = $"/C {arg}";
process.StartInfo = startInfo;
process.Start();
return process;
Console.WriteLine($"[{DateTime.Now}] {e.Data}");
}
}
}
Binary file removed Castor/castor-serve-mod.z2f
Binary file not shown.

0 comments on commit e851b11

Please sign in to comment.