Skip to content

Commit

Permalink
v1.1.0
Browse files Browse the repository at this point in the history
- Generate Documentation File
- Return ProcessInfo on start
  • Loading branch information
BattlefieldDuck committed Feb 12, 2022
1 parent 351befe commit 2cb0b58
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 21 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A library using ConPTY feature to get real-time output from SteamCMD.

```cs
using SteamCMD.ConPTY;
using SteamCMD.ConPTY.Interop.Definitions;

var steamCMDConPTY = new SteamCMDConPTY
{
Expand All @@ -24,7 +25,10 @@ steamCMDConPTY.OutputDataReceived += (sender, data) => { };

steamCMDConPTY.Exited += (sender, exitCode) => { };

steamCMDConPTY.Start();
ProcessInfo processInfo = steamCMDConPTY.Start();

// Get SteamCMD PID by ProcessInfo
Console.WriteLine(processInfo.dwProcessId);
```

## SteamCMD.WPF
Expand Down
24 changes: 23 additions & 1 deletion SteamCMD.ConPTY/Interop/Definitions/CtrlEvent.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
namespace SteamCMD.ConPTY.Interop.Definitions
{
/// <summary>
/// Ctrl Event
/// </summary>
public enum CtrlEvent : uint
{
/// <summary>
/// Ctrl C
/// </summary>
CtrlC = 0,

/// <summary>
/// Ctrl Break
/// </summary>
CtrlBreak = 1,

/// <summary>
/// Ctrl Close
/// </summary>
CtrlClose = 2,

/// <summary>
/// Ctrl LogOff
/// </summary>
CtrlLogOff = 5,
CtrlShoutDown = 6,

/// <summary>
/// Ctrl ShutDown
/// </summary>
CtrlShutDown = 6,
}
}
20 changes: 19 additions & 1 deletion SteamCMD.ConPTY/Interop/Definitions/ProcessInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,30 @@

namespace SteamCMD.ConPTY.Interop.Definitions
{
/// <summary>
/// Process Information
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct ProcessInfo
public struct ProcessInfo
{
/// <summary>
/// Process handle
/// </summary>
public IntPtr hProcess;

/// <summary>
/// Thread handle
/// </summary>
public IntPtr hThread;

/// <summary>
/// Process Id
/// </summary>
public int dwProcessId;

/// <summary>
/// Thread Id
/// </summary>
public int dwThreadId;
}
}
5 changes: 5 additions & 0 deletions SteamCMD.ConPTY/Interop/Delegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@

namespace SteamCMD.ConPTY.Interop
{
/// <summary>
/// Delegate CtrlEvent
/// </summary>
/// <param name="ctrlEvent"></param>
/// <returns></returns>
public delegate bool CtrlEventDelegate(CtrlEvent ctrlEvent);
}
2 changes: 0 additions & 2 deletions SteamCMD.ConPTY/Interop/ProcessApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,5 @@ public static extern bool CreateProcess(

[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool GetExitCodeProcess(IntPtr hProcess, out uint exitCode);


}
}
25 changes: 25 additions & 0 deletions SteamCMD.ConPTY/InteropException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,45 @@

namespace SteamCMD.ConPTY
{
/// <summary>
/// Interop Exception
/// </summary>
[Serializable]
public class InteropException : Exception
{
/// <summary>
/// Interop Exception
/// </summary>
public InteropException() { }

/// <summary>
/// Interop Exception
/// </summary>
/// <param name="message"></param>
public InteropException(string message)
: base(message) { }

/// <summary>
/// Interop Exception
/// </summary>
/// <param name="message"></param>
/// <param name="innerException"></param>
public InteropException(string message, Exception innerException)
: base(message, innerException) { }

/// <summary>
/// Interop Exception
/// </summary>
/// <param name="serializationInfo"></param>
/// <param name="streamingContext"></param>
protected InteropException(SerializationInfo serializationInfo, StreamingContext streamingContext)
: base(serializationInfo, streamingContext) { }

/// <summary>
/// Create exception with inner HResult exception
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public static InteropException CreateWithInnerHResultException(string message)
{
return new InteropException(
Expand Down
36 changes: 36 additions & 0 deletions SteamCMD.ConPTY/NativeConsole.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,60 @@

namespace SteamCMD.ConPTY
{
/// <summary>
/// Native Console
/// </summary>
public class NativeConsole : IDisposable
{
private IntPtr handle;
private bool isDisposed;
private Pipe stdOut, stdErr, stdIn;

/// <summary>
/// Native Console
/// </summary>
/// <param name="hidden"></param>
public NativeConsole(bool hidden = true)
{
Initialise(hidden);
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
~NativeConsole()
{
Dispose(false);
}

/// <summary>
/// StdOut
/// </summary>
public FileStream Output { get; private set; }

/// <summary>
/// StdErr
/// </summary>
public FileStream Error { get; private set; }

/// <summary>
/// StdIn
/// </summary>
public FileStream Input { get; private set; }

/// <summary>
/// Send CtrlEvent to the console
/// </summary>
/// <param name="ctrlEvent"></param>
public static void SendCtrlEvent(CtrlEvent ctrlEvent)
{
ConsoleApi.GenerateConsoleCtrlEvent(ctrlEvent, 0);
}

/// <summary>
/// Register OnClose Action
/// </summary>
/// <param name="action"></param>
public static void RegisterOnCloseAction(Action action)
{
RegisterCtrlEventFunction((ctrlEvent) =>
Expand All @@ -45,17 +72,26 @@ public static void RegisterOnCloseAction(Action action)
});
}

/// <summary>
/// Register Ctrl Event Function
/// </summary>
/// <param name="function"></param>
public static void RegisterCtrlEventFunction(CtrlEventDelegate function)
{
ConsoleApi.SetConsoleCtrlHandler(function, true);
}

/// <inheritdoc/>
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}

/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <param name="disposing"></param>
protected virtual void Dispose(bool disposing)
{
if (isDisposed)
Expand Down
2 changes: 2 additions & 0 deletions SteamCMD.ConPTY/SteamCMD.ConPTY.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<RepositoryUrl>https://github.com/WindowsGSM/SteamCMD.ConPTY</RepositoryUrl>
<PackageTags>steamcmd, conpty, windows-10</PackageTags>
<PackageIcon>icon.png</PackageIcon>
<Version>1.1.0</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
10 changes: 7 additions & 3 deletions SteamCMD.ConPTY/SteamCMDConPTY.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
using System.IO;
using SteamCMD.ConPTY.Interop.Definitions;
using System.IO;
using System.IO.Compression;
using System.Net;

namespace SteamCMD.ConPTY
{
/// <summary>
/// SteamCMD ConPTY
/// </summary>
public class SteamCMDConPTY : WindowsPseudoConsole
{
/// <summary>
/// Start steamcmd.exe
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
public void Start(short width = 120, short height = 30)
public ProcessInfo Start(short width = 120, short height = 30)
{
string fileName = "steamcmd.exe";

Expand All @@ -33,7 +37,7 @@ public void Start(short width = 120, short height = 30)
File.Delete(zipPath);
}

base.Start(fileName, width, height);
return base.Start(fileName, width, height);
}
}
}
Loading

0 comments on commit 2cb0b58

Please sign in to comment.