Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 248ec5e

Browse files
committedSep 8, 2017
fix missing statusbar, fix crash if no downloadassist url in html page, adding upgrade project dialog (not finished)
1 parent c3936f4 commit 248ec5e

File tree

7 files changed

+443
-46
lines changed

7 files changed

+443
-46
lines changed
 

‎UnityLauncher/Form1.Designer.cs

Lines changed: 52 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎UnityLauncher/Form1.cs

Lines changed: 83 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace UnityLauncher
1515
public partial class Form1 : Form
1616
{
1717
// version,exe path (example: 5.6.1f1,c:\prog\unity561\editor\unity.exe)
18-
Dictionary<string, string> unityList = new Dictionary<string, string>();
18+
public static Dictionary<string, string> unityList = new Dictionary<string, string>();
1919

2020
const int settingsTabIndex = 3;
2121
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
@@ -296,8 +296,8 @@ void LaunchProject(string pathArg = null, bool openProject = true)
296296
var version = GetProjectVersion(pathArg);
297297
//Console.WriteLine("Detected project version: " + version);
298298

299-
bool installed = HaveExactVersionInstalled(version);
300-
if (installed == true)
299+
bool haveExactVersion = HaveExactVersionInstalled(version);
300+
if (haveExactVersion == true)
301301
{
302302
//Console.WriteLine("Opening unity version " + version);
303303
SetStatus("Launching project in unity " + version);
@@ -370,8 +370,15 @@ string GetDownloadUrlForUnityVersion(string releaseUrl)
370370
string html = client.DownloadString(releaseUrl);
371371
Regex regex = new Regex(@"(http).+(UnityDownloadAssistant)+[^\s*]*(.exe)");
372372
Match match = regex.Match(html);
373-
url = match.Groups[0].Captures[0].Value;
374-
Console.WriteLine(url);
373+
if (match.Success == true)
374+
{
375+
url = match.Groups[0].Captures[0].Value;
376+
// Console.WriteLine(url);
377+
}
378+
else
379+
{
380+
SetStatus("Cannot find UnityDownloadAssistant.exe for this version..");
381+
}
375382
}
376383
return url;
377384
}
@@ -825,6 +832,76 @@ private void btnRunUnityOnly_Click(object sender, EventArgs e)
825832
LaunchSelectedProject(openProject: false);
826833
}
827834

828-
#endregion
835+
private void btnUpgradeProject_Click(object sender, EventArgs e)
836+
{
837+
UpgradeProject();
838+
}
839+
#endregion UI events
840+
841+
842+
public static string FindNearestVersion(string version, List<string> allAvailable)
843+
{
844+
if (version.Contains("2017"))
845+
{
846+
return FindNearestVersionFromSimilarVersions(version, allAvailable.Where(x => x.Contains("2017")));
847+
}
848+
return FindNearestVersionFromSimilarVersions(version, allAvailable.Where(x => !x.Contains("2017")));
849+
}
850+
851+
private static string FindNearestVersionFromSimilarVersions(string version, IEnumerable<string> allAvailable)
852+
{
853+
Dictionary<string, string> stripped = new Dictionary<string, string>();
854+
var enumerable = allAvailable as string[] ?? allAvailable.ToArray();
855+
856+
foreach (var t in enumerable)
857+
{
858+
stripped.Add(new Regex("[a-zA-z]").Replace(t, "."), t);
859+
}
860+
861+
var comparableVersion = new Regex("[a-zA-z]").Replace(version, ".");
862+
if (!stripped.ContainsKey(comparableVersion))
863+
{
864+
stripped.Add(comparableVersion, version);
865+
Console.WriteLine(comparableVersion + " : " + version);
866+
}
867+
868+
var comparables = stripped.Keys.OrderBy(x => x).ToList();
869+
var actualIndex = comparables.IndexOf(comparableVersion);
870+
871+
if (actualIndex < stripped.Count) return stripped[comparables[actualIndex + 1]];
872+
return null;
873+
}
874+
875+
void UpgradeProject()
876+
{
877+
var selected = gridRecent.CurrentCell.RowIndex;
878+
if (selected > -1)
879+
{
880+
SetStatus("Upgrading project..");
881+
882+
var path = gridRecent.Rows[selected].Cells["_path"].Value.ToString();
883+
var currentVersion = GetProjectVersion(path);
884+
885+
bool haveExactVersion = HaveExactVersionInstalled(currentVersion);
886+
if (haveExactVersion == true)
887+
{
888+
// you already have same version, are you sure?
889+
}
890+
891+
Form2 upgradeDialog = new Form2();
892+
Form2.currentVersion = currentVersion;
893+
894+
if (upgradeDialog.ShowDialog(this) == DialogResult.OK)
895+
{
896+
// yes, upgrade
897+
}
898+
else
899+
{
900+
// cancelled
901+
}
902+
upgradeDialog.Close();
903+
904+
}
905+
}
829906
}
830907
}

‎UnityLauncher/Form1.resx

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121-
<value>376, 18</value>
120+
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
121+
<value>14, 20</value>
122122
</metadata>
123123
<metadata name="_project.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
124124
<value>True</value>
@@ -156,9 +156,6 @@
156156
<metadata name="_unityPath.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
157157
<value>True</value>
158158
</metadata>
159-
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
160-
<value>14, 20</value>
161-
</metadata>
162159
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
163160
<value>111, 20</value>
164161
</metadata>
@@ -1051,8 +1048,8 @@
10511048
AAA=
10521049
</value>
10531050
</data>
1054-
<metadata name="toolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
1055-
<value>14, 20</value>
1051+
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
1052+
<value>492, 18</value>
10561053
</metadata>
10571054
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
10581055
<value>43</value>

‎UnityLauncher/Form2.Designer.cs

Lines changed: 123 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎UnityLauncher/Form2.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Windows.Forms;
10+
11+
namespace UnityLauncher
12+
{
13+
public partial class Form2 : Form
14+
{
15+
public static string currentVersion = "";
16+
17+
public Form2()
18+
{
19+
InitializeComponent();
20+
}
21+
22+
private void Form2_Load(object sender, EventArgs e)
23+
{
24+
// fill textbox
25+
txtUpgradeCurrentVersion.Text = currentVersion;
26+
27+
// update unity installations list
28+
lstUnityVersions.Items.AddRange(Form1.unityList.Keys.ToArray());
29+
30+
// show available versions, autoselect nearest one
31+
if (string.IsNullOrEmpty(currentVersion) == false)
32+
{
33+
string nearestVersion = Form1.FindNearestVersion(currentVersion, Form1.unityList.Keys.ToList());
34+
Console.WriteLine("nearest:" + nearestVersion);
35+
36+
// preselect most likely version
37+
int likelyIndex = lstUnityVersions.FindString(currentVersion);
38+
if (likelyIndex > -1)
39+
{
40+
lstUnityVersions.SetSelected(likelyIndex, true);
41+
}
42+
}
43+
else // we dont know current version
44+
{
45+
46+
}
47+
}
48+
}
49+
}

‎UnityLauncher/Form2.resx

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<root>
3+
<!--
4+
Microsoft ResX Schema
5+
6+
Version 2.0
7+
8+
The primary goals of this format is to allow a simple XML format
9+
that is mostly human readable. The generation and parsing of the
10+
various data types are done through the TypeConverter classes
11+
associated with the data types.
12+
13+
Example:
14+
15+
... ado.net/XML headers & schema ...
16+
<resheader name="resmimetype">text/microsoft-resx</resheader>
17+
<resheader name="version">2.0</resheader>
18+
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
19+
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
20+
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
21+
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
22+
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
23+
<value>[base64 mime encoded serialized .NET Framework object]</value>
24+
</data>
25+
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
26+
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
27+
<comment>This is a comment</comment>
28+
</data>
29+
30+
There are any number of "resheader" rows that contain simple
31+
name/value pairs.
32+
33+
Each data row contains a name, and value. The row also contains a
34+
type or mimetype. Type corresponds to a .NET class that support
35+
text/value conversion through the TypeConverter architecture.
36+
Classes that don't support this are serialized and stored with the
37+
mimetype set.
38+
39+
The mimetype is used for serialized objects, and tells the
40+
ResXResourceReader how to depersist the object. This is currently not
41+
extensible. For a given mimetype the value must be set accordingly:
42+
43+
Note - application/x-microsoft.net.object.binary.base64 is the format
44+
that the ResXResourceWriter will generate, however the reader can
45+
read any of the formats listed below.
46+
47+
mimetype: application/x-microsoft.net.object.binary.base64
48+
value : The object must be serialized with
49+
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
50+
: and then encoded with base64 encoding.
51+
52+
mimetype: application/x-microsoft.net.object.soap.base64
53+
value : The object must be serialized with
54+
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
55+
: and then encoded with base64 encoding.
56+
57+
mimetype: application/x-microsoft.net.object.bytearray.base64
58+
value : The object must be serialized into a byte array
59+
: using a System.ComponentModel.TypeConverter
60+
: and then encoded with base64 encoding.
61+
-->
62+
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
63+
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
64+
<xsd:element name="root" msdata:IsDataSet="true">
65+
<xsd:complexType>
66+
<xsd:choice maxOccurs="unbounded">
67+
<xsd:element name="metadata">
68+
<xsd:complexType>
69+
<xsd:sequence>
70+
<xsd:element name="value" type="xsd:string" minOccurs="0" />
71+
</xsd:sequence>
72+
<xsd:attribute name="name" use="required" type="xsd:string" />
73+
<xsd:attribute name="type" type="xsd:string" />
74+
<xsd:attribute name="mimetype" type="xsd:string" />
75+
<xsd:attribute ref="xml:space" />
76+
</xsd:complexType>
77+
</xsd:element>
78+
<xsd:element name="assembly">
79+
<xsd:complexType>
80+
<xsd:attribute name="alias" type="xsd:string" />
81+
<xsd:attribute name="name" type="xsd:string" />
82+
</xsd:complexType>
83+
</xsd:element>
84+
<xsd:element name="data">
85+
<xsd:complexType>
86+
<xsd:sequence>
87+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
88+
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
89+
</xsd:sequence>
90+
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
91+
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
92+
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
93+
<xsd:attribute ref="xml:space" />
94+
</xsd:complexType>
95+
</xsd:element>
96+
<xsd:element name="resheader">
97+
<xsd:complexType>
98+
<xsd:sequence>
99+
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
100+
</xsd:sequence>
101+
<xsd:attribute name="name" type="xsd:string" use="required" />
102+
</xsd:complexType>
103+
</xsd:element>
104+
</xsd:choice>
105+
</xsd:complexType>
106+
</xsd:element>
107+
</xsd:schema>
108+
<resheader name="resmimetype">
109+
<value>text/microsoft-resx</value>
110+
</resheader>
111+
<resheader name="version">
112+
<value>2.0</value>
113+
</resheader>
114+
<resheader name="reader">
115+
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
116+
</resheader>
117+
<resheader name="writer">
118+
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119+
</resheader>
120+
<metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
121+
<value>True</value>
122+
</metadata>
123+
</root>

‎UnityLauncher/UnityLauncher.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,20 @@
8181
<Compile Include="Form1.Designer.cs">
8282
<DependentUpon>Form1.cs</DependentUpon>
8383
</Compile>
84+
<Compile Include="Form2.cs">
85+
<SubType>Form</SubType>
86+
</Compile>
87+
<Compile Include="Form2.Designer.cs">
88+
<DependentUpon>Form2.cs</DependentUpon>
89+
</Compile>
8490
<Compile Include="Program.cs" />
8591
<Compile Include="Properties\AssemblyInfo.cs" />
8692
<EmbeddedResource Include="Form1.resx">
8793
<DependentUpon>Form1.cs</DependentUpon>
8894
</EmbeddedResource>
95+
<EmbeddedResource Include="Form2.resx">
96+
<DependentUpon>Form2.cs</DependentUpon>
97+
</EmbeddedResource>
8998
<EmbeddedResource Include="Properties\Resources.resx">
9099
<Generator>ResXFileCodeGenerator</Generator>
91100
<LastGenOutput>Resources.Designer.cs</LastGenOutput>

0 commit comments

Comments
 (0)
This repository has been archived.