public void Shutdown()
        {
            this.ready = false;
            Process process = this.process;

            if (process != null)
            {
                process.Exited -= new EventHandler(this.OnProcessExited);
            }
            this.process = null;
            if (this.client == null)
            {
                return;
            }
            this.client.Message -= new ConnectionMessageEventHandler <CompilerMessage, CompilerMessage>(this.OnMessage);
            this.client.Error   -= new StreamExceptionEventHandler(PluginCompiler.OnError);
            this.client.PushMessage(new CompilerMessage()
            {
                Type = CompilerMessageType.Exit
            });
            this.client.Stop();
            this.client = null;
            if (process == null)
            {
                return;
            }
            ThreadPool.QueueUserWorkItem((object _) => {
                Thread.Sleep(5000);
                if (!process.HasExited)
                {
                    process.Close();
                }
            });
        }
Ejemplo n.º 2
0
        public void Shutdown()
        {
            ready = false;
            var endedProcess = process;

            if (endedProcess != null)
            {
                endedProcess.Exited -= OnProcessExited;
            }
            process = null;
            if (client == null)
            {
                return;
            }
            client.Message -= OnMessage;
            client.Error   -= OnError;
            client.PushMessage(new CompilerMessage {
                Type = CompilerMessageType.Exit
            });
            client.Stop();
            client = null;
            if (endedProcess == null)
            {
                return;
            }
            ThreadPool.QueueUserWorkItem(_ =>
            {
                Thread.Sleep(5000);
                // Calling Close can block up to 60 seconds on certain machines
                if (!endedProcess.HasExited)
                {
                    endedProcess.Close();
                }
            });
        }
Ejemplo n.º 3
0
        private bool CheckCompiler()
        {
            CheckCompilerBinary();
            idleTimer?.Destroy();
            if (BinaryPath == null)
            {
                return(false);
            }
            if (process != null && !process.HasExited)
            {
                return(true);
            }
            PurgeOldLogs();
            Shutdown();
            var args = new [] { "/service", "/logPath:" + EscapeArgument(Interface.Oxide.LogDirectory) };

            try
            {
                process = new Process
                {
                    StartInfo =
                    {
                        FileName               = BinaryPath,
                        Arguments              = string.Join(" ", args),
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true
                    },
                    EnableRaisingEvents = true
                };
                process.Exited += OnProcessExited;
                process.Start();
            }
            catch (Exception ex)
            {
                process?.Dispose();
                process = null;
                Interface.Oxide.LogException("Exception while starting compiler: ", ex);
                if (ex.GetBaseException() != ex)
                {
                    Interface.Oxide.LogException("BaseException: ", ex.GetBaseException());
                }
            }
            if (process == null)
            {
                return(false);
            }
            client          = new ObjectStreamClient <CompilerMessage>(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
            client.Message += OnMessage;
            client.Error   += OnError;
            client.Start();
            return(true);
        }
Ejemplo n.º 4
0
        private bool CheckCompiler()
        {
            CheckCompilerBinary();
            idleTimer?.Destroy();
            if (BinaryPath == null)
            {
                return(false);
            }
            if (process != null && !process.HasExited)
            {
                return(true);
            }
            PurgeOldLogs();
            Shutdown();
            var args = new[] { "/service", "/logPath:" + EscapeArgument(Interface.Oxide.LogDirectory) };

            try
            {
                process = new Process
                {
                    StartInfo =
                    {
                        FileName               = BinaryPath,
                        Arguments              = string.Join(" ", args),
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true
                    },
                    EnableRaisingEvents = true
                };
                //string path;
                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.Win32NT:
                    //var currentPath = process.StartInfo.EnvironmentVariables["PATH"] ?? Environment.GetEnvironmentVariable("PATH");
                    //path = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, "x86")}";
                    //var newPath = string.IsNullOrEmpty(currentPath) ? path : $"{currentPath}{Path.PathSeparator}{path}";
                    process.StartInfo.EnvironmentVariables["PATH"] = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, "x86")}";
                    break;

                case PlatformID.Unix:
                case PlatformID.MacOSX:
                    //var currentLdLibraryPath = process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] ?? Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
                    //path = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")}";
                    //var newLdLibraryPath = string.IsNullOrEmpty(currentLdLibraryPath) ? path : $"{currentLdLibraryPath}{Path.PathSeparator}{path}";
                    process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")}";
                    break;
                }
                process.Exited += OnProcessExited;
                process.Start();
            }
            catch (Exception ex)
            {
                process?.Dispose();
                process = null;
                Interface.Oxide.LogException("Exception while starting compiler: ", ex); // TODO: Expand, warn that it may not be executable?
                if (ex.GetBaseException() != ex)
                {
                    Interface.Oxide.LogException("BaseException: ", ex.GetBaseException());
                }
            }
            if (process == null)
            {
                return(false);
            }
            client          = new ObjectStreamClient <CompilerMessage>(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
            client.Message += OnMessage;
            client.Error   += OnError;
            client.Start();
            return(true);
        }
Ejemplo n.º 5
0
 public void Shutdown()
 {
     ready = false;
     var ended_process = process;
     if (ended_process != null) ended_process.Exited -= OnProcessExited;
     process = null;
     if (client == null) return;
     client.Message -= OnMessage;
     client.Error -= OnError;
     client.PushMessage(new CompilerMessage { Type = CompilerMessageType.Exit });
     client.Stop();
     client = null;
     if (ended_process == null) return;
     ThreadPool.QueueUserWorkItem(_ =>
     {
         Thread.Sleep(5000);
         // Calling Close can block up to 60 seconds on certain machines
         if (!ended_process.HasExited) ended_process.Close();
     });
 }
Ejemplo n.º 6
0
 private bool CheckCompiler()
 {
     CheckCompilerBinary();
     idleTimer?.Destroy();
     if (BinaryPath == null) return false;
     if (process != null && !process.HasExited) return true;
     PurgeOldLogs();
     Shutdown();
     var args = new [] {"/service", "/logPath:" + EscapeArgument(Interface.Oxide.LogDirectory)};
     try
     {
         process = new Process
         {
             StartInfo =
             {
                 FileName = BinaryPath,
                 Arguments = string.Join(" ", args),
                 CreateNoWindow = true,
                 UseShellExecute = false,
                 RedirectStandardInput = true,
                 RedirectStandardOutput = true
             },
             EnableRaisingEvents = true
         };
         string path;
         switch (Environment.OSVersion.Platform)
         {
             case PlatformID.Win32S:
             case PlatformID.Win32Windows:
             case PlatformID.Win32NT:
                 var currentPath = process.StartInfo.EnvironmentVariables["PATH"] ?? Environment.GetEnvironmentVariable("PATH");
                 path = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, "x86")}";
                 var newPath = string.IsNullOrEmpty(currentPath) ? path : $"{currentPath}{Path.PathSeparator}{path}";
                 process.StartInfo.EnvironmentVariables["PATH"] = newPath;
                 break;
             case PlatformID.Unix:
             case PlatformID.MacOSX:
                 var currentLdLibraryPath = process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] ?? Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
                 path = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")}";
                 var newLdLibraryPath = string.IsNullOrEmpty(currentLdLibraryPath) ? path : $"{currentLdLibraryPath}{Path.PathSeparator}{path}";
                 process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] = newLdLibraryPath;
                 break;
         }
         process.Exited += OnProcessExited;
         process.Start();
     }
     catch (Exception ex)
     {
         process?.Dispose();
         process = null;
         Interface.Oxide.LogException("Exception while starting compiler: ", ex);
         if (ex.GetBaseException() != ex) Interface.Oxide.LogException("BaseException: ", ex.GetBaseException());
     }
     if (process == null) return false;
     client = new ObjectStreamClient<CompilerMessage>(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
     client.Message += OnMessage;
     client.Error += OnError;
     client.Start();
     return true;
 }
Ejemplo n.º 7
0
        private bool CheckCompiler()
        {
            CheckCompilerBinary();
            idleTimer?.Destroy();

            if (BinaryPath == null)
            {
                return(false);
            }
            if (process != null && process.Handle != IntPtr.Zero && !process.HasExited)
            {
                return(true);
            }

            SetCompilerVersion();
            PurgeOldLogs();
            Shutdown();

            var args = new[] { "/service", "/logPath:" + EscapePath(Interface.Oxide.LogDirectory) };

            try
            {
                process = new Process
                {
                    StartInfo =
                    {
                        FileName               = BinaryPath,
                        Arguments              = string.Join(" ", args),
                        CreateNoWindow         = true,
                        UseShellExecute        = false,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true
                    },
                    EnableRaisingEvents = true
                };
                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.Win32NT:
                    process.StartInfo.EnvironmentVariables["PATH"] = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, "x86")}";
                    break;

                case PlatformID.Unix:
                case PlatformID.MacOSX:
                    process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] = $"{Path.Combine(Interface.Oxide.ExtensionDirectory, IntPtr.Size == 8 ? "x64" : "x86")}";
                    break;
                }
                process.Exited += OnProcessExited;
                process.Start();
            }
            catch (Exception ex)
            {
                process?.Dispose();
                process = null;
                Interface.Oxide.LogException($"Exception while starting compiler v{CompilerVersion}: ", ex);
                if (BinaryPath.Contains("'"))
                {
                    Interface.Oxide.LogWarning("Server directory path contains an apostrophe, compiler will not work until path is renamed");
                }
                else if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    Interface.Oxide.LogWarning("Compiler may not be set as executable; chmod +x or 0744/0755 required");
                }
                if (ex.GetBaseException() != ex)
                {
                    Interface.Oxide.LogException("BaseException: ", ex.GetBaseException());
                }
                var win32 = ex as Win32Exception;
                if (win32 != null)
                {
                    Interface.Oxide.LogError("Win32 NativeErrorCode: {0} ErrorCode: {1} HelpLink: {2}", win32.NativeErrorCode, win32.ErrorCode, win32.HelpLink);
                }
            }

            if (process == null)
            {
                return(false);
            }

            client          = new ObjectStreamClient <CompilerMessage>(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
            client.Message += OnMessage;
            client.Error   += OnError;
            client.Start();
            return(true);
        }
Ejemplo n.º 8
0
 private bool CheckCompiler()
 {
     CheckCompilerBinary();
     idleTimer?.Destroy();
     if (BinaryPath == null) return false;
     if (process != null && !process.HasExited) return true;
     PurgeOldLogs();
     Shutdown();
     var args = new [] {"/service", "/logPath:" + EscapeArgument(Interface.Oxide.LogDirectory)};
     try
     {
         process = new Process
         {
             StartInfo =
             {
                 FileName = BinaryPath,
                 Arguments = string.Join(" ", args),
                 CreateNoWindow = true,
                 UseShellExecute = false,
                 RedirectStandardInput = true,
                 RedirectStandardOutput = true
             },
             EnableRaisingEvents = true
         };
         process.Exited += OnProcessExited;
         process.Start();
     }
     catch (Exception ex)
     {
         Interface.Oxide.LogException("Exception while starting compiler: ", ex);
     }
     if (process == null) return false;
     client = new ObjectStreamClient<CompilerMessage>(process.StandardOutput.BaseStream, process.StandardInput.BaseStream);
     client.Message += OnMessage;
     client.Error += OnError;
     client.Start();
     return true;
 }
        private bool CheckCompiler()
        {
            PluginCompiler.CheckCompilerBinary();
            Oxide.Core.Libraries.Timer.TimerInstance timerInstance = this.idleTimer;
            if (timerInstance != null)
            {
                timerInstance.Destroy();
            }
            else
            {
            }
            if (PluginCompiler.BinaryPath == null)
            {
                return(false);
            }
            if (this.process != null && this.process.Handle != IntPtr.Zero && !this.process.HasExited)
            {
                return(true);
            }
            PluginCompiler.SetCompilerVersion();
            PluginCompiler.PurgeOldLogs();
            this.Shutdown();
            string[] strArrays = new string[] { "/service", string.Concat("/logPath:", PluginCompiler.EscapePath(Interface.Oxide.LogDirectory)) };
            try
            {
                Process process = new Process();
                process.StartInfo.FileName               = PluginCompiler.BinaryPath;
                process.StartInfo.Arguments              = string.Join(" ", strArrays);
                process.StartInfo.CreateNoWindow         = true;
                process.StartInfo.UseShellExecute        = false;
                process.StartInfo.RedirectStandardInput  = true;
                process.StartInfo.RedirectStandardOutput = true;
                process.EnableRaisingEvents              = true;
                this.process = process;
                switch (Environment.OSVersion.Platform)
                {
                case PlatformID.Win32S:
                case PlatformID.Win32Windows:
                case PlatformID.Win32NT:
                {
                    string environmentVariable = Environment.GetEnvironmentVariable("PATH");
                    Environment.SetEnvironmentVariable("PATH", string.Concat(environmentVariable, ";", Path.Combine(Interface.Oxide.ExtensionDirectory, "x86")));
                    goto case PlatformID.Xbox;
                }

                case PlatformID.WinCE:
                case PlatformID.Xbox:
                {
                    this.process.Exited += new EventHandler(this.OnProcessExited);
                    this.process.Start();
                    break;
                }

                case PlatformID.Unix:
                case PlatformID.MacOSX:
                {
                    string str = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
                    this.process.StartInfo.EnvironmentVariables["LD_LIBRARY_PATH"] = Path.Combine(Interface.Oxide.ExtensionDirectory, (IntPtr.Size == 8 ? "x64" : "x86"));
                    Environment.SetEnvironmentVariable("LD_LIBRARY_PATH", string.Concat(str, ":", Path.Combine(Interface.Oxide.ExtensionDirectory, (IntPtr.Size == 8 ? "x64" : "x86"))));
                    goto case PlatformID.Xbox;
                }

                default:
                {
                    goto case PlatformID.Xbox;
                }
                }
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                Process   process1  = this.process;
                if (process1 != null)
                {
                    process1.Dispose();
                }
                else
                {
                }
                this.process = null;
                Interface.Oxide.LogException(string.Concat("Exception while starting compiler version ", PluginCompiler.CompilerVersion, ": "), exception);
                if (PluginCompiler.BinaryPath.Contains("'"))
                {
                    Interface.Oxide.LogWarning("Server directory path contains an apostrophe, compiler will not work until path is renamed", Array.Empty <object>());
                }
                else if (Environment.OSVersion.Platform == PlatformID.Unix)
                {
                    Interface.Oxide.LogWarning("Compiler may not be set as executable; chmod +x or 0744/0755 required", Array.Empty <object>());
                }
                if (exception.GetBaseException() != exception)
                {
                    Interface.Oxide.LogException("BaseException: ", exception.GetBaseException());
                }
                Win32Exception win32Exception = exception as Win32Exception;
                if (win32Exception != null)
                {
                    Interface.Oxide.LogError("Win32 NativeErrorCode: {0} ErrorCode: {1} HelpLink: {2}", new object[] { win32Exception.NativeErrorCode, win32Exception.ErrorCode, win32Exception.HelpLink });
                }
            }
            if (this.process == null)
            {
                return(false);
            }
            this.client          = new ObjectStreamClient <CompilerMessage>(this.process.StandardOutput.BaseStream, this.process.StandardInput.BaseStream);
            this.client.Message += new ConnectionMessageEventHandler <CompilerMessage, CompilerMessage>(this.OnMessage);
            this.client.Error   += new StreamExceptionEventHandler(PluginCompiler.OnError);
            this.client.Start();
            return(true);
        }