Skip to content

Commit 7d70301

Browse files
committed
fix add project button, add Fast Create button (to create empty project in 1 click), add new projects root folder setting field
1 parent 56d8839 commit 7d70301

File tree

8 files changed

+172
-41
lines changed

8 files changed

+172
-41
lines changed

Diff for: UnityLauncherPro/App.config

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@
5151
<setting name="preferredVersion" serializeAs="String">
5252
<value />
5353
</setting>
54+
<setting name="newProjectsRoot" serializeAs="String">
55+
<value />
56+
</setting>
5457
</UnityLauncherPro.Properties.Settings>
5558
</userSettings>
5659
</configuration>

Diff for: UnityLauncherPro/Data/UnityInstallation.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ public class UnityInstallation : IValueConverter
1111
public string Platforms { set; get; }
1212
public bool IsPreferred { set; get; }
1313

14-
// color project unity version cells, depending if have that version installed
1514
// https://stackoverflow.com/a/5551986/5452781
1615
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
1716
{
1817
string version = value as string;
19-
//return MainWindow.unityInstalledVersions.ContainsKey(version) ? Brushes.Yellow : Brushes.Red;
20-
return MainWindow.unityInstalledVersions.ContainsKey(version);// ? "Red" : "Blue";
21-
//return Brushes.Yellow;
22-
// DependencyProperty.UnsetValue
18+
if (string.IsNullOrEmpty(version)) return null;
19+
return MainWindow.unityInstalledVersions.ContainsKey(version);
2320
}
2421

2522
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)

Diff for: UnityLauncherPro/GetProjects.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static class GetProjects
1111
// which registries we want to scan for projects
1212
static readonly string[] registryPathsToCheck = new string[] { @"SOFTWARE\Unity Technologies\Unity Editor 5.x", @"SOFTWARE\Unity Technologies\Unity Editor 4.x" };
1313

14-
public static Project[] Scan(bool getGitBranch = false, bool getArguments = false, bool showMissingFolders = false)
14+
public static List<Project> Scan(bool getGitBranch = false, bool getArguments = false, bool showMissingFolders = false)
1515
{
1616
List<Project> projectsFound = new List<Project>();
1717

@@ -125,7 +125,7 @@ public static Project[] Scan(bool getGitBranch = false, bool getArguments = fals
125125
} // each key
126126
} // for each registry root
127127

128-
return projectsFound.ToArray();
128+
return projectsFound;
129129
} // Scan()
130130

131131
} // class

Diff for: UnityLauncherPro/MainWindow.xaml

+26-13
Original file line numberDiff line numberDiff line change
@@ -371,26 +371,28 @@
371371
<!-- bottom buttoms row -->
372372
<Grid VerticalAlignment="Bottom" Margin="4,0,8,5">
373373
<Grid.ColumnDefinitions>
374+
<ColumnDefinition Width="12*" />
374375
<ColumnDefinition Width="20*" />
375-
<ColumnDefinition Width="20*" />
376-
<ColumnDefinition Width="50*" />
377376
<ColumnDefinition Width="15*" />
377+
<ColumnDefinition Width="50*" />
378+
<ColumnDefinition Width="12*" />
378379
</Grid.ColumnDefinitions>
379380
<Grid.RowDefinitions>
380381
<RowDefinition Height="32" />
381382
</Grid.RowDefinitions>
382383
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnUpgradeProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="5,0,0,0" BorderBrush="{x:Null}" Click="BtnUpgradeProject_Click">
383384
<Label Content="_Upgrade" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
384385
</Button>
385-
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnLaunchUnity" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnLaunchUnity_Click" >
386+
<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="_Fast Create" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
388+
</Button>
389+
<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" >
386390
<Label Content="_Run Unity" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
387391
</Button>
388-
389-
<Button Grid.Column="2" Style="{StaticResource CustomButton}" x:Name="btnLaunchProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnLaunchProject_Click" AutomationProperties.AccessKey="o" >
392+
<Button Grid.Column="3" Style="{StaticResource CustomButton}" x:Name="btnLaunchProject" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnLaunchProject_Click" AutomationProperties.AccessKey="o" >
390393
<Label Content="_Open Project" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
391394
</Button>
392-
393-
<Button Grid.Column="3" Style="{StaticResource CustomButton}" x:Name="btnExplore" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnExplore_Click" >
395+
<Button Grid.Column="4" Style="{StaticResource CustomButton}" x:Name="btnExplore" Background="{DynamicResource ButtonBackground}" Foreground="#FFC1C1C1" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnExplore_Click" >
394396
<Label Content="_Explore" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
395397
</Button>
396398
</Grid>
@@ -463,24 +465,29 @@
463465
<Grid VerticalAlignment="Bottom" Margin="4,0,8,5">
464466
<Grid.ColumnDefinitions>
465467
<ColumnDefinition Width="20*" />
468+
<ColumnDefinition Width="15*" />
466469
<ColumnDefinition Width="20*" />
467-
<ColumnDefinition Width="45*" />
470+
<ColumnDefinition Width="40*" />
468471
<ColumnDefinition Width="15*" />
469-
470472
</Grid.ColumnDefinitions>
473+
471474
<Grid.RowDefinitions>
472475
<RowDefinition Height="32" />
473476
</Grid.RowDefinitions>
477+
474478
<Button Grid.Column="0" Style="{StaticResource CustomButton}" x:Name="btnReleaseNotes" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="5,0,0,0" BorderBrush="{x:Null}" Click="BtnReleaseNotes_Click">
475479
<Label Content="Release _Notes" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
476480
</Button>
477-
<Button Grid.Column="1" Style="{StaticResource CustomButton}" x:Name="btnUpdateUnity" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnUpdateUnity_Click">
478-
<Label Content="Go to Updates" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
481+
<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="_Fast Create" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
483+
</Button>
484+
<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">
485+
<Label Content="Check Updates" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
479486
</Button>
480-
<Button Grid.Column="2" Style="{StaticResource CustomButton}" x:Name="btnRunUnity" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnRunUnity_Click" >
487+
<Button Grid.Column="3" Style="{StaticResource CustomButton}" x:Name="btnRunUnity" Background="{DynamicResource ButtonBackground}" Foreground="{DynamicResource ButtonForeground}" Margin="8,0,0,0" BorderBrush="{x:Null}" Click="BtnRunUnity_Click" >
481488
<Label Content="_Run Unity" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
482489
</Button>
483-
<Button Grid.Column="3" Style="{StaticResource CustomButton}" x:Name="btnExploreUnity" Background="{DynamicResource ButtonBackground}" Margin="8,0,0,0" BorderBrush="{x:Null}" Foreground="{DynamicResource ButtonForeground}" Click="BtnExploreUnity_Click" >
490+
<Button Grid.Column="4" Style="{StaticResource CustomButton}" x:Name="btnExploreUnity" Background="{DynamicResource ButtonBackground}" Margin="8,0,0,0" BorderBrush="{x:Null}" Foreground="{DynamicResource ButtonForeground}" Click="BtnExploreUnity_Click" >
484491
<Label Content="_Explore" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
485492
</Button>
486493

@@ -639,6 +646,12 @@
639646
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show Git Branch Column" Foreground="{DynamicResource ButtonForeground}" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" Margin="0,0,0,3"/>
640647
<CheckBox x:Name="chkShowMissingFolderProjects" Content="Show projects that dont exist on disk" Foreground="{DynamicResource ButtonForeground}" Checked="ChkShowMissingFolderProjects_CheckedChanged" Unchecked="ChkShowMissingFolderProjects_CheckedChanged" Margin="0,0,0,3" ToolTip="List recent projects, even if the project folder is missing"/>
641648
<CheckBox x:Name="chkAllowSingleInstanceOnly" Content="Allow single instance only" Foreground="{DynamicResource ButtonForeground}" Checked="ChkAllowSingleInstanceOnly_CheckedChanged" Unchecked="ChkAllowSingleInstanceOnly_CheckedChanged" Margin="0,0,0,3" ToolTip="Activates already running instance, instead of starting new exe"/>
649+
650+
<StackPanel Grid.Row="3" Orientation="Horizontal">
651+
<Label Content="Root Folder for New Projects" Foreground="{DynamicResource ButtonForeground}" />
652+
<TextBox x:Name="txtRootFolderForNewProjects" MinWidth="250" 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" />
653+
<Button x:Name="btnBrowseProjectRootFolder" Content="..." Margin="6,0,0,0" MinWidth="32" Click="BtnBrowseProjectRootFolder_Click" />
654+
</StackPanel>
642655
</StackPanel>
643656

644657
<!-- links-->

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+41-21
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ public partial class MainWindow : Window
3232
[DllImport("user32")]
3333
static extern bool OpenIcon(IntPtr hWnd);
3434

35-
Project[] projectsSource;
35+
//Project[] projectsSource;
36+
List<Project> projectsSource;
37+
38+
3639
Updates[] updatesSource;
3740
UnityInstallation[] unityInstallationsSource;
3841
public static Dictionary<string, string> unityInstalledVersions = new Dictionary<string, string>();
@@ -239,6 +242,7 @@ void LoadSettings()
239242
chkShowGitBranchColumn.IsChecked = Properties.Settings.Default.showGitBranchColumn;
240243
chkShowMissingFolderProjects.IsChecked = Properties.Settings.Default.showProjectsMissingFolder;
241244
chkAllowSingleInstanceOnly.IsChecked = Properties.Settings.Default.AllowSingleInstanceOnly;
245+
txtRootFolderForNewProjects.Text = Properties.Settings.Default.newProjectsRoot;
242246

243247
// update optional grid columns, hidden or visible
244248
gridRecent.Columns[4].Visibility = (bool)chkShowLauncherArgumentsColumn.IsChecked ? Visibility.Visible : Visibility.Collapsed;
@@ -265,7 +269,6 @@ void LoadSettings()
265269

266270
private void SaveSettingsOnExit()
267271
{
268-
269272
// save list column widths
270273
List<int> gridWidths;
271274
if (Properties.Settings.Default.gridColumnWidths != null)
@@ -434,26 +437,13 @@ private void OnSearchTextChanged(object sender, TextChangedEventArgs e)
434437

435438
private void BtnAddProjectFolder_Click(object sender, RoutedEventArgs e)
436439
{
437-
// https://stackoverflow.com/a/50261723/5452781
438-
// Create a "Save As" dialog for selecting a directory (HACK)
439-
var dialog = new Microsoft.Win32.SaveFileDialog();
440-
dialog.InitialDirectory = "c:"; // Use current value for initial dir
441-
dialog.Title = "Select Project Folder to Add it Into Projects List";
442-
dialog.Filter = "Project Folder|*.Folder"; // Prevents displaying files
443-
dialog.FileName = "Project"; // Filename will then be "select.this.directory"
444-
if (dialog.ShowDialog() == true)
440+
var folder = Tools.BrowseForOutputFolder("Select Project Folder to Add it Into Projects List");
441+
if (string.IsNullOrEmpty(folder) == false)
445442
{
446-
string path = dialog.FileName;
447-
// Remove fake filename from resulting path
448-
path = path.Replace("\\Project.Folder", "");
449-
path = path.Replace("Project.Folder", "");
450-
// If user has changed the filename, create the new directory
451-
if (!Directory.Exists(path))
452-
{
453-
Directory.CreateDirectory(path);
454-
}
455-
// Our final value is in path
456-
Console.WriteLine(path);
443+
var p = new Project();
444+
p.Path = folder;
445+
projectsSource.Insert(0, p);
446+
gridRecent.Items.Refresh();
457447
}
458448
}
459449

@@ -1163,5 +1153,35 @@ private void MenuItemCopyPath_Click(object sender, RoutedEventArgs e)
11631153
}
11641154
if (copy != null) Clipboard.SetText(copy);
11651155
}
1156+
1157+
// creates empty project into default project root with selected unity version
1158+
private void BtnCreateEmptyProject_Click(object sender, RoutedEventArgs e)
1159+
{
1160+
Tools.FastCreateProject(GetSelectedProject().Version, txtRootFolderForNewProjects.Text);
1161+
}
1162+
1163+
private void BtnBrowseProjectRootFolder_Click(object sender, RoutedEventArgs e)
1164+
{
1165+
var folder = Tools.BrowseForOutputFolder("Select root folder for New Projects");
1166+
if (string.IsNullOrEmpty(folder) == false)
1167+
{
1168+
txtRootFolderForNewProjects.Text = folder;
1169+
Properties.Settings.Default.newProjectsRoot = folder;
1170+
Properties.Settings.Default.Save();
1171+
}
1172+
// save to prefs when? onchange
1173+
}
1174+
1175+
private void TxtRootFolderForNewProjects_TextChanged(object sender, TextChangedEventArgs e)
1176+
{
1177+
Properties.Settings.Default.newProjectsRoot = txtRootFolderForNewProjects.Text;
1178+
Properties.Settings.Default.Save();
1179+
}
1180+
1181+
1182+
private void BtnCreateEmptyProjectUnity_Click(object sender, RoutedEventArgs e)
1183+
{
1184+
Tools.FastCreateProject(GetSelectedUnity().Version, txtRootFolderForNewProjects.Text);
1185+
}
11661186
} // class
11671187
} //namespace

Diff for: UnityLauncherPro/Properties/Settings.Designer.cs

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: UnityLauncherPro/Properties/Settings.settings

+3
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,8 @@
4444
<Setting Name="preferredVersion" Type="System.String" Scope="User">
4545
<Value Profile="(Default)" />
4646
</Setting>
47+
<Setting Name="newProjectsRoot" Type="System.String" Scope="User">
48+
<Value Profile="(Default)" />
49+
</Setting>
4750
</Settings>
4851
</SettingsFile>

Diff for: UnityLauncherPro/Tools.cs

+83
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,91 @@ public static void SetFocusToGrid(DataGrid targetGrid, int index = -1)
695695

696696
row.Focus();
697697
Keyboard.Focus(row);
698+
}
699+
700+
public static string BrowseForOutputFolder(string title)
701+
{
702+
// https://stackoverflow.com/a/50261723/5452781
703+
// Create a "Save As" dialog for selecting a directory (HACK)
704+
var dialog = new Microsoft.Win32.SaveFileDialog();
705+
dialog.InitialDirectory = "c:"; // Use current value for initial dir
706+
dialog.Title = title;
707+
dialog.Filter = "Project Folder|*.Folder"; // Prevents displaying files
708+
dialog.FileName = "Project"; // Filename will then be "select.this.directory"
709+
if (dialog.ShowDialog() == true)
710+
{
711+
string path = dialog.FileName;
712+
// Remove fake filename from resulting path
713+
path = path.Replace("\\Project.Folder", "");
714+
path = path.Replace("Project.Folder", "");
715+
// If user has changed the filename, create the new directory
716+
if (!Directory.Exists(path))
717+
{
718+
Directory.CreateDirectory(path);
719+
}
720+
return path;
721+
}
722+
return null;
723+
}
724+
725+
public static void FastCreateProject(string version, string baseFolder)
726+
{
727+
// check for base folders in settings tab
728+
//string baseFolder = txtRootFolderForNewProjects.Text;
729+
if (string.IsNullOrEmpty(baseFolder))
730+
{
731+
Console.WriteLine("Missing txtRootFolderForNewProjects");
732+
//tabControl.SelectedIndex = tabControl.Items.Count - 1;
733+
return;
734+
}
735+
736+
// check if base folder exists
737+
if (Directory.Exists(baseFolder) == false)
738+
{
739+
Console.WriteLine("Missing txtRootFolderForNewProjects folder");
740+
//tabControl.SelectedIndex = tabControl.Items.Count - 1;
741+
return;
742+
}
743+
744+
// check selected unity version
745+
//var currentProject = GetSelectedProject();
746+
if (string.IsNullOrEmpty(version) == true)
747+
{
748+
Console.WriteLine("Missing unity version");
749+
return;
750+
}
698751

752+
// find next free character folder a-z
753+
var unityBaseVersion = version.Substring(0, version.IndexOf('.'));
754+
for (int i = 97; i < 122; i++)
755+
{
756+
var newProject = unityBaseVersion + "_" + ((char)i);
757+
var path = Path.Combine(baseFolder, newProject);
758+
if (Directory.Exists(path))
759+
{
760+
Console.WriteLine("directory exists..trying again");
761+
}
762+
else // its available
763+
{
764+
Console.WriteLine("create folder: " + path);
765+
Directory.CreateDirectory(path);
766+
767+
// create project version file, to avoid wrong version warning
768+
var settingsPath = Path.Combine(path, "ProjectSettings");
769+
Directory.CreateDirectory(settingsPath);
770+
var settingsFile = Path.Combine(settingsPath, "ProjectVersion.txt");
771+
File.WriteAllText(settingsFile, "m_EditorVersion: " + version);
772+
773+
// launch project
774+
var p = new Project();
775+
p.Path = path;
776+
p.Version = version;
777+
Tools.LaunchProject(p);
778+
break;
779+
}
780+
}
699781
}
700782

783+
701784
} // class
702785
} // namespace

0 commit comments

Comments
 (0)