Compare commits
No commits in common. "14877f47112b7cb97f19f92e5f0e9114e4f55803" and "ef59ca99453250412a7ea1fe29367bbd1236b863" have entirely different histories.
14877f4711
...
ef59ca9945
@ -1,7 +1,6 @@
|
||||
using FakeeDeck.Class;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -84,7 +83,7 @@ namespace FakeeDeck.ButtonType
|
||||
foreach (var key in stratogems[stratogem])
|
||||
{
|
||||
KeyboardMacro.SendKey(key);
|
||||
Debug.WriteLine(key);
|
||||
Console.WriteLine(key);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -2,37 +2,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
|
||||
namespace FakeeDeck.Class
|
||||
{
|
||||
public class AutoUpdateHelper
|
||||
internal class AutoUpdateHelper
|
||||
{
|
||||
public AutoUpdateHelper() {
|
||||
AutoUpdater.ParseUpdateInfoEvent += AutoUpdaterOnParseUpdateInfoEvent;
|
||||
AutoUpdater.Synchronous = true;
|
||||
AutoUpdater.ShowRemindLaterButton = false;
|
||||
AutoUpdater.ReportErrors = Debugger.IsAttached;
|
||||
AutoUpdater.HttpUserAgent = ("FakeDeck-v" + Assembly.GetExecutingAssembly().GetName().Version);
|
||||
AutoUpdater.Start("https://api.github.com/repos/GamerClassN7/FakeDeck/releases/latest");
|
||||
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')+ ".0",
|
||||
CurrentVersion = json.GetProperty("tag_name").ToString().TrimStart('v'),
|
||||
DownloadURL = json.GetProperty("zipball_url").ToString(),
|
||||
};
|
||||
Debug.WriteLine("calling Updater");
|
||||
|
||||
Debug.WriteLine(json.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,39 +1,21 @@
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using System.Reflection.PortableExecutable;
|
||||
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 static string pageHeader =
|
||||
"<!DOCTYPE>" +
|
||||
"<html>" +
|
||||
" <head>" +
|
||||
" <title>HttpListener Example</title>" +
|
||||
" <link href=\"https://yarnpkg.com/en/package/normalize.css\" rel=\"stylesheet\">" +
|
||||
" <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css\" rel=\"stylesheet\">" +
|
||||
" <link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css\" rel=\"stylesheet\">" +
|
||||
" </head>" +
|
||||
" <body>" +
|
||||
" <div class=\"d-flex flex-wrap\">" +
|
||||
" <div class=\"m-2\">" +
|
||||
" <p style=\"margin-bottom: 0px; width: 150px;height: 150px;background-color: aquamarine;\" >Page Views: {0}</p>" +
|
||||
" </div>";
|
||||
public static string pageFooter =
|
||||
" <div class=\"m-2\">" +
|
||||
" <button style=\"width: 150px;height: 150px;background-color: aquamarine;\" onclick=\"!document.fullscreenElement ? document.documentElement.requestFullscreen() : document.exitFullscreen();\">" +
|
||||
" <i class=\"fa-solid fa-maximize\"></i>" +
|
||||
" </button>" +
|
||||
" </div>" +
|
||||
" </div>" +
|
||||
" <script src=\"StaticFiles/app.js\"></script>" +
|
||||
" </body>" +
|
||||
"</html>";
|
||||
public string pageData = "";
|
||||
public FakeDeckMain(YamlHelper yaml)
|
||||
{
|
||||
HttpServer server = new HttpServer(yaml.getData().GetProperty("server").GetProperty("port").ToString());
|
||||
@ -43,13 +25,10 @@ namespace FakeeDeck.Class
|
||||
Debug.WriteLine("PAGE: " + item.GetProperty("page"));
|
||||
foreach (JsonElement button in item.GetProperty("buttons").EnumerateArray())
|
||||
{
|
||||
pageData += AbstractionHelper.getButtonVisual(button);
|
||||
server.pageData += AbstractionHelper.getButtonVisual(button);
|
||||
}
|
||||
}
|
||||
|
||||
server.addRoute(servViewResponseAsync, "GET", "/");
|
||||
server.addRoute(servButtonResponseAsync, "POST", "/button/");
|
||||
|
||||
/*foreach (var stratogem in HelldiversTwoMacro.stratogems)
|
||||
{
|
||||
server.pageData += HelldiversTwoMacro.getButton(stratogem.Key);
|
||||
@ -62,72 +41,5 @@ namespace FakeeDeck.Class
|
||||
|
||||
server.serv();
|
||||
}
|
||||
|
||||
private static void callButtonAction(string module, Dictionary<string, string> 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<object> parameters = new List<object>();
|
||||
|
||||
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 async Task servViewResponseAsync(HttpListenerRequest req, HttpListenerResponse resp)
|
||||
{
|
||||
string disableSubmit = false ? "disabled" : "";
|
||||
byte[] data = Encoding.UTF8.GetBytes(string.Format(pageHeader + this.pageData + pageFooter, 0, disableSubmit));
|
||||
resp.ContentType = "text/html";
|
||||
resp.ContentEncoding = Encoding.UTF8;
|
||||
resp.ContentLength64 = data.LongLength;
|
||||
await resp.OutputStream.WriteAsync(data, 0, data.Length);
|
||||
}
|
||||
|
||||
private async Task servButtonResponseAsync(HttpListenerRequest req, HttpListenerResponse resp, Dictionary<string, string> postParams)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,6 @@ using System.Xml.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text.Json;
|
||||
using System.Collections;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FakeeDeck.Class
|
||||
{
|
||||
@ -97,21 +95,36 @@ namespace FakeeDeck.Class
|
||||
{".xpi", "application/x-xpinstall"},
|
||||
{".zip", "application/zip"},
|
||||
};
|
||||
private Dictionary<string, Dictionary<string, Delegate>> routes = new Dictionary<string, Dictionary<string, Delegate>>();
|
||||
|
||||
public static HttpListener listener;
|
||||
public static int pageViews = 0;
|
||||
public static int requestCount = 0;
|
||||
|
||||
public void addRoute(Delegate callback, string method = "GET", string route = "/")
|
||||
{
|
||||
if (!routes.ContainsKey(method))
|
||||
{
|
||||
routes.Add(method, new Dictionary<string, Delegate>());
|
||||
}
|
||||
|
||||
routes[method].Add(route, callback);
|
||||
}
|
||||
public static string pageHeader =
|
||||
"<!DOCTYPE>" +
|
||||
"<html>" +
|
||||
" <head>" +
|
||||
" <title>HttpListener Example</title>" +
|
||||
" <link href=\"https://yarnpkg.com/en/package/normalize.css\" rel=\"stylesheet\">" +
|
||||
" <link href=\"https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css\" rel=\"stylesheet\">" +
|
||||
" <link href=\"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css\" rel=\"stylesheet\">" +
|
||||
" </head>" +
|
||||
" <body>" +
|
||||
" <div class=\"d-flex flex-wrap\">" +
|
||||
" <div class=\"m-2\">" +
|
||||
" <p style=\"margin-bottom: 0px; width: 150px;height: 150px;background-color: aquamarine;\" >Page Views: {0}</p>" +
|
||||
" </div>";
|
||||
public static string pageFooter =
|
||||
" <div class=\"m-2\">" +
|
||||
" <button style=\"width: 150px;height: 150px;background-color: aquamarine;\" onclick=\"!document.fullscreenElement ? document.documentElement.requestFullscreen() : document.exitFullscreen();\">" +
|
||||
" <i class=\"fa-solid fa-maximize\"></i>" +
|
||||
" </button>" +
|
||||
" </div>" +
|
||||
" </div>" +
|
||||
" <script src=\"StaticFiles/app.js\"></script>" +
|
||||
" </body>" +
|
||||
"</html>";
|
||||
public string pageData = "";
|
||||
private Dictionary<string, Dictionary<string, Action>> routes;
|
||||
public async Task HandleIncomingConnections()
|
||||
{
|
||||
bool runServer = true;
|
||||
@ -127,45 +140,61 @@ namespace FakeeDeck.Class
|
||||
HttpListenerResponse resp = ctx.Response;
|
||||
|
||||
// Print out some info about the request
|
||||
/*Debug.WriteLine("Request #: {0}", ++requestCount);
|
||||
Debug.WriteLine(req.Url.ToString());
|
||||
Debug.WriteLine(req.HttpMethod);
|
||||
Debug.WriteLine(req.UserHostName);
|
||||
Debug.WriteLine(req.UserAgent);*/
|
||||
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 == "GET" && req.Url.AbsolutePath.Contains("."))
|
||||
if (req.HttpMethod == "POST")
|
||||
{
|
||||
await servFileResponseAsync(req, resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
bool isMatch = false;
|
||||
foreach (var route in routes[req.HttpMethod])
|
||||
//Parse Port Parameters
|
||||
Dictionary<string, string> postParams = parsePostRequestParameters(req);
|
||||
// If `shutdown` url requested w/ POST, then shutdown the server after serving the page
|
||||
if (req.Url.AbsolutePath == "/shutdown")
|
||||
{
|
||||
isMatch = Regex.IsMatch(req.Url.AbsolutePath, route.Key, RegexOptions.IgnoreCase);
|
||||
if (isMatch)
|
||||
Console.WriteLine("Shutdown requested");
|
||||
runServer = false;
|
||||
}
|
||||
else if (req.Url.AbsolutePath.StartsWith("/button"))
|
||||
{
|
||||
try
|
||||
{
|
||||
Debug.WriteLine(route.Key);
|
||||
Delegate gelegate = route.Value;
|
||||
if (req.HttpMethod == "POST")
|
||||
{
|
||||
Dictionary<string, string> postParams = parsePostRequestParameters(req);
|
||||
gelegate.DynamicInvoke([req, resp, postParams]);
|
||||
}
|
||||
else
|
||||
{
|
||||
gelegate.DynamicInvoke([req, resp]);
|
||||
}
|
||||
string module = req.Url.AbsolutePath.Replace("/button", "");
|
||||
Console.WriteLine("Call module " + module);
|
||||
callButtonAction(module, postParams);
|
||||
resp.StatusCode = (int)HttpStatusCode.OK;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isMatch)
|
||||
{
|
||||
resp.StatusCode = (int)HttpStatusCode.NotFound;
|
||||
await resp.OutputStream.FlushAsync();
|
||||
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;
|
||||
}
|
||||
}
|
||||
resp.Close();
|
||||
else if (req.HttpMethod == "GET")
|
||||
{
|
||||
if (req.Url.AbsolutePath.Contains("."))
|
||||
{
|
||||
await servFileResponseAsync(req, resp);
|
||||
}
|
||||
else
|
||||
{
|
||||
await servViewResponseAsync(req, resp);
|
||||
}
|
||||
resp.Close();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -186,13 +215,50 @@ namespace FakeeDeck.Class
|
||||
listener.Close();
|
||||
}
|
||||
|
||||
private static void callButtonAction(string module, Dictionary<string, string> 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<object> parameters = new List<object>();
|
||||
|
||||
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;
|
||||
return;
|
||||
resp.Close();
|
||||
}
|
||||
|
||||
try
|
||||
@ -226,6 +292,16 @@ namespace FakeeDeck.Class
|
||||
}
|
||||
}
|
||||
|
||||
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<string, string> parsePostRequestParameters(HttpListenerRequest req)
|
||||
{
|
||||
Dictionary<string, string> postParams = new Dictionary<string, string>();
|
||||
|
@ -7,11 +7,6 @@
|
||||
mc:Ignorable="d"
|
||||
Title="MainWindow" Height="450" Width="270" Activated="FakeDeckUI_Activated" WindowStartupLocation="CenterScreen">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="270*"/>
|
||||
<RowDefinition Height="50*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Image x:Name="qr_code" Margin="10,10,10,10"/>
|
||||
<TextBox Margin="10,10,10,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Grid.Row="1"/>
|
||||
<Image x:Name="qr_code" Margin="10,10,10,174"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -16,7 +16,6 @@ using static QRCoder.QRCodeGenerator;
|
||||
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
using System.Drawing;
|
||||
using Color = System.Drawing.Color;
|
||||
using AutoUpdaterDotNET;
|
||||
|
||||
namespace FakeDeck
|
||||
{
|
||||
@ -40,7 +39,7 @@ namespace FakeDeck
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
@ -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("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FakeDeck", "FakeDeckUI\FakeDeck\FakeDeck.csproj", "{D04AFC99-A929-4336-BD2C-1D49D149DB18}"
|
||||
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
|
||||
@ -11,6 +13,10 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D8C79B08-1920-426A-9138-CF0C8BAE0EF7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{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
|
||||
|
Loading…
Reference in New Issue
Block a user