Skip to content
This repository was archived by the owner on May 19, 2021. It is now read-only.

Commit 248ec5e

Browse files
committed
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>

0 commit comments

Comments
 (0)