-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathUpgradeWindow.xaml.cs
More file actions
155 lines (130 loc) · 5 KB
/
Copy pathUpgradeWindow.xaml.cs
File metadata and controls
155 lines (130 loc) · 5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace UnityLauncherPro
{
/// <summary>
/// Interaction logic for UpgradeWindow.xaml
/// </summary>
public partial class UpgradeWindow : Window
{
public static string upgradeVersion = null;
public UpgradeWindow(string currentVersion, string projectPath, string commandLineArguments = null)
{
InitializeComponent();
txtCurrentVersion.Text = currentVersion;
txtCurrentPlatform.Text = Tools.GetTargetPlatform(projectPath);
if (gridAvailableVersions.ItemsSource == null)
{
gridAvailableVersions.ItemsSource = MainWindow.unityInstallationsSource;
}
gridAvailableVersions.SelectedItem = null;
// we have current version info in project
// enable release and dl buttons
btnOpenReleasePage.IsEnabled = true;
btnDownload.IsEnabled = true;
// if dont have exact version, show red outline
if (MainWindow.unityInstalledVersions.ContainsKey(currentVersion) == false)
{
txtCurrentVersion.BorderBrush = Brushes.Red;
txtCurrentVersion.BorderThickness = new Thickness(1);
}
// find nearest version
string nearestVersion = Tools.FindNearestVersion(currentVersion, MainWindow.unityInstalledVersions.Keys.ToList());
if (nearestVersion != null)
{
// select nearest version
for (int i = 0; i < MainWindow.unityInstallationsSource.Count; i++)
{
if (MainWindow.unityInstallationsSource[i].Version == nearestVersion)
{
gridAvailableVersions.SelectedIndex = i;
gridAvailableVersions.ScrollIntoView(gridAvailableVersions.SelectedItem);
break;
}
}
}
gridAvailableVersions.Focus();
}
private void BtnUpgradeProject_Click(object sender, RoutedEventArgs e)
{
Upgrade();
}
private void BtnCancelUpgrade_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
private void BtnOpenReleasePage_Click(object sender, RoutedEventArgs e)
{
Tools.OpenReleaseNotes(txtCurrentVersion.Text);
}
private void BtnDownloadEditor_Click(object sender, RoutedEventArgs e)
{
Tools.DownloadInBrowser(txtCurrentVersion.Text);
}
private void BtnDownload_Click(object sender, RoutedEventArgs e)
{
Tools.DownloadInBrowser(txtCurrentVersion.Text);
}
private void btnInstall_Click(object sender, RoutedEventArgs e)
{
Tools.DownloadAndInstall(txtCurrentVersion.Text);
}
private void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
// override Enter for datagrid
if (e.Key == Key.Return && e.KeyboardDevice.Modifiers == ModifierKeys.None)
{
e.Handled = true;
var k = (UnityInstallation)gridAvailableVersions.SelectedItem;
upgradeVersion = k.Version;
DialogResult = true;
return;
}
else // other keys
{
switch (e.Key)
{
case Key.Escape:
DialogResult = false;
break;
default:
break;
}
}
base.OnKeyDown(e);
}
private void GridAvailableVersions_PreviewKeyDown(object sender, KeyEventArgs e)
{
Tools.HandleDataGridScrollKeys(sender, e);
}
private void GridAvailableVersions_Loaded(object sender, RoutedEventArgs e)
{
Tools.SetFocusToGrid(gridAvailableVersions);
// bolded for current item
DataGridRow row = (DataGridRow)((DataGrid)sender).ItemContainerGenerator.ContainerFromIndex(gridAvailableVersions.SelectedIndex);
if (row == null) return;
row.Foreground = Brushes.White;
row.FontWeight = FontWeights.Bold;
}
private void GridAvailableVersions_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var src = VisualTreeHelper.GetParent((DependencyObject)e.OriginalSource);
var srcType = src.GetType();
if (srcType == typeof(ContentPresenter))
{
Upgrade();
}
}
void Upgrade()
{
var k = (UnityInstallation)gridAvailableVersions.SelectedItem;
upgradeVersion = k.Version;
DialogResult = true;
}
}
}