Esempio n. 1
0
        public static void CheckRestart()
        {
            string[] files = ScriptCompiler.GetScripts("*.cs");

            if (files.Length == 0)
            {
                m_Mobile.SendMessage("No scripts found to compile!");
                return;
            }

            if (AlreadyCached(files))
            {
                m_Mobile.SendMessage("Scripts are already cached. Restarting...");
                DoRestart(new object[] { false });
                return;
            }

            using (CSharpCodeProvider provider = new CSharpCodeProvider())
            {
                string path = GetUnusedPath("Scripts.CS");

                CompilerParameters parms = new CompilerParameters(ScriptCompiler.GetReferenceAssemblies(), path, m_Debug);

                string defines = ScriptCompiler.GetDefines();

                if (defines != null)
                {
                    parms.CompilerOptions = string.Format("/D:{0}", defines);
                }

                m_Mobile.SendMessage("Compiling C# scripts, please wait...");
                World.Broadcast(1154, true, "[ATTENTION]:The server is restarting shortly...");

                CompilerResults results = provider.CompileAssemblyFromFile(parms, files);

                if (results.Errors.Count > 0)
                {
                    m_Mobile.SendMessage("There were errors in compiling the scripts. QuickRestart can NOT restart.");
                    World.Broadcast(1154, true, "[ATTENTION]:Server restart has been aborted.");
                    m_Restarting = false;
                    return;
                }

                if (Path.GetFileName(path) == "Scripts.CS.dll.new")
                {
                    try
                    {
                        byte[] hashCode = GetHashCode(path, files, false);

                        using (FileStream fs = new FileStream("Scripts/Output/Scripts.CS.hash.new", FileMode.Create, FileAccess.Write, FileShare.None))
                        {
                            using (BinaryWriter bin = new BinaryWriter(fs))
                            {
                                bin.Write(hashCode, 0, hashCode.Length);
                            }
                        }
                    }
                    catch { }
                }

                m_Mobile.SendMessage("Compilation successful. Restarting in 15 seconds.");
                World.Broadcast(1154, true, "[ATTENTION]:The server will restart in 15 seconds.");
                Timer.DelayCall(TimeSpan.FromSeconds(15.0), new TimerStateCallback(DoRestart), new object[] { true });
            }
        }