Skip to content

Commit d1bd18a

Browse files
committed
testing project thumbnail (loaded from ProjectSettings/icon.png, if exists) and displayed in projects Context menu #142
1 parent 2d69c9a commit d1bd18a

File tree

4 files changed

+83
-0
lines changed

4 files changed

+83
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Globalization;
3+
using System.IO;
4+
using System.Windows.Data;
5+
using System.Windows.Media.Imaging;
6+
7+
namespace UnityLauncherPro.Converters
8+
{
9+
public class ThumbnailConverter : IValueConverter
10+
{
11+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
12+
{
13+
if (value is Project project)
14+
{
15+
if (!string.IsNullOrEmpty(project.Path))
16+
{
17+
string thumbnailPath = Path.Combine(project.Path, "ProjectSettings", "icon.png");
18+
19+
if (File.Exists(thumbnailPath))
20+
{
21+
try
22+
{
23+
var bitmap = new BitmapImage();
24+
bitmap.BeginInit();
25+
bitmap.CacheOption = BitmapCacheOption.OnLoad;
26+
bitmap.CreateOptions = BitmapCreateOptions.IgnoreImageCache;
27+
bitmap.UriSource = new Uri(thumbnailPath, UriKind.Absolute);
28+
bitmap.DecodePixelWidth = 64; // Match your display size
29+
bitmap.DecodePixelHeight = 64;
30+
31+
bitmap.EndInit();
32+
33+
// Freeze for cross-thread access
34+
if (bitmap.CanFreeze)
35+
{
36+
bitmap.Freeze();
37+
}
38+
39+
return bitmap;
40+
}
41+
catch
42+
{
43+
// Ignore and fall back to null
44+
}
45+
}
46+
}
47+
return null;
48+
}
49+
50+
return null;
51+
}
52+
53+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
54+
{
55+
throw new NotImplementedException();
56+
}
57+
}
58+
}

UnityLauncherPro/MainWindow.xaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<converters:LastModifiedConverter x:Key="lastModifiedConverter"/>
1313
<converters:LastModifiedConverterTooltip x:Key="LastModifiedConverterTooltip"/>
1414
<converters:ReleaseDateConverter x:Key="releaseDateConverter"/>
15+
<converters:ThumbnailConverter x:Key="thumbnailConverter"/>
1516
</Window.Resources>
1617

1718
<!-- UI -->
@@ -258,6 +259,21 @@
258259
</MenuItem>
259260
<Separator/>
260261
<MenuItem x:Name="menuRemoveProject" Header="Remove from recent list" Click="MenuRemoveProject_Click" />
262+
<Separator/>
263+
<Image Margin="0,0,0,0" SnapsToDevicePixels="True" MouseDown="Image_MouseDown">
264+
<Image.Width>
265+
<Binding Path="PlacementTarget.SelectedItem" RelativeSource="{RelativeSource AncestorType=ContextMenu}"
266+
Converter="{StaticResource thumbnailConverter}" ConverterParameter="Width"/>
267+
</Image.Width>
268+
<Image.Height>
269+
<Binding Path="PlacementTarget.SelectedItem" RelativeSource="{RelativeSource AncestorType=ContextMenu}"
270+
Converter="{StaticResource thumbnailConverter}" ConverterParameter="Height"/>
271+
</Image.Height>
272+
<Image.Source>
273+
<Binding Path="PlacementTarget.SelectedItem" RelativeSource="{RelativeSource AncestorType=ContextMenu}"
274+
Converter="{StaticResource thumbnailConverter}"/>
275+
</Image.Source>
276+
</Image>
261277
<!--<MenuItem x:Name="menuProjectProperties" Header="Properties..." Click="menuProjectProperties_Click" />-->
262278
</ContextMenu>
263279
</DataGrid.ContextMenu>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4211,6 +4211,14 @@ private void gridRecent_SelectionChanged(object sender, SelectionChangedEventArg
42114211

42124212
}
42134213

4214+
private void Image_MouseDown(object sender, MouseButtonEventArgs e)
4215+
{
4216+
var proj = GetSelectedProject();
4217+
if (proj == null) return;
4218+
var thumbnailPath = Path.Combine(proj.Path, "ProjectSettings", "icon.png");
4219+
Tools.LaunchExe(thumbnailPath);
4220+
}
4221+
42144222
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
42154223
//{
42164224
// var proj = GetSelectedProject();

UnityLauncherPro/UnityLauncherPro.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
</ApplicationDefinition>
8686
<Compile Include="Converters\ReleaseDateConverter.cs" />
8787
<Compile Include="Converters\LastModifiedConverter.cs" />
88+
<Compile Include="Converters\ThumbnailConverter.cs" />
8889
<Compile Include="Data\BuildReport.cs" />
8990
<Compile Include="Data\BuildReportItem.cs" />
9091
<Compile Include="Data\DownloadProgress.cs" />

0 commit comments

Comments
 (0)