Skip to content

Commit 109be68

Browse files
committed
projects: handle null values for sorting columns, sort projects by modified date (so that it doesnt depend on registry order)
1 parent f7bc172 commit 109be68

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

UnityLauncherPro/GetProjects.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ public static class GetProjects
1414
// convert target platform name into valid buildtarget platform name, NOTE this depends on unity version, now only 2019 and later are supported
1515
public static Dictionary<string, string> remapPlatformNames = new Dictionary<string, string> { { "StandaloneWindows64", "Win64" }, { "StandaloneWindows", "Win" }, { "Android", "Android" }, { "WebGL", "WebGL" } };
1616

17-
// TODO separate scan and folders
1817
public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false)
1918
{
2019
List<Project> projectsFound = new List<Project>();
@@ -152,6 +151,8 @@ public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranc
152151
} // for each registry root
153152

154153
// NOTE sometimes projects are in wrong order, seems to be related to messing up your unity registry, the keys are received in created order (so if you had removed/modified them manually, it might return wrong order instead of 0 - 40)
154+
// thats why need to sort projects list by modified date
155+
projectsFound.Sort((x, y) => y.Modified.Value.CompareTo(x.Modified.Value));
155156

156157
return projectsFound;
157158
} // Scan()

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,10 +2750,18 @@ public int Compare(Object a, Object b)
27502750
case "Project":
27512751
return direction == ListSortDirection.Ascending ? ((Project)a).Title.CompareTo(((Project)b).Title) : ((Project)b).Title.CompareTo(((Project)a).Title);
27522752
case "Version":
2753+
// handle null values
2754+
if (((Project)a).Version == null && ((Project)b).Version == null) return 0;
2755+
if (((Project)a).Version == null) return direction == ListSortDirection.Ascending ? -1 : 1;
2756+
if (((Project)b).Version == null) return direction == ListSortDirection.Ascending ? 1 : -1;
27532757
return direction == ListSortDirection.Ascending ? Tools.VersionAsInt(((Project)a).Version).CompareTo(Tools.VersionAsInt(((Project)b).Version)) : Tools.VersionAsInt(((Project)b).Version).CompareTo(Tools.VersionAsInt(((Project)a).Version));
27542758
case "Path":
27552759
return direction == ListSortDirection.Ascending ? ((Project)a).Path.CompareTo(((Project)b).Path) : ((Project)b).Path.CompareTo(((Project)a).Path);
27562760
case "Modified":
2761+
// handle null values
2762+
if (((Project)a).Modified == null && ((Project)b).Modified == null) return 0;
2763+
if (((Project)a).Modified == null) return direction == ListSortDirection.Ascending ? -1 : 1;
2764+
if (((Project)b).Modified == null) return direction == ListSortDirection.Ascending ? 1 : -1;
27572765
return direction == ListSortDirection.Ascending ? ((DateTime)((Project)a).Modified).CompareTo(((Project)b).Modified) : ((DateTime)((Project)b).Modified).CompareTo(((Project)a).Modified);
27582766
case "Arguments":
27592767
// handle null values
@@ -2913,6 +2921,7 @@ private void menuInstallLastAPK_Click(object sender, RoutedEventArgs e)
29132921
}
29142922
}
29152923

2924+
// launch app
29162925
if (string.IsNullOrEmpty(packageName) == false)
29172926
{
29182927
pars += $" && adb shell monkey -p {packageName} 1";

0 commit comments

Comments
 (0)