diff --git a/NUGET.md b/NUGET.md index 088f2e0..e064677 100644 --- a/NUGET.md +++ b/NUGET.md @@ -7,6 +7,10 @@ **Author's website and contact information:** [https://barraider.com](https://barraider.com) ** Samples of plugins using this framework: [Samples][1] +### Version 3.1 is out! +- Updated Logger class to include process name and thread id +- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio + ### Version 3.0 is out! - Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods - Removed obsolete MD5 functions, use SHA512 functions instead diff --git a/README.md b/README.md index 1c979ea..b931278 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,10 @@ * [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio - Automatically creates a project with all the files needed to compile a plugin * [Profiles](https://barraider.com/profiles) Downloadable empty profiles for the XL (32-key), Classic (15-key), Mini (6-key) and Mobile devices at https://barraider.com/profiles +### Version 3.1 is out! +- Updated Logger class to include process name and thread id +- Updated [StreamDeck-Tools Template](https://github.com/BarRaider/streamdeck-tools/raw/master/utils/StreamDeck-Tools%20Template.vsix) for Visual Studio + ### Version 3.0 is out! - Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods - Removed obsolete MD5 functions, use SHA512 functions instead @@ -310,6 +314,18 @@ private void SetGlobalSettings() ``` # Change Log +### Version 3.1 is out! +- Updated Logger class to include process name and thread id + +### Version 3.0 is out! +- Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods +- Removed obsolete MD5 functions, use SHA512 functions instead +- `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width +- New `Tools.FormatBytes` function converts bytes to human-readable value +- New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line +- Updated dependency packages to latest versions +- Bug fix where FileNameProperty attribute + ### Version 2.7 is out! - Fully wrapped all Stream Deck events (All part of the SDConneciton class). See ***"Subscribing to events"*** section below - Added extension methods for multiple classes related to brushes/colors diff --git a/barraider-sdtools/Backend/PluginContainer.cs b/barraider-sdtools/Backend/PluginContainer.cs index 4b7738a..25c3f19 100644 --- a/barraider-sdtools/Backend/PluginContainer.cs +++ b/barraider-sdtools/Backend/PluginContainer.cs @@ -43,13 +43,16 @@ public void Run(StreamDeckOptions options) connection.OnKeyUp += Connection_OnKeyUp; connection.OnWillAppear += Connection_OnWillAppear; connection.OnWillDisappear += Connection_OnWillDisappear; - + // Settings changed connection.OnDidReceiveSettings += Connection_OnDidReceiveSettings; connection.OnDidReceiveGlobalSettings += Connection_OnDidReceiveGlobalSettings; // Start the connection connection.Run(); +#if DEBUG + Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin Loaded: UUID: {pluginUUID} Device Info: {deviceInfo}"); +#endif Logger.Instance.LogMessage(TracingLevel.INFO, $"Plugin version: {deviceInfo.Plugin.Version}"); Logger.Instance.LogMessage(TracingLevel.INFO, "Connecting to Stream Deck"); @@ -76,6 +79,10 @@ private async void Connection_OnKeyDown(object sender, StreamDeckEventReceivedEv await instancesLock.WaitAsync(); try { +#if DEBUG + Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin Keydown: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}"); +#endif + if (instances.ContainsKey(e.Event.Context)) { KeyPayload payload = new KeyPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates), @@ -95,6 +102,10 @@ private async void Connection_OnKeyUp(object sender, StreamDeckEventReceivedEven await instancesLock.WaitAsync(); try { +#if DEBUG + Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin Keyup: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}"); +#endif + if (instances.ContainsKey(e.Event.Context)) { KeyPayload payload = new KeyPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates), @@ -133,6 +144,10 @@ private async void Connection_OnWillAppear(object sender, StreamDeckEventReceive await instancesLock.WaitAsync(); try { +#if DEBUG + Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnWillAppear: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}"); +#endif + if (supportedActions.ContainsKey(e.Event.Action)) { try @@ -167,6 +182,10 @@ private async void Connection_OnWillDisappear(object sender, StreamDeckEventRece await instancesLock.WaitAsync(); try { +#if DEBUG + Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnWillDisappear: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}"); +#endif + if (instances.ContainsKey(e.Event.Context)) { instances[e.Event.Context].Destroy(); @@ -185,6 +204,10 @@ private async void Connection_OnDidReceiveSettings(object sender, StreamDeckEven await instancesLock.WaitAsync(); try { +#if DEBUG + Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnDidReceiveSettings: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}"); +#endif + if (instances.ContainsKey(e.Event.Context)) { instances[e.Event.Context].ReceivedSettings(JObject.FromObject(e.Event.Payload).ToObject()); @@ -202,6 +225,10 @@ private async void Connection_OnDidReceiveGlobalSettings(object sender, StreamDe await instancesLock.WaitAsync(); try { +#if DEBUG + Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnDidReceiveGlobalSettings: Settings: {e.Event.Payload?.ToStringEx()}"); +#endif + var globalSettings = JObject.FromObject(e.Event.Payload).ToObject(); foreach (string key in instances.Keys) { @@ -235,5 +262,6 @@ private KeyCoordinates GenerateKeyCoordinates(Coordinates coordinates) return new KeyCoordinates() { Column = coordinates.Columns, Row = coordinates.Rows }; } + } } diff --git a/barraider-sdtools/Backend/SDWrapper.cs b/barraider-sdtools/Backend/SDWrapper.cs index 3f5170d..3168eee 100644 --- a/barraider-sdtools/Backend/SDWrapper.cs +++ b/barraider-sdtools/Backend/SDWrapper.cs @@ -34,7 +34,7 @@ public static class SDWrapper /// public static void Run(string[] args, PluginActionId[] supportedActionIds) { - Logger.Instance.LogMessage(TracingLevel.INFO, $"Plugin Loading - {supportedActionIds.Length} Actions Found"); + Logger.Instance.LogMessage(TracingLevel.INFO, $"Plugin [{GetExeName()}] Loading - {supportedActionIds.Length} Actions Found"); System.AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionTrapper; #if DEBUG @@ -83,5 +83,18 @@ private static void UnhandledExceptionTrapper(object sender, UnhandledExceptionE { Logger.Instance.LogMessage(TracingLevel.FATAL, $"Unhandled Exception: {e.ExceptionObject}"); } + + private static string GetExeName() + { + try + { + return System.IO.Path.GetFileNameWithoutExtension(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName); + } + catch (Exception ex) + { + Logger.Instance.LogMessage(TracingLevel.WARN, $"GetExeName failed {ex}"); + } + return String.Empty; + } } } \ No newline at end of file diff --git a/barraider-sdtools/StreamDeckInfo/StreamDeckApplicationInfo.cs b/barraider-sdtools/StreamDeckInfo/StreamDeckApplicationInfo.cs index cc675fe..912ec2e 100644 --- a/barraider-sdtools/StreamDeckInfo/StreamDeckApplicationInfo.cs +++ b/barraider-sdtools/StreamDeckInfo/StreamDeckApplicationInfo.cs @@ -29,5 +29,14 @@ public class StreamDeckApplicationInfo /// [JsonProperty(PropertyName = "version")] public string Version { get; private set; } + + /// + /// Shows class information as string + /// + /// + public override string ToString() + { + return $"Language: {Language} Platform: {Platform} Version: {Version}"; + } } } diff --git a/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceInfo.cs b/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceInfo.cs index 3d562d6..943a74a 100644 --- a/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceInfo.cs +++ b/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceInfo.cs @@ -30,7 +30,12 @@ public enum StreamDeckDeviceType /// /// StreamDeck Mobile version /// - StreamDeckMobile = 3 + StreamDeckMobile = 3, + + /// + /// Corsair G-Keys version + /// + CorsairGKeys = 4 } /// @@ -68,5 +73,14 @@ public StreamDeckDeviceInfo(StreamDeckDeviceSize size, StreamDeckDeviceType type Type = type; Id = deviceId; } + + /// + /// Shows class information as string + /// + /// + public override string ToString() + { + return $"Id: {Id} Type: {Type} Size: {Size?.ToString()}"; + } } } diff --git a/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceSize.cs b/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceSize.cs index 21dc8c2..10457db 100644 --- a/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceSize.cs +++ b/barraider-sdtools/StreamDeckInfo/StreamDeckDeviceSize.cs @@ -34,5 +34,14 @@ public StreamDeckDeviceSize(int rows, int cols) Rows = rows; Cols = cols; } + + /// + /// Shows class information as string + /// + /// + public override string ToString() + { + return $"Rows: {Rows} Columns: {Cols}"; + } } } diff --git a/barraider-sdtools/StreamDeckInfo/StreamDeckInfo.cs b/barraider-sdtools/StreamDeckInfo/StreamDeckInfo.cs index 5940951..4e45cbb 100644 --- a/barraider-sdtools/StreamDeckInfo/StreamDeckInfo.cs +++ b/barraider-sdtools/StreamDeckInfo/StreamDeckInfo.cs @@ -35,5 +35,36 @@ public class StreamDeckInfo /// [JsonProperty(PropertyName = "devicePixelRatio")] public int DevicePixelRatio { get; private set; } + + /// + /// Shows class information as string + /// + /// + public override string ToString() + { + StringBuilder sb = new StringBuilder(); + if (Devices != null) + { + sb.Append("Devices:\n"); + for (int device = 0; device < Devices.Length; device++) + { + if (Devices[device] != null) + { + sb.Append($"[{Devices[device]}]\n"); + } + } + } + + if (Application != null) + { + sb.Append($"ApplicationInfo: {Application}\n"); + } + + if (Plugin != null) + { + sb.Append($"PluginInfo: {Plugin}\n"); + } + return sb.ToString(); + } } } diff --git a/barraider-sdtools/StreamDeckInfo/StreamDeckPluginInfo.cs b/barraider-sdtools/StreamDeckInfo/StreamDeckPluginInfo.cs index 69e5699..56ccd58 100644 --- a/barraider-sdtools/StreamDeckInfo/StreamDeckPluginInfo.cs +++ b/barraider-sdtools/StreamDeckInfo/StreamDeckPluginInfo.cs @@ -17,5 +17,14 @@ public class StreamDeckPluginInfo /// [JsonProperty(PropertyName = "version")] public string Version { get; private set; } + + /// + /// Shows class information as string + /// + /// + public override string ToString() + { + return $"Version: {Version}"; + } } } diff --git a/barraider-sdtools/Tools/Logger.cs b/barraider-sdtools/Tools/Logger.cs index 63ee624..af03d8f 100644 --- a/barraider-sdtools/Tools/Logger.cs +++ b/barraider-sdtools/Tools/Logger.cs @@ -73,7 +73,7 @@ public static Logger Instance private Logger() { var config = new NLog.Config.LoggingConfiguration(); - var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "pluginlog.log", ArchiveEvery=NLog.Targets.FileArchivePeriod.Day, MaxArchiveFiles=10, ArchiveFileName="logs/log.{###}.log", ArchiveNumbering=NLog.Targets.ArchiveNumberingMode.Rolling }; + var logfile = new NLog.Targets.FileTarget("logfile") { FileName = "pluginlog.log", ArchiveEvery=NLog.Targets.FileArchivePeriod.Day, MaxArchiveFiles=3, ArchiveFileName="archive/log.{###}.log", ArchiveNumbering=NLog.Targets.ArchiveNumberingMode.Rolling, Layout = "${longdate}|${level:uppercase=true}|${processname}|${threadid}|${message}" }; config.AddRule(LogLevel.Debug, LogLevel.Fatal, logfile); NLog.LogManager.Configuration = config; log = LogManager.GetCurrentClassLogger(); diff --git a/barraider-sdtools/Tools/PayloadExtensionMethods.cs b/barraider-sdtools/Tools/PayloadExtensionMethods.cs new file mode 100644 index 0000000..0010380 --- /dev/null +++ b/barraider-sdtools/Tools/PayloadExtensionMethods.cs @@ -0,0 +1,46 @@ +using streamdeck_client_csharp.Events; +using System; +using System.Collections.Generic; +using System.Text; + +namespace BarRaider.SdTools +{ + internal static class PayloadExtensionMethods + { + internal static string ToStringEx(this ReceiveSettingsPayload rsp) + { + if (rsp == null) + { + return "ReceiveSettingsPayload is null!"; + } + return $"IsInMultiAction: {rsp.IsInMultiAction} Coordinates: ({rsp.Coordinates?.Rows},{rsp.Coordinates?.Columns}) Settings: {rsp.Settings}"; + } + + internal static string ToStringEx(this AppearancePayload ap) + { + if (ap == null) + { + return "AppearancePayload is null!"; + } + return $"State: {ap.State} IsInMultiAction: {ap.IsInMultiAction} Coordinates: ({ap.Coordinates?.Rows},{ap.Coordinates?.Columns}) Settings: {ap.Settings}"; + } + + internal static string ToStringEx(this streamdeck_client_csharp.Events.KeyPayload kp) + { + if (kp == null) + { + return "KeyPayload is null!"; + } + return $"State: {kp.State} IsInMultiAction: {kp.IsInMultiAction} DesiredState: {kp.UserDesiredState} Coordinates: ({kp.Coordinates?.Rows},{kp.Coordinates?.Columns}) Settings: {kp.Settings}"; + } + + internal static string ToStringEx(this ReceiveGlobalSettingsPayload gsp) + { + if (gsp == null) + { + return "ReceiveGlobalSettingsPayload is null!"; + } + return $"Settings: {gsp.Settings}"; + } + } +} diff --git a/barraider-sdtools/Tools/PluginBase.cs b/barraider-sdtools/Tools/PluginBase.cs index 919247a..46c3586 100644 --- a/barraider-sdtools/Tools/PluginBase.cs +++ b/barraider-sdtools/Tools/PluginBase.cs @@ -82,7 +82,9 @@ public void Destroy() /// /// Communication module with Stream Deck /// Plugin settings - NOTE: Not used in base class, should be consumed by deriving class +#pragma warning disable IDE0060 // Remove unused parameter public PluginBase(SDConnection connection, InitialPayload payload) +#pragma warning restore IDE0060 // Remove unused parameter { Connection = connection; } diff --git a/barraider-sdtools/barraider-sdtools.csproj b/barraider-sdtools/barraider-sdtools.csproj index 6e39d68..923ef4b 100644 --- a/barraider-sdtools/barraider-sdtools.csproj +++ b/barraider-sdtools/barraider-sdtools.csproj @@ -13,20 +13,17 @@ Feel free to contact me for more information: https://barraider.comhttps://github.com/BarRaider/streamdeck-tools/blob/master/LICENSE https://github.com/BarRaider/streamdeck-tools https://github.com/BarRaider/streamdeck-tools - StreamDeck Elgato Library Plugin Stream Deck + StreamDeck Elgato Library Plugin Stream Deck Toolkit StreamDeck-Tools - https://raw.githubusercontent.com/BarRaider/barraider.github.io/master/images/BRLogo.png - 3.0.0.0 - 3.0.0.0 - 3.0 - 3.0 - 1. Updated file handling in `Tools.AutoPopulateSettings` and `Tools.FilenameFromPayload` methods -2. Removed obsolete MD5 functions, use SHA512 functions instead -3. `Tools.CenterText` function now has optional out `textFitsImage` value to verify the text does not exceed the image width -4. New `Tools.FormatBytes` function converts bytes to human-readable value -5. New `Graphics.GetFontSizeWhereTextFitsImage` function helps locate the best size for a text to fit an image on 1 line -6. Updated dependencies + + 3.1.0.0 + 3.1.0.0 + 3.1 + 3.1 - 1. Updated Logger class to include process name and thread id +2. Updated StreamDeck-Tools template for Visual Studio BarRaider.SdTools StreamDeckTools + BRLogo_460.png @@ -43,4 +40,10 @@ Feel free to contact me for more information: https://barraider.com + + + True + + + \ No newline at end of file diff --git a/streamdeck-tools.xml b/streamdeck-tools.xml index fc17dd1..bbf16fd 100644 --- a/streamdeck-tools.xml +++ b/streamdeck-tools.xml @@ -677,6 +677,12 @@ Current version of the StreamDeck app + + + Shows class information as string + + + Type of StreamDeck hardware device, currently two are supported (classic and mini) @@ -702,6 +708,11 @@ StreamDeck Mobile version + + + Corsair G-Keys version + + Class which holds information on the StreamDeck hardware device @@ -730,6 +741,12 @@ + + + Shows class information as string + + + Layout of the keys on the StreamDeck hardware device @@ -752,6 +769,12 @@ + + + Shows class information as string + + + Class which holds information on the StreamDeck app and StreamDeck hardware device that the plugin is communicating with @@ -777,6 +800,12 @@ Device pixel ratio + + + Shows class information as string + + + Holds general information on the StreamDeck App we're communicating with @@ -787,6 +816,12 @@ Current version of the plugin + + + Shows class information as string + + + Extension methods for various objects