Added new configuration manager.

More misc changes.
This commit is contained in:
David Khachaturov 2018-08-18 14:21:20 +03:00
parent 96e3da735d
commit 82fbf36796
7 changed files with 89 additions and 23 deletions

View file

@ -19,8 +19,8 @@
<!--The controller's HD rumble settings for the low/high frequency rumble. Change to change the pitch of the rumble.--> <!--The controller's HD rumble settings for the low/high frequency rumble. Change to change the pitch of the rumble.-->
<!--Don't set above ~1200. Default: 160 and 320 --> <!--Don't set above ~1200. Default: 160 and 320 -->
<add key="LowFreqRumble" value="160" /> <add key="LowFreqRumble" value="80" />
<add key="HighFreqRumble" value="320" /> <add key="HighFreqRumble" value="160" />
<!--Rumble Setting. Turns rumble on or off.--> <!--Rumble Setting. Turns rumble on or off.-->
<!--On is "true"; off is "false". Default: true --> <!--On is "true"; off is "false". Default: true -->

View file

@ -83,6 +83,7 @@
<HintPath>..\packages\Crc32.NET.1.2.0\lib\net20\Crc32.NET.dll</HintPath> <HintPath>..\packages\Crc32.NET.1.2.0\lib\net20\Crc32.NET.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Numerics" /> <Reference Include="System.Numerics" />
@ -96,6 +97,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Config.cs" />
<Compile Include="HIDapi.cs" /> <Compile Include="HIDapi.cs" />
<Compile Include="Joycon.cs" /> <Compile Include="Joycon.cs" />
<Compile Include="MainForm.cs"> <Compile Include="MainForm.cs">

View file

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BetterJoyForCemu {
public static class Config { // stores dynamic configuration, including
const string PATH = "settings";
static Dictionary<string, bool> variables = new Dictionary<string, bool>();
public static void Init() {
variables["ProgressiveScan"] = true;
if (File.Exists(PATH)) {
using (StreamReader file = new StreamReader(PATH)) {
string line = String.Empty;
while ((line = file.ReadLine()) != null) {
string[] vs = line.Split();
try {
variables[vs[0]] = Boolean.Parse(vs[1]);
} catch { }
}
}
} else {
using (StreamWriter file = new StreamWriter(PATH)) {
foreach (string k in variables.Keys)
file.WriteLine(String.Format("{0} {1}", k, variables[k]));
}
}
}
public static bool Value(string key) {
if (!variables.TryGetValue(key, out bool temp)) {
return false;
}
return variables[key];
}
public static void Save(string key, bool value) {
variables[key] = value;
using (StreamWriter file = new StreamWriter(PATH, false)) {
foreach (string k in variables.Keys)
file.WriteLine(String.Format("{0} {1}", k, variables[k]));
}
}
}
}

View file

@ -207,13 +207,13 @@ namespace BetterJoyForCemu {
public Xbox360Controller xin; public Xbox360Controller xin;
Xbox360Report report; Xbox360Report report;
int rumblePeriod = Int32.Parse(ConfigurationSettings.AppSettings["RumblePeriod"]); int rumblePeriod = Int32.Parse(ConfigurationManager.AppSettings["RumblePeriod"]);
int lowFreq = Int32.Parse(ConfigurationSettings.AppSettings["LowFreqRumble"]); int lowFreq = Int32.Parse(ConfigurationManager.AppSettings["LowFreqRumble"]);
int highFreq = Int32.Parse(ConfigurationSettings.AppSettings["HighFreqRumble"]); int highFreq = Int32.Parse(ConfigurationManager.AppSettings["HighFreqRumble"]);
bool toRumble = Boolean.Parse(ConfigurationSettings.AppSettings["EnableRumble"]); bool toRumble = Boolean.Parse(ConfigurationManager.AppSettings["EnableRumble"]);
bool showAsXInput = Boolean.Parse(ConfigurationSettings.AppSettings["ShowAsXInput"]); bool showAsXInput = Boolean.Parse(ConfigurationManager.AppSettings["ShowAsXInput"]);
public MainForm form; public MainForm form;

View file

@ -31,7 +31,7 @@
this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.contextMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.label2 = new System.Windows.Forms.Label(); this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button(); this.btn_conf = new System.Windows.Forms.Button();
this.passiveScanBox = new System.Windows.Forms.CheckBox(); this.passiveScanBox = new System.Windows.Forms.CheckBox();
this.linkLabel1 = new System.Windows.Forms.LinkLabel(); this.linkLabel1 = new System.Windows.Forms.LinkLabel();
this.contextMenu.SuspendLayout(); this.contextMenu.SuspendLayout();
@ -88,14 +88,15 @@
this.label2.TabIndex = 2; this.label2.TabIndex = 2;
this.label2.Text = "v5.0"; this.label2.Text = "v5.0";
// //
// button1 // btn_conf
// //
this.button1.Location = new System.Drawing.Point(12, 200); this.btn_conf.Enabled = false;
this.button1.Name = "button1"; this.btn_conf.Location = new System.Drawing.Point(12, 200);
this.button1.Size = new System.Drawing.Size(260, 26); this.btn_conf.Name = "btn_conf";
this.button1.TabIndex = 3; this.btn_conf.Size = new System.Drawing.Size(260, 26);
this.button1.Text = "Open Controller Configuration"; this.btn_conf.TabIndex = 3;
this.button1.UseVisualStyleBackColor = true; this.btn_conf.Text = "Open Controller Configuration";
this.btn_conf.UseVisualStyleBackColor = true;
// //
// passiveScanBox // passiveScanBox
// //
@ -109,6 +110,7 @@
this.passiveScanBox.TabIndex = 4; this.passiveScanBox.TabIndex = 4;
this.passiveScanBox.Text = "Passive Scan"; this.passiveScanBox.Text = "Passive Scan";
this.passiveScanBox.UseVisualStyleBackColor = true; this.passiveScanBox.UseVisualStyleBackColor = true;
this.passiveScanBox.CheckedChanged += new System.EventHandler(this.passiveScanBox_CheckedChanged);
// //
// linkLabel1 // linkLabel1
// //
@ -128,7 +130,7 @@
this.ClientSize = new System.Drawing.Size(284, 261); this.ClientSize = new System.Drawing.Size(284, 261);
this.Controls.Add(this.linkLabel1); this.Controls.Add(this.linkLabel1);
this.Controls.Add(this.passiveScanBox); this.Controls.Add(this.passiveScanBox);
this.Controls.Add(this.button1); this.Controls.Add(this.btn_conf);
this.Controls.Add(this.label2); this.Controls.Add(this.label2);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.console); this.Controls.Add(this.console);
@ -153,7 +155,7 @@
private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label2;
private System.Windows.Forms.ContextMenuStrip contextMenu; private System.Windows.Forms.ContextMenuStrip contextMenu;
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button btn_conf;
private System.Windows.Forms.CheckBox passiveScanBox; private System.Windows.Forms.CheckBox passiveScanBox;
private System.Windows.Forms.LinkLabel linkLabel1; private System.Windows.Forms.LinkLabel linkLabel1;
} }

View file

@ -1,12 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Configuration;
using System.Data; using System.Data;
using System.Drawing; using System.Drawing;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml.Linq;
namespace BetterJoyForCemu { namespace BetterJoyForCemu {
public partial class MainForm : Form { public partial class MainForm : Form {
@ -33,19 +35,23 @@ namespace BetterJoyForCemu {
notifyIcon.Visible = false; notifyIcon.Visible = false;
this.Show(); this.Show();
Program.Start(); Program.Start();
Config.Init();
passiveScanBox.Checked = Config.Value("ProgressiveScan");
} }
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
try { try {
Program.Stop(); Program.Stop();
Close(); Environment.Exit(0);
} catch { } } catch { }
} }
private void exitToolStripMenuItem_Click(object sender, EventArgs e) { private void exitToolStripMenuItem_Click(object sender, EventArgs e) {
try { try {
Program.Stop(); Program.Stop();
Close(); Environment.Exit(0);
} catch { } } catch { }
} }
@ -53,5 +59,9 @@ namespace BetterJoyForCemu {
linkLabel1.LinkVisited = true; linkLabel1.LinkVisited = true;
System.Diagnostics.Process.Start("http://paypal.me/DavidKhachaturov/5"); System.Diagnostics.Process.Start("http://paypal.me/DavidKhachaturov/5");
} }
private void passiveScanBox_CheckedChanged(object sender, EventArgs e) {
Config.Save("ProgressiveScan", passiveScanBox.Checked);
}
} }
} }

View file

@ -246,7 +246,7 @@ namespace BetterJoyForCemu {
static MainForm form; static MainForm form;
static bool useHIDG = Boolean.Parse(ConfigurationSettings.AppSettings["UseHIDG"]); static bool useHIDG = Boolean.Parse(ConfigurationManager.AppSettings["UseHIDG"]);
public static void Start() { public static void Start() {
pid = Process.GetCurrentProcess().Id.ToString(); // get current process id for HidCerberus.Srv pid = Process.GetCurrentProcess().Id.ToString(); // get current process id for HidCerberus.Srv
@ -268,7 +268,7 @@ namespace BetterJoyForCemu {
} }
HttpWebResponse response; HttpWebResponse response;
if (Boolean.Parse(ConfigurationSettings.AppSettings["PurgeWhitelist"])) { if (Boolean.Parse(ConfigurationManager.AppSettings["PurgeWhitelist"])) {
try { try {
response = (HttpWebResponse)WebRequest.Create(@"http://localhost:26762/api/v1/hidguardian/whitelist/purge/").GetResponse(); // remove all programs allowed to see controller response = (HttpWebResponse)WebRequest.Create(@"http://localhost:26762/api/v1/hidguardian/whitelist/purge/").GetResponse(); // remove all programs allowed to see controller
} catch (Exception e) { } catch (Exception e) {
@ -304,7 +304,7 @@ namespace BetterJoyForCemu {
server = new UdpServer(mgr.j); server = new UdpServer(mgr.j);
server.form = form; server.form = form;
server.Start(IPAddress.Parse(ConfigurationSettings.AppSettings["IP"]), Int32.Parse(ConfigurationSettings.AppSettings["Port"])); server.Start(IPAddress.Parse(ConfigurationManager.AppSettings["IP"]), Int32.Parse(ConfigurationManager.AppSettings["Port"]));
timer = new HighResTimer(pollsPerSecond, new HighResTimer.ActionDelegate(mgr.Update)); timer = new HighResTimer(pollsPerSecond, new HighResTimer.ActionDelegate(mgr.Update));
timer.Start(); timer.Start();
@ -313,7 +313,7 @@ namespace BetterJoyForCemu {
public static void Stop() { public static void Stop() {
try { try {
HttpWebResponse response = (HttpWebResponse)WebRequest.Create(@"http://localhost:26762/api/v1/hidguardian/whitelist/remove/" + pid).GetResponse(); // add BetterJoyForCemu to allowed processes HttpWebResponse response = (HttpWebResponse)WebRequest.Create(@"http://localhost:26762/api/v1/hidguardian/whitelist/remove/" + pid).GetResponse();
} catch (Exception e) { } catch (Exception e) {
form.console.Text += "Unable to remove program from whitelist.\r\n"; form.console.Text += "Unable to remove program from whitelist.\r\n";
} }
@ -321,6 +321,8 @@ namespace BetterJoyForCemu {
server.Stop(); server.Stop();
timer.Stop(); timer.Stop();
mgr.OnApplicationQuit(); mgr.OnApplicationQuit();
form.console.Text += "";
} }
static void Main(string[] args) { static void Main(string[] args) {