Skip to content

Commit d0065b7

Browse files
committed
fix unity version number sorting, fix FindNearestVersion to properly get next available version: fixes #5, #build
1 parent aac1c6b commit d0065b7

File tree

4 files changed

+49
-49
lines changed

4 files changed

+49
-49
lines changed

Diff for: UnityLauncherPro/GetUnityInstallations.cs

+1-32
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ public static UnityInstallation[] Scan()
6565
} // got folders
6666
} // all root folders
6767

68-
// sort by unity version NOTE we might want to sort by install date also..
69-
results.Sort((s1, s2) => VersionAsFloat(s2.Version).CompareTo(VersionAsFloat(s1.Version)));
68+
results.Sort((s1, s2) => Tools.VersionAsInt(s2.Version).CompareTo(Tools.VersionAsInt(s1.Version)));
7069

7170
return results.ToArray();
7271
} // scan()
7372

74-
//static Dictionary<string, string> platformNames = new Dictionary<string, string> { windowsstandalonesupport};
7573
static string[] GetPlatforms(string dataFolder)
7674
{
7775
// get all folders inside
@@ -90,39 +88,10 @@ static string[] GetPlatforms(string dataFolder)
9088
{
9189
directories[i] = foldername;
9290
}
93-
//Console.WriteLine(directories[i]);
9491
}
9592

9693
return directories;
9794
}
9895

99-
// string to float 2017.4.1f1 > 2017.411
100-
static float VersionAsFloat(string version)
101-
{
102-
float result = 0;
103-
if (string.IsNullOrEmpty(version)) return result;
104-
105-
// remove a,b,f,p
106-
string cleanVersion = version.Replace("a", ".");
107-
cleanVersion = cleanVersion.Replace("b", ".");
108-
cleanVersion = cleanVersion.Replace("f", ".");
109-
cleanVersion = cleanVersion.Replace("p", ".");
110-
111-
// split values
112-
string[] splitted = cleanVersion.Split('.');
113-
if (splitted != null && splitted.Length > 0)
114-
{
115-
// get float
116-
float multiplier = 1;
117-
for (int i = 0, length = splitted.Length; i < length; i++)
118-
{
119-
int n = int.Parse(splitted[i]);
120-
result += n * multiplier;
121-
multiplier /= 10;
122-
}
123-
}
124-
return result;
125-
}
126-
12796
} // class
12897
} // namespace

Diff for: UnityLauncherPro/MainWindow.xaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@
371371
<!-- bottom buttoms row -->
372372
<Grid VerticalAlignment="Bottom" Margin="4,0,8,5">
373373
<Grid.ColumnDefinitions>
374-
<ColumnDefinition Width="12*" />
375-
<ColumnDefinition Width="18*" />
374+
<ColumnDefinition Width="14*" />
375+
<ColumnDefinition Width="17*" />
376376
<ColumnDefinition Width="15*" />
377377
<ColumnDefinition Width="50*" />
378378
<ColumnDefinition Width="14*" />
@@ -384,7 +384,7 @@
384384
<Label Content="_Upgrade" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
385385
</Button>
386386
<Button Grid.Column="1" ToolTip="With selected Unity" Style="{StaticResource CustomButton}" x:Name="btnCreateEmptyProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnCreateEmptyProject_Click" >
387-
<Label Content="_Quick Project" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
387+
<Label Content="_New Project" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
388388
</Button>
389389
<Button Grid.Column="2" Style="{StaticResource CustomButton}" x:Name="btnLaunchUnity" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnLaunchUnity_Click" >
390390
<Label Content="_Run Unity" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
@@ -465,7 +465,7 @@
465465
<Grid VerticalAlignment="Bottom" Margin="4,0,8,5">
466466
<Grid.ColumnDefinitions>
467467
<ColumnDefinition Width="20*" />
468-
<ColumnDefinition Width="18*" />
468+
<ColumnDefinition Width="17*" />
469469
<ColumnDefinition Width="20*" />
470470
<ColumnDefinition Width="40*" />
471471
<ColumnDefinition Width="15*" />
@@ -479,7 +479,7 @@
479479
<Label Content="Release _Notes" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
480480
</Button>
481481
<Button Grid.Column="1" ToolTip="With selected Unity" Style="{StaticResource CustomButton}" x:Name="btnCreateEmptyProjectUnity" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnCreateEmptyProjectUnity_Click" >
482-
<Label Content="_Quick Project" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
482+
<Label Content="_New Project" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
483483
</Button>
484484
<Button Grid.Column="2" Style="{StaticResource CustomButton}" x:Name="btnUpdateUnity" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnUpdateUnity_Click">
485485
<Label Content="Check Updates" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+1
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ void UpdateUnityInstallationsList()
317317
unityInstalledVersions.Add(version, unityInstallationsSource[i].Path);
318318
}
319319
}
320+
320321
lblFoundXInstallations.Content = "Found " + unityInstallationsSource.Length + " installations";
321322
}
322323

Diff for: UnityLauncherPro/Tools.cs

+42-12
Original file line numberDiff line numberDiff line change
@@ -426,22 +426,52 @@ static string ParseDownloadURLFromWebpage(string version)
426426
return url;
427427
}
428428

429-
430429
public static string FindNearestVersion(string currentVersion, List<string> allAvailable)
431430
{
432-
if (currentVersion.Contains("2019"))
433-
{
434-
return FindNearestVersionFromSimilarVersions(currentVersion, allAvailable.Where(x => x.Contains("2019")));
435-
}
436-
if (currentVersion.Contains("2018"))
431+
string result = null;
432+
433+
// add current version to list
434+
allAvailable.Add(currentVersion);
435+
436+
// sort list
437+
allAvailable.Sort((s1, s2) => VersionAsInt(s2).CompareTo(VersionAsInt(s1)));
438+
439+
// check version above our current version
440+
int currentIndex = allAvailable.IndexOf(currentVersion);
441+
// if its index 0, we select that row anyways later
442+
if (currentIndex > 0 && currentIndex < allAvailable.Count)
437443
{
438-
return FindNearestVersionFromSimilarVersions(currentVersion, allAvailable.Where(x => x.Contains("2018")));
444+
result = allAvailable[currentIndex - 1];
439445
}
440-
if (currentVersion.Contains("2017"))
446+
447+
return result;
448+
}
449+
450+
// string to integer for sorting by version 2017.1.5f1 > 2017010501
451+
public static int VersionAsInt(string version)
452+
{
453+
int result = 0;
454+
if (string.IsNullOrEmpty(version)) return result;
455+
456+
// remove a,b,f,p
457+
string cleanVersion = version.Replace("a", ".");
458+
cleanVersion = cleanVersion.Replace("b", ".");
459+
cleanVersion = cleanVersion.Replace("f", ".");
460+
cleanVersion = cleanVersion.Replace("p", ".");
461+
462+
// split values
463+
string[] splitted = cleanVersion.Split('.');
464+
if (splitted != null && splitted.Length > 0)
441465
{
442-
return FindNearestVersionFromSimilarVersions(currentVersion, allAvailable.Where(x => x.Contains("2017")));
466+
int multiplier = 1;
467+
for (int i = 0, length = splitted.Length; i < length; i++)
468+
{
469+
int n = int.Parse(splitted[splitted.Length - 1 - i]);
470+
result += n * multiplier;
471+
multiplier *= 100;
472+
}
443473
}
444-
return FindNearestVersionFromSimilarVersions(currentVersion, allAvailable.Where(x => !x.Contains("2017")));
474+
return result;
445475
}
446476

447477
private static string FindNearestVersionFromSimilarVersions(string version, IEnumerable<string> allAvailable)
@@ -526,11 +556,11 @@ public static void DisplayUpgradeDialog(Project proj, MainWindow owner)
526556

527557
// inject new version for this item
528558
proj.Version = upgradeToVersion;
529-
Tools.LaunchProject(proj);
559+
LaunchProject(proj);
530560
}
531561
else
532562
{
533-
Console.WriteLine("results = " + results);
563+
//Console.WriteLine("results = " + results);
534564
}
535565
}
536566

0 commit comments

Comments
 (0)