diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3a9e3da..7248422 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,73 +1,89 @@ -name: Build and Package - -on: [push] - -permissions: - contents: write - -jobs: - - # Build artifacts - build: - runs-on: windows-latest - - steps: - - name: Checkout - uses: actions/checkout@v4 - - # We need dotnet - - name: Add dotnet - uses: actions/setup-dotnet@v4 - with: - dotnet-version: 8.x - - - name: Setup NuGet - uses: NuGet/setup-nuget@v1 - - - name: Restore NuGet Packages - run: nuget restore artwork4DMD.sln - - # Build artifacts when git tag - - if: startsWith(github.ref, 'refs/tags/') - name: Build - run: | - dotnet publish -r win-x64 --self-contained=false /p:PublishSingleFile=true artwork4dmd.csproj /p:Version=${{ github.ref_name }} - - - if: "!startsWith(github.ref, 'refs/tags/')" - name: Build - run: | - dotnet publish -r win-x64 --self-contained=false /p:PublishSingleFile=true artwork4dmd.csproj - tree - - # Upload artifacts - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: artwork4DMD - path: .\bin\Release\net8.0-windows\win-x64\publish - retention-days: 7 - - - name: Generate zip bundle - run: | - 7z a -tzip artwork4DMD.zip .\bin\Release\net8.0-windows\win-x64\publish\* - - - if: github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true - name: Publish latest pre-release - uses: ncipollo/release-action@v1 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - generateReleaseNotes: true - prerelease: true - artifacts: | - artwork4DMD.zip - - - if: startsWith(github.ref, 'refs/tags/') - name: Publish tagged release - uses: ncipollo/release-action@v1 - with: - token: "${{ secrets.GITHUB_TOKEN }}" - generateReleaseNotes: true - prerelease: false - allowUpdates: true - artifacts: | - artwork4DMD.zip +name: Build and Package + +on: [push] + +permissions: + contents: write + +jobs: + build-windows: + runs-on: windows-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: | + if ('${{ startsWith(github.ref, 'refs/tags/') }}' -eq 'true') { + dotnet publish -r win-x64 -c Release /p:Version=${{ github.ref_name }} + } else { + dotnet publish -r win-x64 -c Release + } + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: artwork4dmd-windows + path: .\bin\Release\net8.0\win-x64\publish\ + retention-days: 7 + + build-linux: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup .NET + uses: actions/setup-dotnet@v4 + with: + dotnet-version: 8.x + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: | + if [[ ${{ github.ref }} == refs/tags/* ]]; then + dotnet publish -r linux-x64 -c Release /p:Version=${{ github.ref_name }} + else + dotnet publish -r linux-x64 -c Release + fi + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: artwork4dmd-linux + path: ./bin/Release/net8.0/linux-x64/publish/ + + create-release: + needs: [build-windows, build-linux] + runs-on: ubuntu-latest + if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')) + steps: + - name: Download Windows artifact + uses: actions/download-artifact@v4 + with: + name: artwork4dmd-windows + + - name: Download Linux artifact + uses: actions/download-artifact@v4 + with: + name: artwork4dmd-linux + + - name: Create Release + uses: ncipollo/release-action@v1 + with: + token: "${{ secrets.GITHUB_TOKEN }}" + generateReleaseNotes: true + prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }} + allowUpdates: true + artifacts: "artwork4dmd-windows.zip,artwork4dmd-linux.zip" + tag: ${{ startsWith(github.ref, 'refs/tags/') && github.ref_name || format('v{0}', github.sha) }} diff --git a/Program.cs b/Program.cs index 2c3b36c..bd5ad09 100644 --- a/Program.cs +++ b/Program.cs @@ -40,6 +40,7 @@ using System.Net; using System.Threading; using System.Collections.ObjectModel; +using System.Runtime.InteropServices; class Program { @@ -79,6 +80,12 @@ public sealed class Settings public static Settings gSettings; static async Task Main(string[] args) { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + // Set the MAGICK_HOME environment variable to the directory containing ImageMagick libraries + Environment.SetEnvironmentVariable("MAGICK_HOME", AppDomain.CurrentDomain.BaseDirectory); + } + string iniPath = Path.Combine(Environment.CurrentDirectory, "settings.ini"); IConfigurationRoot config = new ConfigurationBuilder() .AddIniFile(iniPath) @@ -124,9 +131,10 @@ static async Task DownloadPicture(GameInfo game) { Directory.CreateDirectory($"{gSettings.OutputFolder}/orig/{game.Platform}"); // If overwrite config is false AND file already exist, then don't do anything - if ((gSettings.Overwrite == false) && File.Exists($"{gSettings.OutputFolder}\\orig\\{game.Platform}\\{game.Name}.png")) + string filePath = Path.Combine(gSettings.OutputFolder, "orig", game.Platform, $"{game.Name}.png"); + if ((gSettings.Overwrite == false) && File.Exists(filePath)) { - Console.WriteLine($"Skipping download of {gSettings.OutputFolder}\\orig\\{game.Platform}\\{game.Name}.png because it already exists"); + Console.WriteLine($"Skipping download of {filePath} because it already exists"); return; } if (game.Name.Contains(":")) { @@ -338,7 +346,7 @@ static void ConvertPicture(string inputPath, bool isGif) string outputPath = Path.Combine( gSettings.OutputFolder, $"{width}x{height}", - Path.GetDirectoryName(inputPath).Split('\\').Last(), + Path.GetFileName(Path.GetDirectoryName(inputPath)), $"{Path.GetFileNameWithoutExtension(inputPath)}{outputExtension}" ); //Console.WriteLine($"Converting {Path.GetFileName(inputPath)} to {Path.GetFileName(outputPath)}"); diff --git a/artwork4dmd.csproj b/artwork4dmd.csproj index 2417aac..d4be25b 100644 --- a/artwork4dmd.csproj +++ b/artwork4dmd.csproj @@ -2,8 +2,9 @@ Exe - net8.0-windows + net8.0 true + false true None true