Skip to content

Commit 29a928f

Browse files
committed
fix invaliddeployment exception (when loading online template images), fix current selected unity version when creating new empty project, #GITBUILD
1 parent 8e4b047 commit 29a928f

File tree

4 files changed

+60
-29
lines changed

4 files changed

+60
-29
lines changed

UnityLauncherPro/Data/OnlineTemplateItem.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.ComponentModel;
2+
using System.Windows.Media.Imaging;
23

34
namespace UnityLauncherPro.Data
45
{
@@ -11,6 +12,7 @@ public class OnlineTemplateItem : INotifyPropertyChanged
1112
public string RenderPipeline { get; set; }
1213
public string Type { get; set; } // Core, Learning, Sample,
1314
public string PreviewImageURL { get; set; }
15+
public BitmapImage PreviewImage { get; set; }
1416
public string TarBallURL { get; set; }
1517

1618
public bool IsDownloaded

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,9 @@ private void SaveSettingsOnExit()
866866

867867
public void UpdateUnityInstallationsList()
868868
{
869+
// keep currently selected row
870+
var currentSelection = GetSelectedUnity();
871+
869872
// Reset preferred string, if user changed it
870873
//preferredVersion = "none";
871874

@@ -886,8 +889,21 @@ public void UpdateUnityInstallationsList()
886889
}
887890

888891
lblFoundXInstallations.Content = "Found " + unityInstallationsSource.Count + " installations";
889-
890892
btnCreateEmptyProject.IsEnabled = unityInstallationsSource.Count > 0;
893+
894+
// try to select previous selection
895+
if (currentSelection != null)
896+
{
897+
for (int i = 0, len = unityInstallationsSource.Count; i < len; i++)
898+
{
899+
if (unityInstallationsSource[i].Version == currentSelection.Version && unityInstallationsSource[i].Path == currentSelection.Path)
900+
{
901+
dataGridUnitys.SelectedIndex = i;
902+
Tools.SetFocusToGrid(dataGridUnitys);
903+
break;
904+
}
905+
}
906+
}
891907
}
892908

893909
Project GetSelectedProject()
@@ -2100,7 +2116,19 @@ void CreateNewEmptyProject(string targetFolder = null)
21002116
}
21012117
}
21022118

2103-
// refresh unity installations
2119+
string newVersion = null;
2120+
2121+
// if in maintab
2122+
if (tabControl.SelectedIndex == 0)
2123+
{
2124+
newVersion = GetSelectedProject()?.Version == null ? preferredVersion : GetSelectedProject().Version;
2125+
}
2126+
else // unity tab
2127+
{
2128+
newVersion = (GetSelectedUnity() == null || GetSelectedUnity().Version == null) ? preferredVersion : GetSelectedUnity().Version;
2129+
}
2130+
2131+
// refresh unity installations (so that latest installs are listed)
21042132
UpdateUnityInstallationsList();
21052133

21062134
if (string.IsNullOrEmpty(initScriptFileFullPath) == true)
@@ -2111,25 +2139,12 @@ void CreateNewEmptyProject(string targetFolder = null)
21112139
// for new projects created from explorer, always ask for name
21122140
if (chkAskNameForQuickProject.IsChecked == true || targetFolder != null)
21132141
{
2114-
string newVersion = null;
2115-
2116-
// if in maintab
2117-
if (tabControl.SelectedIndex == 0)
2118-
{
2119-
newVersion = GetSelectedProject()?.Version == null ? preferredVersion : GetSelectedProject().Version;
2120-
}
2121-
else // unity tab
2122-
{
2123-
newVersion = (GetSelectedUnity() == null || GetSelectedUnity().Version == null) ? preferredVersion : GetSelectedUnity().Version;
2124-
}
2125-
21262142
if (string.IsNullOrEmpty(newVersion))
21272143
{
21282144
Console.WriteLine("Missing selected Unity version, probably launching from context menu");
21292145
newVersion = preferredVersion;
21302146
// if no preferred version, use latest
21312147
if (string.IsNullOrEmpty(newVersion)) newVersion = unityInstallationsSource[0].Version;
2132-
21332148
}
21342149

21352150
string suggestedName = targetFolder != null ? Path.GetFileName(targetFolder) : Tools.GetSuggestedProjectName(newVersion, rootFolder);
@@ -2164,22 +2179,10 @@ void CreateNewEmptyProject(string targetFolder = null)
21642179
}
21652180
else // use automatic name (project is instantly created, without asking anything)
21662181
{
2167-
string newVersion = null;
2168-
// if in maintab
2169-
if (tabControl.SelectedIndex == 0)
2170-
{
2171-
newVersion = GetSelectedProject().Version == null ? preferredVersion : GetSelectedProject().Version;
2172-
}
2173-
else // unity tab
2174-
{
2175-
newVersion = GetSelectedUnity().Version == null ? preferredVersion : GetSelectedUnity().Version;
2176-
}
21772182
var p = Tools.FastCreateProject(newVersion, rootFolder, null, null, null, null, (bool)chkUseInitScript.IsChecked, initScriptFileFullPath);
2178-
21792183
if (p != null) AddNewProjectToList(p);
21802184
}
2181-
2182-
}
2185+
} // CreateNewEmptyProject
21832186

21842187
private void ChkAskNameForQuickProject_Checked(object sender, RoutedEventArgs e)
21852188
{

UnityLauncherPro/NewProject.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<DataTemplate>
114114
<StackPanel Orientation="Vertical" Margin="3">
115115
<Grid>
116-
<Image Source="{Binding PreviewImageURL}"
116+
<Image Source="{Binding PreviewImage}"
117117
Margin="0,0,0,5"
118118
ToolTip="{Binding Description}"
119119
Stretch="Uniform"

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using System.Windows.Controls;
1111
using System.Windows.Input;
1212
using System.Windows.Media;
13+
using System.Windows.Media.Imaging;
1314
using UnityLauncherPro.Data;
1415
using UnityLauncherPro.Properties;
1516

@@ -524,6 +525,31 @@ private async Task LoadOnlineTemplatesAsync(string baseVersion, CancellationToke
524525

525526
var templates = ParseTemplatesFromJson(responseString);
526527

528+
// Download preview images to bypass WPF's ClickOnce security check on HTTPS URIs
529+
foreach (var template in templates)
530+
{
531+
if (cancellationToken.IsCancellationRequested) return;
532+
533+
try
534+
{
535+
if (!string.IsNullOrEmpty(template.PreviewImageURL) && !template.PreviewImageURL.StartsWith("pack://"))
536+
{
537+
var imageData = await client.GetByteArrayAsync(template.PreviewImageURL);
538+
var bitmap = new BitmapImage();
539+
bitmap.BeginInit();
540+
bitmap.CacheOption = BitmapCacheOption.OnLoad;
541+
bitmap.StreamSource = new MemoryStream(imageData);
542+
bitmap.EndInit();
543+
if (bitmap.CanFreeze) bitmap.Freeze();
544+
template.PreviewImage = bitmap;
545+
}
546+
}
547+
catch
548+
{
549+
// Failed to download preview image, leave PreviewImage as null
550+
}
551+
}
552+
527553
// Update UI on dispatcher thread only if not cancelled
528554
if (!cancellationToken.IsCancellationRequested)
529555
{

0 commit comments

Comments
 (0)