Skip to content

Commit

Permalink
Merge pull request #682 from ztanczos/fix_relative_paths
Browse files Browse the repository at this point in the history
Fix handling relative paths in module manifests
  • Loading branch information
ztanczos authored Jun 12, 2024
2 parents aab5771 + 0bc5322 commit 1012b98
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace MorganStanley.ComposeUI.ModuleLoader;

public sealed class NativeManifestDetails
{
public Uri Path { get; init; }
public Uri Path { get; set; }
public Uri? Icon { get; init; }
public string[] Arguments { get; init; } = Array.Empty<string>();
public Dictionary<string, string> EnvironmentVariables { get; init; } = new Dictionary<string, string>();
Expand Down
17 changes: 10 additions & 7 deletions src/shell/dotnet/Shell/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using System.Windows;
using System.Windows.Controls.Ribbon;
using CommunityToolkit.Mvvm.ComponentModel;
using Infragistics.Windows.DockManager;
using MorganStanley.ComposeUI.ModuleLoader;
using MorganStanley.ComposeUI.Shell.ImageSource;
using MorganStanley.ComposeUI.Shell.Utilities;
Expand Down Expand Up @@ -112,14 +111,18 @@ public ModuleViewModel(IModuleManifest manifest, ImageSourceProvider imageSource
}
else if (manifest.TryGetDetails<NativeManifestDetails>(out var nativeManifestDetails))
{
using var icon =
System.Drawing.Icon.ExtractAssociatedIcon(Path.GetFullPath(nativeManifestDetails.Path.ToString()));

if (icon != null)
var path = nativeManifestDetails.Path.IsAbsoluteUri ? nativeManifestDetails.Path.AbsolutePath : nativeManifestDetails.Path.ToString();
if (File.Exists(path))
{
using var bitmap = icon.ToBitmap();
using var icon =
System.Drawing.Icon.ExtractAssociatedIcon(path);

if (icon != null)
{
using var bitmap = icon.ToBitmap();

ImageSource = bitmap.ToImageSource();
ImageSource = bitmap.ToImageSource();
}
}
}
}
Expand Down
26 changes: 21 additions & 5 deletions src/shell/dotnet/Shell/Modules/ModuleCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
using System.Text.Json;
Expand Down Expand Up @@ -60,11 +61,26 @@ public Task<IEnumerable<string>> GetModuleIds()
private async Task LoadFromFile(string path)
{
await using var stream = _fileSystem.File.OpenRead(path);
_modules = (await JsonSerializer.DeserializeAsync<ModuleManifest[]>(
stream,
JsonSerializerOptions))
?.ToDictionary(m => m.Id)
?? new Dictionary<string, ModuleManifest>();

var moduleManifests = await JsonSerializer.DeserializeAsync<ModuleManifest[]>(
stream,
JsonSerializerOptions);

if (moduleManifests == null)
{
_modules = [];
return;
}

foreach (var moduleManifest in moduleManifests.OfType<NativeModuleManifest>())
{
if (!moduleManifest.Details.Path.IsAbsoluteUri)
{
moduleManifest.Details.Path = new Uri(Path.GetFullPath(moduleManifest.Details.Path.ToString(), Path.GetDirectoryName(path)!));
}
}

_modules = moduleManifests.ToDictionary(m => m.Id);
}

internal void Add(ModuleManifest manifest)
Expand Down
2 changes: 1 addition & 1 deletion src/shell/dotnet/examples/module-catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"Name": "Diagnostics WPF",
"ModuleType": "native",
"Details": {
"Path": "..\\..\\..\\..\\..\\..\\..\\examples\\dotnet-diagnostics\\DiagnosticsExample\\bin\\Debug\\net6.0-windows\\DiagnosticsExample.exe",
"Path": "..\\..\\..\\..\\examples\\dotnet-diagnostics\\DiagnosticsExample\\bin\\Debug\\net6.0-windows\\DiagnosticsExample.exe",
"EnvironmentVariables": { "CUSTOM_GREETINGS": "Hello ComposeUI!" }
}
},
Expand Down

0 comments on commit 1012b98

Please sign in to comment.