Skip to content

Commit 81ca264

Browse files
committed
fixed: crash if no projects in the list and click create new project, fixed: no project created when no quick project path is assigned first in settings, fixed: if user creates new quick project, but unity fails to start (then project does not get added to list, but folder is generated), now project is added to list temporarily, so can launch it again
1 parent 335b66a commit 81ca264

File tree

4 files changed

+52
-24
lines changed

4 files changed

+52
-24
lines changed

Diff for: UnityLauncherPro.sln

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnityLauncherPro", "UnityLauncherPro\UnityLauncherPro.csproj", "{EC78D91A-3E63-4CAA-8BC3-9673A30FDA45}"
77
EndProject
88
Global
9+
GlobalSection(Performance) = preSolution
10+
HasPerformanceSessions = true
11+
EndGlobalSection
912
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1013
Debug|Any CPU = Debug|Any CPU
1114
Release|Any CPU = Release|Any CPU
@@ -22,4 +25,7 @@ Global
2225
GlobalSection(ExtensibilityGlobals) = postSolution
2326
SolutionGuid = {CD70E364-F81A-402C-A387-1BEB396796A2}
2427
EndGlobalSection
28+
GlobalSection(Performance) = preSolution
29+
HasPerformanceSessions = true
30+
EndGlobalSection
2531
EndGlobal

Diff for: UnityLauncherPro/MainWindow.xaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@
919919
</StackPanel>
920920

921921
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
922-
<TextBox x:Name="txtRootFolderForNewProjects" MinWidth="300" ToolTip="When you click &quot;Create Project&quot; in main page, new project is generated under this path+UnityVersion (eg. /2017a/)" Padding="0,3,0,0" TextChanged="TxtRootFolderForNewProjects_TextChanged" />
922+
<TextBox x:Name="txtRootFolderForNewProjects" MinWidth="300" ToolTip="Root folder for quick New Projects (so that you dont have to pick project folder every time)" Padding="0,3,0,0" TextChanged="TxtRootFolderForNewProjects_TextChanged" />
923923
<Button x:Name="btnBrowseProjectRootFolder" Content="..." Margin="6,0,0,0" MinWidth="32" Click="BtnBrowseProjectRootFolder_Click" />
924924
<Label Content="Root Folder for New Projects" Foreground="{DynamicResource ThemeButtonForeground}" />
925925
</StackPanel>

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+38-18
Original file line numberDiff line numberDiff line change
@@ -610,24 +610,31 @@ private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
610610
var folder = Tools.BrowseForOutputFolder("Select Project Folder to Add it Into Projects List");
611611
if (string.IsNullOrEmpty(folder) == false)
612612
{
613-
// create new project item
614-
var p = new Project();
615-
p.Path = folder;
616-
p.Title = Path.GetFileName(folder);
617-
p.Version = Tools.GetProjectVersion(folder);
618-
p.Arguments = Tools.ReadCustomLaunchArguments(folder, MainWindow.launcherArgumentsFile);
619-
if ((bool)chkShowPlatform.IsChecked == true) p.TargetPlatform = Tools.GetTargetPlatform(folder);
620-
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder);
621-
622-
// add to list
623-
projectsSource.Insert(0, p);
624-
gridRecent.Items.Refresh();
625-
Tools.SetFocusToGrid(gridRecent); // force focus
626-
gridRecent.SelectedIndex = 0;
627-
613+
var proj = GetNewProjectData(folder);
614+
AddNewProjectToList(proj);
628615
}
629616
}
630617

618+
Project GetNewProjectData(string folder)
619+
{
620+
var p = new Project();
621+
p.Path = folder;
622+
p.Title = Path.GetFileName(folder);
623+
p.Version = Tools.GetProjectVersion(folder);
624+
p.Arguments = Tools.ReadCustomLaunchArguments(folder, MainWindow.launcherArgumentsFile);
625+
if ((bool)chkShowPlatform.IsChecked == true) p.TargetPlatform = Tools.GetTargetPlatform(folder);
626+
if ((bool)chkShowGitBranchColumn.IsChecked == true) p.GITBranch = Tools.ReadGitBranchInfo(folder);
627+
return p;
628+
}
629+
630+
void AddNewProjectToList(Project proj)
631+
{
632+
projectsSource.Insert(0, proj);
633+
gridRecent.Items.Refresh();
634+
Tools.SetFocusToGrid(gridRecent); // force focus
635+
gridRecent.SelectedIndex = 0;
636+
}
637+
631638
private void BtnClose_Click(object sender, RoutedEventArgs e)
632639
{
633640
this.Close();
@@ -1530,6 +1537,15 @@ private void BtnCreateEmptyProjectUnity_Click(object sender, RoutedEventArgs e)
15301537

15311538
void CreateNewEmptyProject()
15321539
{
1540+
// first check if quick project path is assigned, if not, need to set it
1541+
if (Directory.Exists(txtRootFolderForNewProjects.Text) == false)
1542+
{
1543+
tabControl.SelectedIndex = 4;
1544+
this.UpdateLayout();
1545+
txtRootFolderForNewProjects.Focus();
1546+
return;
1547+
}
1548+
15331549
if (chkAskNameForQuickProject.IsChecked == true)
15341550
{
15351551
// ask name
@@ -1538,7 +1554,7 @@ void CreateNewEmptyProject()
15381554
// if in maintab
15391555
if (tabControl.SelectedIndex == 0)
15401556
{
1541-
newVersion = GetSelectedProject().Version == null ? preferredVersion : GetSelectedProject().Version;
1557+
newVersion = GetSelectedProject()?.Version == null ? preferredVersion : GetSelectedProject().Version;
15421558
}
15431559
else // unity tab
15441560
{
@@ -1566,7 +1582,10 @@ void CreateNewEmptyProject()
15661582
Console.WriteLine("Create project " + NewProject.newVersion + " : " + projectPath);
15671583
if (string.IsNullOrEmpty(projectPath)) return;
15681584

1569-
Tools.FastCreateProject(NewProject.newVersion, projectPath, NewProject.newProjectName, NewProject.templateZipPath);
1585+
var p = Tools.FastCreateProject(NewProject.newVersion, projectPath, NewProject.newProjectName, NewProject.templateZipPath);
1586+
1587+
// add to list (just in case new project fails to start, then folder is already generated..)
1588+
if (p != null) AddNewProjectToList(p);
15701589
}
15711590
else // false, cancel
15721591
{
@@ -1586,7 +1605,8 @@ void CreateNewEmptyProject()
15861605
{
15871606
newVersion = GetSelectedUnity().Version == null ? preferredVersion : GetSelectedUnity().Version;
15881607
}
1589-
Tools.FastCreateProject(newVersion, txtRootFolderForNewProjects.Text);
1608+
var p = Tools.FastCreateProject(newVersion, txtRootFolderForNewProjects.Text);
1609+
if (p != null) AddNewProjectToList(p);
15901610
}
15911611

15921612
}

Diff for: UnityLauncherPro/Tools.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -957,27 +957,27 @@ public static string BrowseForOutputFolder(string title)
957957
return null;
958958
}
959959

960-
public static void FastCreateProject(string version, string baseFolder, string projectName = null, string templateZipPath = null)
960+
public static Project FastCreateProject(string version, string baseFolder, string projectName = null, string templateZipPath = null)
961961
{
962962
// check for base folders in settings tab
963963
if (string.IsNullOrEmpty(baseFolder) == true)
964964
{
965965
Console.WriteLine("Missing baseFolder value");
966-
return;
966+
return null;
967967
}
968968

969969
// check if base folder exists
970970
if (Directory.Exists(baseFolder) == false)
971971
{
972972
Console.WriteLine("Missing baseFolder: " + baseFolder);
973-
return;
973+
return null;
974974
}
975975

976976
// check selected unity version
977977
if (string.IsNullOrEmpty(version) == true)
978978
{
979979
Console.WriteLine("Missing unity version");
980-
return;
980+
return null;
981981
}
982982

983983
string newPath = null;
@@ -988,7 +988,7 @@ public static void FastCreateProject(string version, string baseFolder, string p
988988
Console.WriteLine(baseFolder);
989989
projectName = GetSuggestedProjectName(version, baseFolder);
990990
// failed getting new path a-z
991-
if (projectName == null) return;
991+
if (projectName == null) return null;
992992
}
993993
newPath = Path.Combine(baseFolder, projectName);
994994

@@ -1003,10 +1003,12 @@ public static void FastCreateProject(string version, string baseFolder, string p
10031003

10041004
// launch empty project
10051005
var proj = new Project();
1006+
proj.Title = projectName;
10061007
proj.Path = Path.Combine(baseFolder, newPath);
10071008
proj.Version = version;
10081009
var proc = LaunchProject(proj);
10091010
ProcessHandler.Add(proj, proc);
1011+
return proj;
10101012
} // FastCreateProject
10111013

10121014

0 commit comments

Comments
 (0)