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 }); } }
public void Check() { Console.Write("AutoPublish: Updating SVN..."); new SVNCommand(null, false); Console.WriteLine("done."); int pubrev = AutoPublish.PublishRevision; if (File.Exists(AutoPublish.PublishCFG)) { using (StreamReader ip = new StreamReader(AutoPublish.PublishCFG)) { string line; if ((line = ip.ReadLine()) != null) { pubrev = Utility.ToInt32(line); } } if (m_Force || pubrev > AutoPublish.PublishRevision) //New code to push! { if (pubrev > AutoPublish.PublishRevision) { Console.Write("AutoPublish: Publish {0} found, creating compiler...", pubrev); } else { Console.Write("AutoPublish: Publish forced, creating compiler..."); } string serverpath = "NextPublish.Server.exe"; bool failed = false; if (File.Exists(serverpath)) { File.Delete(serverpath); } #if Framework_3_5 using (CSharpCodeProvider provider = new CSharpCodeProvider(new Dictionary <string, string>() { { "CompilerVersion", "v3.5" } })) #else using (CSharpCodeProvider provider = new CSharpCodeProvider()) #endif { CompilerParameters parms = new CompilerParameters(new string[0], serverpath, Core.Debug); string defines = ScriptCompiler.GetDefines(); if (!String.IsNullOrEmpty(defines)) { parms.CompilerOptions = defines; } if (Core.HaltOnWarning) { parms.WarningLevel = 4; } parms.GenerateExecutable = true; //Make an exe! parms.Win32Resource = "Server\runuo.ico"; #if !MONO CompilerResults results = provider.CompileAssemblyFromFile(parms, ScriptCompiler.GetScripts("Server", "*.cs")); #else parms.CompilerOptions = String.Format("{0} /nowarn:169,219,414 /recurse:Server/*.cs", parms.CompilerOptions); CompilerResults results = provider.CompileAssemblyFromFile(parms, String.Empty); #endif //ScriptCompiler.Display( results ); #if !MONO if (results.Errors.Count > 0) { failed = true; } #else if (results.Errors.Count > 0) { foreach (CompilerError err in results.Errors) { if (!err.IsWarning) { failed = true; break; } } } #endif } if (!failed) { Console.WriteLine("done."); Console.Write("AutoPublish: Compiling scripts..."); ProcessStartInfo publishinfo = new ProcessStartInfo(serverpath); publishinfo.Arguments = "-publish"; publishinfo.WindowStyle = ProcessWindowStyle.Hidden; publishinfo.CreateNoWindow = true; publishinfo.UseShellExecute = false; publishinfo.WorkingDirectory = Core.BaseDirectory; Process publishproc = new Process(); publishproc.StartInfo = publishinfo; publishproc.Start(); publishproc.WaitForExit(600000); if (publishproc != null && !publishproc.HasExited) { Console.WriteLine("failed. (timed out at 600s)"); publishproc.Kill(); } else { Console.WriteLine("done."); } if (File.Exists(@"Scripts\Output\NextPublish.Scripts.CS.dll") && File.Exists(@"Scripts\Output\NextPublish.Scripts.CS.hash")) { if (TestCenter.Enabled) { SchedulePublish(TimeSpan.FromMinutes(10.0)); } else { SchedulePublish(TimeSpan.FromHours(48.0)); } AutoPublish.PublishRevision = pubrev; } } else { Console.WriteLine("failed."); } } } }