Skip to content

Commit a830670

Browse files
committed
Settings tab: Browse scripts folder goes to inside scripts folder now, Add Fetch button for init script, Init script field is now URL or local file path (to fetch init script), set default init URL to my example init script repo, init script is always fixed "InitializeProject.cs", add init script downloader, remove old "customInitFile" setting, add new setting "customInitFileURL", fixes #114
1 parent 89349de commit a830670

File tree

5 files changed

+136
-58
lines changed

5 files changed

+136
-58
lines changed

Diff for: UnityLauncherPro/MainWindow.xaml

+6-5
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,12 @@
647647
<Label Content="(Experimental!)" Foreground="{DynamicResource ThemeButtonForeground}" />
648648
</StackPanel>
649649
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
650-
<CheckBox x:Name="chkUseInitScript" Content="Use Init script for new projects" ToolTip="..." HorizontalAlignment="Left" Checked="chkUseInitScript_Checked" Unchecked="chkUseInitScript_Checked"/>
651-
<!--<Label Content="Init script for new projects" Foreground="{DynamicResource ThemeButtonForeground}" HorizontalAlignment="Left" />-->
652-
<TextBox x:Name="txtCustomInitFile" BorderBrush="Transparent" MinWidth="128" ToolTip="Default is InitProject.cs" Padding="0,3,0,0" Margin="5,0,0,0" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" Text="InitializeProject.cs" PreviewKeyDown="txtCustomInitFile_PreviewKeyDown" LostFocus="txtCustomInitFile_LostFocus" />
653-
<Button Style="{StaticResource CustomButton}" ToolTip="Explore Scripts folder" x:Name="btnExploreScriptsFolder" Content="..." Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="btnExploreScriptsFolder_Click" Margin="5,0,0,0"/>
650+
<CheckBox x:Name="chkUseInitScript" Content="Use Init script for new projects" ToolTip="Runs editor script on new project (to do custom setup)" HorizontalAlignment="Left" Checked="chkUseInitScript_Checked" Unchecked="chkUseInitScript_Checked"/>
651+
<TextBox x:Name="txtCustomInitFileURL" BorderBrush="Transparent" MinWidth="191" MaxWidth="191" ToolTip="URL OR local folder to fetch init file from (NOTE: Not automatically fetched, only if press Fetch button)" Padding="0,3,0,0" Margin="5,0,0,0" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" Text="https://raw.githubusercontent.com/unitycoder/UnityInitializeProject/main/Assets/Editor/InitializeProject.cs" PreviewKeyDown="txtCustomInitFileURL_PreviewKeyDown" LostFocus="txtCustomInitFileURL_LostFocus" />
652+
<Button x:Name="btnExploreScriptsFolder" Style="{StaticResource CustomButton}" ToolTip="Explore Scripts folder" Content="..." Height="22" Width="22" HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="16" Padding="1,-2,1,1" BorderBrush="{x:Null}" Click="btnExploreScriptsFolder_Click" Margin="5,0,0,0"/>
653+
<Button Style="{StaticResource CustomButton}" x:Name="btnFetchLatestInitScript" Margin="5,0,0,0" FontSize="11" Height="24" BorderBrush="{x:Null}" HorizontalAlignment="Left" VerticalAlignment="Top" ToolTip="Copies latest script from this location (Renames existing script as *.bak)" Click="btnFetchLatestInitScript_Click">
654+
<Label Content="Fetch" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
655+
</Button>
654656
</StackPanel>
655657

656658
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,4">
@@ -663,7 +665,6 @@
663665
<TextBox x:Name="txtWebglRelativePath" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="192" ToolTip="Inside Builds/ folder you might have separate folder for webgl builds, like webgl/. Used for starting WebGL server there" Padding="0,3,0,0" TextChanged="TxtWebglRelativePath_TextChanged" />
664666
</StackPanel>
665667

666-
667668
</StackPanel>
668669
</GroupBox>
669670

Diff for: UnityLauncherPro/MainWindow.xaml.cs

+36-30
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public partial class MainWindow : Window
3636
public static readonly string projectNameFile = "ProjectName.txt";
3737
public static string preferredVersion = null;
3838
public static int projectNameSetting = 0; // 0 = folder or ProjectName.txt if exists, 1=ProductName
39+
public static readonly string initScriptFileFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts", "InitializeProject.cs");
3940

4041
const string contextRegRoot = "Software\\Classes\\Directory\\Background\\shell";
4142
const string githubURL = "https://github.com/unitycoder/UnityLauncherPro";
@@ -473,30 +474,30 @@ void LoadSettings()
473474

474475
// if we dont have any values, get & set them now
475476
// also, if user has disabled optional columns, saved order must be reset to default
476-
if (order == null || gridRecent.Columns.Count != Properties.Settings.Default.recentColumnsOrder.Length)
477+
if (order == null || gridRecent.Columns.Count != Settings.Default.recentColumnsOrder.Length)
477478
{
478-
Properties.Settings.Default.recentColumnsOrder = new Int32[gridRecent.Columns.Count];
479+
Settings.Default.recentColumnsOrder = new Int32[gridRecent.Columns.Count];
479480
for (int i = 0; i < gridRecent.Columns.Count; i++)
480481
{
481-
Properties.Settings.Default.recentColumnsOrder[i] = gridRecent.Columns[i].DisplayIndex;
482+
Settings.Default.recentColumnsOrder[i] = gridRecent.Columns[i].DisplayIndex;
482483
}
483-
Properties.Settings.Default.Save();
484+
Settings.Default.Save();
484485
}
485486
else // load existing order
486487
{
487488
for (int i = 0; i < gridRecent.Columns.Count; i++)
488489
{
489-
if (Properties.Settings.Default.recentColumnsOrder[i] > -1)
490+
if (Settings.Default.recentColumnsOrder[i] > -1)
490491
{
491-
gridRecent.Columns[i].DisplayIndex = Properties.Settings.Default.recentColumnsOrder[i];
492+
gridRecent.Columns[i].DisplayIndex = Settings.Default.recentColumnsOrder[i];
492493
}
493494
}
494495
}
495496

496-
adbLogCatArgs = Properties.Settings.Default.adbLogCatArgs;
497+
adbLogCatArgs = Settings.Default.adbLogCatArgs;
497498
txtLogCatArgs.Text = adbLogCatArgs;
498499

499-
projectNameSetting = Properties.Settings.Default.projectName;
500+
projectNameSetting = Settings.Default.projectName;
500501
switch (projectNameSetting)
501502
{
502503
case 0:
@@ -513,22 +514,22 @@ void LoadSettings()
513514
// set default .bat folder location to appdata/.., if nothing is set, or current one is invalid
514515
if (string.IsNullOrEmpty(txtShortcutBatchFileFolder.Text) || Directory.Exists(txtShortcutBatchFileFolder.Text) == false)
515516
{
516-
Properties.Settings.Default.shortcutBatchFileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appName);
517-
txtShortcutBatchFileFolder.Text = Properties.Settings.Default.shortcutBatchFileFolder;
517+
Settings.Default.shortcutBatchFileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appName);
518+
txtShortcutBatchFileFolder.Text = Settings.Default.shortcutBatchFileFolder;
518519
}
519520

520-
chkUseInitScript.IsChecked = Properties.Settings.Default.useInitScript;
521-
txtCustomInitFile.Text = Properties.Settings.Default.customInitFile;
521+
chkUseInitScript.IsChecked = Settings.Default.useInitScript;
522+
txtCustomInitFileURL.Text = Settings.Default.customInitFileURL;
522523

523524
// load webgl port
524-
txtWebglPort.Text = "" + Properties.Settings.Default.webglPort;
525-
webglPort = Properties.Settings.Default.webglPort;
525+
txtWebglPort.Text = "" + Settings.Default.webglPort;
526+
webglPort = Settings.Default.webglPort;
526527

527-
txtMaxProjectCount.Text = Properties.Settings.Default.maxProjectCount.ToString();
528-
chkOverride40ProjectCount.IsChecked = Properties.Settings.Default.override40ProjectCount;
528+
txtMaxProjectCount.Text = Settings.Default.maxProjectCount.ToString();
529+
chkOverride40ProjectCount.IsChecked = Settings.Default.override40ProjectCount;
529530
if ((bool)chkOverride40ProjectCount.IsChecked)
530531
{
531-
maxProjectCount = Properties.Settings.Default.maxProjectCount;
532+
maxProjectCount = Settings.Default.maxProjectCount;
532533
}
533534
else
534535
{
@@ -1836,7 +1837,7 @@ void CreateNewEmptyProject(string targetFolder = null)
18361837
Console.WriteLine("Create project " + NewProject.newVersion + " : " + rootFolder);
18371838
if (string.IsNullOrEmpty(rootFolder)) return;
18381839

1839-
var p = Tools.FastCreateProject(NewProject.newVersion, rootFolder, NewProject.newProjectName, NewProject.templateZipPath, NewProject.platformsForThisUnity, NewProject.selectedPlatform, (bool)chkUseInitScript.IsChecked, txtCustomInitFile.Text);
1840+
var p = Tools.FastCreateProject(NewProject.newVersion, rootFolder, NewProject.newProjectName, NewProject.templateZipPath, NewProject.platformsForThisUnity, NewProject.selectedPlatform, (bool)chkUseInitScript.IsChecked, initScriptFileFullPath);
18401841

18411842
// add to list (just in case new project fails to start, then folder is already generated..)
18421843
if (p != null) AddNewProjectToList(p);
@@ -1859,7 +1860,7 @@ void CreateNewEmptyProject(string targetFolder = null)
18591860
{
18601861
newVersion = GetSelectedUnity().Version == null ? preferredVersion : GetSelectedUnity().Version;
18611862
}
1862-
var p = Tools.FastCreateProject(newVersion, rootFolder, null, null, null, null, (bool)chkUseInitScript.IsChecked, txtCustomInitFile.Text);
1863+
var p = Tools.FastCreateProject(newVersion, rootFolder, null, null, null, null, (bool)chkUseInitScript.IsChecked, initScriptFileFullPath);
18631864

18641865
if (p != null) AddNewProjectToList(p);
18651866
}
@@ -3055,40 +3056,41 @@ public int Compare(Object a, Object b)
30553056
}
30563057
}
30573058

3059+
3060+
30583061
private void btnExploreScriptsFolder_Click(object sender, RoutedEventArgs e)
30593062
{
3060-
// TODO later this script should be inside some unity project, for easier updating..
3061-
if (Tools.LaunchExplorer(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Scripts")) == false)
3063+
if (Tools.LaunchExplorer(initScriptFileFullPath) == false)
30623064
{
3063-
Tools.LaunchExplorer(Path.Combine(AppDomain.CurrentDomain.BaseDirectory));
3065+
Tools.LaunchExplorer(Path.GetDirectoryName(initScriptFileFullPath));
30643066
}
30653067
}
30663068

3067-
private void txtCustomInitFile_PreviewKeyDown(object sender, KeyEventArgs e)
3069+
private void txtCustomInitFileURL_PreviewKeyDown(object sender, KeyEventArgs e)
30683070
{
30693071
switch (e.Key)
30703072
{
30713073
case Key.Return: // pressed enter in theme file text box
3072-
Properties.Settings.Default.customInitFile = txtCustomInitFile.Text;
3073-
Properties.Settings.Default.Save();
3074+
Settings.Default.customInitFileURL = txtCustomInitFileURL.Text;
3075+
Settings.Default.Save();
30743076
break;
30753077
}
30763078
}
30773079

3078-
private void txtCustomInitFile_LostFocus(object sender, RoutedEventArgs e)
3080+
private void txtCustomInitFileURL_LostFocus(object sender, RoutedEventArgs e)
30793081
{
30803082
var s = (TextBox)sender;
3081-
Properties.Settings.Default.customInitFile = s.Text;
3082-
Properties.Settings.Default.Save();
3083+
Settings.Default.customInitFileURL = s.Text;
3084+
Settings.Default.Save();
30833085
}
30843086

30853087
private void chkUseInitScript_Checked(object sender, RoutedEventArgs e)
30863088
{
30873089
if (this.IsActive == false) return; // dont run code on window init
30883090

30893091
var isChecked = (bool)((CheckBox)sender).IsChecked;
3090-
Properties.Settings.Default.useInitScript = isChecked;
3091-
Properties.Settings.Default.Save();
3092+
Settings.Default.useInitScript = isChecked;
3093+
Settings.Default.Save();
30923094
}
30933095

30943096
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
@@ -3359,6 +3361,10 @@ private void tabControl_PreviewKeyDown(object sender, KeyEventArgs e)
33593361
}
33603362
}
33613363

3364+
private void btnFetchLatestInitScript_Click(object sender, RoutedEventArgs e)
3365+
{
3366+
Tools.DownloadInitScript(initScriptFileFullPath, txtCustomInitFileURL.Text);
3367+
}
33623368
} // class
33633369
} //namespace
33643370

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

+14-13
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-3
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@
113113
&lt;string&gt;C:\Program Files\&lt;/string&gt;
114114
&lt;/ArrayOfString&gt;</Value>
115115
</Setting>
116-
<Setting Name="customInitFile" Type="System.String" Scope="User">
117-
<Value Profile="(Default)">InitializeProject.cs</Value>
118-
</Setting>
119116
<Setting Name="useInitScript" Type="System.Boolean" Scope="User">
120117
<Value Profile="(Default)">False</Value>
121118
</Setting>
@@ -132,5 +129,8 @@
132129
<Setting Name="maxProjectCount" Type="System.Int32" Scope="User">
133130
<Value Profile="(Default)">50</Value>
134131
</Setting>
132+
<Setting Name="customInitFileURL" Type="System.String" Scope="User">
133+
<Value Profile="(Default)">https://raw.githubusercontent.com/unitycoder/UnityInitializeProject/main/Assets/Editor/InitializeProject.cs</Value>
134+
</Setting>
135135
</Settings>
136136
</SettingsFile>

0 commit comments

Comments
 (0)