Ads QR codes for CIDs

This commit is contained in:
benbierens 2024-11-08 16:09:47 +01:00
parent b1cb61b51c
commit 7b45a1171e
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
3 changed files with 54 additions and 2 deletions

View File

@ -8,6 +8,10 @@
<UseWPF>true</UseWPF> <UseWPF>true</UseWPF>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="QRCoder" Version="1.6.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\ProjectPlugins\CodexPlugin\CodexPlugin.csproj" /> <ProjectReference Include="..\ProjectPlugins\CodexPlugin\CodexPlugin.csproj" />
<ProjectReference Include="..\Tools\AutoClient\AutoClient.csproj" /> <ProjectReference Include="..\Tools\AutoClient\AutoClient.csproj" />

View File

@ -5,14 +5,27 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DevconBoothImages" xmlns:local="clr-namespace:DevconBoothImages"
mc:Ignorable="d" mc:Ignorable="d"
Title="DevconBoothImages" Height="450" Width="800" WindowState="Maximized"> Title="CodexBoothImages" Height="450" Width="800" WindowState="Maximized">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
<RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Image Grid.Row="0" Name="Img" /> <Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Name="Img" />
<StackPanel Grid.Column="1">
<TextBlock Text="Local CID:"/>
<Image Name="ImgLocalCid" />
<TextBlock Text="TestNet CID:"/>
<Image Name="ImgTestnetCid" />
</StackPanel>
</Grid>
<StackPanel Grid.Row="1"> <StackPanel Grid.Row="1">
<TextBlock Name="Txt" HorizontalAlignment="Center" /> <TextBlock Name="Txt" HorizontalAlignment="Center" />
<Button Content="Check Codex connections" Click="Button_Click_2" /> <Button Content="Check Codex connections" Click="Button_Click_2" />

View File

@ -1,8 +1,12 @@
using AutoClient; using AutoClient;
using CodexOpenApi; using CodexOpenApi;
using Logging; using Logging;
using QRCoder;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO; using System.IO;
using System.Windows; using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging; using System.Windows.Media.Imaging;
namespace DevconBoothImages namespace DevconBoothImages
@ -29,6 +33,7 @@ namespace DevconBoothImages
private async void Button_Click(object sender, RoutedEventArgs e) private async void Button_Click(object sender, RoutedEventArgs e)
{ {
// image // image
Log("Getting image..."); Log("Getting image...");
var file = await imageGenerator.Generate(); var file = await imageGenerator.Generate();
@ -49,6 +54,33 @@ namespace DevconBoothImages
InfoToClipboard(); InfoToClipboard();
} }
private BitmapImage GenerateQr(string text)
{
using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(text, QRCodeGenerator.ECCLevel.Default))
using (PngByteQRCode qrCode = new PngByteQRCode(qrCodeData))
{
byte[] qrCodeImage = qrCode.GetGraphic(12);
using (var ms = new MemoryStream(qrCodeImage))
{
var img = Image.FromStream(ms);
using (var ms2 = new MemoryStream())
{
img.Save(ms2, ImageFormat.Png);
ms.Seek(0, SeekOrigin.Begin);
var bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.StreamSource = ms2;
bitmapImage.EndInit();
return bitmapImage;
}
}
}
}
private async void Button_Click_1(object sender, RoutedEventArgs e) private async void Button_Click_1(object sender, RoutedEventArgs e)
{ {
InfoToClipboard(); InfoToClipboard();
@ -115,6 +147,9 @@ namespace DevconBoothImages
Clipboard.SetText(msg); Clipboard.SetText(msg);
Log("CID info copied to clipboard. Paste it in Discord plz!"); Log("CID info copied to clipboard. Paste it in Discord plz!");
ImgLocalCid.Source = GenerateQr(currentLocalCid);
ImgTestnetCid.Source = GenerateQr(currentPublicCid);
} }
private void Log(string v) private void Log(string v)