|
8 | 8 | using System.Diagnostics;
|
9 | 9 | using System.Drawing; // for notifyicon
|
10 | 10 | using System.IO;
|
| 11 | +using System.Net; |
| 12 | +using System.Net.NetworkInformation; |
11 | 13 | using System.Runtime.InteropServices;
|
12 | 14 | using System.Threading;
|
13 | 15 | using System.Threading.Tasks;
|
@@ -1940,9 +1942,13 @@ private void BtnClearBuildReport_Click(object sender, RoutedEventArgs e)
|
1940 | 1942 |
|
1941 | 1943 | private void MenuStartWebGLServer_Click(object sender, RoutedEventArgs e)
|
1942 | 1944 | {
|
1943 |
| - // runs unity SimpleWebServer.exe and launches default Browser into project build/ folder' |
1944 |
| - |
1945 | 1945 | var proj = GetSelectedProject();
|
| 1946 | + LaunchWebGL(proj); |
| 1947 | + } |
| 1948 | + |
| 1949 | + // runs unity SimpleWebServer.exe and launches default Browser into project build/ folder' |
| 1950 | + void LaunchWebGL(Project proj) |
| 1951 | + { |
1946 | 1952 | var projPath = proj?.Path.Replace('/', '\\');
|
1947 | 1953 | if (string.IsNullOrEmpty(projPath) == true) return;
|
1948 | 1954 |
|
@@ -1970,13 +1976,37 @@ private void MenuStartWebGLServer_Click(object sender, RoutedEventArgs e)
|
1970 | 1976 | Random rnd = new Random();
|
1971 | 1977 | int port = rnd.Next(50000, 61000);
|
1972 | 1978 |
|
| 1979 | + // check if port is available https://stackoverflow.com/a/2793289 |
| 1980 | + //bool isAvailable = true; |
| 1981 | + //IPGlobalProperties ipGlobalProperties = IPGlobalProperties.GetIPGlobalProperties(); |
| 1982 | + //IPEndPoint[] objEndPoints = ipGlobalProperties.GetActiveTcpListeners(); |
| 1983 | + |
| 1984 | + //// compare with existing ports, if available |
| 1985 | + //foreach (IPEndPoint tcpi in objEndPoints) |
| 1986 | + //{ |
| 1987 | + // if (tcpi.Port == port) |
| 1988 | + // { |
| 1989 | + // isAvailable = false; |
| 1990 | + // break; |
| 1991 | + // } |
| 1992 | + //} |
| 1993 | + |
| 1994 | + bool serverLaunched = false; |
| 1995 | + |
| 1996 | + //if (isAvailable == false) |
| 1997 | + //{ |
| 1998 | + // Console.WriteLine("failed to open port " + port + " (should be open already, or something else is using it?)"); |
| 1999 | + //} |
| 2000 | + //else |
| 2001 | + //{ |
1973 | 2002 | // take process id from unity, if have it (then webserver closes automatically when unity is closed)
|
1974 | 2003 | var proc = ProcessHandler.Get(proj.Path);
|
1975 | 2004 | int pid = proc == null ? -1 : proc.Id;
|
1976 | 2005 | var param = "\"" + webExe + "\" \"" + buildPath + "\" " + port + (pid == -1 ? "" : " " + pid); // server exe path, build folder and port
|
| 2006 | + // TODO take process reference, so can check if its already running |
| 2007 | + serverLaunched = Tools.LaunchExe(monoExe, param); |
| 2008 | + //} |
1977 | 2009 |
|
1978 |
| - // then open browser |
1979 |
| - var serverLaunched = Tools.LaunchExe(monoExe, param); |
1980 | 2010 | if (serverLaunched == true)
|
1981 | 2011 | {
|
1982 | 2012 | Tools.OpenURL("http://localhost:" + port);
|
|
0 commit comments