Storing and retrieving the list of configs

feature/joystick-binding
Brian Lima 7 years ago
parent 78ce24a09b
commit e6183e29f7

@ -9,16 +9,10 @@ namespace UWPHook
public partial class App : Application public partial class App : Application
{ {
public static TrayIcon icon; public static TrayIcon icon;
public static EventsHook eventsHook;
private void Application_Startup(object sender, StartupEventArgs e) private void Application_Startup(object sender, StartupEventArgs e)
{ {
icon = new TrayIcon(); icon = new TrayIcon();
eventsHook = new EventsHook();
eventsHook.StartHooking();
} }
} }

@ -15,6 +15,11 @@ namespace UWPHook
private byte[] _outputReport = new byte[8]; private byte[] _outputReport = new byte[8];
KeyboardToController keyboardToController; KeyboardToController keyboardToController;
public EventsHook(KeyboardToController _keyboardToController)
{
keyboardToController = _keyboardToController;
}
public void StartHooking() public void StartHooking()
{ {
KeyboardWatcher.Start(); KeyboardWatcher.Start();
@ -36,7 +41,6 @@ namespace UWPHook
throw; throw;
} }
} }
private void MouseWatcher_OnMouseInput(object sender, MouseEventArgs e) private void MouseWatcher_OnMouseInput(object sender, MouseEventArgs e)

@ -1,4 +1,6 @@
using SharpSteam; using Newtonsoft.Json;
using ScpDriverInterface;
using SharpSteam;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
@ -19,6 +21,8 @@ namespace UWPHook
{ {
AppEntryModel Apps; AppEntryModel Apps;
BackgroundWorker bwrLoad, bwrSave; BackgroundWorker bwrLoad, bwrSave;
EventsHook hook;
List<KeyboardToController> listJoystick;
public GamesWindow() public GamesWindow()
{ {
@ -47,6 +51,41 @@ namespace UWPHook
this.Title = "UWPHook: Streaming a game"; this.Title = "UWPHook: Streaming a game";
this.label.Content = "UWPHook is streaming your game, fasten your seatbelts."; this.label.Content = "UWPHook is streaming your game, fasten your seatbelts.";
//The user is trying to Stream his game probably, so let's start to emulate his controller
KeyboardToController Joystick = null;
if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json"))
{
File.Create(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json");
this.listJoystick = new List<KeyboardToController>();
//TODO: Launch joystick setup for this game
}
else
{
this.listJoystick = JsonConvert.DeserializeObject<List<KeyboardToController>>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json"));
//Try to load the config for this game
foreach (var item in listJoystick)
{
if (item.Game == Environment.GetCommandLineArgs()[1])
{
Joystick = item;
break;
}
}
//Joystick = (KeyboardToController)(listJoystick.q(x => x.Game == "X"/*Environment.GetCommandLineArgs()[1]*/)[0]);
}
var json = JsonConvert.SerializeObject(listJoystick);
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/Joysticks.json", json);
if (Joystick == null)
{
//TODO: Launch joystick setup for this game
}
hook = new EventsHook(Joystick);
hook.StartHooking();
Thread.Sleep(10000); Thread.Sleep(10000);
} }
@ -89,6 +128,11 @@ namespace UWPHook
ScriptManager.RunScript("Set - WinUILanguageOverride " + currentLanguage); ScriptManager.RunScript("Set - WinUILanguageOverride " + currentLanguage);
} }
if (Properties.Settings.Default.StreamMode)
{
hook.StopHooking();
}
//The user has probably finished using the app, so let's close UWPHook to keep the experience clean //The user has probably finished using the app, so let's close UWPHook to keep the experience clean
this.Close(); this.Close();
App.icon.Close(); App.icon.Close();

@ -4,7 +4,7 @@ using ScpDriverInterface;
namespace UWPHook namespace UWPHook
{ {
class KeyboardToController public class KeyboardToController
{ {
private string _game; private string _game;
@ -23,7 +23,7 @@ namespace UWPHook
} }
} }
class KeyToXboxButton public class KeyToXboxButton
{ {
private string _key; private string _key;

@ -69,6 +69,9 @@
<Reference Include="MaterialDesignThemes.Wpf, Version=2.3.1.953, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="MaterialDesignThemes.Wpf, Version=2.3.1.953, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath> <HintPath>..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="Nito.AsyncEx, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Nito.AsyncEx, Version=3.0.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.dll</HintPath> <HintPath>..\packages\Nito.AsyncEx.3.0.1\lib\net45\Nito.AsyncEx.dll</HintPath>
</Reference> </Reference>

@ -4,6 +4,7 @@
<package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net461" /> <package id="Hardcodet.NotifyIcon.Wpf" version="1.0.8" targetFramework="net461" />
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" /> <package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" />
<package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net461" /> <package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" />
<package id="Nito.AsyncEx" version="3.0.1" targetFramework="net461" /> <package id="Nito.AsyncEx" version="3.0.1" targetFramework="net461" />
<package id="System.Management.Automation" version="6.1.7601.17515" targetFramework="net461" /> <package id="System.Management.Automation" version="6.1.7601.17515" targetFramework="net461" />
</packages> </packages>
Loading…
Cancel
Save