Skip to content

Commit

Permalink
code cleanup and reference update
Browse files Browse the repository at this point in the history
  • Loading branch information
Valkirie committed Dec 13, 2021
1 parent b985446 commit bc8d4bd
Show file tree
Hide file tree
Showing 20 changed files with 93 additions and 263 deletions.
4 changes: 0 additions & 4 deletions ControllerCommon/OneEuroFilter.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControllerCommon
{
Expand Down
4 changes: 2 additions & 2 deletions ControllerCommon/PipeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public PipeServerController()
[Serializable]
public class PipeServerSettings : PipeMessage
{
public Dictionary<string, string> settings = new Dictionary<string, string>();
public Dictionary<string, string> settings = new();

public PipeServerSettings()
{
Expand Down Expand Up @@ -84,7 +84,7 @@ public PipeClientScreen()
[Serializable]
public class PipeClientSettings : PipeMessage
{
public Dictionary<string, string> settings = new Dictionary<string, string>();
public Dictionary<string, string> settings = new();

public PipeClientSettings()
{
Expand Down
10 changes: 5 additions & 5 deletions ControllerCommon/PipeServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public class PipeServer
public event ClientMessageEventHandler ClientMessage;
public delegate void ClientMessageEventHandler(Object sender, PipeMessage e);

private ConcurrentQueue<PipeMessage> m_queue;
private Timer m_timer;
private readonly ConcurrentQueue<PipeMessage> m_queue;
private readonly Timer m_timer;

public bool connected;

Expand All @@ -71,9 +71,9 @@ public PipeServer(string pipeName)
m_timer = new Timer(1000) { Enabled = false, AutoReset = true };
m_timer.Elapsed += SendMessageQueue;

PipeSecurity ps = new PipeSecurity();
System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
PipeAccessRule par = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
PipeSecurity ps = new();
System.Security.Principal.SecurityIdentifier sid = new(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
PipeAccessRule par = new(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
ps.AddAccessRule(par);

server = new NamedPipeServer<PipeMessage>(pipeName, ps);
Expand Down
8 changes: 1 addition & 7 deletions ControllerCommon/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ public class Profile
[JsonIgnore] public ProfileErrorCode error;
[JsonIgnore] public string fullpath { get; set; }

public event DeletedEventHandler Deleted;
public delegate void DeletedEventHandler(Object sender);

public event DisconnectedEventHandler Disconnected;
public delegate void DisconnectedEventHandler(Object sender);

public Profile()
{
{
}

public Profile(string name, string path)
Expand Down
7 changes: 1 addition & 6 deletions ControllerCommon/ServiceHelper.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.InteropServices;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace ControllerCommon
{
Expand Down Expand Up @@ -55,7 +50,7 @@ public static void ChangeStartMode(ServiceController svc, ServiceStartMode mode)
svc.ServiceName,
SERVICE_QUERY_CONFIG | SERVICE_CHANGE_CONFIG);
}
catch (Exception ex)
catch (Exception)
{
return;
}
Expand Down
17 changes: 8 additions & 9 deletions ControllerCommon/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ public static byte NormalizeInput(short input)

public static bool IsTextAValidIPAddress(string text)
{
IPAddress test;
return IPAddress.TryParse(text, out test);
return IPAddress.TryParse(text, out _);
}

public static string GetPathToApp(Process process)
Expand All @@ -74,7 +73,7 @@ public static string GetPathToApp(Process process)
catch
{
string query = "SELECT ExecutablePath, ProcessID FROM Win32_Process";
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
ManagementObjectSearcher searcher = new(query);

foreach (ManagementObject item in searcher.Get())
{
Expand Down Expand Up @@ -143,7 +142,7 @@ public static bool IsDirectoryWritable(string dirPath, bool throwIfFails = false
{ }
return true;
}
catch(Exception ex)
catch (Exception ex)
{
Console.WriteLine(ex.Message);
if (throwIfFails)
Expand All @@ -158,18 +157,18 @@ public class OneEuroFilterPair
public const double DEFAULT_WHEEL_CUTOFF = 0.1;
public const double DEFAULT_WHEEL_BETA = 0.1;

public OneEuroFilter axis1Filter = new OneEuroFilter(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis2Filter = new OneEuroFilter(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis1Filter = new(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis2Filter = new(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
}

public class OneEuroFilter3D
{
public const double DEFAULT_WHEEL_CUTOFF = 0.4;
public const double DEFAULT_WHEEL_BETA = 0.2;

public OneEuroFilter axis1Filter = new OneEuroFilter(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis2Filter = new OneEuroFilter(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis3Filter = new OneEuroFilter(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis1Filter = new(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis2Filter = new(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);
public OneEuroFilter axis3Filter = new(minCutoff: DEFAULT_WHEEL_CUTOFF, beta: DEFAULT_WHEEL_BETA);

public void SetFilterAttrs(double minCutoff, double beta)
{
Expand Down
14 changes: 5 additions & 9 deletions ControllerHelper/CmdParser.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CommandLine;
using CommandLine;
using ControllerCommon;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
using static ControllerHelper.Options;

namespace ControllerHelper
Expand All @@ -30,7 +26,7 @@ public void ParseArgs(string[] args)
{
this.args = args;

if (args.Length == 0)
if (args.Length == 0)
return;

logger?.LogInformation("Parsing command: {0}", String.Join(' ', args));
Expand Down
8 changes: 3 additions & 5 deletions ControllerHelper/ControllerHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CommandLine;
using ControllerCommon;
using ControllerCommon;
using Microsoft.Extensions.Logging;
using Microsoft.Win32.TaskScheduler;
using System;
Expand All @@ -12,7 +11,6 @@
using System.ServiceProcess;
using System.Timers;
using System.Windows.Forms;
using static ControllerHelper.Options;
using Timer = System.Timers.Timer;

namespace ControllerHelper
Expand Down Expand Up @@ -371,7 +369,7 @@ public void UpdateSettings(Dictionary<string, string> args)
string name = pair.Key;
string property = pair.Value;

switch(name)
switch (name)
{
case "HIDmode":
cB_HidMode.SelectedItem = HIDmodes[args[name]];
Expand Down Expand Up @@ -764,7 +762,7 @@ public void UpdateService(ServiceControllerStatus status, ServiceStartMode start
break;
}

switch(starttype)
switch (starttype)
{
case ServiceStartMode.Disabled:
if (b_ServiceStart.Enabled == true) b_ServiceStart.Enabled = false;
Expand Down
6 changes: 4 additions & 2 deletions ControllerHelper/ControllerHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<Copyright>Copyright © 2021</Copyright>
<OutputPath>$(SolutionDir)bin\</OutputPath>
<ApplicationIcon>gamepad.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AssemblyVersion>0.8.1.4</AssemblyVersion>
<FileVersion>0.8.1.4</FileVersion>
</PropertyGroup>
Expand All @@ -23,6 +22,9 @@
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Remove="app.manifest" />
</ItemGroup>
<ItemGroup>
<None Remove="helpersettings.json" />
</ItemGroup>
Expand All @@ -37,13 +39,13 @@
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.8.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageReference Include="MouseKeyHook" Version="5.6.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.3.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="System.ServiceProcess.ServiceController" Version="6.0.0" />
<PackageReference Include="TaskScheduler" Version="2.9.2" />
<PackageReference Include="WindowsHook" Version="1.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion ControllerHelper/MouseHook.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using ControllerCommon;
using Gma.System.MouseKeyHook;
using Microsoft.Extensions.Logging;
using System.Threading;
using System.Timers;
using System.Windows.Forms;
using WindowsHook;
using MouseButtons = WindowsHook.MouseButtons;
using Timer = System.Timers.Timer;

namespace ControllerHelper
Expand Down
83 changes: 39 additions & 44 deletions ControllerHelper/Options.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,50 @@
using CommandLine;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ControllerHelper
{
public class Options
{
public enum ProfileOptionMode
{
[Description("xinput")]
xinput,
[Description("ds4")]
ds4
}
public class Options
{
public enum ProfileOptionMode
{
[Description("xinput")]
xinput,
[Description("ds4")]
ds4
}

[Verb("profile", false, HelpText = "create or update profile for specified app")]
public class ProfileOption
{
[Option('m', "mode", Required = true)]
public ProfileOptionMode mode { get; set; }
[Verb("profile", false, HelpText = "create or update profile for specified app")]
public class ProfileOption
{
[Option('m', "mode", Required = true)]
public ProfileOptionMode mode { get; set; }

[Option('e', "exe", Required = true)]
public string exe { get; set; }
}
[Option('e', "exe", Required = true)]
public string exe { get; set; }
}

public enum ProfileServiceAction
{
[Description("install")]
install,
[Description("uninstall")]
uninstall,
[Description("create")]
create,
[Description("delete")]
delete,
[Description("start")]
start,
[Description("stop")]
stop
}
public enum ProfileServiceAction
{
[Description("install")]
install,
[Description("uninstall")]
uninstall,
[Description("create")]
create,
[Description("delete")]
delete,
[Description("start")]
start,
[Description("stop")]
stop
}

[Verb("service", false, HelpText = "create, update or delete the service")]
public class ProfileService
{
[Option('a', "action", Required = true)]
public ProfileServiceAction action { get; set; }
}
}
[Verb("service", false, HelpText = "create, update or delete the service")]
public class ProfileService
{
[Option('a', "action", Required = true)]
public ProfileServiceAction action { get; set; }
}
}

}
2 changes: 1 addition & 1 deletion ControllerHelper/ProfileManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private void ProfileCreated(object sender, FileSystemEventArgs e)
public void DeleteProfile(Profile profile)
{
string settingsPath = Path.Combine(path, $"{profile.name}.json");

if (profiles.ContainsKey(profile.name))
{
UnregisterApplication(profile);
Expand Down
10 changes: 1 addition & 9 deletions ControllerHelper/Program.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
using CommandLine;
using ControllerCommon;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualBasic.ApplicationServices;
using Serilog;
using Serilog.Events;
using Serilog.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
using static ControllerHelper.Options;

namespace ControllerHelper
{
Expand Down Expand Up @@ -63,7 +55,7 @@ static void Main(params string[] Arguments)
PipeClient.Connected += OnServerConnected;
PipeClient.ServerMessage += OnServerMessage;
PipeClient.Start();

// Wait for work method to signal and kill after 4seconds
autoEvent.WaitOne(4000);
}
Expand Down
Loading

0 comments on commit bc8d4bd

Please sign in to comment.