From ef59ca99453250412a7ea1fe29367bbd1236b863 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Thu, 12 Sep 2024 11:05:00 -0700 Subject: [PATCH] Working Configuration --- FakeDeckUI/FakeDeck/App.xaml | 9 + FakeDeckUI/FakeDeck/App.xaml.cs | 32 ++ FakeDeckUI/FakeDeck/AssemblyInfo.cs | 10 + FakeDeckUI/FakeDeck/ButtonType/Button.cs | 47 +++ .../FakeDeck/ButtonType/HelldiversTwoMacro.cs | 102 ++++++ .../FakeDeck/ButtonType/KeyboardMacro.cs | 24 ++ FakeDeckUI/FakeDeck/ButtonType/MediaMacro.cs | 35 ++ .../FakeDeck/Class/AbstractionHelper.cs | 41 +++ FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs | 33 ++ FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs | 45 +++ FakeDeckUI/FakeDeck/Class/GeneralHelper.cs | 28 ++ FakeDeckUI/FakeDeck/Class/HttpServer.cs | 322 ++++++++++++++++++ FakeDeckUI/FakeDeck/Class/KeyboardCode.cs | 201 +++++++++++ FakeDeckUI/FakeDeck/Class/YamlHelper.cs | 29 ++ FakeDeckUI/FakeDeck/FakeDeck.csproj | 24 ++ FakeDeckUI/FakeDeck/MainWindow.xaml | 12 + FakeDeckUI/FakeDeck/MainWindow.xaml.cs | 46 +++ FakeDeckUI/FakeDeck/StaticFiles/app.js | 38 +++ FakeDeckUI/FakeDeck/configuration.yaml | 60 ++++ FakeeDeck.sln | 8 +- FakeeDeck/Class/AutoUpdateHelper.cs | 33 ++ FakeeDeck/FakeeDeck.csproj | 3 +- FakeeDeck/Program.cs | 2 + 23 files changed, 1182 insertions(+), 2 deletions(-) create mode 100644 FakeDeckUI/FakeDeck/App.xaml create mode 100644 FakeDeckUI/FakeDeck/App.xaml.cs create mode 100644 FakeDeckUI/FakeDeck/AssemblyInfo.cs create mode 100644 FakeDeckUI/FakeDeck/ButtonType/Button.cs create mode 100644 FakeDeckUI/FakeDeck/ButtonType/HelldiversTwoMacro.cs create mode 100644 FakeDeckUI/FakeDeck/ButtonType/KeyboardMacro.cs create mode 100644 FakeDeckUI/FakeDeck/ButtonType/MediaMacro.cs create mode 100644 FakeDeckUI/FakeDeck/Class/AbstractionHelper.cs create mode 100644 FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs create mode 100644 FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs create mode 100644 FakeDeckUI/FakeDeck/Class/GeneralHelper.cs create mode 100644 FakeDeckUI/FakeDeck/Class/HttpServer.cs create mode 100644 FakeDeckUI/FakeDeck/Class/KeyboardCode.cs create mode 100644 FakeDeckUI/FakeDeck/Class/YamlHelper.cs create mode 100644 FakeDeckUI/FakeDeck/FakeDeck.csproj create mode 100644 FakeDeckUI/FakeDeck/MainWindow.xaml create mode 100644 FakeDeckUI/FakeDeck/MainWindow.xaml.cs create mode 100644 FakeDeckUI/FakeDeck/StaticFiles/app.js create mode 100644 FakeDeckUI/FakeDeck/configuration.yaml create mode 100644 FakeeDeck/Class/AutoUpdateHelper.cs diff --git a/FakeDeckUI/FakeDeck/App.xaml b/FakeDeckUI/FakeDeck/App.xaml new file mode 100644 index 0000000..d271c4e --- /dev/null +++ b/FakeDeckUI/FakeDeck/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/FakeDeckUI/FakeDeck/App.xaml.cs b/FakeDeckUI/FakeDeck/App.xaml.cs new file mode 100644 index 0000000..59bb2a5 --- /dev/null +++ b/FakeDeckUI/FakeDeck/App.xaml.cs @@ -0,0 +1,32 @@ +using FakeeDeck.Class; +using Microsoft.VisualBasic.Logging; +using System.Configuration; +using System.Data; +using System.Drawing; +using System.Windows; +using System.Windows.Forms; +using Application = System.Windows.Application; + +namespace FakeDeck +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + public YamlHelper yaml; + + protected override void OnStartup(StartupEventArgs e) + { + yaml = new YamlHelper(); + + new Thread(() => + { + Thread.CurrentThread.IsBackground = true; + FakeDeckMain fakeDeck = new FakeDeckMain(yaml); + }).Start(); + + base.OnStartup(e); + } + } +} diff --git a/FakeDeckUI/FakeDeck/AssemblyInfo.cs b/FakeDeckUI/FakeDeck/AssemblyInfo.cs new file mode 100644 index 0000000..b0ec827 --- /dev/null +++ b/FakeDeckUI/FakeDeck/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/FakeDeckUI/FakeDeck/ButtonType/Button.cs b/FakeDeckUI/FakeDeck/ButtonType/Button.cs new file mode 100644 index 0000000..abce292 --- /dev/null +++ b/FakeDeckUI/FakeDeck/ButtonType/Button.cs @@ -0,0 +1,47 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FakeeDeck.ButtonType +{ + internal class Button + { + public static string getButtonHTML(string icon, string image, string name, string action, Dictionary parameters = null) + { + + string body = ""; + + body += "
"; + body += "
"; + + if (parameters is not null) + { + foreach (var parameter in parameters) + { + body += ""; + } + } + + body += ""; + + body += "
"; + body += "
"; + + return body; + } + + public static string getButton(string Key) + { + return getButtonHTML(null, "https://docs.itego.cz/uploads/images/system/2022-04/OdRTPJ4iTTInmhdP-jagq7dfjpi2lilfg-imageedit-2-6604933313.gif", "Test", "test/test"); + } + + public static bool invokeAction(string Key) + { + return false; + } + } +} diff --git a/FakeDeckUI/FakeDeck/ButtonType/HelldiversTwoMacro.cs b/FakeDeckUI/FakeDeck/ButtonType/HelldiversTwoMacro.cs new file mode 100644 index 0000000..19e41dc --- /dev/null +++ b/FakeDeckUI/FakeDeck/ButtonType/HelldiversTwoMacro.cs @@ -0,0 +1,102 @@ +using FakeeDeck.Class; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using static System.Net.WebRequestMethods; + +namespace FakeeDeck.ButtonType +{ + class HelldiversTwoMacro : Button + { + const uint Key_Up = 0x68; + const uint Key_Down = 0x62; + const uint Key_Left = 0x64; + const uint Key_Right = 0x66; + + //https://helldivers.wiki.gg/wiki/Stratagems + //https://helldivers.fandom.com/wiki/Stratagems_(Helldivers_2) + + public static Dictionary stratogems = new Dictionary + { + //Mission + { "reinforce", new uint[] { 0x65, Key_Up, Key_Down, Key_Right, Key_Left, Key_Up}}, + { "resupply", new uint[] { 0x65, Key_Down, Key_Down, Key_Up, Key_Right }}, + + //Support Weapons + { "anti-material", new uint[] { 0x65, Key_Down, Key_Left, Key_Right, Key_Up, Key_Down}}, + { "flamethrower", new uint[] { 0x65, Key_Down, Key_Left, Key_Up, Key_Down, Key_Up}}, + { "autocannon", new uint[] { 0x65, Key_Down, Key_Left, Key_Down, Key_Up, Key_Up, Key_Right}}, + { "grenade-launcher", new uint[] { 0x65, Key_Down, Key_Left, Key_Up, Key_Left, Key_Down}}, + + //Offensive: Orbital Strikes + { "orbital-precision-strike", new uint[] { 0x65, Key_Right, Key_Right, Key_Up}}, + + //Defensive + { "mortar-sentry", new uint[] { 0x65, Key_Down, Key_Up, Key_Right, Key_Down}}, + { "gatling-sentry", new uint[] { 0x65, Key_Down, Key_Up, Key_Right, Key_Left}}, + + + //Supply: Backpacks + + //Offensive: Eagle + { "strafing-run", new uint[] { 0x65, Key_Up, Key_Right, Key_Right}}, + { "airstrike", new uint[] { 0x65, Key_Up, Key_Right, Key_Down, Key_Right}}, + { "cluster-bomb", new uint[] { 0x65, Key_Up, Key_Right, Key_Down, Key_Down, Key_Right}}, + { "napalm-airstrike", new uint[] { 0x65, Key_Up, Key_Right, Key_Down, Key_Up}}, + { "smoke-strike", new uint[] { 0x65, Key_Up, Key_Right, Key_Up, Key_Down}}, + { "rocket-pods", new uint[] { 0x65, Key_Up, Key_Right, Key_Up, Key_Left}}, + { "bomb", new uint[] { 0x65, Key_Up, Key_Right, Key_Up, Key_Right}}, + + }; + + public static Dictionary stratogemsIcons = new Dictionary + { + { "reinforce", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/5/5a/HD2_Reinforce.png"}, + { "resupply", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/7/72/HD2_Resupply.png"}, + { "anti-material", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/c/c3/APW-1_Anti-Materiel_Rifle_Icon.png"}, + { "flamethrower", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/c/cc/FLAM-40_Flamethrower_Icon.png"}, + { "autocannon", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/c/c6/AC-8_Autocannon_Icon.png"}, + { "grenade-launcher","https://static.wikia.nocookie.net/helldivers_gamepedia/images/6/66/GL-21_Grenade_Launcher_Icon.png"}, + { "orbital-precision-strike", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/4/47/Orbital_Precision_Strike_Icon.png"}, + { "mortar-sentry", "https://static.wikia.nocookie.net/helldivers_gamepedia/images/1/1d/A_M-12_Mortar_Sentry_Icon.png"}, + { "gatling-sentry","https://static.wikia.nocookie.net/helldivers_gamepedia/images/4/48/A_G-16_Gatling_Sentry_Icon.png"}, + + //Offensive: Eagle + { "strafing-run","https://static.wikia.nocookie.net/helldivers_gamepedia/images/3/33/Eagle_Strafing_Run_Icon.png"}, + { "airstrike","https://static.wikia.nocookie.net/helldivers_gamepedia/images/7/7e/Eagle_Airstrike_Icon.png"}, + { "cluster-bomb","https://static.wikia.nocookie.net/helldivers_gamepedia/images/8/89/Eagle_Cluster_Bomb_Icon.png"}, + { "napalm-airstrike","https://static.wikia.nocookie.net/helldivers_gamepedia/images/d/d4/Eagle_Napalm_Airstrike_Icon.png"}, + { "smoke-strike","https://static.wikia.nocookie.net/helldivers_gamepedia/images/1/1a/Eagle_Smoke_Strike_Icon.png"}, + { "rocket-pods","https://static.wikia.nocookie.net/helldivers_gamepedia/images/e/e3/Eagle_110MM_Rocket_Pods_Icon.png"}, + { "bomb","https://static.wikia.nocookie.net/helldivers_gamepedia/images/5/5a/Eagle_500KG_Bomb_Icon.png"}, + }; + + public static string getButton(string Key) + { + return getButtonHTML(null, stratogemsIcons[Key].ToString(), Key, "button\\HelldiversTwoMacro", new Dictionary() { { "stratogem", Key } }); + } + + public static bool invokeAction(string stratogem) + { + foreach (var key in stratogems[stratogem]) + { + KeyboardMacro.SendKey(key); + Console.WriteLine(key); + } + return true; + } + + private static string FirstLetterToUpper(string str) + { + if (str == null) + return null; + + if (str.Length > 1) + return char.ToUpper(str[0]) + str.Substring(1); + + return str.ToUpper(); + } + } +} diff --git a/FakeDeckUI/FakeDeck/ButtonType/KeyboardMacro.cs b/FakeDeckUI/FakeDeck/ButtonType/KeyboardMacro.cs new file mode 100644 index 0000000..449f8a5 --- /dev/null +++ b/FakeDeckUI/FakeDeck/ButtonType/KeyboardMacro.cs @@ -0,0 +1,24 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; + +namespace FakeeDeck.ButtonType +{ + internal class KeyboardMacro + { + [DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)] + public static extern void keybd_event(uint bVk, uint bScan, uint dwFlags, uint dwExtraInfo); + + public static void SendKey(uint Key) + { + System.Threading.Thread.Sleep(60); + keybd_event(Key, 0, 0, 0); + System.Threading.Thread.Sleep(60); + keybd_event(Key, 0, 2, 0); + + } + } +} diff --git a/FakeDeckUI/FakeDeck/ButtonType/MediaMacro.cs b/FakeDeckUI/FakeDeck/ButtonType/MediaMacro.cs new file mode 100644 index 0000000..2c35a6b --- /dev/null +++ b/FakeDeckUI/FakeDeck/ButtonType/MediaMacro.cs @@ -0,0 +1,35 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FakeeDeck.ButtonType +{ + internal class MediaMacro : Button + { + public static Dictionary mediaControls = new Dictionary + { + { "play/pause", new uint[] { 0xB3}}, + { "mute", new uint[] { 0xAD }}, + }; + + public static Dictionary mediaIcons = new Dictionary + { + { "play/pause", "fa-play"}, + { "mute", "fa-volume-xmark"}, + }; + + public static string getButton(string Key) + { + return getButtonHTML(mediaIcons[Key], null, Key, "button\\MediaMacro", new Dictionary() { { "control_action", Key } }); + } + + public static bool invokeAction(string control_action) + { + KeyboardMacro.SendKey(mediaControls[control_action][0]); + Console.WriteLine(control_action); + return true; + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/AbstractionHelper.cs b/FakeDeckUI/FakeDeck/Class/AbstractionHelper.cs new file mode 100644 index 0000000..0aaece1 --- /dev/null +++ b/FakeDeckUI/FakeDeck/Class/AbstractionHelper.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace FakeeDeck.Class +{ + internal class AbstractionHelper + { + public static Type? resolvType(string className) + { + string cleanClass = "FakeeDeck.ButtonType." + className.Trim('/'); + + Type? buttonClass = Type.GetType(cleanClass, true); + + if (buttonClass is null) + return null; + + return buttonClass; + } + + public static string getButtonVisual(JsonElement button) + { + string calssName = button.GetProperty("function").ToString(); + MethodInfo? renderMethod = AbstractionHelper.resolvType(calssName).GetMethod("getButton"); + ParameterInfo[] pars = renderMethod.GetParameters(); + List parameters = new List(); + + foreach (ParameterInfo p in pars) + { + JsonElement parameter = button.GetProperty("parameters").EnumerateArray().SingleOrDefault(item => item.GetProperty("name").ToString() == p.Name); + parameters.Insert(p.Position, parameter.GetProperty("value").ToString()); + } + + return renderMethod.Invoke(null, [.. parameters]).ToString(); + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs b/FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs new file mode 100644 index 0000000..208957f --- /dev/null +++ b/FakeDeckUI/FakeDeck/Class/AutoUpdateHelper.cs @@ -0,0 +1,33 @@ +using AutoUpdaterDotNET; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net.Http.Json; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace FakeeDeck.Class +{ + internal class AutoUpdateHelper + { + public AutoUpdateHelper() { + AutoUpdater.ParseUpdateInfoEvent += AutoUpdaterOnParseUpdateInfoEvent; + AutoUpdater.Synchronous = true; + AutoUpdater.ShowRemindLaterButton = false; + AutoUpdater.Start("https://api.github.com/repos/ravibpatel/AutoUpdater.NET/releases/latest"); + } + private void AutoUpdaterOnParseUpdateInfoEvent(ParseUpdateInfoEventArgs args) + { + JsonElement json = JsonDocument.Parse(args.RemoteData).RootElement; + args.UpdateInfo = new UpdateInfoEventArgs + { + CurrentVersion = json.GetProperty("tag_name").ToString().TrimStart('v'), + DownloadURL = json.GetProperty("zipball_url").ToString(), + }; + + Debug.WriteLine(json.ToString()); + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs b/FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs new file mode 100644 index 0000000..98ff66a --- /dev/null +++ b/FakeDeckUI/FakeDeck/Class/FakeDeckMain.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YamlDotNet.Serialization.NamingConventions; +using YamlDotNet.Serialization; +using System.Diagnostics; +using System.IO; +using System.Text.Json; +using System.Reflection; +using FakeeDeck.ButtonType; +using YamlDotNet.Serialization; + +namespace FakeeDeck.Class +{ + internal class FakeDeckMain + { + public FakeDeckMain(YamlHelper yaml) + { + HttpServer server = new HttpServer(yaml.getData().GetProperty("server").GetProperty("port").ToString()); + + foreach (JsonElement item in yaml.getData().GetProperty("pages").EnumerateArray()) + { + Debug.WriteLine("PAGE: " + item.GetProperty("page")); + foreach (JsonElement button in item.GetProperty("buttons").EnumerateArray()) + { + server.pageData += AbstractionHelper.getButtonVisual(button); + } + } + + /*foreach (var stratogem in HelldiversTwoMacro.stratogems) + { + server.pageData += HelldiversTwoMacro.getButton(stratogem.Key); + } + + foreach (var control in MediaMacro.mediaControls) + { + server.pageData += MediaMacro.getButton(control.Key); + }*/ + + server.serv(); + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/GeneralHelper.cs b/FakeDeckUI/FakeDeck/Class/GeneralHelper.cs new file mode 100644 index 0000000..6cac593 --- /dev/null +++ b/FakeDeckUI/FakeDeck/Class/GeneralHelper.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace FakeDeck.Class +{ + class GeneralHelper + { + public static BitmapImage BitmapToImageSource(System.Drawing.Bitmap bitmap) + { + using (MemoryStream memory = new MemoryStream()) + { + bitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp); + memory.Position = 0; + BitmapImage bitmapimage = new BitmapImage(); + bitmapimage.BeginInit(); + bitmapimage.StreamSource = memory; + bitmapimage.CacheOption = BitmapCacheOption.OnLoad; + bitmapimage.EndInit(); + return bitmapimage; + } + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/HttpServer.cs b/FakeDeckUI/FakeDeck/Class/HttpServer.cs new file mode 100644 index 0000000..c5d8ebf --- /dev/null +++ b/FakeDeckUI/FakeDeck/Class/HttpServer.cs @@ -0,0 +1,322 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using System; +using System.IO; +using System.Text; +using System.Net; +using System.Threading.Tasks; +using FakeeDeck.ButtonType; +using System.Web; +using static System.Net.WebRequestMethods; +using File = System.IO.File; +using System.Reflection.Metadata; +using System.Xml.Linq; +using System.Reflection; +using System.Text.Json; +using System.Collections; + +namespace FakeeDeck.Class +{ + internal class HttpServer + { + public string port = "8000"; + public HttpServer(string port) + { + port = port; + } + + private static IDictionary mimeTypes = new Dictionary(StringComparer.InvariantCultureIgnoreCase) { + {".asf", "video/x-ms-asf"}, + {".asx", "video/x-ms-asf"}, + {".avi", "video/x-msvideo"}, + {".bin", "application/octet-stream"}, + {".cco", "application/x-cocoa"}, + {".crt", "application/x-x509-ca-cert"}, + {".css", "text/css"}, + {".deb", "application/octet-stream"}, + {".der", "application/x-x509-ca-cert"}, + {".dll", "application/octet-stream"}, + {".dmg", "application/octet-stream"}, + {".ear", "application/java-archive"}, + {".eot", "application/octet-stream"}, + {".exe", "application/octet-stream"}, + {".flv", "video/x-flv"}, + {".gif", "image/gif"}, + {".hqx", "application/mac-binhex40"}, + {".htc", "text/x-component"}, + {".htm", "text/html"}, + {".html", "text/html"}, + {".ico", "image/x-icon"}, + {".img", "application/octet-stream"}, + {".iso", "application/octet-stream"}, + {".jar", "application/java-archive"}, + {".jardiff", "application/x-java-archive-diff"}, + {".jng", "image/x-jng"}, + {".jnlp", "application/x-java-jnlp-file"}, + {".jpeg", "image/jpeg"}, + {".jpg", "image/jpeg"}, + {".js", "application/x-javascript"}, + {".mml", "text/mathml"}, + {".mng", "video/x-mng"}, + {".mov", "video/quicktime"}, + {".mp3", "audio/mpeg"}, + {".mpeg", "video/mpeg"}, + {".mpg", "video/mpeg"}, + {".msi", "application/octet-stream"}, + {".msm", "application/octet-stream"}, + {".msp", "application/octet-stream"}, + {".pdb", "application/x-pilot"}, + {".pdf", "application/pdf"}, + {".pem", "application/x-x509-ca-cert"}, + {".pl", "application/x-perl"}, + {".pm", "application/x-perl"}, + {".png", "image/png"}, + {".prc", "application/x-pilot"}, + {".ra", "audio/x-realaudio"}, + {".rar", "application/x-rar-compressed"}, + {".rpm", "application/x-redhat-package-manager"}, + {".rss", "text/xml"}, + {".run", "application/x-makeself"}, + {".sea", "application/x-sea"}, + {".shtml", "text/html"}, + {".sit", "application/x-stuffit"}, + {".swf", "application/x-shockwave-flash"}, + {".tcl", "application/x-tcl"}, + {".tk", "application/x-tcl"}, + {".txt", "text/plain"}, + {".war", "application/java-archive"}, + {".wbmp", "image/vnd.wap.wbmp"}, + {".wmv", "video/x-ms-wmv"}, + {".xml", "text/xml"}, + {".xpi", "application/x-xpinstall"}, + {".zip", "application/zip"}, + }; + + public static HttpListener listener; + public static int pageViews = 0; + public static int requestCount = 0; + public static string pageHeader = + "" + + "" + + " " + + " HttpListener Example" + + " " + + " " + + " " + + " " + + " " + + "
" + + "
" + + "

Page Views: {0}

" + + "
"; + public static string pageFooter = + "
" + + " " + + "
" + + "
" + + " " + + " " + + ""; + public string pageData = ""; + private Dictionary> routes; + public async Task HandleIncomingConnections() + { + bool runServer = true; + + // While a user hasn't visited the `shutdown` url, keep on handling requests + while (runServer) + { + // Will wait here until we hear from a connection + HttpListenerContext ctx = await listener.GetContextAsync(); + + // Peel out the requests and response objects + HttpListenerRequest req = ctx.Request; + HttpListenerResponse resp = ctx.Response; + + // Print out some info about the request + Console.WriteLine("Request #: {0}", ++requestCount); + Console.WriteLine(req.Url.ToString()); + Console.WriteLine(req.HttpMethod); + Console.WriteLine(req.UserHostName); + Console.WriteLine(req.UserAgent); + Console.WriteLine(); + + if (req.HttpMethod == "POST") + { + //Parse Port Parameters + Dictionary postParams = parsePostRequestParameters(req); + // If `shutdown` url requested w/ POST, then shutdown the server after serving the page + if (req.Url.AbsolutePath == "/shutdown") + { + Console.WriteLine("Shutdown requested"); + runServer = false; + } + else if (req.Url.AbsolutePath.StartsWith("/button")) + { + try + { + string module = req.Url.AbsolutePath.Replace("/button", ""); + Console.WriteLine("Call module " + module); + callButtonAction(module, postParams); + resp.StatusCode = (int)HttpStatusCode.OK; + } + catch (Exception ex) + { + byte[] errorData = Encoding.UTF8.GetBytes(ex.Message); + resp.ContentType = "text/html"; + resp.ContentEncoding = Encoding.UTF8; + resp.ContentLength64 = errorData.LongLength; + resp.StatusCode = (int)HttpStatusCode.InternalServerError; + await resp.OutputStream.WriteAsync(errorData, 0, errorData.Length); + } + finally + { + resp.Close(); + } + continue; + } + } + else if (req.HttpMethod == "GET") + { + if (req.Url.AbsolutePath.Contains(".")) + { + await servFileResponseAsync(req, resp); + } + else + { + await servViewResponseAsync(req, resp); + } + resp.Close(); + continue; + } + } + } + + public void serv() + { + string url = "http://*:" + port + "/"; + // Create a Http server and start listening for incoming connections + listener = new HttpListener(); + listener.Prefixes.Add(url); + listener.Start(); + Console.WriteLine("Listening for connections on {0}", url); + + // Handle requests + Task listenTask = HandleIncomingConnections(); + listenTask.GetAwaiter().GetResult(); + + // Close the listener + listener.Close(); + } + + private static void callButtonAction(string module, Dictionary postParams) + { + string cleanClass = "FakeeDeck.ButtonType." + module.Trim('/'); + + Type? buttonClass = Type.GetType(cleanClass, true); + + if (buttonClass is null) + return; + + MethodInfo? method = buttonClass.GetMethod("invokeAction"); + + if (method is null) + return; + + ParameterInfo[] pars = method.GetParameters(); + List parameters = new List(); + + foreach (ParameterInfo p in pars) + { + if (p == null) + { + continue; + } + + if (p.Name != null && postParams.ContainsKey(p.Name)) + { + parameters.Insert(p.Position, postParams[p.Name]); + } + else if (p.IsOptional && p.DefaultValue != null) + { + parameters.Insert(p.Position, p.DefaultValue); + } + } + + _ = method.Invoke(null, [.. parameters]).ToString(); + } + + private static async Task servFileResponseAsync(HttpListenerRequest req, HttpListenerResponse resp) + { + string filename = Path.Combine("./", req.Url.AbsolutePath.Substring(1)); + if (!File.Exists(filename)) + { + resp.StatusCode = (int)HttpStatusCode.NotFound; + resp.Close(); + } + + try + { + Stream input = new FileStream(filename, FileMode.Open); + + string mime; + resp.ContentType = mimeTypes.TryGetValue(Path.GetExtension(filename), out mime) + ? mime + : "application/octet-stream"; + resp.ContentLength64 = input.Length; + resp.AddHeader("Date", DateTime.Now.ToString("r")); + resp.AddHeader("Last-Modified", File.GetLastWriteTime(filename).ToString("r")); + + byte[] buffer = new byte[1024 * 32]; + int nbytes; + while ((nbytes = input.Read(buffer, 0, buffer.Length)) > 0) + resp.OutputStream.Write(buffer, 0, nbytes); + input.Close(); + resp.OutputStream.Flush(); + resp.StatusCode = (int)HttpStatusCode.OK; + } + catch (Exception ex) + { + byte[] errorData = Encoding.UTF8.GetBytes(ex.Message); + resp.ContentType = "text/html"; + resp.ContentEncoding = Encoding.UTF8; + resp.ContentLength64 = errorData.LongLength; + resp.StatusCode = (int)HttpStatusCode.InternalServerError; + await resp.OutputStream.WriteAsync(errorData, 0, errorData.Length); + } + } + + private async Task servViewResponseAsync(HttpListenerRequest req, HttpListenerResponse resp) + { + string disableSubmit = false ? "disabled" : ""; + byte[] data = Encoding.UTF8.GetBytes(string.Format(pageHeader + this.pageData + pageFooter, pageViews, disableSubmit)); + resp.ContentType = "text/html"; + resp.ContentEncoding = Encoding.UTF8; + resp.ContentLength64 = data.LongLength; + await resp.OutputStream.WriteAsync(data, 0, data.Length); + } + + private static Dictionary parsePostRequestParameters(HttpListenerRequest req) + { + Dictionary postParams = new Dictionary(); + + using (var reader = new StreamReader(req.InputStream, req.ContentEncoding)) + { + string postData = reader.ReadToEnd(); + var parsedData = HttpUtility.ParseQueryString(postData); + foreach (string key in parsedData) + { + postParams[key] = parsedData[key]; + } + } + + return postParams; + } + } +} diff --git a/FakeDeckUI/FakeDeck/Class/KeyboardCode.cs b/FakeDeckUI/FakeDeck/Class/KeyboardCode.cs new file mode 100644 index 0000000..0745c19 --- /dev/null +++ b/FakeDeckUI/FakeDeck/Class/KeyboardCode.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace FakeeDeck.Class +{ + internal class KeyboardCode + { + public const uint LBUTTON = 0x01; // Left mouse button + public const uint RBUTTON = 0x02; // Right mouse button + public const uint CANCEL = 0x03; // Control-break processing + public const uint MBUTTON = 0x04; // Middle mouse button (three-button mouse) + public const uint XBUTTON1 = 0x05; // X1 mouse button + public const uint XBUTTON2 = 0x06; // X2 mouse button + public const uint BACK = 0x08; // BACKSPACE key + public const uint TAB = 0x09; // TAB key + public const uint CLEAR = 0x0C; // CLEAR key + public const uint RETURN = 0x0D; // ENTER key + public const uint SHIFT = 0x10; // SHIFT key + public const uint CONTROL = 0x11; // CTRL key + public const uint MENU = 0x12; // ALT key + public const uint PAUSE = 0x13; // PAUSE key + public const uint CAPITAL = 0x14; // CAPS LOCK key + public const uint KANA = 0x15; // IME Kana mode + public const uint HANGUL = 0x15; // IME Hangul mode + public const uint JUNJA = 0x17; // IME Junja mode + public const uint FINAL = 0x18; // IME final mode + public const uint HANJA = 0x19; // IME Hanja mode + public const uint KANJI = 0x19; // IME Kanji mode + public const uint ESCAPE = 0x1B; // ESC key + public const uint CONVERT = 0x1C; // IME convert + public const uint NONCONVERT = 0x1D; // IME nonconvert + public const uint ACCEPT = 0x1E; // IME accept + public const uint MODECHANGE = 0x1F; // IME mode change request + public const uint SPACE = 0x20; // SPACEBAR + public const uint PRIOR = 0x21; // PAGE UP key + public const uint NEXT = 0x22; // PAGE DOWN key + public const uint END = 0x23; // END key + public const uint HOME = 0x24; // HOME key + public const uint LEFT = 0x25; // LEFT ARROW key + public const uint UP = 0x26; // UP ARROW key + public const uint RIGHT = 0x27; // RIGHT ARROW key + public const uint DOWN = 0x28; // DOWN ARROW key + public const uint SELECT = 0x29; // SELECT key + public const uint PRINT = 0x2A; // PRINT key + public const uint EXECUTE = 0x2B; // EXECUTE key + public const uint SNAPSHOT = 0x2C; // PRINT SCREEN key + public const uint INSERT = 0x2D; // INS key + public const uint DELETE = 0x2E; // DEL key + public const uint HELP = 0x2F; // HELP key + public const uint N0 = 0x30; // '0' key + public const uint N1 = 0x31; // '1' key + public const uint N2 = 0x32; // '2' key + public const uint N3 = 0x33; // '3' key + public const uint N4 = 0x34; // '4' key + public const uint N5 = 0x35; // '5' key + public const uint N6 = 0x36; // '6' key + public const uint N7 = 0x37; // '7' key + public const uint N8 = 0x38; // '8' key + public const uint N9 = 0x39; // '9' key + public const uint A = 0x41; // 'A' key + public const uint B = 0x42; // 'B' key + public const uint C = 0x43; // 'C' key + public const uint D = 0x44; // 'D' key + public const uint E = 0x45; // 'E' key + public const uint F = 0x46; // 'F' key + public const uint G = 0x47; // 'G' key + public const uint H = 0x48; // 'H' key + public const uint I = 0x49; // 'I' key + public const uint J = 0x4A; // 'J' key + public const uint K = 0x4B; // 'K' key + public const uint L = 0x4C; // 'L' key + public const uint M = 0x4D; // 'M' key + public const uint N = 0x4E; // 'N' key + public const uint O = 0x4F; // 'O' key + public const uint P = 0x50; // 'P' key + public const uint Q = 0x51; // 'Q' key + public const uint R = 0x52; // 'R' key + public const uint S = 0x53; // 'S' key + public const uint T = 0x54; // 'T' key + public const uint U = 0x55; // 'U' key + public const uint V = 0x56; // 'V' key + public const uint W = 0x57; // 'W' key + public const uint X = 0x58; // 'X' key + public const uint Y = 0x59; // 'Y' key + public const uint Z = 0x5A; // 'Z' key + public const uint LWIN = 0x5B; // Left Windows key (Natural keyboard) + public const uint RWIN = 0x5C; // Right Windows key (Natural keyboard) + public const uint APPS = 0x5D; // Applications key (Natural keyboard) + public const uint SLEEP = 0x5F; // Computer Sleep key + public const uint NUMPAD0 = 0x60; // Numeric keypad '0' key + public const uint NUMPAD1 = 0x61; // Numeric keypad '1' key + public const uint NUMPAD2 = 0x62; // Numeric keypad '2' key + public const uint NUMPAD3 = 0x63; // Numeric keypad '3' key + public const uint NUMPAD4 = 0x64; // Numeric keypad '4' key + public const uint NUMPAD5 = 0x65; // Numeric keypad '5' key + public const uint NUMPAD6 = 0x66; // Numeric keypad '6' key + public const uint NUMPAD7 = 0x67; // Numeric keypad '7' key + public const uint NUMPAD8 = 0x68; // Numeric keypad '8' key + public const uint NUMPAD9 = 0x69; // Numeric keypad '9' key + public const uint MULTIPLY = 0x6A; // Multiply key + public const uint ADD = 0x6B; // Add key + public const uint SEPARATOR = 0x6C; // Separator key + public const uint SUBTRACT = 0x6D; // Subtract key + public const uint DECIMAL = 0x6E; // Decimal key + public const uint DIVIDE = 0x6F; // Divide key + public const uint F1 = 0x70; // F1 key + public const uint F2 = 0x71; // F2 key + public const uint F3 = 0x72; // F3 key + public const uint F4 = 0x73; // F4 key + public const uint F5 = 0x74; // F5 key + public const uint F6 = 0x75; // F6 key + public const uint F7 = 0x76; // F7 key + public const uint F8 = 0x77; // F8 key + public const uint F9 = 0x78; // F9 key + public const uint F10 = 0x79; // F10 key + public const uint F11 = 0x7A; // F11 key + public const uint F12 = 0x7B; // F12 key + public const uint F13 = 0x7C; // F13 key + public const uint F14 = 0x7D; // F14 key + public const uint F15 = 0x7E; // F15 key + public const uint F16 = 0x7F; // F16 key + public const uint F17 = 0x80; // F17 key + public const uint F18 = 0x81; // F18 key + public const uint F19 = 0x82; // F19 key + public const uint F20 = 0x83; // F20 key + public const uint F21 = 0x84; // F21 key + public const uint F22 = 0x85; // F22 key + public const uint F23 = 0x86; // F23 key + public const uint F24 = 0x87; // F24 key + public const uint NUMLOCK = 0x90; // NUM LOCK key + public const uint SCROLL = 0x91; // SCROLL LOCK key + public const uint LSHIFT = 0xA0; // Left SHIFT key + public const uint RSHIFT = 0xA1; // Right SHIFT key + public const uint LCONTROL = 0xA2; // Left CONTROL key + public const uint RCONTROL = 0xA3; // Right CONTROL key + public const uint LMENU = 0xA4; // Left MENU key + public const uint RMENU = 0xA5; // Right MENU key + public const uint BROWSER_BACK = 0xA6; // Browser Back key + public const uint BROWSER_FORWARD = 0xA7; // Browser Forward key + public const uint BROWSER_REFRESH = 0xA8; // Browser Refresh key + public const uint BROWSER_STOP = 0xA9; // Browser Stop key + public const uint BROWSER_SEARCH = 0xAA; // Browser Search key + public const uint BROWSER_FAVORITES = 0xAB; // Browser Favorites key + public const uint BROWSER_HOME = 0xAC; // Browser Start and Home key + public const uint VOLUME_MUTE = 0xAD; // Volume Mute key + public const uint VOLUME_DOWN = 0xAE; // Volume Down key + public const uint VOLUME_UP = 0xAF; // Volume Up key + public const uint MEDIA_NEXT_TRACK = 0xB0; // Next Track key + public const uint MEDIA_PREV_TRACK = 0xB1; // Previous Track key + public const uint MEDIA_STOP = 0xB2; // Stop Media key + public const uint MEDIA_PLAY_PAUSE = 0xB3; // Play/Pause Media key + public const uint LAUNCH_MAIL = 0xB4; // Start Mail key + public const uint LAUNCH_MEDIA_SELECT = 0xB5; // Select Media key + public const uint LAUNCH_APP1 = 0xB6; // Start Application 1 key + public const uint LAUNCH_APP2 = 0xB7; // Start Application 2 key + public const uint OEM_1 = 0xBA; // For the US standard keyboard, the ';:' key + public const uint OEM_PLUS = 0xBB; // For any country/region, the '+' key + public const uint OEM_COMMA = 0xBC; // For any country/region, the ',' key + public const uint OEM_MINUS = 0xBD; // For any country/region, the '-' key + public const uint OEM_PERIOD = 0xBE; // For any country/region, the '.' key + public const uint OEM_2 = 0xBF; // For the US standard keyboard, the '/?' key + public const uint OEM_3 = 0xC0; // For the US standard keyboard, the '`~' key + public const uint OEM_4 = 0xDB; // For the US standard keyboard, the '[{' key + public const uint OEM_5 = 0xDC; // For the US standard keyboard, the '\|' key + public const uint OEM_6 = 0xDD; // For the US standard keyboard, the ']}' key + public const uint OEM_7 = 0xDE; // For the US standard keyboard, the 'single-quote/double-quote' key + public const uint OEM_8 = 0xDF; // Used for miscellaneous characters; it can vary by keyboard. + public const uint OEM_AX = 0xE1; // OEM specific + public const uint OEM_102 = 0xE2; // The angle bracket key or the backslash key on the RT 102-key keyboard + public const uint ICO_HELP = 0xE3; // Help key on ICO + public const uint ICO_00 = 0xE4; // 00 key on ICO + public const uint PROCESSKEY = 0xE5; // IME PROCESS key + public const uint ICO_CLEAR = 0xE6; // Clear key on ICO + public const uint PACKET = 0xE7; // Used to pass Unicode characters as if they were keystrokes. + public const uint OEM_RESET = 0xE9; // OEM specific + public const uint OEM_JUMP = 0xEA; // OEM specific + public const uint OEM_PA1 = 0xEB; // OEM specific + public const uint OEM_PA2 = 0xEC; // OEM specific + public const uint OEM_PA3 = 0xED; // OEM specific + public const uint OEM_WSCTRL = 0xEE; // OEM specific + public const uint OEM_CUSEL = 0xEF; // OEM specific + public const uint OEM_ATTN = 0xF0; // OEM specific + public const uint OEM_FINISH = 0xF1; // OEM specific + public const uint OEM_COPY = 0xF2; // OEM specific + public const uint OEM_AUTO = 0xF3; // OEM specific + public const uint OEM_ENLW = 0xF4; // OEM specific + public const uint OEM_BACKTAB = 0xF5; // OEM specific + public const uint ATTN = 0xF6; // Attn key + public const uint CRSEL = 0xF7; // CrSel key + public const uint EXSEL = 0xF8; // ExSel key + public const uint EREOF = 0xF9; // Erase EOF key + public const uint PLAY = 0xFA; // Play key + public const uint ZOOM = 0xFB; // Zoom key + public const uint NONAME = 0xFC; // Reserved + public const uint PA1 = 0xFD; // PA1 key + public const uint OEM_CLEAR = 0xFE; // Clear key + } +} diff --git a/FakeDeckUI/FakeDeck/Class/YamlHelper.cs b/FakeDeckUI/FakeDeck/Class/YamlHelper.cs new file mode 100644 index 0000000..dff4d38 --- /dev/null +++ b/FakeDeckUI/FakeDeck/Class/YamlHelper.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; +using YamlDotNet.Serialization; + +namespace FakeeDeck.Class +{ + public class YamlHelper + { + JsonDocument jsonObjecz; + public YamlHelper() + { + var r = new StreamReader("./configuration.yaml"); + var deserializer = new Deserializer(); + object yamlObject = deserializer.Deserialize(r); + string json = System.Text.Json.JsonSerializer.Serialize(yamlObject); + jsonObjecz = JsonDocument.Parse(json); + } + + public JsonElement getData() + { + return jsonObjecz.RootElement; + } + } +} diff --git a/FakeDeckUI/FakeDeck/FakeDeck.csproj b/FakeDeckUI/FakeDeck/FakeDeck.csproj new file mode 100644 index 0000000..cdd83a5 --- /dev/null +++ b/FakeDeckUI/FakeDeck/FakeDeck.csproj @@ -0,0 +1,24 @@ + + + + WinExe + net8.0-windows + enable + enable + true + + + + + + + + + PreserveNewest + + + PreserveNewest + + + + diff --git a/FakeDeckUI/FakeDeck/MainWindow.xaml b/FakeDeckUI/FakeDeck/MainWindow.xaml new file mode 100644 index 0000000..95d2775 --- /dev/null +++ b/FakeDeckUI/FakeDeck/MainWindow.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/FakeDeckUI/FakeDeck/MainWindow.xaml.cs b/FakeDeckUI/FakeDeck/MainWindow.xaml.cs new file mode 100644 index 0000000..514750c --- /dev/null +++ b/FakeDeckUI/FakeDeck/MainWindow.xaml.cs @@ -0,0 +1,46 @@ +using FakeDeck.Class; +using FakeeDeck.Class; +using QRCoder; +using System.Reflection.Emit; +using System.Text; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; +using static QRCoder.QRCodeGenerator; +using static System.Runtime.CompilerServices.RuntimeHelpers; +using System.Drawing; +using Color = System.Drawing.Color; + +namespace FakeDeck +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + } + + private void FakeDeckUI_Activated(object sender, EventArgs e) + { + string port = ((App)Application.Current).yaml.getData().GetProperty("server").GetProperty("port").ToString(); + string url = "http://localhost:" + port; + + PayloadGenerator.Url qrCodePayload = new PayloadGenerator.Url(url); + QRCodeGenerator qrCodeGenerator = new QRCodeGenerator(); + QRCodeData qrCodeData = qrCodeGenerator.CreateQrCode(qrCodePayload.ToString(), 0); + QRCode qrCode = new QRCode(qrCodeData); + qr_code.Source = GeneralHelper.BitmapToImageSource(qrCode.GetGraphic(20, Color.Black, Color.White, false)); + + AutoUpdateHelper updater = new AutoUpdateHelper(); + } + } +} \ No newline at end of file diff --git a/FakeDeckUI/FakeDeck/StaticFiles/app.js b/FakeDeckUI/FakeDeck/StaticFiles/app.js new file mode 100644 index 0000000..65c69c1 --- /dev/null +++ b/FakeDeckUI/FakeDeck/StaticFiles/app.js @@ -0,0 +1,38 @@ +[].forEach.call(document.querySelectorAll('form'), function (form) { + form.addEventListener('submit', function (event) { + event.preventDefault(); + const target = event.currentTarget; + + console.log(target.method, target.action); + console.log(form.method, form.action); + console.log(form === target); + + var formData = new FormData(form); + + const xhttp = new XMLHttpRequest(); + xhttp.onload = function () { } + xhttp.onreadystatechange = function () { + if (xhttp.readyState === 4) { + if (xhttp.status === 200) { + console.log('successful'); + } else { + console.log('failed'); + } + } + } + + xhttp.open(target.method, target.action, true); + xhttp.send(urlencodeFormData(formData)); + }); +}); + +function urlencodeFormData(fd){ + var s = ''; + function encode(s){ return encodeURIComponent(s).replace(/%20/g,'+'); } + for(var pair of fd.entries()){ + if(typeof pair[1]=='string'){ + s += (s?'&':'') + encode(pair[0])+'='+encode(pair[1]); + } + } + return s; +} \ No newline at end of file diff --git a/FakeDeckUI/FakeDeck/configuration.yaml b/FakeDeckUI/FakeDeck/configuration.yaml new file mode 100644 index 0000000..9cd2bc1 --- /dev/null +++ b/FakeDeckUI/FakeDeck/configuration.yaml @@ -0,0 +1,60 @@ + +server: + port: 8000 + +pages: + - page: helldivers + buttons: + - button: reinforce + function: HelldiversTwoMacro + parameters: + - name: Key + value: "reinforce" + + - button: strafing-run + function: HelldiversTwoMacro + parameters: + - name: Key + value: strafing-run + + - button: airstrike + function: HelldiversTwoMacro + parameters: + - name: Key + value: airstrike + + - button: cluster-bomb + function: HelldiversTwoMacro + parameters: + - name: Key + value: cluster-bomb + + - button: napalm-airstrike + function: HelldiversTwoMacro + parameters: + - name: Key + value: napalm-airstrike + + - button: smoke-strike + function: HelldiversTwoMacro + parameters: + - name: Key + value: smoke-strike + + - button: rocket-pods + function: HelldiversTwoMacro + parameters: + - name: Key + value: rocket-pods + + - button: bomb + function: HelldiversTwoMacro + parameters: + - name: Key + value: bomb + + - button: mute + function: MediaMacro + parameters: + - name: Key + value: "mute" \ No newline at end of file diff --git a/FakeeDeck.sln b/FakeeDeck.sln index 28dc9b3..2f152b4 100644 --- a/FakeeDeck.sln +++ b/FakeeDeck.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.11.35219.272 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeeDeck", "FakeeDeck\FakeeDeck.csproj", "{D8C79B08-1920-426A-9138-CF0C8BAE0EF7}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakeeDeck", "FakeeDeck\FakeeDeck.csproj", "{D8C79B08-1920-426A-9138-CF0C8BAE0EF7}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FakeDeck", "FakeDeckUI\FakeDeck\FakeDeck.csproj", "{D04AFC99-A929-4336-BD2C-1D49D149DB18}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,6 +17,10 @@ Global {D8C79B08-1920-426A-9138-CF0C8BAE0EF7}.Debug|Any CPU.Build.0 = Debug|Any CPU {D8C79B08-1920-426A-9138-CF0C8BAE0EF7}.Release|Any CPU.ActiveCfg = Release|Any CPU {D8C79B08-1920-426A-9138-CF0C8BAE0EF7}.Release|Any CPU.Build.0 = Release|Any CPU + {D04AFC99-A929-4336-BD2C-1D49D149DB18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D04AFC99-A929-4336-BD2C-1D49D149DB18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D04AFC99-A929-4336-BD2C-1D49D149DB18}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D04AFC99-A929-4336-BD2C-1D49D149DB18}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/FakeeDeck/Class/AutoUpdateHelper.cs b/FakeeDeck/Class/AutoUpdateHelper.cs new file mode 100644 index 0000000..cffe244 --- /dev/null +++ b/FakeeDeck/Class/AutoUpdateHelper.cs @@ -0,0 +1,33 @@ +using AutoUpdaterDotNET; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Net.Http.Json; +using System.Text; +using System.Text.Json; +using System.Threading.Tasks; + +namespace FakeeDeck.Class +{ + internal class AutoUpdateHelper + { + public AutoUpdateHelper() { + AutoUpdater.ParseUpdateInfoEvent += AutoUpdaterOnParseUpdateInfoEvent; + AutoUpdater.Synchronous = true; + AutoUpdater.ShowRemindLaterButton = false; + AutoUpdater.Start("https://github.com/GamerClassN7/FakeDeck/releases/latest/download/meta.xml"); + } + private void AutoUpdaterOnParseUpdateInfoEvent(ParseUpdateInfoEventArgs args) + { + JsonElement json = JsonDocument.Parse(args.RemoteData).RootElement; + args.UpdateInfo = new UpdateInfoEventArgs + { + CurrentVersion = json.GetProperty("tag_name").ToString().TrimStart('v'), + DownloadURL = json.GetProperty("zipball_url").ToString(), + }; + + Debug.WriteLine(json.ToString()); + } + } +} diff --git a/FakeeDeck/FakeeDeck.csproj b/FakeeDeck/FakeeDeck.csproj index 9983fff..227f2b3 100644 --- a/FakeeDeck/FakeeDeck.csproj +++ b/FakeeDeck/FakeeDeck.csproj @@ -2,7 +2,7 @@ Exe - net8.0 + net8.0-windows enable enable @@ -12,6 +12,7 @@ + diff --git a/FakeeDeck/Program.cs b/FakeeDeck/Program.cs index 54648cc..62af403 100644 --- a/FakeeDeck/Program.cs +++ b/FakeeDeck/Program.cs @@ -2,6 +2,8 @@ using FakeeDeck.Class; using System.Diagnostics; using System.Text.Json; +using AutoUpdaterDotNET; +AutoUpdateHelper updater = new AutoUpdateHelper(); FakeDeck fakeDeck = new FakeDeck(); \ No newline at end of file