Skip to content

Commit 4dcee8b

Browse files
committed
initial version of fetching Security warnings from Releases API. (displays orange outline in version column, with tooltip). #GITBUILD
1 parent 600fd17 commit 4dcee8b

File tree

5 files changed

+109
-23
lines changed

5 files changed

+109
-23
lines changed

UnityLauncherPro/Data/Project.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Globalization;
34
using System.Windows.Data;
45

56
namespace UnityLauncherPro
67
{
7-
public class Project : IValueConverter
8+
public class Project : IValueConverter, INotifyPropertyChanged
89
{
910
public string Title { set; get; }
1011
public string Version { set; get; }
@@ -18,6 +19,19 @@ public class Project : IValueConverter
1819
public bool folderExists { set; get; }
1920
public string SRP { set; get; } // Scriptable Render Pipeline, TODO add version info?
2021

22+
//public string InfoLabel { set; get; } // this is additional info from Releases API (like vulnerabilities..)
23+
private string _infoLabel;
24+
public string InfoLabel
25+
{
26+
get => _infoLabel;
27+
set
28+
{
29+
if (_infoLabel == value) return;
30+
_infoLabel = value;
31+
OnPropertyChanged(nameof(InfoLabel));
32+
}
33+
}
34+
2135
// WPF keeps calling this method from AppendFormatHelper, GetNameCore..? not sure if need to return something else or default would be faster?
2236
public override string ToString()
2337
{
@@ -41,5 +55,8 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
4155
{
4256
throw new NotSupportedException();
4357
}
58+
59+
public event PropertyChangedEventHandler PropertyChanged;
60+
protected void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
4461
}
4562
}

UnityLauncherPro/Data/UnityInstallation.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
using System;
2+
using System.ComponentModel;
23
using System.Windows.Data;
34

45
namespace UnityLauncherPro
56
{
6-
public class UnityInstallation : IValueConverter
7+
public class UnityInstallation : IValueConverter, INotifyPropertyChanged
78
{
89
public string Version { set; get; }
910
public long VersionCode { set; get; } // version as number, cached for sorting
@@ -15,7 +16,19 @@ public class UnityInstallation : IValueConverter
1516
public bool IsPreferred { set; get; }
1617
public string ReleaseType { set; get; } // Alpha, Beta, LTS.. TODO could be enum
1718

18-
public string InfoLabel { set; get; } // this is additional info from Releases API (like vulnerabilities..)
19+
//public string InfoLabel { set; get; } // this is additional info from Releases API (like vulnerabilities..)
20+
21+
private string _infoLabel;
22+
public string InfoLabel
23+
{
24+
get => _infoLabel;
25+
set
26+
{
27+
if (_infoLabel == value) return;
28+
_infoLabel = value;
29+
OnPropertyChanged(nameof(InfoLabel));
30+
}
31+
}
1932

2033
// https://stackoverflow.com/a/5551986/5452781
2134
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
@@ -30,7 +43,7 @@ public object Convert(object value, Type targetType, object parameter, System.Gl
3043
//Console.WriteLine("checking version: "+version);
3144
if (checkInfoLabel && string.IsNullOrEmpty(InfoLabel) == false)
3245
{
33-
Console.WriteLine("Contains warning: "+version);
46+
Console.WriteLine("Contains warning: " + version);
3447
return -1; // has warning
3548
}
3649
else
@@ -49,5 +62,9 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
4962
throw new NotSupportedException();
5063
}
5164

65+
// status label results are ready
66+
public event PropertyChangedEventHandler PropertyChanged;
67+
protected void OnPropertyChanged(string name) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
68+
5269
}
5370
}

UnityLauncherPro/MainWindow.xaml

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
<!-- Tab: Projects-->
5050
<TabItem Header="Projects" Style="{DynamicResource TabItemStyle1}" Padding="0,0,0,0" Margin="-1,1,1,-1" BorderBrush="{x:Null}">
5151
<Grid>
52-
<Grid.ColumnDefinitions>
53-
<ColumnDefinition Width="185*"/>
54-
<ColumnDefinition Width="693*"/>
55-
</Grid.ColumnDefinitions>
5652
<!-- search box -->
5753
<Grid Background="{DynamicResource ThemeTextBoxBackground}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="222" Margin="6,5,0,0" Height="20" Grid.ColumnSpan="2" >
5854
<!--<TextBlock Margin="3,2" MinWidth="100" Text="Search" Foreground="{DynamicResource ThemeSearchPlaceholder}" Visibility="{Binding Text.IsEmpty, Converter={StaticResource MyBoolToVisibilityConverter}, ElementName=txtSearchBox}" Height="24" />-->
@@ -117,19 +113,41 @@
117113
<DataGridTextColumn.CellStyle>
118114
<Style TargetType="{x:Type DataGridCell}">
119115
<Setter Property="Foreground" Value="{DynamicResource ThemeGridRedText}" />
120-
<Setter Property="BorderBrush" Value="{x:Null}" />
116+
<Setter Property="BorderBrush" Value="Orange" />
121117
<Style.Triggers>
122118
<DataTrigger Binding="{Binding Version, Converter={StaticResource VersionInstalledConverter}}" Value="1">
123119
<Setter Property="Foreground" Value="{DynamicResource ThemeGridGreenText}" />
124-
<Setter Property="BorderBrush" Value="{x:Null}" />
120+
<!--<Setter Property="BorderBrush" Value="{x:Null}" />-->
125121
</DataTrigger>
126122
<DataTrigger Binding="{Binding Version, Converter={StaticResource VersionInstalledConverter}}" Value="-1">
127123
<Setter Property="Foreground" Value="{DynamicResource ThemeGridGreenText}" />
128-
<Setter Property="BorderBrush" Value="Orange" />
124+
<!--<Setter Property="BorderBrush" Value="Orange" />-->
125+
</DataTrigger>
126+
<DataTrigger Binding="{Binding InfoLabel, IsAsync=True}" Value="{x:Null}">
127+
<Setter Property="BorderBrush" Value="{x:Null}" />
129128
</DataTrigger>
130129
</Style.Triggers>
131130
</Style>
132131
</DataGridTextColumn.CellStyle>
132+
<DataGridTextColumn.ElementStyle>
133+
<Style TargetType="TextBlock">
134+
<Setter Property="ToolTip">
135+
<Setter.Value>
136+
<ToolTip>
137+
<TextBlock Text="{Binding InfoLabel, IsAsync=True}" TextWrapping="Wrap" MaxWidth="480"/>
138+
</ToolTip>
139+
</Setter.Value>
140+
</Setter>
141+
<Style.Triggers>
142+
<DataTrigger Binding="{Binding InfoLabel}" Value="{x:Null}">
143+
<Setter Property="ToolTip" Value="{x:Null}"/>
144+
</DataTrigger>
145+
<DataTrigger Binding="{Binding InfoLabel}" Value="">
146+
<Setter Property="ToolTip" Value="{x:Null}"/>
147+
</DataTrigger>
148+
</Style.Triggers>
149+
</Style>
150+
</DataGridTextColumn.ElementStyle>
133151
</DataGridTextColumn>
134152
<!--CellStyle="{StaticResource NoFocusCellStyle"}-->
135153
<DataGridTextColumn Header="Path" x:Name="txtColumnPath" Binding="{Binding Path}" ClipboardContentBinding="{x:Null}" IsReadOnly="True" Width="185">
@@ -368,7 +386,23 @@
368386
</DataGridTextColumn.ElementStyle>
369387
</DataGridTextColumn>
370388

371-
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="90"/>
389+
<DataGridTextColumn Binding="{Binding Version}" ClipboardContentBinding="{x:Null}" Header="Version" IsReadOnly="True" MinWidth="90">
390+
<DataGridTextColumn.HeaderTemplate>
391+
<DataTemplate>
392+
<TextBlock Text="Version" IsHitTestVisible="False" />
393+
</DataTemplate>
394+
</DataGridTextColumn.HeaderTemplate>
395+
<DataGridTextColumn.CellStyle>
396+
<Style TargetType="{x:Type DataGridCell}">
397+
<Setter Property="BorderBrush" Value="Orange" />
398+
<Style.Triggers>
399+
<DataTrigger Binding="{Binding InfoLabel, IsAsync=True}" Value="{x:Null}">
400+
<Setter Property="BorderBrush" Value="{x:Null}" />
401+
</DataTrigger>
402+
</Style.Triggers>
403+
</Style>
404+
</DataGridTextColumn.CellStyle>
405+
</DataGridTextColumn>
372406
<DataGridTextColumn Header="Release" Binding="{Binding ReleaseType}" IsReadOnly="True" CanUserResize="False" MinWidth="50" />
373407
<DataGridTextColumn Binding="{Binding PlatformsCombined}" ClipboardContentBinding="{x:Null}" Header="Platforms" IsReadOnly="True"/>
374408
<DataGridTextColumn Binding="{Binding Installed, StringFormat=\{0:dd/MM/yyyy HH:mm:ss\}}" ClipboardContentBinding="{x:Null}" Header="Installed" IsReadOnly="True"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4125,6 +4125,11 @@ private void chkFetchAdditionalInfo_Checked(object sender, RoutedEventArgs e)
41254125
Settings.Default.Save();
41264126
}
41274127

4128+
private void gridRecent_SelectionChanged(object sender, SelectionChangedEventArgs e)
4129+
{
4130+
4131+
}
4132+
41284133
//private void menuProjectProperties_Click(object sender, RoutedEventArgs e)
41294134
//{
41304135
// var proj = GetSelectedProject();

UnityLauncherPro/Tools.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,7 +2925,7 @@ private static async Task FetchImplAsync()
29252925
{
29262926
foreach (var version in MainWindow.unityInstalledVersions.Keys)
29272927
{
2928-
Console.WriteLine("******** Fetching " + version);
2928+
//Console.WriteLine("******** Fetching " + version);
29292929

29302930
var url = $"https://services.api.unity.com/unity/editor/release/v1/releases?order=RELEASE_DATE_DESC&limit=1&version={Uri.EscapeDataString(version)}";
29312931

@@ -2953,17 +2953,30 @@ private static async Task FetchImplAsync()
29532953
//Console.WriteLine(label.description);
29542954

29552955
var u = MainWindow.unityInstallationsSource.FirstOrDefault(x => x.Version == version);
2956-
u.InfoLabel = label.labelText;
2957-
// replace old item in list
2956+
2957+
string infoText = label.labelText + "\n" + label.description; ;
2958+
2959+
u.InfoLabel = infoText;
29582960

29592961
int index = MainWindow.unityInstallationsSource.IndexOf(u);
29602962
if (index >= 0)
29612963
{
29622964
MainWindow.unityInstallationsSource[index] = u;
29632965
}
29642966

2965-
SetStatus($"Info for {version}: {label.labelText}");
2966-
Console.WriteLine("got infolabel for "+version);
2967+
// update all projectsSource items with this version too
2968+
foreach (var p in MainWindow.projectsSource)
2969+
{
2970+
if (p.Version == version)
2971+
{
2972+
p.InfoLabel = infoText;
2973+
}
2974+
}
2975+
2976+
2977+
2978+
//SetStatus($"Info for {version}: {label.labelText}");
2979+
//Console.WriteLine("got infolabel for " + version);
29672980
}
29682981
}
29692982

@@ -2974,7 +2987,7 @@ private static async Task FetchImplAsync()
29742987
}
29752988

29762989
// delay
2977-
await Task.Delay(5000).ConfigureAwait(false);
2990+
await Task.Delay(500).ConfigureAwait(false);
29782991

29792992
} // foreach version
29802993
}
@@ -3053,11 +3066,11 @@ private static UnityEditorInfoLabel ExtractLabelText(string json)
30533066
if (json[i] == '\"' && json[i - 1] != '\\') break;
30543067

30553068
if (i > qStart)
3056-
label.description = json.Substring(qStart, i - qStart)
3057-
.Replace("\\\"", "\"")
3058-
.Replace("\\n", "\n")
3059-
.Replace("\\r", "\r")
3060-
.Replace("\\t", "\t");
3069+
{
3070+
label.description = json.Substring(qStart, i - qStart).Replace("\\\"", "\"").Replace("\\n", "\n").Replace("\\r", "\r").Replace("\\t", "\t");
3071+
// strip HTML tags for now
3072+
label.description = System.Text.RegularExpressions.Regex.Replace(label.description, "<.*?>", string.Empty);
3073+
}
30613074
}
30623075
}
30633076

0 commit comments

Comments
 (0)