Skip to content

Commit fa6210a

Browse files
committed
add Run Unity, adding Upgrade project window, add project upgrade,
1 parent e62edb8 commit fa6210a

File tree

6 files changed

+218
-9
lines changed

6 files changed

+218
-9
lines changed

UnityLauncherPro/MainWindow.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,10 +367,10 @@
367367
<Grid.RowDefinitions>
368368
<RowDefinition Height="32" />
369369
</Grid.RowDefinitions>
370-
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnUpgradeProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="5,0,0,0" BorderBrush="{x:Null}">
370+
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnUpgradeProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="5,0,0,0" BorderBrush="{x:Null}" Click="BtnUpgradeProject_Click">
371371
<Label Foreground="{DynamicResource ButtonForeground}">_Upgrade</Label>
372372
</Button>
373-
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnLaunchUnity" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" >
373+
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnLaunchUnity" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnLaunchUnity_Click" >
374374
<Label Foreground="{DynamicResource ButtonForeground}">_Run Unity</Label>
375375
</Button>
376376

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 81 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ void LaunchProject(Project proj)
385385

386386

387387
// we dont have this version installed (or no version info available)
388-
var unityExePath = GetSelectedUnityExePath(proj.Version);
388+
var unityExePath = GetUnityExePath(proj.Version);
389389
if (unityExePath == null)
390390
{
391391
Console.WriteLine("Missing unity version " + proj.Version);
@@ -440,7 +440,7 @@ void LaunchProject(Project proj)
440440
}
441441

442442

443-
string GetSelectedUnityExePath(string version)
443+
string GetUnityExePath(string version)
444444
{
445445
return unityInstalledVersions.ContainsKey(version) ? unityInstalledVersions[version] : null;
446446
}
@@ -483,7 +483,86 @@ private void BtnRefreshProjectList_Click(object sender, RoutedEventArgs e)
483483
gridRecent.ItemsSource = projectsSource;
484484
}
485485

486+
// run unity only
487+
private void BtnLaunchUnity_Click(object sender, RoutedEventArgs e)
488+
{
489+
var proj = GetSelectedProject();
490+
var unitypath = GetUnityExePath(proj?.Version);
491+
Tools.LaunchExe(unitypath);
492+
}
493+
494+
private void BtnUpgradeProject_Click(object sender, RoutedEventArgs e)
495+
{
496+
var proj = GetSelectedProject();
497+
if (proj == null) return;
498+
499+
DisplayUpgradeDialog(proj);
500+
}
486501

502+
void DisplayUpgradeDialog(Project proj)
503+
{
504+
UpgradeWindow modalWindow = new UpgradeWindow(proj.Version, proj.Path, proj.Arguments);
505+
modalWindow.Owner = this;
506+
modalWindow.ShowDialog();
507+
var results = modalWindow.DialogResult.HasValue && modalWindow.DialogResult.Value;
508+
509+
if (results == true)
510+
{
511+
var upgradeToVersion = UpgradeWindow.upgradeVersion;
512+
if (string.IsNullOrEmpty(upgradeToVersion)) return;
513+
514+
// get selected version to upgrade for
515+
Console.WriteLine("Upgrade to " + upgradeToVersion);
516+
517+
// inject new version for this item
518+
proj.Version = upgradeToVersion;
519+
LaunchProject(proj);
520+
}
521+
else
522+
{
523+
Console.WriteLine("results = " + results);
524+
}
525+
526+
527+
/*
528+
// display upgrade dialog (version selector)
529+
Form2 upgradeDialog = new Form2();
530+
Form2.currentVersion = currentVersion;
531+
532+
// check what user selected
533+
var results = upgradeDialog.ShowDialog(this);
534+
switch (results)
535+
{
536+
case DialogResult.Ignore: // view release notes page
537+
Tools.OpenReleaseNotes(currentVersion);
538+
// display window again for now..
539+
DisplayUpgradeDialog(currentVersion, projectPath, launchProject, commandLineArguments);
540+
break;
541+
case DialogResult.Cancel: // cancelled
542+
SetStatus("Cancelled project upgrade");
543+
break;
544+
case DialogResult.Retry: // download and install missing version
545+
SetStatus("Download and install missing version " + currentVersion);
546+
string url = Tools.GetUnityReleaseURL(currentVersion);
547+
if (string.IsNullOrEmpty(url) == false)
548+
{
549+
DownloadInBrowser(url, currentVersion);
550+
}
551+
else
552+
{
553+
SetStatus("Failed getting Unity Installer URL");
554+
}
555+
break;
556+
case DialogResult.Yes: // upgrade
557+
SetStatus("Upgrading project to " + Form2.currentVersion);
558+
if (launchProject == true) LaunchProject(projectPath, Form2.currentVersion);
559+
break;
560+
default:
561+
Console.WriteLine("Unknown DialogResult: " + results);
562+
break;
563+
}
564+
upgradeDialog.Close();*/
565+
}
487566

488567
} // class
489568
} //namespace

UnityLauncherPro/Tools.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,18 +127,28 @@ public static void ExploreProjectFolder(Project proj)
127127
// opens Explorer to target folder
128128
public static bool LaunchExplorer(string folder)
129129
{
130-
bool result = false;
131130
if (Directory.Exists(folder) == true)
132131
{
133132
Process.Start(folder);
134-
result = true;
133+
return true;
135134
}
136-
else
135+
return false;
136+
}
137+
138+
// run any exe
139+
public static bool LaunchExe(string path)
140+
{
141+
if (string.IsNullOrEmpty(path)) return false;
142+
143+
if (File.Exists(path) == true)
137144
{
138-
result = false;
145+
Process.Start(path);
146+
return true;
139147
}
140-
return result;
148+
return false;
141149
}
142150

151+
152+
143153
} // class
144154
} // namespace

UnityLauncherPro/UnityLauncherPro.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@
8282
<Compile Include="Tools.cs" />
8383
<Compile Include="Data\UnityInstallation.cs" />
8484
<Compile Include="Data\Updates.cs" />
85+
<Compile Include="UpgradeWindow.xaml.cs">
86+
<DependentUpon>UpgradeWindow.xaml</DependentUpon>
87+
</Compile>
8588
<Page Include="Resources\Colors.xaml">
8689
<SubType>Designer</SubType>
8790
<Generator>MSBuild:Compile</Generator>
@@ -98,6 +101,10 @@
98101
<DependentUpon>MainWindow.xaml</DependentUpon>
99102
<SubType>Code</SubType>
100103
</Compile>
104+
<Page Include="UpgradeWindow.xaml">
105+
<SubType>Designer</SubType>
106+
<Generator>MSBuild:Compile</Generator>
107+
</Page>
101108
</ItemGroup>
102109
<ItemGroup>
103110
<Compile Include="Data\Project.cs" />

UnityLauncherPro/UpgradeWindow.xaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<Window x:Class="UnityLauncherPro.UpgradeWindow"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
5+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:local="clr-namespace:UnityLauncherPro"
7+
mc:Ignorable="d"
8+
Title="Upgrade Project Version" Height="533.165" Width="418.684" Background="{DynamicResource DarkestBackground}" MinWidth="319" MinHeight="555" ResizeMode="NoResize" ShowInTaskbar="False" WindowStartupLocation="CenterOwner" HorizontalAlignment="Left" VerticalAlignment="Top">
9+
<Window.Resources>
10+
<!-- custom buttons -->
11+
<Style x:Key="CustomButton" TargetType="{x:Type Button}">
12+
<Setter Property="SnapsToDevicePixels" Value="true"/>
13+
<Setter Property="OverridesDefaultStyle" Value="true"/>
14+
<Setter Property="Template">
15+
<Setter.Value>
16+
<ControlTemplate TargetType="{x:Type Button}">
17+
<Border x:Name="shortcutbutton" BorderThickness="0" BorderBrush="Black" Background="{TemplateBinding Background}">
18+
<ContentPresenter Margin="0" HorizontalAlignment="Center" VerticalAlignment="Center" RecognizesAccessKey="True"/>
19+
</Border>
20+
<ControlTemplate.Triggers>
21+
<Trigger Property="IsMouseOver" Value="true">
22+
<Setter TargetName="shortcutbutton" Property="Background" Value="#FF494949" />
23+
<!--<Setter Property="TextElement.Foreground" TargetName="shortcutbutton" Value="Blue"/>-->
24+
</Trigger>
25+
<Trigger Property="IsPressed" Value="true">
26+
<Setter TargetName="shortcutbutton" Property="Background" Value="#FF0F0F0F" />
27+
<!--<Setter Property="TextElement.Foreground" TargetName="shortcutbutton" Value="Red"/>-->
28+
</Trigger>
29+
</ControlTemplate.Triggers>
30+
</ControlTemplate>
31+
</Setter.Value>
32+
</Setter>
33+
</Style>
34+
35+
</Window.Resources>
36+
<Grid>
37+
<Label x:Name="lblCurrentVersion" Content="Project Current Version" HorizontalAlignment="Left" Margin="9,11,0,0" VerticalAlignment="Top" Foreground="{DynamicResource ButtonForeground}" Width="139"/>
38+
<TextBox MinWidth="100" CaretBrush="#FFE2E2E2" x:Name="txtCurrentVersion" Background="{DynamicResource DarkMenuBar}" BorderBrush="{x:Null}" Foreground="#FFC7C7C7" SelectionBrush="#FF003966" BorderThickness="0" Margin="173,16,37,0" UndoLimit="64" Text="Version" IsReadOnly="True" VerticalAlignment="Top" />
39+
40+
<Label x:Name="lblAvailableVersions" Content="Available Unity Versions" HorizontalAlignment="Left" Margin="9,94,0,0" VerticalAlignment="Top" Foreground="{DynamicResource ButtonForeground}"/>
41+
<Button Style="{StaticResource CustomButton}" x:Name="btnDownload" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="0,47,8,0" BorderBrush="{x:Null}" HorizontalAlignment="Right" VerticalAlignment="Top" Height="35" >
42+
<Label Foreground="{DynamicResource ButtonForeground}" Content="_Download in Browser"/>
43+
</Button>
44+
<Button Style="{StaticResource CustomButton}" x:Name="btnOpenReleasePage" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="9,47,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="35" >
45+
<Label Foreground="{DynamicResource ButtonForeground}" Content="_Open Release Page"/>
46+
</Button>
47+
<Button Style="{StaticResource CustomButton}" x:Name="btnCancelUpgrade" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="9,434,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" Width="111" VerticalAlignment="Top" Height="51" Click="BtnCancelUpgrade_Click" >
48+
<Label Foreground="{DynamicResource ButtonForeground}" Content="_Cancel"/>
49+
</Button>
50+
<Button Style="{StaticResource CustomButton}" x:Name="btnUpgradeProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="0,434,8,0" BorderBrush="{x:Null}" HorizontalAlignment="Right" Width="159" VerticalAlignment="Top" Height="51" Click="BtnUpgradeProject_Click" >
51+
<Label Foreground="{DynamicResource ButtonForeground}" Content="_Upgrade Project"/>
52+
</Button>
53+
<DataGrid x:Name="gridAvailableVersions" SelectionMode="Single" HorizontalAlignment="Left" Height="304" Margin="10,121,0,0" VerticalAlignment="Top" Width="393" HeadersVisibility="None" AutoGenerateColumns="False">
54+
<DataGrid.Columns>
55+
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True" />
56+
<DataGridTextColumn Header="Value" Binding="{Binding Value}" IsReadOnly="True" />
57+
</DataGrid.Columns>
58+
</DataGrid>
59+
60+
</Grid>
61+
</Window>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Data;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace UnityLauncherPro
10+
{
11+
/// <summary>
12+
/// Interaction logic for UpgradeWindow.xaml
13+
/// </summary>
14+
public partial class UpgradeWindow : Window
15+
{
16+
17+
public static string upgradeVersion = null;
18+
19+
public UpgradeWindow(string currentVersion, string projectPath, string commandLineArguments = null)
20+
{
21+
InitializeComponent();
22+
23+
txtCurrentVersion.Text = currentVersion;
24+
25+
gridAvailableVersions.ItemsSource = MainWindow.unityInstalledVersions;
26+
27+
//lstUnityVersionsForUpgrade.Items.Clear();
28+
//lstUnityVersionsForUpgrade.Items.Add(MainWindow.unityInstalledVersions.ToArray());
29+
30+
//lstUnityVersionsForUpgrade.ItemsSource = MainWindow.unityInstalledVersions;
31+
//lstUnityVersionsForUpgrade.DataValueField = "Key";
32+
//lstUnityVersionsForUpgrade.DataTextField = "Value";
33+
//lstUnityVersionsForUpgrade.DataBind();
34+
35+
}
36+
37+
38+
39+
private void BtnUpgradeProject_Click(object sender, RoutedEventArgs e)
40+
{
41+
var k = (gridAvailableVersions.SelectedItem) as KeyValuePair<string, string>?;
42+
//Console.WriteLine(k.Value.Key);
43+
upgradeVersion = k.Value.Key;
44+
DialogResult = true;
45+
}
46+
47+
private void BtnCancelUpgrade_Click(object sender, RoutedEventArgs e)
48+
{
49+
DialogResult = false;
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)