diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 4c57030..e888168 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,38 +1,50 @@ -name: Deploy Docs to GitHub Pages with Catalog Builder Tool - -on: - push: - branches: - - main - paths: - - '.github/workflows/**' - - 'docs/**' - - 'src/**' - -jobs: - deploy: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - # Setup .NET Core SDK - - name: Setup .NET Core - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.0.x - - # Build Catalog Builder tool - - name: Build Catalog Builder Tool - run: dotnet build src/TableCloth.CatalogBuilder/TableCloth.CatalogBuilder.csproj --configuration Release - - # Run Catalog Builder tool - - name: Run Catalog Builder Tool - run: dotnet run --project src/TableCloth.CatalogBuilder/TableCloth.CatalogBuilder.csproj --configuration Release -- ./docs/ ./outputs/ - - # Deploy to GitHub Pages - - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 - with: - github_token: ${{ secrets.GITHUB_TOKEN }} - publish_dir: ./outputs - publish_branch: gh-pages +name: Deploy Docs to GitHub Pages with Catalog Builder Tool + +on: + push: + branches: + - main + paths: + - '.github/workflows/**' + - 'docs/**' + - 'src/**' + +jobs: + deploy: + 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 + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.0.x + + # Build Catalog Builder tool + - name: Build Catalog Builder Tool + run: dotnet build src/TableCloth.CatalogBuilder/TableCloth.CatalogBuilder.csproj --configuration Release + + # Run Catalog Builder tool + - name: Run Catalog Builder Tool + run: dotnet run --project src/TableCloth.CatalogBuilder/TableCloth.CatalogBuilder.csproj --configuration Release -- ./docs/ ./outputs/ + + # Build Win32 Icon Library DLL + - name: Build Win32 Icon Library DLL + run: | + /usr/bin/x86_64-w64-mingw32-windres -i ./outputs/Catalog.rc -o ./outputs/Catalog.o + /usr/bin/x86_64-w64-mingw32-gcc -shared -mwindows -L -lcreate -o ./outputs/Catalog.dll ./outputs/Catalog.o + rm ./outputs/Catalog.rc + rm ./outputs/Catalog.o + + # Deploy to GitHub Pages + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./outputs + publish_branch: gh-pages diff --git a/src/TableCloth.CatalogBuilder/Program.cs b/src/TableCloth.CatalogBuilder/Program.cs index d0a6653..8c917bb 100644 --- a/src/TableCloth.CatalogBuilder/Program.cs +++ b/src/TableCloth.CatalogBuilder/Program.cs @@ -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; @@ -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."); @@ -293,6 +292,72 @@ 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( + """ + #include + + """); + int count = 1; + foreach (var eachIcoFile in icoFiles) + { + var resourceName = Path.GetFileNameWithoutExtension(eachIcoFile)?.ToUpperInvariant(); + + if (string.IsNullOrWhiteSpace(resourceName)) + resourceName = $"IDI_ICON_{count}"; + else + resourceName = $"IDI_{resourceName}"; + + var relativePath = Path.GetRelativePath(targetDirectory, eachIcoFile); + rcWriter.WriteLine($"{resourceName} ICON \"{relativePath}\""); + count++; + } + rcWriter.WriteLine( + """ + VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION 1,0,0,0 + FILEFLAGSMASK 0x3fL + FILEFLAGS 0x0L + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L + BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "CompanyName", "rkttu.com\0" + VALUE "FileDescription", "Catalog Icon Library for Win32 applications\0" + VALUE "FileVersion", "1.0.0.0\0" + VALUE "InternalName", "Catalog.dll\0" + VALUE "LegalCopyright", "(c) rkttu.com, All rights reserved.\0" + VALUE "OriginalFilename", "Catalog.dll\0" + VALUE "ProductName", "TableCloth\0" + VALUE "ProductVersion", "1.0.0.0\0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END + END + """); + } +} + // https://stackoverflow.com/questions/21387391/how-to-convert-an-image-to-an-icon-without-losing-transparency static void ConvertImageToIcon(string sourceImageFilePath, string targetIconFilePath) {