Skip to content

Commit d0fc733

Browse files
committed
settings: check for default unity installation folders, if no root folders added yet (#93)
1 parent c6f80bd commit d0fc733

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

UnityLauncherPro/GetUnityInstallations.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static UnityInstallation[] Scan()
2121
// unityversion, exe_path
2222
List<UnityInstallation> results = new List<UnityInstallation>();
2323

24-
// iterate all root folders
24+
// iterate all folders under root folders
2525
foreach (string rootFolder in rootFolders)
2626
{
2727
// if folder exists
@@ -89,6 +89,26 @@ public static UnityInstallation[] Scan()
8989
return results.ToArray();
9090
} // scan()
9191

92+
public static bool HasUnityInstallations(string path)
93+
{
94+
var directories = Directory.GetDirectories(path);
95+
96+
// loop folders inside root
97+
for (int i = 0, length = directories.Length; i < length; i++)
98+
{
99+
var editorFolder = Path.Combine(directories[i], "Editor");
100+
if (Directory.Exists(editorFolder) == false) continue;
101+
102+
var editorExe = Path.Combine(editorFolder, "Unity.exe");
103+
if (File.Exists(editorExe) == false) continue;
104+
105+
// have atleast 1 installation
106+
return true;
107+
}
108+
109+
return false;
110+
}
111+
92112
// scans unity installation folder for installed platforms
93113
static string[] GetPlatforms(string dataFolder)
94114
{

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,38 @@ void LoadSettings()
384384

385385
// update installations folder listbox
386386
lstRootFolders.Items.Clear();
387+
388+
// check if no installation root folders are added, then add default folder(s), this usually happens only on first run (or if user has not added any folders)
389+
if (Properties.Settings.Default.rootFolders.Count == 0)
390+
{
391+
// default hub installation folder
392+
string baseFolder = "\\Program Files\\Unity\\Hub\\Editor";
393+
string baseFolder2 = "\\Program Files\\";
394+
string defaultFolder1 = "C:" + baseFolder;
395+
string defaultFolder2 = "D:" + baseFolder;
396+
string defaultFolder3 = "C:" + baseFolder2;
397+
string defaultFolder4 = "D:" + baseFolder2;
398+
if (Directory.Exists(defaultFolder1))
399+
{
400+
Properties.Settings.Default.rootFolders.Add(defaultFolder1);
401+
}
402+
else if (Directory.Exists(defaultFolder2))
403+
{
404+
Properties.Settings.Default.rootFolders.Add(defaultFolder2);
405+
}
406+
else if (Directory.Exists(defaultFolder3))
407+
{
408+
if (GetUnityInstallations.HasUnityInstallations(defaultFolder3))
409+
{
410+
Properties.Settings.Default.rootFolders.Add(defaultFolder3);
411+
}
412+
else if (GetUnityInstallations.HasUnityInstallations(defaultFolder4))
413+
{
414+
Properties.Settings.Default.rootFolders.Add(defaultFolder4);
415+
}
416+
}
417+
}
418+
387419
lstRootFolders.ItemsSource = Properties.Settings.Default.rootFolders;
388420

389421
// restore recent project datagrid column widths
@@ -1729,8 +1761,8 @@ void CreateNewEmptyProject(string targetFolder = null)
17291761

17301762
if (string.IsNullOrEmpty(newVersion))
17311763
{
1732-
Console.WriteLine("Missing selected unity version");
1733-
SetStatus("Missing selected unity version (its null)");
1764+
Console.WriteLine("Missing selected Unity version");
1765+
SetStatus("Missing selected Unity version (it's null, this should not happen)");
17341766
return;
17351767
}
17361768

0 commit comments

Comments
 (0)