add windows build support

This commit is contained in:
Denys Konovalov 2024-09-14 23:22:12 +02:00
parent 4bd93fa87e
commit a115f37c95
8 changed files with 138 additions and 7 deletions

1
.gitignore vendored

@ -3,6 +3,7 @@
project.lock.json project.lock.json
.DS_Store .DS_Store
*.pyc *.pyc
*.exe
nupkg/ nupkg/
# Visual Studio Code # Visual Studio Code

74
Photomator.nsi Normal file

@ -0,0 +1,74 @@
Unicode true
!include "MUI2.nsh"
!include "x64.nsh"
!include "nsDialogs.nsh"
!include "FileFunc.nsh"
Function .onInit
${If} ${RunningX64}
# 64 bit code
SetRegView 64
${Else}
# 32 bit code
MessageBox MB_OK "Photomator unterstützt nur 64-Bit-Systeme."
Abort
${EndIf}
FunctionEnd
!define ARP "Software\Microsoft\Windows\CurrentVersion\Uninstall\Photomator"
Name "Photomator"
OutFile "photomator-setup.exe"
BrandingText "Copyright (c) 2024 Denys Konovalov"
InstallDir "$PROGRAMFILES\GCG\Photomator"
RequestExecutionLevel admin
!insertmacro MUI_LANGUAGE "German"
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
Section "Install"
SetOutPath $INSTDIR
File /nonfatal /a /r "Photomator\bin\Release\net8.0\win-x64\publish\"
CreateShortcut "$SMPROGRAMS\Photomator.lnk" "$INSTDIR\bin\Photomator.exe"
WriteUninstaller "$INSTDIR\Uninstall.exe"
${GetSize} "$INSTDIR" "/S=0K" $0 $1 $2
IntFmt $0 "0x%08X" $0
WriteRegDWORD HKLM "${ARP}" "EstimatedSize" "$0"
WriteRegStr HKLM "${ARP}" "DisplayName" "Photomator"
WriteRegStr HKLM "${ARP}" "InstallLocation" "$\"$INSTDIR$\""
WriteRegStr HKLM "${ARP}" "Publisher" "Georg-Cantor-Gymnasium Halle (Saale)"
WriteRegStr HKLM "${ARP}" "VersionMajor" "0"
WriteRegStr HKLM "${ARP}" "VersionMinor" "01"
WriteRegStr HKLM "${ARP}" "UninstallString" "$\"$INSTDIR\Uninstall.exe$\""
SectionEnd
Section "uninstall"
SetRegView 64
Delete "$SMPROGRAMS\Photomator.lnk"
Delete "$INSTDIR\Uninstall.exe"
RMDir /R "$INSTDIR\bin\"
RMDir /R "$INSTDIR\lib\"
RMDir /R "$INSTDIR\share\"
DeleteRegKey HKLM "${ARP}"
RMDir /R $INSTDIR
SectionEnd

@ -1,10 +1,25 @@
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Webp; using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using System.Runtime.InteropServices;
namespace Photomator; namespace Photomator;
public static class Lib { public static class Lib {
const int SW_HIDE = 0;
const int SW_SHOW = 5;
readonly static IntPtr handle = GetConsoleWindow();
[DllImport("kernel32.dll")] static extern IntPtr GetConsoleWindow();
[DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd,int nCmdShow);
public static void HideConsole() {
ShowWindow(handle,SW_HIDE);
}
public static void ShowConsole() {
ShowWindow(handle,SW_SHOW);
}
public static async Task Convert(string src, string dest, ConvertOptions options) { public static async Task Convert(string src, string dest, ConvertOptions options) {
Image img = await Image.LoadAsync(src); Image img = await Image.LoadAsync(src);
img.Mutate(i => { img.Mutate(i => {

@ -5,6 +5,8 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<SelfContained>true</SelfContained>
<ApplicationIcon>Resources\de.cantorgymnasium.Photomator.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -17,8 +19,26 @@
</ItemGroup> </ItemGroup>
<Target Name="PreBuild" BeforeTargets="PreBuildEvent"> <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
<Exec Command="echo Compiling extra resources..." /> <RemoveDir Directories="$(PublishDir)" />
<Message Text="=== Compiling extra resources... ===" Importance="high"/>
<Exec Command="glib-compile-resources --sourcedir ./Resources ./Resources/de.cantorgymnasium.Photomator.gresource.xml --target=$(OutDir)/de.cantorgymnasium.Photomator.gresource" /> <Exec Command="glib-compile-resources --sourcedir ./Resources ./Resources/de.cantorgymnasium.Photomator.gresource.xml --target=$(OutDir)/de.cantorgymnasium.Photomator.gresource" />
<Message Text="=== Done ===" Importance="high"/>
</Target> </Target>
<Target Name="CopyFiles" AfterTargets="Publish" Condition="'$(RuntimeIdentifier)' == 'win-x64'">
<Message Text="=== Copying Gtk files for win-x65 runtime ===" Importance="high"/>
<ItemGroup>
<SourceFiles Include="$(PublishDir)\**\*.*" />
<GtkDlls Include="libgtk-4-1.dll;libadwaita-1-0.dll;libappstream-5.dll;libbrotlicommon.dll;libbrotlidec.dll;libbz2-1.dll;libcairo-2.dll;libcairo-gobject-2.dll;libcairo-script-interpreter-2.dll;libcrypto-3-x64.dll;libcurl-4.dll;libdatrie-1.dll;libdeflate.dll;libepoxy-0.dll;libexpat-1.dll;libffi-8.dll;libfontconfig-1.dll;libfreetype-6.dll;libfribidi-0.dll;libgcc_s_seh-1.dll;libgdk_pixbuf-2.0-0.dll;libgio-2.0-0.dll;libglib-2.0-0.dll;libgmodule-2.0-0.dll;libgobject-2.0-0.dll;libgraphene-1.0-0.dll;libgraphite2.dll;libharfbuzz-0.dll;libharfbuzz-gobject-0.dll;libiconv-2.dll;libidn2-0.dll;libintl-8.dll;libjbig-0.dll;libjpeg-8.dll;libLerc.dll;liblzma-5.dll;liblzo2-2.dll;libnghttp2-14.dll;libnghttp3-9.dll;libpango-1.0-0.dll;libpangocairo-1.0-0.dll;libpangoft2-1.0-0.dll;libpangowin32-1.0-0.dll;libpcre2-8-0.dll;libpixman-1-0.dll;libpng16-16.dll;libpsl-5.dll;librsvg-2-2.dll;libsharpyuv-0.dll;libssh2-1.dll;libssl-3-x64.dll;libstdc++-6.dll;libthai-0.dll;libtiff-6.dll;libunistring-5.dll;libwebp-7.dll;libwinpthread-1.dll;libxml2-2.dll;libxmlb-2.dll;libyaml-0-2.dll;libzstd.dll;zlib1.dll;gdbus.exe"/>
<Icons Include="C:\msys64\mingw64\share\icons\**\*.*" />
</ItemGroup>
<Move SourceFiles="@(SourceFiles)" DestinationFolder="$(PublishDir)\bin" />
<Copy SourceFiles="$(OutDir)/de.cantorgymnasium.Photomator.gresource" DestinationFolder="$(PublishDir)\share\de.cantorgymnasium.Photomator" />
<Copy SourceFiles="@(GtkDlls->'C:\msys64\mingw64\bin\%(Filename)%(Extension)')" DestinationFolder="$(PublishDir)\bin" />
<Copy SourceFiles="C:\msys64\mingw64\lib\gdk-pixbuf-2.0\2.10.0\loaders\libpixbufloader-svg.dll" DestinationFolder="$(PublishDir)\lib\gdk-pixbuf-2.0\2.10.0\loaders" />
<Copy SourceFiles=".\Resources\loaders.cache" DestinationFolder="$(PublishDir)\lib\gdk-pixbuf-2.0\2.10.0" />
<Copy SourceFiles="C:\msys64\mingw64\share\glib-2.0\schemas\gschemas.compiled" DestinationFolder="$(PublishDir)\share\glib-2.0\schemas" />
<Copy SourceFiles="@(Icons)" DestinationFolder="$(PublishDir)\share\icons\%(RecursiveDir)" />
<Message Text="=== Done ===" Importance="high"/>
</Target>
</Project> </Project>

@ -11,10 +11,12 @@ public partial class Program {
public static int Main() => new Program().Run(); public static int Main() => new Program().Run();
public Program() { public Program() {
Lib.HideConsole();
_application = Adw.Application.New("de.cantorgymnasium.Photomator", Gio.ApplicationFlags.FlagsNone); _application = Adw.Application.New("de.cantorgymnasium.Photomator", Gio.ApplicationFlags.FlagsNone);
Gtk.Window.SetDefaultIconName("de.cantorgymnasium.Photomator"); Gtk.Window.SetDefaultIconName("de.cantorgymnasium.Photomator");
if (File.Exists(Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!) + "/de.cantorgymnasium.Photomator.gresource")) string localPath = Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!) + "/de.cantorgymnasium.Photomator.gresource";
Gio.Functions.ResourcesRegister(Gio.Functions.ResourceLoad(Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!) + "/de.cantorgymnasium.Photomator.gresource")); if (File.Exists(localPath))
Gio.Functions.ResourcesRegister(Gio.Functions.ResourceLoad(localPath));
else { else {
var prefixes = new List<string> { var prefixes = new List<string> {
Directory.GetParent(Directory.GetParent(Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!))!.FullName)!.FullName, Directory.GetParent(Directory.GetParent(Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!))!.FullName)!.FullName,

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

@ -0,0 +1,7 @@
"lib\\gdk-pixbuf-2.0\\2.10.0\\loaders\\libpixbufloader-svg.dll"
"svg" 6 "gdk-pixbuf" "Scalable Vector Graphics" "LGPL"
"image/svg+xml" "image/svg" "image/svg-xml" "image/vnd.adobe.svg+xml" "text/xml-svg" "image/svg+xml-compressed" ""
"svg" "svgz" "svg.gz" ""
" <svg" "* " 100
" <!DOCTYPE svg" "* " 100

@ -1,6 +1,8 @@
using Gtk; using Gtk;
using Adw; using Adw;
using System.Text; using System.Text;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace Photomator.Views; namespace Photomator.Views;
@ -71,8 +73,13 @@ public partial class StatusDialog : Adw.Window {
Button btnOpen = Button.NewWithLabel("Ordner öffnen"); Button btnOpen = Button.NewWithLabel("Ordner öffnen");
btnOpen.OnClicked += async (_, _) => { btnOpen.OnClicked += async (_, _) => {
FileLauncher fileLauncher = FileLauncher.New(Gio.FileHelper.NewForPath(dest)); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
await fileLauncher.LaunchAsync(_mainWindow); FileLauncher fileLauncher = FileLauncher.New(Gio.FileHelper.NewForPath(dest));
await fileLauncher.LaunchAsync(_mainWindow);
} else {
Process.Start("explorer.exe", @$"{dest}");
}
Close(); Close();
}; };
btnOpen.SetCssClasses(["pill", "suggested-action"]); btnOpen.SetCssClasses(["pill", "suggested-action"]);
@ -102,8 +109,13 @@ public partial class StatusDialog : Adw.Window {
if (convertErrors.Length < number) { if (convertErrors.Length < number) {
Button btnOpen = Button.NewWithLabel("Ordner öffnen"); Button btnOpen = Button.NewWithLabel("Ordner öffnen");
btnOpen.OnClicked += async (_, _) => { btnOpen.OnClicked += async (_, _) => {
FileLauncher fileLauncher = FileLauncher.New(Gio.FileHelper.NewForPath(dest)); if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) {
await fileLauncher.LaunchAsync(_mainWindow); FileLauncher fileLauncher = FileLauncher.New(Gio.FileHelper.NewForPath(dest));
await fileLauncher.LaunchAsync(_mainWindow);
} else {
Process.Start("explorer.exe", @$"{dest}");
}
Close(); Close();
}; };
btnOpen.SetCssClasses(["pill", "suggested-action"]); btnOpen.SetCssClasses(["pill", "suggested-action"]);