Skip to content

Commit 02329a8

Browse files
committed
add plastic branch check option and method, move webgl launcher to Tools,
1 parent 31f8c4a commit 02329a8

File tree

7 files changed

+233
-173
lines changed

7 files changed

+233
-173
lines changed

UnityLauncherPro/App.config

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@
108108
<setting name="searchProjectPathAlso" serializeAs="String">
109109
<value>False</value>
110110
</setting>
111+
<setting name="checkPlasticBranch" serializeAs="String">
112+
<value>False</value>
113+
</setting>
111114
</UnityLauncherPro.Properties.Settings>
112115
</userSettings>
113116
</configuration>

UnityLauncherPro/GetProjects.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class GetProjects
1515
public static Dictionary<string, string> remapPlatformNames = new Dictionary<string, string> { { "StandaloneWindows64", "Win64" }, { "StandaloneWindows", "Win" }, { "Android", "Android" }, { "WebGL", "WebGL" } };
1616

1717
// TODO separate scan and folders
18-
public static List<Project> Scan(bool getGitBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false)
18+
public static List<Project> Scan(bool getGitBranch = false, bool getPlasticBranch = false, bool getArguments = false, bool showMissingFolders = false, bool showTargetPlatform = false)
1919
{
2020
List<Project> projectsFound = new List<Project>();
2121

@@ -98,6 +98,11 @@ public static List<Project> Scan(bool getGitBranch = false, bool getArguments =
9898
if (getGitBranch == true)
9999
{
100100
gitBranch = folderExists ? Tools.ReadGitBranchInfo(projectPath) : null;
101+
// check for plastic, if enabled
102+
if (getPlasticBranch == true && gitBranch == null)
103+
{
104+
gitBranch = folderExists ? Tools.ReadPlasticBranchInfo(projectPath) : null;
105+
}
101106
}
102107

103108
string targetPlatform = "";

UnityLauncherPro/MainWindow.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,10 @@
10041004
<CheckBox x:Name="chkQuitAfterOpen" Content="Close after opening project" Checked="ChkQuitAfterOpen_CheckedChanged" Unchecked="ChkQuitAfterOpen_CheckedChanged" ToolTip="Closes launcher after running project (not really useful)" HorizontalAlignment="Left"/>
10051005
<CheckBox x:Name="chkQuitAfterCommandline" Content="Close after launching from Explorer" Unchecked="ChkQuitAfterCommandline_CheckedChanged" Checked="ChkQuitAfterCommandline_CheckedChanged" ToolTip="Close launcher after running from commandline or Explorer (recommended)" HorizontalAlignment="Left"/>
10061006
<CheckBox x:Name="chkShowLauncherArgumentsColumn" Content="Show commandline arguments column" Unchecked="ChkShowLauncherArgumentsColumn_CheckedChanged" Checked="ChkShowLauncherArgumentsColumn_CheckedChanged" ToolTip="Shows column for custom project commandline params" HorizontalAlignment="Left"/>
1007-
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show git branch column" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" ToolTip="Shows column for project git branch info" HorizontalAlignment="Left"/>
1007+
<StackPanel Grid.Row="3" Orientation="Horizontal" Margin="0,0,0,0">
1008+
<CheckBox x:Name="chkShowGitBranchColumn" Content="Show git branch column" Checked="ChkShowGitBranchColumn_CheckedChanged" Unchecked="ChkShowGitBranchColumn_CheckedChanged" ToolTip="Shows column for project git branch info" HorizontalAlignment="Left"/>
1009+
<CheckBox x:Name="chkCheckPlasticBranch" Content="Check for Plastic branch" ToolTip="Checks for plastic branch, if .git doesnt exists" HorizontalAlignment="Left" Margin="14,0,0,3" Checked="ChkCheckPlasticBranch_Checked" Unchecked="ChkCheckPlasticBranch_Checked"/>
1010+
</StackPanel>
10081011
<CheckBox x:Name="chkShowMissingFolderProjects" Content="Show projects that don't exist on disk" Checked="ChkShowMissingFolderProjects_CheckedChanged" Unchecked="ChkShowMissingFolderProjects_CheckedChanged" ToolTip="List in recent projects, even if the project folder is missing" HorizontalAlignment="Left"/>
10091012
<CheckBox x:Name="chkAllowSingleInstanceOnly" Content="Allow single instance only" Checked="ChkAllowSingleInstanceOnly_CheckedChanged" Unchecked="ChkAllowSingleInstanceOnly_CheckedChanged" ToolTip="Activates already running instance, instead of starting new exe (not working if app is minized to taskbar)" HorizontalAlignment="Left"/>
10101013
<CheckBox x:Name="chkEnableProjectRename" Content="Enable Project title rename (F2)" ToolTip="Renames project title only, DOES NOT rename project folder! New name is saved into ProjectSettings/ProjectName.txt" Checked="ChkEnableProjectRename_Checked" Unchecked="ChkEnableProjectRename_Checked" HorizontalAlignment="Left"/>

UnityLauncherPro/MainWindow.xaml.cs

Lines changed: 8 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
using System.Diagnostics;
99
using System.Drawing; // for notifyicon
1010
using System.IO;
11-
using System.Net;
12-
using System.Net.NetworkInformation;
1311
using System.Runtime.InteropServices;
1412
using System.Threading;
1513
using System.Threading.Tasks;
@@ -110,7 +108,7 @@ void Start()
110108
}
111109

112110
// update projects list
113-
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked);
111+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked);
114112
gridRecent.Items.Clear();
115113
gridRecent.ItemsSource = projectsSource;
116114

@@ -598,7 +596,7 @@ public void RefreshRecentProjects()
598596
// take currently selected project row
599597
lastSelectedProjectIndex = gridRecent.SelectedIndex;
600598
// rescan recent projects
601-
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked);
599+
projectsSource = GetProjects.Scan(getGitBranch: (bool)chkShowGitBranchColumn.IsChecked, getPlasticBranch: (bool)chkCheckPlasticBranch.IsChecked, getArguments: (bool)chkShowLauncherArgumentsColumn.IsChecked, showMissingFolders: (bool)chkShowMissingFolderProjects.IsChecked, showTargetPlatform: (bool)chkShowPlatform.IsChecked);
602600
gridRecent.ItemsSource = projectsSource;
603601
// focus back
604602
Tools.SetFocusToGrid(gridRecent, lastSelectedProjectIndex);
@@ -1943,170 +1941,9 @@ private void BtnClearBuildReport_Click(object sender, RoutedEventArgs e)
19431941
private void MenuStartWebGLServer_Click(object sender, RoutedEventArgs e)
19441942
{
19451943
var proj = GetSelectedProject();
1946-
LaunchWebGL(proj);
1944+
Tools.LaunchWebGL(proj, txtWebglRelativePath.Text);
19471945
}
19481946

1949-
// runs unity SimpleWebServer.exe and launches default Browser into project build/ folder'
1950-
void LaunchWebGL(Project proj)
1951-
{
1952-
var projPath = proj?.Path.Replace('/', '\\');
1953-
if (string.IsNullOrEmpty(projPath) == true) return;
1954-
1955-
var buildPath = Path.Combine(projPath, "Builds", txtWebglRelativePath.Text);
1956-
if (Directory.Exists(buildPath) == false) return;
1957-
1958-
if (unityInstalledVersions.ContainsKey(proj.Version) == false) return;
1959-
1960-
// get mono and server exe paths
1961-
var editorPath = Path.GetDirectoryName(unityInstalledVersions[proj.Version]);
1962-
1963-
var monoToolsPath = Path.Combine(editorPath, "Data/MonoBleedingEdge/bin");
1964-
if (Directory.Exists(monoToolsPath) == false) return;
1965-
1966-
var webglToolsPath = Path.Combine(editorPath, "Data/PlaybackEngines/WebGLSupport/BuildTools");
1967-
if (Directory.Exists(webglToolsPath) == false) return;
1968-
1969-
var monoExe = Path.Combine(monoToolsPath, "mono.exe");
1970-
if (File.Exists(monoExe) == false) return;
1971-
1972-
var webExe = Path.Combine(webglToolsPath, "SimpleWebServer.exe");
1973-
if (File.Exists(webExe) == false) return;
1974-
1975-
// pick initial number for server, TODO make this default start port as setting field (later if needed..)
1976-
int port = 50000;
1977-
1978-
// check if this project already has server running and process is not closed
1979-
if (webglServerProcesses.ContainsKey(port) && webglServerProcesses[port].HasExited == false)
1980-
{
1981-
Console.WriteLine("Port found in cache: " + port + " process=" + webglServerProcesses[port]);
1982-
1983-
// check if project matches
1984-
if (webglServerProcesses[port].StartInfo.Arguments.IndexOf("\"" + buildPath + "\"") > -1)
1985-
{
1986-
Console.WriteLine("this project already has webgl server running.. lets open browser url only");
1987-
// then open browser url only
1988-
Tools.OpenURL("http://localhost:" + port);
1989-
return;
1990-
1991-
}
1992-
else
1993-
{
1994-
Console.WriteLine("Port in use, but its different project: " + port);
1995-
Console.WriteLine(webglServerProcesses[port].StartInfo.Arguments + " == " + "\"" + buildPath + "\"");
1996-
1997-
// then open new port and process
1998-
// -----------------------------------------------------------
1999-
// check if port is available https://stackoverflow.com/a/2793289
2000-
bool isAvailable = true;
2001-
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
2002-
IPEndPoint[] objEndPoints = ipGlobalProperties.GetActiveTcpListeners();
2003-
2004-
// NOTE instead of iterating all ports, just try to open port, if fails, open next one
2005-
// compare with existing ports, if available
2006-
for (int i = 0; i < objEndPoints.Length; i++)
2007-
{
2008-
if (objEndPoints[i].Port == port)
2009-
{
2010-
port++;
2011-
if (port > 65535)
2012-
{
2013-
Console.WriteLine("Failed to find open port..");
2014-
return;
2015-
}
2016-
}
2017-
}
2018-
2019-
Console.WriteLine("Found available port: " + port);
2020-
2021-
if (isAvailable == false)
2022-
{
2023-
Console.WriteLine("failed to open port " + port + " (should be open already, or something else is using it?)");
2024-
}
2025-
else
2026-
{
2027-
// take process id from unity, if have it (then webserver closes automatically when unity is closed)
2028-
var proc = ProcessHandler.Get(proj.Path);
2029-
int pid = proc == null ? -1 : proc.Id;
2030-
var param = "\"" + webExe + "\" \"" + buildPath + "\" " + port + (pid == -1 ? "" : " " + pid); // server exe path, build folder and port
2031-
2032-
var webglServerProcess = Tools.LaunchExe(monoExe, param);
2033-
2034-
if (webglServerProcesses.ContainsKey(port))
2035-
{
2036-
Console.WriteLine("Error> Should not happen - this port is already in dictionary! port: " + port);
2037-
}
2038-
else // keep reference to this process on this port
2039-
{
2040-
// TODO how to remove process once its closed? (or unlikely to have many processes in total? can also remove during check, if process already null)
2041-
webglServerProcesses.Add(port, webglServerProcess);
2042-
Console.WriteLine("Added port " + port);
2043-
}
2044-
2045-
Tools.OpenURL("http://localhost:" + port);
2046-
}
2047-
// -----------------------------------------------------------
2048-
2049-
}
2050-
}
2051-
else
2052-
{
2053-
Console.WriteLine("Port not running in cache or process already closed, remove it from cache: " + port);
2054-
if (webglServerProcesses.ContainsKey(port)) webglServerProcesses.Remove(port);
2055-
2056-
// TODO remove duplicate code
2057-
// then open new process
2058-
// -----------------------------------------------------------
2059-
// check if port is available https://stackoverflow.com/a/2793289
2060-
bool isAvailable = true;
2061-
IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties();
2062-
IPEndPoint[] objEndPoints = ipGlobalProperties.GetActiveTcpListeners();
2063-
2064-
// compare with existing ports, if available
2065-
for (int i = 0; i < objEndPoints.Length; i++)
2066-
{
2067-
if (objEndPoints[i].Port == port)
2068-
{
2069-
// TODO doesnt stop at max port number 65535
2070-
port++;
2071-
}
2072-
}
2073-
2074-
Console.WriteLine("Found available port: " + port);
2075-
2076-
if (isAvailable == false)
2077-
{
2078-
Console.WriteLine("failed to open port " + port + " (should be open already, or something else is using it?)");
2079-
}
2080-
else
2081-
{
2082-
// take process id from unity, if have it(then webserver closes automatically when unity is closed)
2083-
var proc = ProcessHandler.Get(proj.Path);
2084-
int pid = proc == null ? -1 : proc.Id;
2085-
var param = "\"" + webExe + "\" \"" + buildPath + "\" " + port + (pid == -1 ? "" : " " + pid); // server exe path, build folder and port
2086-
2087-
var webglServerProcess = Tools.LaunchExe(monoExe, param);
2088-
2089-
if (webglServerProcesses.ContainsKey(port))
2090-
{
2091-
Console.WriteLine("Error> Should not happen - this port is already in dictionary! port: " + port);
2092-
}
2093-
else // keep reference to this process on this port
2094-
{
2095-
// TODO how to remove process once its closed? (or unlikely to have many processes in total? can also remove during check, if process already null)
2096-
webglServerProcesses.Add(port, webglServerProcess);
2097-
Console.WriteLine("Added port " + port);
2098-
}
2099-
2100-
Tools.OpenURL("http://localhost:" + port);
2101-
}
2102-
// -----------------------------------------------------------
2103-
2104-
}
2105-
} // LaunchWebGL()
2106-
2107-
// reference to already running webgl server processes and ports
2108-
Dictionary<int, Process> webglServerProcesses = new Dictionary<int, Process>();
2109-
21101947
private void TxtWebglRelativePath_TextChanged(object sender, TextChangedEventArgs e)
21111948
{
21121949
Properties.Settings.Default.webglBuildPath = txtWebglRelativePath.Text;
@@ -2590,7 +2427,11 @@ private void MenuBatchBuildIOS_Click(object sender, RoutedEventArgs e)
25902427
Tools.BuildProject(proj, Platform.iOS);
25912428
}
25922429

2593-
2430+
private void ChkCheckPlasticBranch_Checked(object sender, RoutedEventArgs e)
2431+
{
2432+
Properties.Settings.Default.checkPlasticBranch = (bool)chkCheckPlasticBranch.IsChecked;
2433+
Properties.Settings.Default.Save();
2434+
}
25942435

25952436
//private void BtnBrowseTemplateUnityPackagesFolder_Click(object sender, RoutedEventArgs e)
25962437
//{

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
@@ -107,5 +107,8 @@
107107
<Setting Name="searchProjectPathAlso" Type="System.Boolean" Scope="User">
108108
<Value Profile="(Default)">False</Value>
109109
</Setting>
110+
<Setting Name="checkPlasticBranch" Type="System.Boolean" Scope="User">
111+
<Value Profile="(Default)">False</Value>
112+
</Setting>
110113
</Settings>
111114
</SettingsFile>

0 commit comments

Comments
 (0)