Skip to content

Commit

Permalink
Add icon library cross compile task
Browse files Browse the repository at this point in the history
  • Loading branch information
rkttu committed Aug 23, 2024
1 parent d96868d commit b6781e2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

# Setup MingW32 cross compiler
- name: Setup MingW32 cross compiler
run: sudo apt update && sudo apt-get -y install mingw-w64

# Setup .NET Core SDK
- name: Setup .NET Core
Expand Down
34 changes: 32 additions & 2 deletions src/TableCloth.CatalogBuilder/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using SixLabors.ImageSharp.Formats.Png;
using System.Collections.Concurrent;
using System.IO.Compression;
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using System.Xml;
using System.Xml.Schema;
Expand Down Expand Up @@ -38,6 +36,7 @@ static void AppMain(string[] args)

ConvertSiteLogoImagesIntoIconFiles(logWriter, targetDirectory);
CreateImageResourceZipFile(logWriter, targetDirectory);
GenerateWin32RCFile(logWriter, targetDirectory);
ValidatingCatalogSchemaFile(logWriter, targetDirectory, true);

logWriter.WriteLine(Console.Out, "Info: Catalog builder runs with succeed result.");
Expand Down Expand Up @@ -293,6 +292,37 @@ static void ConvertSiteLogoImagesIntoIconFiles(TextWriter logWriter, string targ
}
}

static void GenerateWin32RCFile(TextWriter logWriter, string targetDirectory)
{
var imageDirectory = Path.Combine(targetDirectory, "images");
logWriter.WriteLine(Console.Out, $"Info: Investigating directory `{imageDirectory}`...");

var icoFiles = Directory.GetFiles(imageDirectory, "*.ico", SearchOption.AllDirectories);
logWriter.WriteLine(Console.Out, $"Info: Found {icoFiles.Length} ico files in `{imageDirectory}` directory.");

var rcFilePath = Path.Combine(targetDirectory, "Catalog.rc");
logWriter.WriteLine(Console.Out, $"Info: Creating `{rcFilePath}` Win32 resource file...");

using (var rcWriter = new StreamWriter(File.OpenWrite(rcFilePath), Encoding.ASCII))
{
rcWriter.WriteLine($"// {Path.GetFileName(rcFilePath)}");
int count = 1;
foreach (var eachIcoFile in icoFiles)
{
var resourceName = Path.GetFileNameWithoutExtension(eachIcoFile)?.ToUpperInvariant();

if (string.IsNullOrWhiteSpace(resourceName))
resourceName = $"ICON_{count}";
else
resourceName = $"ICON_{resourceName}";

var relativePath = Path.GetRelativePath(imageDirectory, eachIcoFile);
rcWriter.WriteLine($"{resourceName} ICON {relativePath}");
count++;
}
}
}

// https://stackoverflow.com/questions/21387391/how-to-convert-an-image-to-an-icon-without-losing-transparency
static void ConvertImageToIcon(string sourceImageFilePath, string targetIconFilePath)
{
Expand Down

0 comments on commit b6781e2

Please sign in to comment.