4 Commits
Author SHA1 Message Date
krjan02 fd20b19d8f Fixed Version String replacements
Build and Relase / build-release (push) Successful in 2m14s
Build and Relase / create-release (push) Successful in 24s
2025-01-14 20:23:07 +01:00
krjan02 fdf4bd22eb Version 1.0.1 (Dynamic Icon, Update Checker, Wired Support)
Build and Relase / build-release (push) Successful in 1m38s
Build and Relase / create-release (push) Successful in 25s
2025-01-13 23:25:36 +01:00
krjan02 86ac38324e renamed file - modified csproj 2025-01-13 23:24:53 +01:00
krjan02 116750ec58 Added dynamic icon (displays battery state) 2025-01-13 23:24:22 +01:00
5 changed files with 78 additions and 9 deletions
+3 -3
View File
@@ -19,15 +19,15 @@ function Replace-Version {
} }
# Update SoraV2BatteryHelperSetup.vdproj # Update SoraV2BatteryHelperSetup.vdproj
$vdprojFile = "SoraV2BatteryHelperSetup\SoraV2BatteryHelperSetup.vdproj" $vdprojFile = "SoraV2Utils_Setup\SoraV2Utils_Setup.vdproj"
$vdprojPattern = '(\s*)"ProductVersion" = "8:\d+\.\d+\.\d+"' $vdprojPattern = '(\s*)"ProductVersion" = "8:\d+\.\d+\.\d+"'
$vdprojReplacement = '$1"ProductVersion" = "8:' + $version + '"' $vdprojReplacement = '$1"ProductVersion" = "8:' + $version + '"'
Replace-Version -filePath $vdprojFile -regexPattern $vdprojPattern -replacement $vdprojReplacement Replace-Version -filePath $vdprojFile -regexPattern $vdprojPattern -replacement $vdprojReplacement
# Update AssemblyInfo.cs files # Update AssemblyInfo.cs files
$assemblyFiles = @( $assemblyFiles = @(
"SoraV2BatteryHelperSvc\Properties\AssemblyInfo.cs", "SoraV2Utils_Service\Properties\AssemblyInfo.cs",
"SoraV2BatteryHelperNotification\Properties\AssemblyInfo.cs" "SoraV2Utils_Agent\Properties\AssemblyInfo.cs"
) )
$assemblyVersionPattern = '(\s*)\[assembly: AssemblyVersion\("(\d+\.\d+\.\d+\.\d+)"\)\]' $assemblyVersionPattern = '(\s*)\[assembly: AssemblyVersion\("(\d+\.\d+\.\d+\.\d+)"\)\]'
+67
View File
@@ -0,0 +1,67 @@
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing.Text;
namespace SoraV2Utils_Agent
{
internal class DynamicIcon
{
public static Icon CreateIcon(string text, Color textColor, Font font)
{
if (string.IsNullOrEmpty(text) || text.Length > 3)
throw new ArgumentException("Text must be between 1 and 3 characters long.", nameof(text));
// Create a 32x32 transparent bitmap
using (Bitmap bitmap = new Bitmap(32, 32))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
// Set up transparency
g.Clear(Color.Transparent);
// Enable anti-aliasing for smoother text
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
// Determine the largest font size that will fit within 32x32
float maxFontSize = 48; // Start with a large font size
SizeF textSize;
Font adjustedFont;
do
{
maxFontSize--;
adjustedFont = new Font(font.FontFamily, maxFontSize, font.Style);
textSize = g.MeasureString(text, adjustedFont);
}
while ((textSize.Width > 42 || textSize.Height > 42) && maxFontSize > 1);
if (textSize.Width > 42 || textSize.Height > 42)
{
// Reduce back if the scaled size exceeds 32x32
maxFontSize /= 1.25f;
adjustedFont = new Font(font.FontFamily, maxFontSize, font.Style);
textSize = g.MeasureString(text, adjustedFont);
}
// Calculate the position to center the text
float x = (32 - textSize.Width) / 2;
float y = (32 - textSize.Height) / 2;
// Draw the text
using (SolidBrush textBrush = new SolidBrush(textColor))
{
g.DrawString(text, adjustedFont, textBrush, x, y);
}
}
// Create and return the icon
return Icon.FromHandle(bitmap.GetHicon());
}
}
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ namespace SoraV2Utils_Agent
System.Environment.Exit(1); System.Environment.Exit(1);
}; ; }; ;
var trayicon = new TrayIcon(); var trayicon = new TrayIconForm();
trayicon.Display(); trayicon.Display();
} }
} }
+2 -1
View File
@@ -74,6 +74,7 @@
<Reference Include="Windows.UI" /> <Reference Include="Windows.UI" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="DynamicIcon.cs" />
<Compile Include="NotificationInstaller.cs"> <Compile Include="NotificationInstaller.cs">
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
@@ -85,7 +86,7 @@
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ServiceMonitor.cs" /> <Compile Include="ServiceMonitor.cs" />
<Compile Include="TrayIcon.cs" /> <Compile Include="TrayIconForm.cs" />
<Compile Include="UpdateCheck.cs" /> <Compile Include="UpdateCheck.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@@ -9,15 +9,15 @@ using System.Threading;
namespace SoraV2Utils_Agent namespace SoraV2Utils_Agent
{ {
public class TrayIcon public class TrayIconForm
{ {
public TrayIcon() public TrayIconForm()
{ {
// Create a NotifyIcon instance // Create a NotifyIcon instance
using (NotifyIcon trayIcon = new NotifyIcon()) using (NotifyIcon trayIcon = new NotifyIcon())
{ {
// Set up the tray icon properties // Set up the tray icon properties
trayIcon.Icon = new Icon(SystemIcons.WinLogo, 40, 40); // Choose your own icon trayIcon.Icon = new Icon(DynamicIcon.CreateIcon("##",Color.Red, SystemFonts.IconTitleFont), 40, 40); // Choose your own icon
trayIcon.Visible = true; trayIcon.Visible = true;
// Create a context menu // Create a context menu
@@ -54,6 +54,7 @@ namespace SoraV2Utils_Agent
batteryLevelItem.Text = batteryLevelText; batteryLevelItem.Text = batteryLevelText;
batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}"; batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}";
batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}"; batteryRuntimeItem.Text = $"Battery Runtime: {batteryRuntimeText}";
trayIcon.Icon = new Icon(DynamicIcon.CreateIcon(ServiceIPC.DeviceStatus.Battery.ToString(), Color.White, new Font("Arial",32)), 32, 32);
// Update every second // Update every second
Thread.Sleep(1000); Thread.Sleep(1000);