diff --git a/LICENSE b/LICENSE
deleted file mode 100644
index fa71551..0000000
--- a/LICENSE
+++ /dev/null
@@ -1,21 +0,0 @@
-MIT License
-
-Copyright (c) 2019 BarRaider
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
\ No newline at end of file
diff --git a/NUGET.md b/NUGET.md
index 6a3f38e..72d5d94 100644
--- a/NUGET.md
+++ b/NUGET.md
@@ -7,12 +7,11 @@
**Author's website and contact information:** [https://barraider.com](https://barraider.com)
** Samples of plugins using this framework: [Samples][1]
-### Version 2.8 is out!
-- Introduced `GraphicsUtils` class with a bunch of helper functions to manipulate the SD images
-- Added new `Tools.FormatNumber()` function converts 54265 to 54.27k
-- New ExtensionMethods for `Graphics` object: `DrawAndMeasureString` / `GetTextCenter`
-- Updated dependency packages to latest versions
-- Bug fix where SDConnection was not properly disposed.
+### Version 2.9 is out!
+- Updated plugin creation logic to support issue where Stream Deck sends multiple WillAppear messages in Multi-Actions
+- Updated API to support new State parameter in SetImageAsync/SetTitleAsync
+- Added FIPS-compliant support to SHA512 in Tools module. MD5 functions are now obsolete
+- New GraphicTools.WrapStringToFitImage() function will automatically wrap the text so it wil fit the key when using SetTitleAsync()
## Features
- Sample plugin now included in this project on Github
diff --git a/README.md b/README.md
index d02c1d3..9a05330 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,12 @@
* [Install.bat](https://github.com/BarRaider/streamdeck-tools/blob/master/utils/install.bat) - Script that quickly uninstalls and reinstalls your plugin on the streamdeck (view batch file for more details)
* [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
-### Version 2.8 is out!
+### Version 2.9 is out!
+- Updated plugin creation logic to support issue where Stream Deck sends multiple WillAppear messages in Multi-Actions
+- Updated API to support new State parameter in SetImageAsync/SetTitleAsync
+- Added FIPS-compliant support to SHA512 in Tools module. MD5 functions are now obsolete
+- New GraphicTools.WrapStringToFitImage() function will automatically wrap the text so it wil fit the key when using SetTitleAsync()
+
- Introduced `GraphicsUtils` class with a bunch of helper functions to manipulate the SD images
- Added new `Tools.FormatNumber()` function converts 54265 to 54.27k
- New ExtensionMethods for `Graphics` object: `DrawAndMeasureString` / `GetTextCenter`
diff --git a/SamplePlugin/PluginAction.cs b/SamplePlugin/PluginAction.cs
index 26ec54c..987477b 100644
--- a/SamplePlugin/PluginAction.cs
+++ b/SamplePlugin/PluginAction.cs
@@ -1,8 +1,10 @@
using BarRaider.SdTools;
+using BarRaider.SdTools.Wrappers;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
+using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
@@ -102,12 +104,32 @@ public override void Dispose()
Logger.Instance.LogMessage(TracingLevel.INFO, $"Destructor called");
}
- public override void KeyPressed(KeyPayload payload)
+ public async override void KeyPressed(KeyPayload payload)
{
Logger.Instance.LogMessage(TracingLevel.INFO, "Key Pressed");
+ TitleParameters tp = new TitleParameters(new FontFamily("Arial"), FontStyle.Bold, 20, Color.White, true, TitleVerticalAlignment.Middle);
+ using (Image image = Tools.GenerateGenericKeyImage(out Graphics graphics))
+ {
+ graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, image.Width, image.Height);
+ graphics.AddTextPath(tp, image.Height, image.Width, "Test");
+ graphics.Dispose();
+
+ await Connection.SetImageAsync(image);
+ }
}
- public override void KeyReleased(KeyPayload payload) { }
+ public async override void KeyReleased(KeyPayload payload)
+ {
+ TitleParameters tp = new TitleParameters(new FontFamily("Arial"), FontStyle.Bold, 20, Color.White, true, TitleVerticalAlignment.Middle);
+ using (Image image = Tools.GenerateGenericKeyImage(out Graphics graphics))
+ {
+ graphics.FillRectangle(new SolidBrush(Color.White), 0, 0, image.Width, image.Height);
+ graphics.AddTextPath(tp, image.Height, image.Width, "Test", Color.Black, 7);
+ graphics.Dispose();
+
+ await Connection.SetImageAsync(image);
+ }
+ }
public override void OnTick() { }
diff --git a/SamplePlugin/SamplePlugin.csproj b/SamplePlugin/SamplePlugin.csproj
index 3ed4a67..386b7a3 100644
--- a/SamplePlugin/SamplePlugin.csproj
+++ b/SamplePlugin/SamplePlugin.csproj
@@ -33,17 +33,14 @@
4
-
- ..\packages\CommandLineParser.2.7.82\lib\net461\CommandLine.dll
+
+ ..\packages\CommandLineParser.2.8.0\lib\net461\CommandLine.dll
..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
- ..\packages\NLog.4.6.8\lib\net45\NLog.dll
-
-
- ..\packages\streamdeck-client-csharp.4.1.1\lib\netstandard2.0\streamdeck-client-csharp.dll
+ ..\packages\NLog.4.7.2\lib\net45\NLog.dll
diff --git a/SamplePlugin/packages.config b/SamplePlugin/packages.config
index 76e4e60..c0dd471 100644
--- a/SamplePlugin/packages.config
+++ b/SamplePlugin/packages.config
@@ -1,8 +1,7 @@
-
+
-
-
+
\ No newline at end of file
diff --git a/barraider-sdtools/Backend/PluginContainer.cs b/barraider-sdtools/Backend/PluginContainer.cs
index 24b9ddf..4b7738a 100644
--- a/barraider-sdtools/Backend/PluginContainer.cs
+++ b/barraider-sdtools/Backend/PluginContainer.cs
@@ -126,7 +126,7 @@ private async void RunTick()
}
}
- // Stopwatch instance created
+ // Action is loaded in the Stream Deck
private async void Connection_OnWillAppear(object sender, StreamDeckEventReceivedEventArgs e)
{
SDConnection conn = new SDConnection(connection, pluginUUID, deviceInfo, e.Event.Action, e.Event.Context, e.Event.Device);
@@ -137,13 +137,18 @@ private async void Connection_OnWillAppear(object sender, StreamDeckEventReceive
{
try
{
+ if (instances.ContainsKey(e.Event.Context) && instances[e.Event.Context] != null)
+ {
+ Logger.Instance.LogMessage(TracingLevel.INFO, $"WillAppear called for already existing context {e.Event.Context} (might be inside a multi-action)");
+ return;
+ }
InitialPayload payload = new InitialPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates),
e.Event.Payload.Settings, e.Event.Payload.State, e.Event.Payload.IsInMultiAction, deviceInfo);
instances[e.Event.Context] = (PluginBase)Activator.CreateInstance(supportedActions[e.Event.Action], conn, payload);
}
catch (Exception ex)
{
- Logger.Instance.LogMessage(TracingLevel.FATAL, $"Could not create instance of {supportedActions[e.Event.Action]} - Maybe class does not inherit PluginBase with the same constructor? {ex}");
+ Logger.Instance.LogMessage(TracingLevel.FATAL, $"Could not create instance of {supportedActions[e.Event.Action]} with context {e.Event.Context} - This may be due to an Exception raised in the constructor, or the class does not inherit PluginBase with the same constructor {ex}");
}
}
else
diff --git a/barraider-sdtools/Backend/SDConnection.cs b/barraider-sdtools/Backend/SDConnection.cs
index cfa7cf0..38805b0 100644
--- a/barraider-sdtools/Backend/SDConnection.cs
+++ b/barraider-sdtools/Backend/SDConnection.cs
@@ -121,15 +121,16 @@ public async Task GetGlobalSettingsAsync()
/// Sets an image on the StreamDeck key.
///
/// Base64 encoded image
+ /// A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states.
/// Should image be sent even if it is identical to the one sent previously. Default is false
///
- public async Task SetImageAsync(string base64Image, bool forceSendToStreamdeck = false)
+ public async Task SetImageAsync(string base64Image, int? state = null, bool forceSendToStreamdeck = false)
{
- string hash = Tools.StringToMD5(base64Image);
+ string hash = Tools.StringToSHA512(base64Image);
if (forceSendToStreamdeck || hash != previousImageHash)
{
previousImageHash = hash;
- await StreamDeckConnection.SetImageAsync(base64Image, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware);
+ await StreamDeckConnection.SetImageAsync(base64Image, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware, state);
}
}
@@ -137,15 +138,16 @@ public async Task SetImageAsync(string base64Image, bool forceSendToStreamdeck =
/// Sets an image on the StreamDeck key
///
/// Image object
+ /// A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states.
/// Should image be sent even if it is identical to the one sent previously. Default is false
///
- public async Task SetImageAsync(Image image, bool forceSendToStreamdeck = false)
+ public async Task SetImageAsync(Image image, int? state = null, bool forceSendToStreamdeck = false)
{
- string hash = Tools.ImageToMD5(image);
+ string hash = Tools.ImageToSHA512(image);
if (forceSendToStreamdeck || hash != previousImageHash)
{
previousImageHash = hash;
- await StreamDeckConnection.SetImageAsync(image, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware);
+ await StreamDeckConnection.SetImageAsync(image, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware, state);
}
}
@@ -162,10 +164,11 @@ public async Task SetDefaultImageAsync()
/// Sets a title on the StreamDeck key
///
///
+ /// A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states.
///
- public async Task SetTitleAsync(string title)
+ public async Task SetTitleAsync(string title, int? state = null)
{
- await StreamDeckConnection.SetTitleAsync(title, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware);
+ await StreamDeckConnection.SetTitleAsync(title, ContextId, streamdeck_client_csharp.SDKTarget.HardwareAndSoftware, state);
}
///
diff --git a/barraider-sdtools/Tools/ExtensionMethods.cs b/barraider-sdtools/Tools/ExtensionMethods.cs
index 21493a0..6899db5 100644
--- a/barraider-sdtools/Tools/ExtensionMethods.cs
+++ b/barraider-sdtools/Tools/ExtensionMethods.cs
@@ -1,7 +1,8 @@
-using streamdeck_client_csharp.Events;
+using BarRaider.SdTools.Wrappers;
using System;
using System.Collections.Generic;
using System.Drawing;
+using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
@@ -55,7 +56,7 @@ public static KeyCoordinates ToKeyCoordinates(this streamdeck_client_csharp.Even
///
///
///
- public static StreamDeckDeviceInfo ToStreamDeckDeviceInfo(this DeviceInfo deviceInfo, string deviceId)
+ public static StreamDeckDeviceInfo ToStreamDeckDeviceInfo(this streamdeck_client_csharp.Events.DeviceInfo deviceInfo, string deviceId)
{
if (deviceInfo == null)
{
@@ -163,6 +164,81 @@ public static float GetTextCenter(this Graphics graphics, string text, int image
return stringWidth;
}
+ ///
+ /// Adds a text path to an existing Graphics object. Uses TitleParameters to emulate the Text settings in the Property Inspector
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void AddTextPath(this Graphics graphics, TitleParameters titleParameters, int imageHeight, int imageWidth, string text, int pixelsAlignment = 15)
+ {
+ AddTextPath(graphics, titleParameters, imageHeight, imageWidth, text, Color.Black, 1, pixelsAlignment);
+ }
+
+ ///
+ /// Adds a text path to an existing Graphics object. Uses TitleParameters to emulate the Text settings in the Property Inspector
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static void AddTextPath(this Graphics graphics, TitleParameters titleParameters, int imageHeight, int imageWidth, string text, Color strokeColor, float strokeThickness, int pixelsAlignment = 15)
+ {
+ try
+ {
+ if (titleParameters == null)
+ {
+ Logger.Instance.LogMessage(TracingLevel.ERROR, $"AddTextPath: titleParameters is null");
+ return;
+ }
+
+ Font font = new Font(titleParameters.FontFamily, (float)titleParameters.FontSizeInPixelsScaledToDefaultImage, titleParameters.FontStyle, GraphicsUnit.Pixel);
+ Color color = titleParameters.TitleColor;
+ graphics.PageUnit = GraphicsUnit.Pixel;
+ float ratio = graphics.DpiY / imageWidth;
+ SizeF stringSize = graphics.MeasureString(text, font);
+ float textWidth = stringSize.Width * (1 - ratio);
+ float textHeight = stringSize.Height * (1 - ratio);
+ int stringWidth = 0;
+ if (textWidth < imageWidth)
+ {
+ stringWidth = (int)(Math.Abs((imageWidth - textWidth)) / 2) - pixelsAlignment;
+ }
+
+ int stringHeight = pixelsAlignment; // Top
+ if (titleParameters.VerticalAlignment == TitleVerticalAlignment.Middle)
+ {
+ stringHeight = (imageHeight / 2) - pixelsAlignment;
+ }
+ else if (titleParameters.VerticalAlignment == TitleVerticalAlignment.Bottom)
+ {
+ stringHeight = (int)(Math.Abs((imageHeight - textHeight)) - pixelsAlignment);
+ }
+
+ Pen stroke = new Pen(strokeColor, strokeThickness);
+ GraphicsPath gpath = new GraphicsPath();
+ gpath.AddString(text,
+ font.FontFamily,
+ (int)font.Style,
+ graphics.DpiY * font.SizeInPoints / imageWidth,
+ new Point(stringWidth, stringHeight),
+ new StringFormat());
+ graphics.DrawPath(stroke, gpath);
+ graphics.FillPath(new SolidBrush(color), gpath);
+ }
+ catch (Exception ex)
+ {
+ Logger.Instance.LogMessage(TracingLevel.ERROR, $"AddTextPath Exception {ex}");
+ }
+ }
+
#endregion
}
}
diff --git a/barraider-sdtools/Tools/GraphicsTools.cs b/barraider-sdtools/Tools/GraphicsTools.cs
index 6b2bf58..25a85d4 100644
--- a/barraider-sdtools/Tools/GraphicsTools.cs
+++ b/barraider-sdtools/Tools/GraphicsTools.cs
@@ -1,4 +1,5 @@
-using System;
+using BarRaider.SdTools.Wrappers;
+using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
@@ -217,5 +218,59 @@ public static Image[] DrawMultiLinedText(string text, int currentTextPosition, i
graphics.Dispose();
return images.ToArray();
}
+
+ ///
+ /// Adds line breaks ('\n') to the string every time the text would overflow the image
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string WrapStringToFitImage(string str, TitleParameters titleParameters, int leftPaddingPixels = 3, int rightPaddingPixels = 3, int imageWidthPixels = 72)
+ {
+ try
+ {
+ if (titleParameters == null)
+ {
+ return str;
+ }
+
+ int padding = leftPaddingPixels + rightPaddingPixels;
+ Font font = new Font(titleParameters.FontFamily, (float)titleParameters.FontSizeInPoints, titleParameters.FontStyle, GraphicsUnit.Pixel);
+ StringBuilder finalString = new StringBuilder();
+ StringBuilder currentLine = new StringBuilder();
+ SizeF currentLineSize;
+
+ using (Bitmap img = new Bitmap(imageWidthPixels, imageWidthPixels))
+ {
+ using (Graphics graphics = Graphics.FromImage(img))
+ {
+ for (int idx = 0; idx < str.Length; idx++)
+ {
+ currentLine.Append(str[idx]);
+ currentLineSize = graphics.MeasureString(currentLine.ToString(), font);
+ if (currentLineSize.Width <= img.Width - padding)
+ {
+ finalString.Append(str[idx]);
+ }
+ else // Overflow
+ {
+ finalString.Append("\n" + str[idx]);
+ currentLine = new StringBuilder(str[idx].ToString());
+ }
+ }
+ }
+ }
+
+ return finalString.ToString();
+ }
+ catch (Exception ex)
+ {
+ Logger.Instance.LogMessage(TracingLevel.ERROR, $"SplitStringToFit Exception: {ex}");
+ return str;
+ }
+ }
}
}
diff --git a/barraider-sdtools/Tools/Tools.cs b/barraider-sdtools/Tools/Tools.cs
index 81223b4..8dc15a6 100644
--- a/barraider-sdtools/Tools/Tools.cs
+++ b/barraider-sdtools/Tools/Tools.cs
@@ -11,6 +11,7 @@
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
+using System.Text;
namespace BarRaider.SdTools
{
@@ -209,6 +210,7 @@ private static Bitmap GenerateKeyImage(int height, int width, out Graphics graph
}
///
+ /// Deprecated! Use AddTextPath on the Graphics extension method instead.
/// Adds a text path to an existing Graphics object. Uses TitleParser to emulate the Text settings in the Property Inspector
///
///
@@ -217,46 +219,12 @@ private static Bitmap GenerateKeyImage(int height, int width, out Graphics graph
///
///
///
+ [Obsolete("Use graphics.AddTextPath() extension method instead")]
public static void AddTextPathToGraphics(Graphics graphics, TitleParameters titleParameters, int imageHeight, int imageWidth, string text, int pixelsAlignment = 15)
{
- try
- {
- Font font = new Font(titleParameters.FontFamily, (float)titleParameters.FontSizeInPixelsScaledToDefaultImage, titleParameters.FontStyle);
- Color color = titleParameters.TitleColor;
- graphics.PageUnit = GraphicsUnit.Pixel;
- float ratio = graphics.DpiY / imageWidth;
- SizeF stringSize = graphics.MeasureString(text, font);
- float textWidth = stringSize.Width * (1 - ratio);
- float textHeight = stringSize.Height * (1 - ratio);
- int stringWidth = 0;
- if (textWidth < imageWidth)
- {
- stringWidth = (int)(Math.Abs((imageWidth - textWidth)) / 2) - pixelsAlignment;
- }
-
- int stringHeight = pixelsAlignment; // Top
- if (titleParameters.VerticalAlignment == TitleVerticalAlignment.Middle)
- {
- stringHeight = (imageHeight / 2) - pixelsAlignment;
- }
- else if (titleParameters.VerticalAlignment == TitleVerticalAlignment.Bottom)
- {
- stringHeight = (int)(Math.Abs((imageHeight - textHeight)) - pixelsAlignment);
- }
-
- GraphicsPath gpath = new GraphicsPath();
- gpath.AddString(text,
- font.FontFamily,
- (int)font.Style,
- graphics.DpiY * font.SizeInPoints / imageWidth,
- new Point(stringWidth, stringHeight),
- new StringFormat());
- graphics.DrawPath(Pens.Black, gpath);
- graphics.FillPath(new SolidBrush(color), gpath);
- }
- catch (Exception ex)
+ if (graphics != null)
{
- Logger.Instance.LogMessage(TracingLevel.ERROR, $"AddTextPathToGraphics Exception {ex}");
+ graphics.AddTextPath(titleParameters, imageHeight, imageWidth, text, pixelsAlignment);
}
}
@@ -315,6 +283,125 @@ public static string FormatNumber(long num)
return num.ToString("#,0");
}
+ ///
+ /// Adds line breaks (\n) to the text to make sure it fits the key when using SetTitleAsync()
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public static string SplitStringToFit(string str, TitleParameters titleParameters, int leftPaddingPixels = 3, int rightPaddingPixels = 3, int imageWidthPixels = 72)
+ {
+ try
+ {
+ if (titleParameters == null)
+ {
+ return str;
+ }
+
+ int padding = leftPaddingPixels + rightPaddingPixels;
+ Font font = new Font(titleParameters.FontFamily, (float)titleParameters.FontSizeInPoints, titleParameters.FontStyle, GraphicsUnit.Pixel);
+ StringBuilder finalString = new StringBuilder();
+ StringBuilder currentLine = new StringBuilder();
+ SizeF currentLineSize;
+
+ using (Bitmap img = new Bitmap(imageWidthPixels, imageWidthPixels))
+ {
+ using (Graphics graphics = Graphics.FromImage(img))
+ {
+ for (int idx = 0; idx < str.Length; idx++)
+ {
+ currentLine.Append(str[idx]);
+ currentLineSize = graphics.MeasureString(currentLine.ToString(), font);
+ if (currentLineSize.Width <= img.Width - padding)
+ {
+ finalString.Append(str[idx]);
+ }
+ else // Overflow
+ {
+ finalString.Append("\n" + str[idx]);
+ currentLine = new StringBuilder(str[idx].ToString());
+ }
+ }
+ }
+ }
+
+ return finalString.ToString();
+ }
+ catch (Exception ex)
+ {
+ Logger.Instance.LogMessage(TracingLevel.ERROR, $"SplitStringToFit Exception: {ex}");
+ return str;
+ }
+ }
+
+ #endregion
+
+ #region SHA512
+
+ ///
+ /// Returns SHA512 Hash from an image object
+ ///
+ ///
+ ///
+ public static string ImageToSHA512(Image image)
+ {
+ if (image == null)
+ {
+ return null;
+ }
+
+ try
+ {
+ using (MemoryStream ms = new MemoryStream())
+ {
+ image.Save(ms, ImageFormat.Png);
+ return BytesToSHA512(ms.ToArray());
+ }
+ }
+ catch (Exception ex)
+ {
+ Logger.Instance.LogMessage(TracingLevel.ERROR, $"ImageToSHA512 Exception: {ex}");
+ }
+ return null;
+ }
+
+ ///
+ /// Returns SHA512 Hash from a string
+ ///
+ ///
+ ///
+ public static string StringToSHA512(string str)
+ {
+ if (str == null)
+ {
+ return null;
+ }
+ return BytesToSHA512(System.Text.Encoding.UTF8.GetBytes(str));
+ }
+
+ ///
+ /// Returns SHA512 Hash from a byte stream
+ ///
+ ///
+ ///
+ public static string BytesToSHA512(byte[] byteStream)
+ {
+ try
+ {
+ SHA512CryptoServiceProvider sha512 = new SHA512CryptoServiceProvider();
+ byte[] hash = sha512.ComputeHash(byteStream);
+ return BitConverter.ToString(hash).Replace("-", "").ToLower();
+ }
+ catch (Exception ex)
+ {
+ Logger.Instance.LogMessage(TracingLevel.ERROR, $"BytesToSHA512 Exception: {ex}");
+ }
+ return null;
+ }
+
#endregion
#region MD5
@@ -324,15 +411,17 @@ public static string FormatNumber(long num)
///
///
///
+ [Obsolete("Use ImageToSHA512 instead. MD5 is not FIPS compliant")]
public static string ImageToMD5(Image image)
{
+ Logger.Instance.LogMessage(TracingLevel.WARN, $"ImageToMD5 is obsolete and will soon be deprecated");
if (image == null)
{
return null;
}
try
- {
+ {
using (MemoryStream ms = new MemoryStream())
{
image.Save(ms, ImageFormat.Png);
@@ -351,8 +440,10 @@ public static string ImageToMD5(Image image)
///
///
///
+ [Obsolete("Use StringToSHA512 instead. MD5 is not FIPS compliant")]
public static string StringToMD5(string str)
{
+ Logger.Instance.LogMessage(TracingLevel.WARN, $"StringToMD5 is obsolete and will soon be deprecated");
if (str == null)
{
return null;
@@ -365,8 +456,10 @@ public static string StringToMD5(string str)
///
///
///
+ [Obsolete("Use BytesToSHA512 instead. MD5 is not FIPS compliant")]
public static string BytesToMD5(byte[] byteStream)
{
+ Logger.Instance.LogMessage(TracingLevel.WARN, $"BytesToMD5 is obsolete and will soon be deprecated");
try
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
@@ -385,7 +478,7 @@ public static string BytesToMD5(byte[] byteStream)
#region JObject Related
///
- /// Itterates through the fromJObject, finds the propery that matches in the toSettings object, and sets the value from the fromJObject object
+ /// Iterates through the fromJObject, finds the property that matches in the toSettings object, and sets the value from the fromJObject object
///
///
///
diff --git a/barraider-sdtools/barraider-sdtools.csproj b/barraider-sdtools/barraider-sdtools.csproj
index b9a5da8..9a1c526 100644
--- a/barraider-sdtools/barraider-sdtools.csproj
+++ b/barraider-sdtools/barraider-sdtools.csproj
@@ -16,14 +16,13 @@ Feel free to contact me for more information: https://barraider.comStreamDeck Elgato Library Plugin Stream Deck
StreamDeck-Tools
https://raw.githubusercontent.com/BarRaider/barraider.github.io/master/images/BRLogo.png
- 2.8.0.0
- 2.8.0.0
- 2.8.0
- 2.8 - 1. Introduced GraphicsUtils class with a bunch of more helper functions to manipulate the SD images
-2. Added new FormatNumber function to Tools class (54,265 => 54.27k)
-3. New Graphics ExtensionMethods (DrawAndMeasureString & GetTextCenter)
-4. Updated dependency packages to latest versions
-5. Bug fix where SDConnection was not properly disposed.
+ 2.9.0.0
+ 2.9.0.0
+ 2.9.0
+ 2.9 - 1. Added support to SHA512 in Tools module. MD5 functions are now obsolete
+2. Updated plugin creation logic to support issue where Stream Deck sends multiple WillAppear messages in Multi-Actions
+3. Updated API to support new State parameter in SetImageAsync/SetTitleAsync
+3. New GraphicTools.WrapStringToFitImage() function will automatically wrap the text so it wil fit the key when using SetTitleAsync()
BarRaider.SdTools
StreamDeckTools
@@ -34,10 +33,10 @@ Feel free to contact me for more information: https://barraider.comE:\Projects\GitHub\streamdeck-tools\\streamdeck-tools.xml
-
+
-
-
+
+
diff --git a/streamdeck-tools.xml b/streamdeck-tools.xml
index 424c9b5..0a3313b 100644
--- a/streamdeck-tools.xml
+++ b/streamdeck-tools.xml
@@ -100,19 +100,21 @@
-
+
Sets an image on the StreamDeck key.
Base64 encoded image
+ A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states.
Should image be sent even if it is identical to the one sent previously. Default is false
-
+
Sets an image on the StreamDeck key
Image object
+ A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states.
Should image be sent even if it is identical to the one sent previously. Default is false
@@ -122,11 +124,12 @@
-
+
Sets a title on the StreamDeck key
+ A 0-based integer value representing the state of an action with multiple states. This is an optional parameter. If not specified, the title is set to all states.
@@ -862,6 +865,30 @@
+
+
+ Adds a text path to an existing Graphics object. Uses TitleParameters to emulate the Text settings in the Property Inspector
+
+
+
+
+
+
+
+
+
+
+ Adds a text path to an existing Graphics object. Uses TitleParameters to emulate the Text settings in the Property Inspector
+
+
+
+
+
+
+
+
+
+
Helper class which allows fetching the GlobalSettings of a plugin
@@ -956,6 +983,17 @@
+
+
+ Adds line breaks ('\n') to the string every time the text would overflow the image
+
+
+
+
+
+
+
+
Tracing levels used for Logger
@@ -1164,6 +1202,7 @@
+ Deprecated! Use AddTextPath on the Graphics extension method instead.
Adds a text path to an existing Graphics object. Uses TitleParser to emulate the Text settings in the Property Inspector
@@ -1187,6 +1226,38 @@
+
+
+ Adds line breaks (\n) to the text to make sure it fits the key when using SetTitleAsync()
+
+
+
+
+
+
+
+
+
+
+ Returns SHA512 Hash from an image object
+
+
+
+
+
+
+ Returns SHA512 Hash from a string
+
+
+
+
+
+
+ Returns SHA512 Hash from a byte stream
+
+
+
+
Returns MD5 Hash from an image object
@@ -1210,7 +1281,7 @@
- Itterates through the fromJObject, finds the propery that matches in the toSettings object, and sets the value from the fromJObject object
+ Iterates through the fromJObject, finds the property that matches in the toSettings object, and sets the value from the fromJObject object