diff --git a/ControllerHelper/ControllerHelper.Designer.cs b/ControllerHelper/ControllerHelper.Designer.cs
index 0058154a9..e18f86c6e 100644
--- a/ControllerHelper/ControllerHelper.Designer.cs
+++ b/ControllerHelper/ControllerHelper.Designer.cs
@@ -138,7 +138,6 @@ private void InitializeComponent()
this.notifyIcon1.ContextMenuStrip = this.contextMenuStrip1;
this.notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("notifyIcon1.Icon")));
this.notifyIcon1.Text = "Controller Helper";
- this.notifyIcon1.Visible = true;
this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
//
// contextMenuStrip1
@@ -1001,6 +1000,7 @@ private void InitializeComponent()
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
+ this.openFileDialog1.Filter = "Exe Files (.exe)|*.exe";
//
// toolTip1
//
@@ -1023,7 +1023,6 @@ private void InitializeComponent()
this.Text = "ControllerHelper";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.ControllerHelper_Close);
this.Load += new System.EventHandler(this.ControllerHelper_Load);
- this.Shown += new System.EventHandler(this.ControllerHelper_Shown);
this.Resize += new System.EventHandler(this.ControllerHelper_Resize);
this.contextMenuStrip1.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
diff --git a/ControllerHelper/ControllerHelper.cs b/ControllerHelper/ControllerHelper.cs
index 68f7e3b80..ff9d1184f 100644
--- a/ControllerHelper/ControllerHelper.cs
+++ b/ControllerHelper/ControllerHelper.cs
@@ -56,6 +56,10 @@ public partial class ControllerHelper : Form
private readonly ILogger logger;
+ public ControllerHelper()
+ {
+ }
+
public ControllerHelper(ILogger logger)
{
InitializeComponent();
@@ -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))
{
@@ -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)
diff --git a/ControllerHelper/ControllerHelper.csproj b/ControllerHelper/ControllerHelper.csproj
index 37c27d5ec..0cee0dc07 100644
--- a/ControllerHelper/ControllerHelper.csproj
+++ b/ControllerHelper/ControllerHelper.csproj
@@ -12,8 +12,8 @@
$(SolutionDir)bin\
gamepad.ico
app.manifest
- 0.8.1.1
- 0.8.1.1
+ 0.8.1.3
+ 0.8.1.3
full
@@ -35,6 +35,7 @@
+
diff --git a/ControllerHelper/Options.cs b/ControllerHelper/Options.cs
new file mode 100644
index 000000000..547920234
--- /dev/null
+++ b/ControllerHelper/Options.cs
@@ -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; }
+ }
+ }
+
+}
diff --git a/ControllerHelper/Program.cs b/ControllerHelper/Program.cs
index 74ea4318a..aa5f7fee4 100644
--- a/ControllerHelper/Program.cs
+++ b/ControllerHelper/Program.cs
@@ -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;
@@ -9,6 +12,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
+using static ControllerHelper.Options;
namespace ControllerHelper
{
@@ -47,39 +51,116 @@ private struct Windowplacement
static extern bool GetWindowPlacement(IntPtr hWnd, ref Windowplacement lpwndpl);
#endregion
+ static ControllerHelper MainForm;
+
///
/// The main entry point for the application.
///
[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(args).MapResult(
+ (ProfileOption opts) => RunProfile(opts),
+ errs => RunError(errs)
+ );
+ e.BringToForeground = false;
+ }
- Directory.SetCurrentDirectory(AppDomain.CurrentDomain.BaseDirectory);
+ private static bool RunError(IEnumerable 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)
diff --git a/ControllerHelper/ServiceManager.cs b/ControllerHelper/ServiceManager.cs
index 65a886855..bd15bee76 100644
--- a/ControllerHelper/ServiceManager.cs
+++ b/ControllerHelper/ServiceManager.cs
@@ -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)
{
diff --git a/ControllerService.iss b/ControllerService.iss
index 3e01b7fef..7d163abd4 100644
--- a/ControllerService.iss
+++ b/ControllerService.iss
@@ -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'
@@ -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
diff --git a/ControllerService.sln b/ControllerService.sln
index 868358e18..2535c86b6 100644
--- a/ControllerService.sln
+++ b/ControllerService.sln
@@ -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
diff --git a/ControllerService/AssemblyInfo1.cs b/ControllerService/AssemblyInfo1.cs
index a7fd87d43..19291d242 100644
--- a/ControllerService/AssemblyInfo1.cs
+++ b/ControllerService/AssemblyInfo1.cs
@@ -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")]