Skip to content

Commit 36173fb

Browse files
committed
add webgl default port settings field
1 parent 86f7e5d commit 36173fb

File tree

7 files changed

+94
-6
lines changed

7 files changed

+94
-6
lines changed

UnityLauncherPro/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
<setting name="useInitScript" serializeAs="String">
120120
<value>False</value>
121121
</setting>
122+
<setting name="webglPort" serializeAs="String">
123+
<value>50000</value>
124+
</setting>
122125
</UnityLauncherPro.Properties.Settings>
123126
</userSettings>
124127
</configuration>

UnityLauncherPro/MainWindow.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,11 @@
11531153
<Label Content="Patch Hub editors.json" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Control}}}" />
11541154
</Button>
11551155

1156+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,6,0,0">
1157+
<TextBox x:Name="txtWebglPort" BorderBrush="Transparent" CaretBrush="{DynamicResource ThemeSearchCaret}" Background="{DynamicResource ThemeTextBoxBackground}" SelectionBrush="{DynamicResource ThemeSearchSelection}" Foreground="{DynamicResource ThemeSearchForeground}" MinWidth="80" ToolTip="Initial port for first local WebGL webserver process (next one will be +1)" Padding="0,3,0,0" TextChanged="txtWebglPort_TextChanged" HorizontalAlignment="Left" Text="50000" LostFocus="txtWebglPort_LostFocus" />
1158+
<Label Content="Initial WebGL local server port" Foreground="{DynamicResource ThemeButtonForeground}" />
1159+
</StackPanel>
1160+
11561161
</StackPanel>
11571162
</StackPanel>
11581163

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,8 +443,12 @@ void LoadSettings()
443443
chkUseInitScript.IsChecked = Properties.Settings.Default.useInitScript;
444444
txtCustomInitFile.Text = Properties.Settings.Default.customInitFile;
445445

446+
// load webgl port
447+
txtWebglPort.Text = "" + Properties.Settings.Default.webglPort;
448+
webglPort = Properties.Settings.Default.webglPort;
446449
} // LoadSettings()
447450

451+
internal static int webglPort = 50000;
448452

449453
private void SaveSettingsOnExit()
450454
{
@@ -2361,15 +2365,39 @@ void ValidateFolderFromTextbox(TextBox textBox)
23612365
//Console.WriteLine(textBox.Text);
23622366
if (Directory.Exists(textBox.Text) == true)
23632367
{
2368+
// NOTE this saves for shortcutbat setting, so cannot be used for another fields
23642369
Properties.Settings.Default.shortcutBatchFileFolder = textBox.Text;
23652370
Properties.Settings.Default.Save();
23662371
textBox.BorderBrush = System.Windows.Media.Brushes.Transparent;
23672372
}
23682373
else // invalid format
23692374
{
23702375
textBox.BorderBrush = System.Windows.Media.Brushes.Red;
2371-
//Properties.Settings.Default.shortcutBatchFileFolder = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appName);
2372-
//Properties.Settings.Default.Save();
2376+
}
2377+
}
2378+
2379+
void ValidateIntRange(TextBox textBox, int min, int max)
2380+
{
2381+
int num = 0;
2382+
if (int.TryParse(textBox.Text, out num))
2383+
{
2384+
if (num >= min && num <= max)
2385+
{
2386+
textBox.BorderBrush = null;
2387+
// NOTE this saves for shortcutbat setting, so cannot be used for another fields
2388+
Properties.Settings.Default.webglPort = num;
2389+
Properties.Settings.Default.Save();
2390+
textBox.BorderBrush = null;
2391+
SetStatus("WebGL port set to " + num);
2392+
}
2393+
else
2394+
{
2395+
textBox.BorderBrush = System.Windows.Media.Brushes.Red;
2396+
}
2397+
}
2398+
else
2399+
{
2400+
textBox.BorderBrush = System.Windows.Media.Brushes.Red;
23732401
}
23742402
}
23752403

@@ -2935,6 +2963,43 @@ private void menuInstallLastAPK_Click(object sender, RoutedEventArgs e)
29352963
SetStatus("Installed APK:" + apkName);
29362964
}
29372965

2966+
private void txtWebglPort_TextChanged(object sender, TextChangedEventArgs e)
2967+
{
2968+
if (isInitializing == true) return;
2969+
2970+
var port = txtWebglPort.Text;
2971+
if (port.Length > 0)
2972+
{
2973+
// use tryparse
2974+
int portInt;
2975+
if (int.TryParse(port, out portInt) == true)
2976+
{
2977+
if (portInt >= 50000 && portInt <= 65534)
2978+
{
2979+
// save port
2980+
Properties.Settings.Default.webglPort = portInt;
2981+
Properties.Settings.Default.Save();
2982+
webglPort = portInt;
2983+
}
2984+
else
2985+
{
2986+
// invalid port
2987+
SetStatus("WebGL port must be between 50000 and 60000");
2988+
}
2989+
}
2990+
else
2991+
{
2992+
// invalid port
2993+
SetStatus("WebGL port must be a number");
2994+
}
2995+
}
2996+
}
2997+
2998+
private void txtWebglPort_LostFocus(object sender, RoutedEventArgs e)
2999+
{
3000+
ValidateIntRange((TextBox)sender, 50000, 65534);
3001+
}
3002+
29383003
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
29393004
//{
29403005
// var folder = Tools.BrowseForOutputFolder("Select unitypackage Templates folder");

UnityLauncherPro/NewProject.xaml.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ void UpdateModulesDropdown(string version)
105105
//lblTemplateTitleAndCount.Content = "Templates: (" + (cmbNewProjectTemplate.Items.Count - 1) + ")";
106106
}
107107

108-
109108
private void BtnCreateNewProject_Click(object sender, RoutedEventArgs e)
110109
{
111110
// check if projectname already exists

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
@@ -119,5 +119,8 @@
119119
<Setting Name="useInitScript" Type="System.Boolean" Scope="User">
120120
<Value Profile="(Default)">False</Value>
121121
</Setting>
122+
<Setting Name="webglPort" Type="System.Int32" Scope="User">
123+
<Value Profile="(Default)">50000</Value>
124+
</Setting>
122125
</Settings>
123126
</SettingsFile>

UnityLauncherPro/Tools.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,8 +1466,9 @@ public static void LaunchWebGL(Project proj, string relativeFolder)
14661466
var webExe = Path.Combine(webglToolsPath, "SimpleWebServer.exe");
14671467
if (File.Exists(webExe) == false) return;
14681468

1469-
// pick initial number for server, TODO make this default start port as setting field (later if needed..)
1470-
int port = 50000;
1469+
int port = MainWindow.webglPort;
1470+
if (port < 50000) port = 50000;
1471+
if (port > 65534) port = 65534;
14711472

14721473
// check if this project already has server running and process is not closed
14731474
if (webglServerProcesses.ContainsKey(port) && webglServerProcesses[port].HasExited == false)
@@ -1502,7 +1503,7 @@ public static void LaunchWebGL(Project proj, string relativeFolder)
15021503
if (objEndPoints[i].Port == port)
15031504
{
15041505
port++;
1505-
if (port > 65535)
1506+
if (port > 65534)
15061507
{
15071508
Console.WriteLine("Failed to find open port..");
15081509
isAvailable = false;

0 commit comments

Comments
 (0)