Skip to content

Commit

Permalink
Merge pull request #402 from GtkSharp/develop
Browse files Browse the repository at this point in the history
Merge branch Develop (3.24.24.93-develop) into Main
  • Loading branch information
lytico committed May 8, 2023
2 parents 4517554 + 82dc24c commit 964cb9c
Show file tree
Hide file tree
Showing 109 changed files with 3,066 additions and 371 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on: [push, pull_request]
jobs:
build:
runs-on: ${{ matrix.os }}
permissions:
packages: write
strategy:
matrix:
os: [ubuntu-20.04]
Expand All @@ -24,7 +26,11 @@ jobs:
GITHUB_ACTIONS: true
- uses: actions/upload-artifact@main
with:
name: Nuget Packages
name: NuGet Packages
path: |
BuildOutput/NugetPackages/**/*.nupkg
if-no-files-found: error
- name: Push NuGet to GitHub packages
run: dotnet nuget push BuildOutput/NugetPackages/**/*.nupkg --source https://nuget.pkg.github.com/$GITHUB_REPOSITORY_OWNER/index.json --api-key ${GITHUB_TOKEN}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
211 changes: 211 additions & 0 deletions CakeScripts/TargetEnvironment.cake
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
#addin "nuget:?package=Microsoft.Win32.Registry&version=5.0.0"
using System;
using D = System.IO.Directory;
using F = System.IO.File;
using P = System.IO.Path;
using Pr = System.Diagnostics.Process;
using PSI = System.Diagnostics.ProcessStartInfo;
using R = Microsoft.Win32.Registry;
using RI = System.Runtime.InteropServices.RuntimeInformation;
using Z = System.IO.Compression.ZipFile;

class TargetEnvironment
{
public static string DotNetInstallPath { get; private set; }
public static string DotNetInstalledWorkloadsMetadataPath { get; private set; }
public static string DotNetInstallerTypeMetadataPath { get; private set; }
public static string DotNetManifestPath { get; private set; }
public static string DotNetPacksPath { get; private set; }
public static string DotNetTemplatePacksPath { get; private set; }

public static string DotNetCliPath { get; private set; }
public static string DotNetCliFeatureBand { get; private set; }

static TargetEnvironment()
{
DotNetInstallPath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
if (DotNetInstallPath == null)
{
if (OperatingSystem.IsWindows())
{
DotNetInstallPath = P.Combine(Environment.GetEnvironmentVariable("ProgramFiles"), "dotnet");
}
else if (OperatingSystem.IsLinux())
{
DotNetInstallPath = "/usr/share/dotnet";
}
else if (OperatingSystem.IsMacOS())
{
DotNetInstallPath = "/usr/local/share/dotnet";
}
}

DotNetCliPath = P.Combine(DotNetInstallPath, "dotnet");

var proc = Pr.Start(new PSI()
{
FileName = DotNetCliPath,
Arguments = "--version",
RedirectStandardOutput = true,
});

proc.WaitForExit();

DotNetCliFeatureBand = proc.StandardOutput.ReadToEnd().Trim();
DotNetCliFeatureBand = DotNetCliFeatureBand.Substring(0, DotNetCliFeatureBand.Length - 2) + "00";

DotNetInstalledWorkloadsMetadataPath = P.Combine(DotNetInstallPath, "metadata", "workloads", DotNetCliFeatureBand, "InstalledWorkloads");
DotNetInstallerTypeMetadataPath = P.Combine(DotNetInstallPath, "metadata", "workloads", DotNetCliFeatureBand, "InstallerType");
DotNetManifestPath = P.Combine(DotNetInstallPath, "sdk-manifests", DotNetCliFeatureBand);
DotNetPacksPath = P.Combine(DotNetInstallPath, "packs");
DotNetTemplatePacksPath = P.Combine(DotNetInstallPath, "template-packs");
}

public static void RegisterInstalledWorkload(string workloadName)
{
D.CreateDirectory(DotNetInstalledWorkloadsMetadataPath);
F.WriteAllText(P.Combine(DotNetInstalledWorkloadsMetadataPath, workloadName), string.Empty);
if (F.Exists(P.Combine(DotNetInstallerTypeMetadataPath, "msi")))
{
//HKLM:\SOFTWARE\Microsoft\dotnet\InstalledWorkloads\Standalone\x64\6.0.300\gtk

// TODO: Check for other Windows architectures (x86 and arm64)
var archString = RI.OSArchitecture.ToString().ToLower();

var hklm = R.LocalMachine;
var software = hklm.CreateSubKey("SOFTWARE");
var microsoft = software.CreateSubKey("Microsoft");
var dotnet = microsoft.CreateSubKey("dotnet");
var installedWorkloads = dotnet.CreateSubKey("InstalledWorkloads");
var standalone = installedWorkloads.CreateSubKey("Standalone");
var arch = standalone.CreateSubKey(archString);
var version = arch.CreateSubKey(DotNetCliFeatureBand);
var workload = version.CreateSubKey(workloadName);

workload.Close();
version.Close();
arch.Close();
standalone.Close();
installedWorkloads.Close();
dotnet.Close();
microsoft.Close();
software.Close();
hklm.Close();
}
}

public static void UnregisterInstalledWorkload(string workloadName)
{
F.Delete(P.Combine(DotNetInstalledWorkloadsMetadataPath, workloadName));
if (F.Exists(P.Combine(DotNetInstallerTypeMetadataPath, "msi")))
{
var archString = RI.OSArchitecture.ToString().ToLower();

var hklm = R.LocalMachine;
var software = hklm.CreateSubKey("SOFTWARE");
var microsoft = software.CreateSubKey("Microsoft");
var dotnet = microsoft.CreateSubKey("dotnet");
var installedWorkloads = dotnet.CreateSubKey("InstalledWorkloads");
var standalone = installedWorkloads.CreateSubKey("Standalone");
var arch = standalone.CreateSubKey(archString);
var version = arch.CreateSubKey(DotNetCliFeatureBand);

version.DeleteSubKey(workloadName, false);

version.Close();
arch.Close();
standalone.Close();
installedWorkloads.Close();
dotnet.Close();
microsoft.Close();
software.Close();
hklm.Close();
}
}

public static void InstallManifests(string manifestName, string manifestPackPath)
{
var targetDirectory = P.Combine(DotNetManifestPath, manifestName);
var tempDirectory = P.Combine(targetDirectory, "temp");

// Delete existing installations to avoid conflict.
if (D.Exists(targetDirectory))
{
D.Delete(targetDirectory, true);
}

// Also creates the target
D.CreateDirectory(tempDirectory);

Z.ExtractToDirectory(manifestPackPath, tempDirectory);
var tempDataDirectory = P.Combine(tempDirectory, "data");

foreach (var filePath in D.GetFiles(tempDataDirectory))
{
var targetFilePath = P.Combine(targetDirectory, P.GetFileName(filePath));
F.Copy(filePath, targetFilePath, true);
}

D.Delete(tempDirectory, true);
}

public static void UninstallManifests(string manifestName)
{
var targetDirectory = P.Combine(DotNetManifestPath, manifestName);
if (D.Exists(targetDirectory))
{
D.Delete(targetDirectory, true);
}
}

public static void InstallPack(string name, string version, string packPath)
{
var targetDirectory = P.Combine(DotNetPacksPath, name, version);

if (D.Exists(targetDirectory))
{
D.Delete(targetDirectory, true);
}

D.CreateDirectory(targetDirectory);

Z.ExtractToDirectory(packPath, targetDirectory);
}

public static void UninstallPack(string name, string version)
{
var packInstallDirectory = P.Combine(DotNetPacksPath, name);

var targetDirectory = P.Combine(packInstallDirectory, version);
if (D.Exists(targetDirectory))
{
D.Delete(targetDirectory, true);
}

// Clean up the template if no other verions exist.
try
{
D.Delete(packInstallDirectory, false);
}
catch (System.IO.IOException)
{
// Silently fail. Mostly because the directory is not empty (there are other verions installed).
}
}

public static void InstallTemplatePack(string packName, string packPath)
{
D.CreateDirectory(DotNetTemplatePacksPath);
var targetPath = P.Combine(DotNetTemplatePacksPath, packName);
F.Copy(packPath, targetPath, true);
}

public static void UninstallTemplatePack(string packName)
{
var targetPath = P.Combine(DotNetTemplatePacksPath, packName);
if (F.Exists(targetPath))
{
F.Delete(targetPath);
}
}
}
12 changes: 12 additions & 0 deletions Source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project>
<PropertyGroup>
<_GtkSharpNetVersion>6.0</_GtkSharpNetVersion>
<_GtkSharpSourceDirectory>$(MSBuildThisFileDirectory)</_GtkSharpSourceDirectory>
<_GtkSharpBuildOutputDirectory>$(MSBuildThisFileDirectory)..\BuildOutput\</_GtkSharpBuildOutputDirectory>
</PropertyGroup>

<PropertyGroup>
<PackageProjectUrl>https://github.com/GtkSharp/GtkSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/GtkSharp/GtkSharp</RepositoryUrl>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions Source/Libs/CairoSharp/Context.cs
Original file line number Diff line number Diff line change
Expand Up @@ -737,13 +737,13 @@ public void TransformPoint (ref double x, ref double y)
[Obsolete("Use UserToDeviceDistance instead")]
public void TransformDistance (ref double dx, ref double dy)
{
UserToDevice (ref dx, ref dy);
UserToDeviceDistance (ref dx, ref dy);
}

[Obsolete("Use DeviceToUser instead")]
public void InverseTransformPoint (ref double x, ref double y)
{
UserToDevice (ref x, ref y);
DeviceToUser (ref x, ref y);
}

[Obsolete("Use DeviceToUserDistance instead")]
Expand Down
14 changes: 10 additions & 4 deletions Source/Libs/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />

<PropertyGroup>
<TargetFrameworks>net6.0;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net$(_GtkSharpNetVersion);netstandard2.0</TargetFrameworks>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PackageProjectUrl>https://github.com/GtkSharp/GtkSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/GtkSharp/GtkSharp</RepositoryUrl>
<OutputPath>..\..\..\BuildOutput\$(Configuration)</OutputPath>
<OutputPath>$(_GtkSharpBuildOutputDirectory)\$(Configuration)</OutputPath>
<!--
Microsoft.DotNet.SharedFramework.Sdk requires our framework assemblies to be signed
(to have a "public key token")
-->
<SignAssembly>True</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)\GtkSharp.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
</Project>
6 changes: 3 additions & 3 deletions Source/Libs/GLibSharp/GType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ public static Type LookupType (IntPtr typeid)
// in a patch from bug #400595, and a desire to keep memory usage low
// by avoiding a complete loading of all dependent assemblies.
string ns = type_name.Substring (0, type_name.LastIndexOf ('.'));
string asm_name = ns.ToLower ().Replace ('.', '-') + "-sharp";
string asm_name = ns.Replace (".", "") + "Sharp";
foreach (Assembly asm in assemblies) {
foreach (AssemblyName ref_name in asm.GetReferencedAssemblies ()) {
if (ref_name.Name != asm_name)
continue;
try {
string asm_dir = Path.GetDirectoryName (asm.Location);
string asm_dir = Path.GetDirectoryName (asm.Location); // will be null or empty for single file publish
Assembly ref_asm;
if (File.Exists (Path.Combine (asm_dir, ref_name.Name + ".dll")))
if (!string.IsNullOrEmpty (asm_dir) && File.Exists (Path.Combine (asm_dir, ref_name.Name + ".dll")))
ref_asm = Assembly.LoadFrom (Path.Combine (asm_dir, ref_name.Name + ".dll"));
else
ref_asm = Assembly.Load (ref_name);
Expand Down
14 changes: 6 additions & 8 deletions Source/Libs/GLibSharp/IOChannel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,14 +185,12 @@ public void Dispose ()

public uint AddWatch (int priority, IOCondition condition, IOFunc func)
{
IOFuncWrapper func_wrapper = null;
IntPtr user_data = IntPtr.Zero;
DestroyNotify notify = null;
if (func != null) {
func_wrapper = new IOFuncWrapper (func);
user_data = (IntPtr) GCHandle.Alloc (func_wrapper);
notify = DestroyHelper.NotifyHandler;
}
if (func == null)
return 0;

IOFuncWrapper func_wrapper = new IOFuncWrapper (func);
IntPtr user_data = (IntPtr) GCHandle.Alloc (func_wrapper);
DestroyNotify notify = DestroyHelper.NotifyHandler;
return g_io_add_watch_full (Handle, priority, (int) condition, func_wrapper.NativeDelegate, user_data, notify);
}

Expand Down

0 comments on commit 964cb9c

Please sign in to comment.