Skip to content

Commit

Permalink
update to 0.8.1.3
Browse files Browse the repository at this point in the history
add the ability to pass arguments to running instance of controller helper (create or update a profile).
always recommend the user to restart after new installation.
new profile name will no longer contains exe.
new profile can only point to an executable.
  • Loading branch information
Valkirie committed Dec 8, 2021
1 parent 7d370c9 commit 4475800
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 31 deletions.
3 changes: 1 addition & 2 deletions ControllerHelper/ControllerHelper.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions ControllerHelper/ControllerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public partial class ControllerHelper : Form

private readonly ILogger logger;

public ControllerHelper()
{
}

public ControllerHelper(ILogger logger)
{
InitializeComponent();
Expand Down Expand Up @@ -218,7 +222,7 @@ public void UpdateProcess(int ProcessId, string ProcessPath)
{
try
{
string ProcessExec = Path.GetFileName(ProcessPath);
string ProcessExec = Path.GetFileNameWithoutExtension(ProcessPath);

if (ProfileManager.profiles.ContainsKey(ProcessExec))
{
Expand All @@ -237,10 +241,6 @@ public void UpdateProcess(int ProcessId, string ProcessPath)
catch (Exception) { }
}

private void ControllerHelper_Shown(object sender, EventArgs e)
{
}

private void ControllerHelper_Resize(object sender, EventArgs e)
{
if (CurrentWindowState == WindowState)
Expand Down
5 changes: 3 additions & 2 deletions ControllerHelper/ControllerHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<OutputPath>$(SolutionDir)bin\</OutputPath>
<ApplicationIcon>gamepad.ico</ApplicationIcon>
<ApplicationManifest>app.manifest</ApplicationManifest>
<AssemblyVersion>0.8.1.1</AssemblyVersion>
<FileVersion>0.8.1.1</FileVersion>
<AssemblyVersion>0.8.1.3</AssemblyVersion>
<FileVersion>0.8.1.3</FileVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugType>full</DebugType>
Expand All @@ -35,6 +35,7 @@
</ItemGroup>

<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" />
Expand Down
23 changes: 23 additions & 0 deletions ControllerHelper/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using CommandLine;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

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

}
113 changes: 97 additions & 16 deletions ControllerHelper/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using CommandLine;
using ControllerCommon;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualBasic.ApplicationServices;
using Serilog;
using Serilog.Events;
using Serilog.Extensions.Logging;
Expand All @@ -9,6 +12,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using static ControllerHelper.Options;

namespace ControllerHelper
{
Expand Down Expand Up @@ -47,39 +51,116 @@ private struct Windowplacement
static extern bool GetWindowPlacement(IntPtr hWnd, ref Windowplacement lpwndpl);
#endregion

static ControllerHelper MainForm;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
static void Main(params string[] Arguments)
{
string proc = Process.GetCurrentProcess().ProcessName;
Process[] processes = Process.GetProcessesByName(proc);

if (processes.Length > 1)
if (processes.Length > 1 && Arguments.Length == 0)
{
// get our process
// an instance of helper is already running and no arguments were given
BringWindowToFront(proc);
// exit our process
return;
}
else if (processes.Length > 1 && Arguments.Length != 0)
{
// an instance of helper is already running, pass arguments to it
MainForm = new ControllerHelper();
SingleInstanceApplication.Run(MainForm, NewInstanceHandler);
}
else
{
// no instance of helper is running
Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);

var configuration = new ConfigurationBuilder()
.AddJsonFile("helpersettings.json")
.Build();

var serilogLogger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();

var microsoftLogger = new SerilogLoggerFactory(serilogLogger).CreateLogger("ControllerHelper");

Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

MainForm = new ControllerHelper(microsoftLogger);
SingleInstanceApplication.Run(MainForm, NewInstanceHandler);
}
}

public static void NewInstanceHandler(object sender, StartupNextInstanceEventArgs e)
{
string[] args = new string[e.CommandLine.Count - 1];
Array.Copy(e.CommandLine.ToArray(), 1, args, 0, e.CommandLine.Count - 1);

Parser.Default.ParseArguments<ProfileOption>(args).MapResult(
(ProfileOption opts) => RunProfile(opts),
errs => RunError(errs)
);
e.BringToForeground = false;
}

Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
private static bool RunError(IEnumerable<Error> errs)
{
// do something
return true;
}

private static bool RunProfile(ProfileOption opts)
{
if (!File.Exists(opts.exe))
return false;

var configuration = new ConfigurationBuilder()
.AddJsonFile("helpersettings.json")
.Build();
string ProcessExec = Path.GetFileNameWithoutExtension(opts.exe);

var serilogLogger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
Profile profile = new Profile(ProcessExec, opts.exe);

if (MainForm.ProfileManager.profiles.ContainsKey(ProcessExec))
profile = MainForm.ProfileManager.profiles[ProcessExec];

var microsoftLogger = new SerilogLoggerFactory(serilogLogger).CreateLogger("ControllerHelper");
profile.fullpath = opts.exe;

Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new ControllerHelper(microsoftLogger));
switch(opts.mode)
{
case "xinput":
profile.whitelisted = true;
break;
case "ds4":
profile.whitelisted = false;
break;
default:
return false;
}

MainForm.ProfileManager.UpdateProfile(profile);
MainForm.ProfileManager.SerializeProfile(profile);
return true;
}

public class SingleInstanceApplication : WindowsFormsApplicationBase
{
private SingleInstanceApplication()
{
base.IsSingleInstance = true;
}

public static void Run(Form f, StartupNextInstanceEventHandler startupHandler)
{
SingleInstanceApplication app = new SingleInstanceApplication();
app.MainForm = f;
app.StartupNextInstance += startupHandler;
app.Run(Environment.GetCommandLineArgs());
}
}

private static void BringWindowToFront(string name)
Expand Down
2 changes: 1 addition & 1 deletion ControllerHelper/ServiceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void MonitorHelper(object sender, ElapsedEventArgs e)
{
try
{
controller.WaitForStatus(nextStatus, TimeSpan.FromSeconds(5));
controller.WaitForStatus(nextStatus, TimeSpan.FromSeconds(2));
}
catch (Exception ex)
{
Expand Down
5 changes: 4 additions & 1 deletion ControllerService.iss
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ end;
;#define UseSql2019Express

#define MyAppSetupName 'Controller Service'
#define MyAppVersion '0.8.1.1'
#define MyAppVersion '0.8.1.3'
#define MyAppPublisher 'BenjaminLSR'
#define MyAppCopyright 'Copyright © BenjaminLSR'
#define MyAppURL 'https://github.com/Valkirie/ControllerService'
Expand Down Expand Up @@ -680,6 +680,9 @@ ArchitecturesInstallIn64BitMode=x64
[Languages]
Name: en; MessagesFile: "compiler:Default.isl"

[Setup]
AlwaysRestart = yes

[Files]
#ifdef UseNetCoreCheck
// download netcorecheck.exe: https://go.microsoft.com/fwlink/?linkid=2135256
Expand Down
4 changes: 2 additions & 2 deletions ControllerService.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31702.278
# Visual Studio Version 17
VisualStudioVersion = 17.0.31919.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ControllerService", "ControllerService\ControllerService.csproj", "{6B7B570E-8C8B-4189-9C98-B3BBFE630615}"
EndProject
Expand Down
4 changes: 2 additions & 2 deletions ControllerService/AssemblyInfo1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
// Numéro de build
// Révision
//
[assembly: AssemblyVersion("0.8.1.1")]
[assembly: AssemblyFileVersion("0.8.1.1")]
[assembly: AssemblyVersion("0.8.1.3")]
[assembly: AssemblyFileVersion("0.8.1.3")]

0 comments on commit 4475800

Please sign in to comment.