Compare commits
4
Commits
1.0.0
...
aedeb4a6bb
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aedeb4a6bb | ||
|
|
691bc7ef45 | ||
|
|
ac41113853 | ||
|
|
5db254e0f1 |
@@ -19,12 +19,14 @@ namespace SoraV2Utils_Agent
|
||||
server.RegisterService<IToastNotification>(new NotificationSender());
|
||||
server.Start();
|
||||
|
||||
UpdateCheck.CheckUpdate(); //Check for Updates based on Git Releases
|
||||
|
||||
var serviceMonitor = new ServiceMonitor("SoraV2Utils_Service");
|
||||
serviceMonitor.ServiceStopped += (sender, e) =>
|
||||
{
|
||||
server.Stop();
|
||||
System.Environment.Exit(1);
|
||||
};;
|
||||
}; ;
|
||||
|
||||
var trayicon = new TrayIcon();
|
||||
trayicon.Display();
|
||||
|
||||
@@ -75,13 +75,20 @@ namespace SoraV2Utils_Agent
|
||||
}
|
||||
|
||||
public void Exit()
|
||||
{
|
||||
// Stop the Service
|
||||
try
|
||||
{
|
||||
var client = new Client("SoraV2UtilsDeviceData");
|
||||
var service = client.GetServiceProxy<IMouseData>();
|
||||
service.Exit();
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
}
|
||||
|
||||
// Exit the application gracefully
|
||||
Environment.Exit(0);
|
||||
// Exit the application
|
||||
System.Environment.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ServiceMonitor.cs" />
|
||||
<Compile Include="TrayIcon.cs" />
|
||||
<Compile Include="UpdateCheck.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
@@ -94,6 +95,9 @@
|
||||
<PackageReference Include="EasyPipes">
|
||||
<Version>1.3.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>13.0.3</Version>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include=".NETFramework,Version=v4.7.2">
|
||||
|
||||
@@ -29,9 +29,8 @@ namespace SoraV2Utils_Agent
|
||||
batteryLevelItem.Enabled = false;
|
||||
batteryRuntimeItem.Enabled = false;
|
||||
|
||||
|
||||
// Add an exit menu item
|
||||
contextMenu.MenuItems.Add("Exit", (sender, e) => ServiceIPC.Instance.Exit());
|
||||
contextMenu.MenuItems.Add("Check for Update ", (sender, e) => UpdateCheck.CheckUpdate());
|
||||
|
||||
contextMenu.MenuItems.Add(batteryLevelItem);
|
||||
contextMenu.MenuItems.Add(batteryRuntimeItem);
|
||||
@@ -54,6 +53,7 @@ namespace SoraV2Utils_Agent
|
||||
// Update the context menu items
|
||||
batteryLevelItem.Text = batteryLevelText;
|
||||
batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}";
|
||||
batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}";
|
||||
|
||||
// Update every second
|
||||
Thread.Sleep(1000);
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using System.Xml.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace SoraV2Utils_Agent
|
||||
{
|
||||
public class UpdateCheck
|
||||
{
|
||||
private static string GetLatestReleaseTag()
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
var url = $"https://git.jan.sx/api/v1/repos/krjan02/SoraV2Utils/releases/latest";
|
||||
var response = client.GetStringAsync(url).Result;
|
||||
var json = JObject.Parse(response);
|
||||
return json["tag_name"].ToString();
|
||||
}
|
||||
}
|
||||
|
||||
private static string GetCurrentVersion()
|
||||
{
|
||||
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
|
||||
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
|
||||
return fvi.FileVersion;
|
||||
}
|
||||
|
||||
private static bool IsVersionLower(string currentVersion, string releaseVersion)
|
||||
{
|
||||
Version current = Version.Parse(currentVersion);
|
||||
Version release = Version.Parse(releaseVersion);
|
||||
|
||||
return current.CompareTo(release) < 0;
|
||||
}
|
||||
|
||||
public static void CheckUpdate()
|
||||
{
|
||||
var CurrentVersion = GetCurrentVersion();
|
||||
var LatestVersion = GetLatestReleaseTag();
|
||||
|
||||
if (IsVersionLower(CurrentVersion, LatestVersion))
|
||||
{
|
||||
DialogResult dialogResult = MessageBox.Show("" +
|
||||
String.Format("Version {0} is available. You are running {1}" +
|
||||
"\nDo you want to Update now?", LatestVersion, CurrentVersion),
|
||||
"SoraV2 Utils Updater", MessageBoxButtons.YesNo);
|
||||
if (dialogResult == DialogResult.Yes)
|
||||
{
|
||||
System.Diagnostics.Process.Start("https://git.jan.sx/krjan02/SoraV2Utils/releases/latest");
|
||||
ServiceIPC.Instance.Exit(); //Stop the Service and the Agent
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -87,7 +87,7 @@ namespace SoraV2Utils_Service
|
||||
|
||||
_data["SoraV2Utils"].AddKey("criticalThreshold", "10");
|
||||
_data["SoraV2Utils"].GetKeyData("criticalThreshold").Comments.Add("Threshold for second (critial) warning");
|
||||
this.parser.WriteFile("SoraV2Utils.ini", _data);
|
||||
this.parser.WriteFile(AppDomain.CurrentDomain.BaseDirectory + "\\SoraV2Utils.ini", _data);
|
||||
return _data;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,11 +11,13 @@ namespace SoraV2Tools
|
||||
{
|
||||
private const ushort VID = 0x1915;
|
||||
private const ushort PID_WIRELESS = 0xAE1C;
|
||||
private const ushort PID_WIRED = 0xAE11;
|
||||
private const ushort PID_WIRED = 0xAE12;
|
||||
|
||||
public static List<HidDevice> GetDevice()
|
||||
{
|
||||
var devices = HidDevices.Enumerate(VID, PID_WIRELESS).ToList();
|
||||
List<HidDevice> devices = HidDevices.Enumerate(VID, PID_WIRELESS)
|
||||
.Concat(HidDevices.Enumerate(VID, PID_WIRED))
|
||||
.ToList();
|
||||
|
||||
return devices;
|
||||
}
|
||||
@@ -72,8 +74,12 @@ namespace SoraV2Tools
|
||||
byte fullCharge = responseData[11];
|
||||
byte online = responseData[12];
|
||||
|
||||
if ((device.Attributes.ProductId == PID_WIRELESS && online == 1) ||
|
||||
(device.Attributes.ProductId == PID_WIRED && charging == 1))
|
||||
{
|
||||
return new DeviceStatus(battery, charging, fullCharge, online);
|
||||
}
|
||||
}
|
||||
return new DeviceStatus();
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
Reference in New Issue
Block a user