Skip to content

Commit d0d72ee

Browse files
committed
Add CreateShortcut context menu for projects (creates shortcut to desktop for launching project directly), streamermode: hide batch folder text (as it defaults to user folder), hide quick project folder text (as it might contain private folders), settings: add shortcut .bat folder location (defaults to appdata), fix settings stackpanel widths (bigger than window), add initialdirectory optional arg for BrowseForOutputFolder()
1 parent 55cc3e6 commit d0d72ee

File tree

6 files changed

+142
-13
lines changed

6 files changed

+142
-13
lines changed

UnityLauncherPro/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
<setting name="checkPlasticBranch" serializeAs="String">
112112
<value>False</value>
113113
</setting>
114+
<setting name="shortcutBatchFileFolder" serializeAs="String">
115+
<value />
116+
</setting>
114117
</UnityLauncherPro.Properties.Settings>
115118
</userSettings>
116119
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,7 @@
592592
</MenuItem>
593593
<!--<Separator/>
594594
<MenuItem x:Name="menuRemoveProject" Header="Remove from recent list" Click="MenuRemoveProject_Click" />-->
595+
<MenuItem x:Name="menuCreateDesktopShortCut" Header="Create Shortcut on Desktop" Click="MenuCreateDesktopShortCut_Click" />
595596
</ContextMenu>
596597
</DataGrid.ContextMenu>
597598

@@ -1035,21 +1036,20 @@
10351036

10361037
<StackPanel Grid.Row="3" Orientation="Vertical" Margin="5,10,3,3" >
10371038
<CheckBox x:Name="chkEnablePlatformSelection" Content="Enable Platform Selection (Experimental!)" Checked="ChkEnablePlatformSelection_Checked" Unchecked="ChkEnablePlatformSelection_Checked" ToolTip="Select target platform" HorizontalAlignment="Left"/>
1038-
<StackPanel Orientation="Horizontal">
1039+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
10391040
<CheckBox x:Name="chkRunAutomatically" Content="Run automatically on startup" ToolTip="Run automatically using startup registry key" HorizontalAlignment="Left" Checked="ChkRunAutomatically_Checked" Unchecked="ChkRunAutomatically_Checked"/>
10401041
<CheckBox x:Name="chkRunAutomaticallyMinimized" Content="as minimized" ToolTip="Minimize to tray when started automatically" HorizontalAlignment="Left" Checked="ChkRunAutomaticallyMinimized_Checked" Unchecked="ChkRunAutomaticallyMinimized_Checked" Margin="5,0,0,3"/>
10411042
</StackPanel>
1042-
<StackPanel Orientation="Horizontal">
1043+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
10431044
<CheckBox x:Name="chkUseCustomLastModified" Content="Date format" ToolTip="Last modified date format" HorizontalAlignment="Left" Checked="ChkUseCustomLastModified_Checked" Unchecked="ChkUseCustomLastModified_Checked"/>
1044-
<TextBox x:Name="txtCustomDateTimeFormat" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="150" ToolTip="Default is dd/MM/yyyy HH:mm:ss" Padding="0,3,0,0" Margin="5,0,0,0" Text="dd/MM/yyyy HH:mm:ss" LostFocus="TxtCustomDateTimeFormat_LostFocus" TextChanged="TxtCustomDateTimeFormat_TextChanged">
1045-
</TextBox>
1045+
<TextBox x:Name="txtCustomDateTimeFormat" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="150" ToolTip="Default is dd/MM/yyyy HH:mm:ss" Padding="0,3,0,0" Margin="5,0,0,0" Text="dd/MM/yyyy HH:mm:ss" LostFocus="TxtCustomDateTimeFormat_LostFocus" TextChanged="TxtCustomDateTimeFormat_TextChanged"/>
10461046
</StackPanel>
10471047
<CheckBox x:Name="chkHumanFriendlyDateTime" Content="Use human friendly last modified" ToolTip="Last modified date format" HorizontalAlignment="Left" Checked="ChkHumanFriendlyDateTime_Checked" Unchecked="ChkHumanFriendlyDateTime_Checked"/>
10481048
<CheckBox x:Name="chkSearchProjectPath" Content="Search project path also" ToolTip="Searches from project folder path and project name" HorizontalAlignment="Left" Checked="ChkSearchProjectPath_Checked" Unchecked="ChkSearchProjectPath_Checked"/>
1049-
<Label Foreground="{DynamicResource ThemeButtonForeground}" Padding="0,5,5,0">Project name:</Label>
1050-
<StackPanel Orientation="Horizontal">
1051-
<RadioButton x:Name="radioProjNameFolder" Content="ProjectName.txt or Folder" Margin="3,0,0,0" GroupName="toggleGroupProjectName" IsChecked="True" Checked="RadioProjNameFolder_Checked" ToolTip="Take project name from project folder name OR ProjectName.txt if file exists in ProjectSettings/ folder"/>
1052-
<RadioButton x:Name="radioProjNameProductName" Content="Settings ProductName" Margin="5,0,0,0" GroupName="toggleGroupProjectName" Checked="RadioProjNameProductName_Checked" ToolTip="Take project name from player settings ProductName field"/>
1049+
<Label Foreground="{DynamicResource ThemeButtonForeground}" Padding="0,5,5,0" HorizontalAlignment="Left">Project name:</Label>
1050+
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left">
1051+
<RadioButton x:Name="radioProjNameFolder" Content="ProjectName.txt or Folder" Margin="3,0,0,0" GroupName="toggleGroupProjectName" IsChecked="True" Checked="RadioProjNameFolder_Checked" ToolTip="Take project name from project folder name OR ProjectName.txt if file exists in ProjectSettings/ folder" HorizontalAlignment="Left"/>
1052+
<RadioButton x:Name="radioProjNameProductName" Content="Settings ProductName" Margin="5,0,0,0" GroupName="toggleGroupProjectName" Checked="RadioProjNameProductName_Checked" ToolTip="Take project name from player settings ProductName field" HorizontalAlignment="Left"/>
10531053
</StackPanel>
10541054
<!--<StackPanel Orientation="Horizontal" Margin="0,0,0,4">
10551055
<TextBox x:Name="txtTemplatePackagesFolder" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" ToolTip="Folder for your custom unitypackage templates (for new project)" Padding="0,3,0,0" Width="110" TextChanged="TxtTemplatePackagesFolder_TextChanged" />
@@ -1058,12 +1058,20 @@
10581058
</StackPanel>-->
10591059

10601060
<Label Content="ADB args:" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" VerticalAlignment="Top" VerticalContentAlignment="Center" Margin="0,1,0,-4" />
1061-
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
1061+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4" HorizontalAlignment="Left">
10621062
<TextBox x:Name="txtLogCatArgs" BorderBrush="Transparent" Text="-s Unity ActivityManager PackageManager dalvikvm DEBUG -v color" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="312" ToolTip="ADB commandline arguments" Padding="0,3,0,0" TextChanged="TxtLogCatArgs_TextChanged" Width="312" />
10631063
<Button Style="{StaticResource CustomButton}" x:Name="btnResetLogCatArgs" Margin="10,0,0,0" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="Reset to default logcat args" Click="BtnResetLogCatArgs_Click">
10641064
<Label Content="Reset" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
10651065
</Button>
10661066
</StackPanel>
1067+
1068+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4" HorizontalAlignment="Left">
1069+
<TextBox x:Name="txtShortcutBatchFileFolder" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="150" ToolTip="Save generated .bat files here (they are run from Desktop Shortcut)" Padding="0,3,0,0" HorizontalAlignment="Left" MaxWidth="200" LostFocus="TxtShortcutBatchFileFolder_LostFocus" TextChanged="TxtShortcutBatchFileFolder_TextChanged" />
1070+
<Button Style="{StaticResource CustomButton}" x:Name="btnBrowseBatchFileFolder" Content="..." Margin="6,0,0,0" MinWidth="22" Click="BtnBrowseBatchFileFolder_Click" MinHeight="22" FontSize="16" ToolTip="Browse for .bat folder (default location is inside AppData/UnityLauncherPro/ and works fine, so this is optional)" HorizontalAlignment="Left" />
1071+
<Label Content="Shortcut .bat files folder" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" />
1072+
</StackPanel>
1073+
1074+
10671075

10681076
</StackPanel>
10691077
</StackPanel>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,13 @@ void LoadSettings()
424424
break;
425425
}
426426

427+
// set default .bat folder location to appdata/.., if nothing is set, or current one is invalid
428+
if (string.IsNullOrEmpty(txtShortcutBatchFileFolder.Text) || Directory.Exists(txtShortcutBatchFileFolder.Text) == false)
429+
{
430+
Properties.Settings.Default.shortcutBatchFileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appName);
431+
txtShortcutBatchFileFolder.Text = Properties.Settings.Default.shortcutBatchFileFolder;
432+
}
433+
427434
} // LoadSettings()
428435

429436

@@ -1669,19 +1676,24 @@ private void ChkAskNameForQuickProject_Checked(object sender, RoutedEventArgs e)
16691676
bool isInitializing = true; // used to avoid doing things while still starting up
16701677
private void ChkStreamerMode_Checked(object sender, RoutedEventArgs e)
16711678
{
1672-
// TODO add "(streamer mode)" text in statusbar
1679+
// TODO could add "(streamer mode)" text in statusbar?
16731680

16741681
var isChecked = (bool)((CheckBox)sender).IsChecked;
16751682

16761683
Properties.Settings.Default.streamerMode = isChecked;
16771684
Properties.Settings.Default.Save();
16781685

1679-
// Create cellstyle and assign if enabled
1686+
// Create cellstyle and assign if streamermode is enabled
16801687
Style cellStyle = new Style(typeof(DataGridCell));
16811688
cellStyle.Setters.Add(new Setter(FontSizeProperty, 1.0));
16821689
txtColumnTitle.CellStyle = isChecked ? cellStyle : null;
16831690
txtColumnName.CellStyle = isChecked ? cellStyle : null;
16841691

1692+
Style txtBoxStyle = new Style(typeof(TextBox));
1693+
txtBoxStyle.Setters.Add(new Setter(FontSizeProperty, 1.0));
1694+
txtShortcutBatchFileFolder.Style = isChecked ? txtBoxStyle : null;
1695+
txtRootFolderForNewProjects.Style = isChecked ? txtBoxStyle : null;
1696+
16851697
// need to reload list if user changed setting
16861698
if (isInitializing == false)
16871699
{
@@ -2165,6 +2177,23 @@ void ValidateCustomDateFormat(string format)
21652177
}
21662178
}
21672179

2180+
void ValidateFolderFromTextbox(TextBox textBox)
2181+
{
2182+
Console.WriteLine(textBox.Text);
2183+
if (Directory.Exists(textBox.Text) == true)
2184+
{
2185+
Properties.Settings.Default.shortcutBatchFileFolder = textBox.Text;
2186+
Properties.Settings.Default.Save();
2187+
textBox.BorderBrush = System.Windows.Media.Brushes.Transparent;
2188+
}
2189+
else // invalid format
2190+
{
2191+
textBox.BorderBrush = System.Windows.Media.Brushes.Red;
2192+
//Properties.Settings.Default.shortcutBatchFileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appName);
2193+
//Properties.Settings.Default.Save();
2194+
}
2195+
}
2196+
21682197
private void ChkHumanFriendlyDateTime_Checked(object sender, RoutedEventArgs e)
21692198
{
21702199
if (this.IsActive == false) return; // dont run code on window init
@@ -2433,6 +2462,43 @@ private void ChkCheckPlasticBranch_Checked(object sender, RoutedEventArgs e)
24332462
Properties.Settings.Default.Save();
24342463
}
24352464

2465+
private void MenuCreateDesktopShortCut_Click(object sender, RoutedEventArgs e)
2466+
{
2467+
var proj = GetSelectedProject();
2468+
var res = Tools.CreateDesktopShortCut(proj, txtShortcutBatchFileFolder.Text);
2469+
if (res == false)
2470+
{
2471+
Console.WriteLine("Failed to create shortcut, maybe batch folder location is invalid..");
2472+
}
2473+
}
2474+
2475+
private void TxtShortcutBatchFileFolder_TextChanged(object sender, TextChangedEventArgs e)
2476+
{
2477+
var folder = ((TextBox)sender).Text;
2478+
if (Directory.Exists(folder))
2479+
{
2480+
Properties.Settings.Default.shortcutBatchFileFolder = folder;
2481+
Properties.Settings.Default.Save();
2482+
}
2483+
}
2484+
2485+
private void TxtShortcutBatchFileFolder_LostFocus(object sender, RoutedEventArgs e)
2486+
{
2487+
ValidateFolderFromTextbox((TextBox)sender);
2488+
}
2489+
2490+
private void BtnBrowseBatchFileFolder_Click(object sender, RoutedEventArgs e)
2491+
{
2492+
// TODO change directory browsing window title (now its Project folder)
2493+
var folder = Tools.BrowseForOutputFolder("Select folder for .bat shortcut files", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appName));
2494+
if (string.IsNullOrEmpty(folder) == false)
2495+
{
2496+
txtShortcutBatchFileFolder.Text = folder;
2497+
Properties.Settings.Default.shortcutBatchFileFolder = folder;
2498+
Properties.Settings.Default.Save();
2499+
}
2500+
}
2501+
24362502
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
24372503
//{
24382504
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

UnityLauncherPro/Properties/Settings.Designer.cs

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityLauncherPro/Properties/Settings.settings

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,8 @@
110110
<Setting Name="checkPlasticBranch" Type="System.Boolean" Scope="User">
111111
<Value Profile="(Default)">False</Value>
112112
</Setting>
113+
<Setting Name="shortcutBatchFileFolder" Type="System.String" Scope="User">
114+
<Value Profile="(Default)" />
115+
</Setting>
113116
</Settings>
114117
</SettingsFile>

UnityLauncherPro/Tools.cs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,12 @@ public static void SetFocusToGrid(DataGrid targetGrid, int index = -1)
10171017
Keyboard.Focus(row);
10181018
}
10191019

1020-
public static string BrowseForOutputFolder(string title)
1020+
public static string BrowseForOutputFolder(string title, string initialDirectory = null)
10211021
{
10221022
// https://stackoverflow.com/a/50261723/5452781
10231023
// Create a "Save As" dialog for selecting a directory (HACK)
10241024
var dialog = new Microsoft.Win32.SaveFileDialog();
1025-
//dialog.InitialDirectory = "c:"; // Use current value for initial dir
1025+
if (initialDirectory != null) dialog.InitialDirectory = initialDirectory;
10261026
dialog.Title = title;
10271027
dialog.Filter = "Project Folder|*.Folder"; // Prevents displaying files
10281028
dialog.FileName = "Project"; // Filename will then be "select.this.directory"
@@ -1592,6 +1592,43 @@ public static void LaunchWebGL(Project proj, string relativeFolder)
15921592
}
15931593
} // LaunchWebGL()
15941594

1595+
// creates .bat file to launch UnityLauncherPro and then .url link file on desktop, into that .bat file
1596+
public static bool CreateDesktopShortCut(Project proj, string batchFolder)
1597+
{
1598+
string lnkFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop));
1599+
1600+
if (string.IsNullOrEmpty(batchFolder)) return false;
1601+
1602+
//string batchFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "UnityLauncherPro");
1603+
if (Directory.Exists(batchFolder) == false) Directory.CreateDirectory(batchFolder);
1604+
string batFileName = Path.Combine(batchFolder, proj.Title + ".bat");
1605+
string launcherExe = Process.GetCurrentProcess().MainModule.FileName;
1606+
string args = "-projectPath " + "\"" + proj.Path + "\" " + proj.Arguments;
1607+
string description = "Unity Project: " + proj.Title;
1608+
1609+
// create .bat file
1610+
var batLauncherData = "start \"\" \"" + launcherExe + "\"" + " " + args;
1611+
File.WriteAllText(batFileName, batLauncherData);
1612+
1613+
// create desktop link file
1614+
using (StreamWriter writer = new StreamWriter(lnkFileName + "\\" + proj.Title + ".url"))
1615+
{
1616+
writer.WriteLine("[InternetShortcut]");
1617+
writer.WriteLine("URL=file:///" + batFileName);
1618+
//writer.WriteLine("ShowCommand=7"); // doesnt work for minimized
1619+
writer.WriteLine("IconIndex=0");
1620+
writer.WriteLine("Arguments=-projectPath " + proj.Path);
1621+
// TODO maybe could take icon from project (but then need to convert into .ico)
1622+
string iconExe = GetUnityExePath(proj.Version);
1623+
if (iconExe == null) iconExe = launcherExe;
1624+
string icon = iconExe.Replace('\\', '/');
1625+
writer.WriteLine("IconFile=" + icon);
1626+
}
1627+
1628+
// TODO check for streamwriter and file write success
1629+
1630+
return true;
1631+
}
15951632
} // class
15961633

15971634
} // namespace

0 commit comments

Comments
 (0)