Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension cleanup #46

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified CLib.dll
Binary file not shown.
Binary file modified CLibCompression.dll
Binary file not shown.
Binary file modified CLibCompression_x64.dll
Binary file not shown.
Binary file modified CLibDatabase.dll
Binary file not shown.
Binary file modified CLibDatabase_x64.dll
Binary file not shown.
Binary file modified CLibLogging.dll
Binary file not shown.
Binary file modified CLibLogging_x64.dll
Binary file not shown.
Binary file modified CLibSocket.dll
Binary file not shown.
Binary file modified CLibSocket_x64.dll
Binary file not shown.
Binary file modified CLib_x64.dll
Binary file not shown.
22 changes: 9 additions & 13 deletions extensions/CLib/CLib/ArmaRequest.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
using System;

namespace CLib
{
public class ArmaRequest
{
namespace CLib {
public class ArmaRequest {
public int TaskId { get; private set; }
public string ExtensionName { get; private set; }
public string ActionName { get; private set; }
public string Data { get; private set; }

public static ArmaRequest Parse(string input)
{
int headerStart = input.IndexOf(ControlCharacter.SOH);
int textStart = input.IndexOf(ControlCharacter.STX);
int textEnd = input.IndexOf(ControlCharacter.ETX);
public static ArmaRequest Parse(string input) {
var headerStart = input.IndexOf(ControlCharacter.SOH);
var textStart = input.IndexOf(ControlCharacter.STX);
var textEnd = input.IndexOf(ControlCharacter.ETX);

string header = input.Substring(headerStart < 0 ? 0 : headerStart + 1, (textStart < 0 ? input.Length : textStart) - 1);
string[] headerValues = header.Split(new [] { ControlCharacter.US }, 3);
var header = input.Substring(headerStart < 0 ? 0 : headerStart + 1, (textStart < 0 ? input.Length : textStart) - 1);
var headerValues = header.Split(new [] { ControlCharacter.US }, 3);

var request = new ArmaRequest();
int taskId;
if (!int.TryParse(headerValues[0], out taskId))
if (!int.TryParse(headerValues[0], out var taskId))
throw new ArgumentException($"Invalid task id: {headerValues[0]}");
request.TaskId = taskId;
request.ExtensionName = headerValues[1].Trim();
Expand Down
3 changes: 2 additions & 1 deletion extensions/CLib/CLib/CLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CLib</RootNamespace>
<AssemblyName>CLib_x64</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<AssemblyName>CLib_x64</AssemblyName>
Expand Down
7 changes: 3 additions & 4 deletions extensions/CLib/CLib/ControlCharacter.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace CLib
{
public struct ControlCharacter
{
namespace CLib {
public struct ControlCharacter {
// ReSharper disable InconsistentNaming
public const char SOH = '\x01';
public const char STX = '\x02';
public const char ETX = '\x03';
Expand Down
84 changes: 24 additions & 60 deletions extensions/CLib/CLib/Debugger.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CLib
{
public partial class Debugger : Form
{
public Debugger()
{
InitializeComponent();
namespace CLib {
public partial class Debugger : Form {
public Debugger() {
this.InitializeComponent();

#if Debug
this.Show();
Expand All @@ -23,70 +13,44 @@ public Debugger()
#endif
}

public void Toggle()
{
if (this.rtb_log.InvokeRequired)
{
try
{
this.rtb_log.Invoke(new Action(delegate
{
this.Toggle();
}));
}
catch (ObjectDisposedException) {}
public void Toggle() {
if (this.rtb_log.InvokeRequired) {
try {
this.rtb_log.Invoke(new Action(this.Toggle));
} catch (ObjectDisposedException) {}
return;
}

if (this.Visible)
{
if (this.Visible) {
this.Hide();
}
else
{
} else {
this.Show();
}
}

public void Log(object obj)
{
if (this.rtb_log.InvokeRequired)
{
try
{
this.rtb_log.Invoke(new Action(delegate {
this.Log(obj);
}));
}
catch (ObjectDisposedException) {}
public void Log(object obj) {
if (this.rtb_log.InvokeRequired) {
try {
this.rtb_log.Invoke(new Action(delegate { this.Log(obj); }));
} catch (ObjectDisposedException) {}
return;
}

this.rtb_log.AppendText(obj.ToString() + "\n");
this.rtb_log.AppendText(obj + "\n");
}

protected override void OnFormClosing(FormClosingEventArgs e)
{
if (this.rtb_log.InvokeRequired)
{
try
{
this.rtb_log.Invoke(new Action(delegate
{
this.OnFormClosing(e);
}));
}
catch (ObjectDisposedException) {}
protected override void OnFormClosing(FormClosingEventArgs e) {
if (this.rtb_log.InvokeRequired) {
try {
this.rtb_log.Invoke(new Action(delegate { this.OnFormClosing(e); }));
} catch (ObjectDisposedException) {}
return;
}

if (e.CloseReason != CloseReason.UserClosing)
{
if (e.CloseReason != CloseReason.UserClosing) {
this.Dispose(true);
Application.Exit();
}
else
{
} else {
this.Hide();
}
}
Expand Down
Loading