public Library(LibraryConfig libConfig, string _name, Assembly _assembly) { name = _name; assembly = _assembly; ArrayList typeList = new ArrayList(); foreach (Type type in assembly.GetTypes()) { if (libConfig == null || !libConfig.GetIgnoreType(type)) typeList.Add(type); } types = (Type[])typeList.ToArray(typeof(Type)); typesByName = new TypeTable(types.Length); typesByFullName = new TypeTable(types.Length); Type typeofTypeAliasAttribute = typeof(TypeAliasAttribute); foreach (Type type in types) { typesByName.Add(type.Name, type); typesByFullName.Add(type.FullName, type); if (type.IsDefined(typeofTypeAliasAttribute, false)) { object[] attrs = type.GetCustomAttributes(typeofTypeAliasAttribute, false); if (attrs != null && attrs.Length > 0 && attrs[0] != null) { TypeAliasAttribute attr = attrs[0] as TypeAliasAttribute; foreach (string alias in attr.Aliases) typesByFullName.Add(alias, type); } } } typeCache = new TypeCache(types, typesByName, typesByFullName); }
private static void GetScripts(LibraryConfig libConfig, ArrayList list, string path, string type) { foreach ( string dir in Directory.GetDirectories( path ) ) GetScripts(libConfig, list, dir, type); foreach (string filename in Directory.GetFiles(path, type)) { /* XXX: pass relative filename only */ if (libConfig == null || !libConfig.GetIgnoreSource(filename)) list.Add(filename); } }
private static string[] GetScripts(LibraryConfig libConfig, string path, string type) { ArrayList list = new ArrayList(); GetScripts(libConfig, list, path, type); return (string[])list.ToArray( typeof( string ) ); }
private static bool Compile(string name, string path, LibraryConfig libConfig, bool debug) { DirectoryInfo cache = Core.CacheDirectoryInfo .CreateSubdirectory("lib") .CreateSubdirectory(name); if (!cache.Exists) { Console.WriteLine("Failed to create directory {0}", cache.FullName); return false; } string csFile = Path.Combine(cache.FullName, name + ".dll"); Hashtable files = GetScripts(libConfig, path, "*.cs"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, name + ".stm"); if (File.Exists(csFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", name); } else { CompilerResults results = CompileCSScripts(name, files.Keys, csFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); WriteStampFile(stampFile, files); } } } string vbFile = Path.Combine(cache.FullName, name + "-vb.dll"); files = GetScripts(libConfig, path, "*.vb"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, name + "-vb.stm"); if (File.Exists(vbFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(vbFile))); m_AdditionalReferences.Add(vbFile); Console.Write("{0}/VB. ", name); } else { CompilerResults results = CompileVBScripts(name, files.Keys, vbFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); } } } return true; }
private static void GetScripts(LibraryConfig libConfig, Hashtable list, string path, string type) { foreach ( string dir in Directory.GetDirectories( path ) ) GetScripts(libConfig, list, dir, type); foreach (string filename in Directory.GetFiles(path, type)) { /* XXX: pass relative filename only */ if (libConfig == null || !libConfig.GetIgnoreSource(filename)) list[filename] = File.GetLastWriteTime(filename); } }
private static Hashtable GetScripts(LibraryConfig libConfig, IEnumerable overlays, string type) { Hashtable files = GetScripts(libConfig, type); if (overlays != null) { foreach (LibraryConfig overlay in overlays) { Hashtable files2 = GetScripts(overlay, type); Overlay(libConfig.SourcePath.FullName, files, overlay.SourcePath.FullName, files2); } } return files; }
private static CompilerResults CompileVBScripts(ICollection fileColl, string assemblyFile, LibraryConfig libConfig, bool debug) { VBCodeProvider provider = new VBCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); Console.Write("{0}[VB,{1}", libConfig.Name, files.Length); CompilerResults results = compiler.CompileAssemblyFromFileBatch( new CompilerParameters( GetReferenceAssemblies(), assemblyFile, true ), files ); m_AdditionalReferences.Add(assemblyFile); if ( results.Errors.Count > 0 ) { int errorCount = 0, warningCount = 0; foreach ( CompilerError e in results.Errors ) { if ( e.IsWarning ) ++warningCount; else ++errorCount; } Console.WriteLine(); if ( errorCount > 0 ) Console.WriteLine( "failed ({0} errors, {1} warnings)", errorCount, warningCount ); else Console.WriteLine( "done ({0} errors, {1} warnings)", errorCount, warningCount ); foreach ( CompilerError e in results.Errors ) { Console.WriteLine( " - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText ); } } else { Console.Write("] "); } return results; }
private static bool Compile(LibraryConfig libConfig, bool debug) { /* check if there is source code for this library */ if (libConfig.SourcePath == null) { if (libConfig.BinaryPath == null) { Console.WriteLine("Warning: library {0} does not exist", libConfig.Name); return true; } else if (!libConfig.BinaryPath.Exists) { Console.WriteLine("Warning: library {0} does not exist: {1}", libConfig.Name, libConfig.BinaryPath); return false; } Console.Write("{0}", libConfig.Name); libraries.Add(new Library(libConfig, Assembly.LoadFrom(libConfig.SourcePath.FullName))); m_AdditionalReferences.Add(libConfig.SourcePath.FullName); Console.Write(". "); return true; } else if (!libConfig.SourcePath.Exists) { Console.WriteLine("Warning: library {0} does not exist: {1}", libConfig.Name, libConfig.SourcePath); } DirectoryInfo cache = Core.CacheDirectoryInfo .CreateSubdirectory("lib") .CreateSubdirectory(libConfig.Name); if (!cache.Exists) { Console.WriteLine("Failed to create directory {0}", cache.FullName); return false; } ArrayList overlays = null; if (libConfig.Overlays != null) { overlays = new ArrayList(); foreach (string name in libConfig.Overlays) overlays.Add(Core.Config.GetLibraryConfig(name)); } string csFile = Path.Combine(cache.FullName, libConfig.Name + ".dll"); Hashtable files = GetScripts(libConfig, overlays, "*.cs"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, libConfig.Name + ".stm"); if (File.Exists(csFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", libConfig.Name); } else { /* work around a serious faction bug: the factions code (Reflector.cs) assumes alphabetical directory entry order; simulate this by sorting the array. See my bug report: http://www.runuo.com/forum/showthread.php?p=373540 */ ArrayList sorted = new ArrayList(files.Keys); sorted.Sort(); CompilerResults results = CompileCSScripts(sorted, csFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, results.CompiledAssembly)); WriteStampFile(stampFile, files); } } } string vbFile = Path.Combine(cache.FullName, libConfig.Name + "-vb.dll"); files = GetScripts(libConfig, overlays, "*.vb"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, libConfig.Name + "-vb.stm"); if (File.Exists(vbFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, Assembly.LoadFrom(vbFile))); m_AdditionalReferences.Add(vbFile); Console.Write("{0}/VB. ", libConfig.Name); } else { /* workaround again */ ArrayList sorted = new ArrayList(files.Keys); sorted.Sort(); CompilerResults results = CompileVBScripts(sorted, vbFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, results.CompiledAssembly)); } } } return true; }
public void Load() { document = new XmlDocument(); dataDirectories = new ArrayList(); libraryConfig = new Hashtable(); if (File.Exists(filename)) { XmlTextReader reader = new XmlTextReader(filename); try { document.Load(reader); } finally { reader.Close(); } } else { document.AppendChild(document.CreateElement("sunuo-config")); } XmlElement locations = GetConfiguration("locations"); foreach (XmlElement dp in locations.GetElementsByTagName("data-path")) { string path = dp.InnerText; if (Directory.Exists(path)) dataDirectories.Add(path); } XmlElement librariesEl = GetConfiguration("libraries"); foreach (XmlElement el in librariesEl.GetElementsByTagName("library")) { LibraryConfig lc = new LibraryConfig(el); if (lc.Name != null) libraryConfig[lc.Name] = lc; } XmlElement loginEl = GetConfiguration("login"); loginConfig = loginEl == null ? new LoginConfig() : new LoginConfig(loginEl); }
private static bool Compile(string name, string path, LibraryConfig libConfig, bool debug) { DirectoryInfo cache = Core.CacheDirectoryInfo .CreateSubdirectory("lib") .CreateSubdirectory(name); if (!cache.Exists) { Console.WriteLine("Failed to create directory {0}", cache.FullName); return(false); } string csFile = Path.Combine(cache.FullName, name + ".dll"); Hashtable files = GetScripts(libConfig, path, "*.cs"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, name + ".stm"); if (File.Exists(csFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", name); } else { CompilerResults results = CompileCSScripts(name, files.Keys, csFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) { return(false); } libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); WriteStampFile(stampFile, files); } } } string vbFile = Path.Combine(cache.FullName, name + "-vb.dll"); files = GetScripts(libConfig, path, "*.vb"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, name + "-vb.stm"); if (File.Exists(vbFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(vbFile))); m_AdditionalReferences.Add(vbFile); Console.Write("{0}/VB. ", name); } else { CompilerResults results = CompileVBScripts(name, files.Keys, vbFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) { return(false); } libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); } } } return(true); }
public static bool Compile(bool debug) { Console.Write("Compiling scripts: "); if (m_AdditionalReferences != null) { throw new ApplicationException("already compiled"); } m_AdditionalReferences = new ArrayList(); libraries = new ArrayList(); libraries.Add(new Library(Core.Config.GetLibraryConfig("core"), Core.Assembly)); m_AdditionalReferences.Add(Core.ExePath); /* prepare overlays */ foreach (LibraryConfig libConfig in Core.Config.Libraries) { if (libConfig.Overlays == null || !libConfig.Exists || libConfig.Name == "core") { continue; } if (libConfig.SourcePath == null) { Console.WriteLine("Can't overlay the binary library {0}", libConfig.Name); throw new ApplicationException(); } foreach (string name in libConfig.Overlays) { LibraryConfig overlay = Core.Config.GetLibraryConfig(name); if (overlay == null || !overlay.Exists) { Console.WriteLine("Can't overlay {0} with {1}, because it does not exist", libConfig.Name, overlay.Name); throw new ApplicationException(); } if (overlay.SourcePath == null) { Console.WriteLine("Can't overlay {0} with {1}, because it is binary only", libConfig.Name, overlay.Name); throw new ApplicationException(); } overlay.Disabled = true; } } foreach (LibraryConfig libConfig in Core.Config.Libraries) { if (libConfig.Overlays != null && libConfig.Exists && libConfig.Name != "core" && libConfig.Disabled) { Console.WriteLine("Can't overlay library {0} which is already used as overlay for another library", libConfig.Name); throw new ApplicationException(); } } /* collect LibraryConfig objects, sort them and compile */ ArrayList libConfigs = SortLibrariesByDepends(); foreach (LibraryConfig libConfig in libConfigs) { bool result = Compile(libConfig, debug); if (!result) { return(false); } } /* delete unused cache directories */ DirectoryInfo cacheDir = Core.CacheDirectoryInfo .CreateSubdirectory("lib"); foreach (DirectoryInfo sub in cacheDir.GetDirectories()) { string libName = sub.Name.ToLower(); if (GetLibrary(libName) == null) { sub.Delete(true); } } /* done */ Console.WriteLine(); return(true); }
/** * enqueue a library for compilation, resolving all * dependencies first * * @param dst this array will receive the libraries in the correct order * @param libs source libraries * @param queue somewhat like a stack of libraries currently waiting * @param libConfig the library to be added */ private static void EnqueueLibrary(ArrayList dst, ArrayList libs, Hashtable queue, LibraryConfig libConfig) { string[] depends = libConfig.Depends; if (libConfig.Name == "core" || libConfig.Disabled) { libs.Remove(libConfig); return; } if (!libConfig.Exists) { libs.Remove(libConfig); Console.WriteLine("Warning: library {0} does not exist", libConfig.Name); return; } /* first resolve dependencies */ if (depends != null) { queue[libConfig.Name] = 1; foreach (string depend in depends) { /* if the depended library is already in the * queue, there is a circular dependency */ if (queue.ContainsKey(depend)) { Console.WriteLine("Circular library dependency {0} on {1}", libConfig.Name, depend); throw new ApplicationException(); } LibraryConfig next = Core.Config.GetLibraryConfig(depend); if (next == null || !next.Exists) { Console.WriteLine("Unresolved library dependency: {0} depends on {1}, which does not exist", libConfig.Name, depend); throw new ApplicationException(); } if (next.Disabled) { Console.WriteLine("Unresolved library dependency: {0} depends on {1}, which is disabled", libConfig.Name, depend); throw new ApplicationException(); } if (!dst.Contains(next)) { EnqueueLibrary(dst, libs, queue, next); } } queue.Remove(libConfig.Name); } /* then add it to 'dst' */ dst.Add(libConfig); libs.Remove(libConfig); }
private static CompilerResults CompileCSScripts(ICollection fileColl, string assemblyFile, LibraryConfig libConfig, bool debug) { CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files; Console.Write("{0}[C#,{1}", libConfig.Name, fileColl.Count); string tempFile = compiler.GetType().FullName == "Mono.CSharp.CSharpCodeCompiler" ? Path.GetTempFileName() : null; if (tempFile == String.Empty) tempFile = null; if (tempFile == null) { files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); } else { /* to prevent an "argument list too long" error, we write a list of file names to a temporary file and add them with @filename */ StreamWriter w = new StreamWriter(tempFile, false); foreach (string file in fileColl) { w.Write("\"" + file + "\" "); } w.Close(); files = new string[0]; } CompilerParameters parms = new CompilerParameters( GetReferenceAssemblies(), assemblyFile, debug ); if (tempFile != null) parms.CompilerOptions += "@" + tempFile; if (libConfig.WarningLevel >= 0) parms.WarningLevel = libConfig.WarningLevel; CompilerResults results = null; try { results = compiler.CompileAssemblyFromFileBatch( parms, files ); } catch (System.ComponentModel.Win32Exception e) { /* from WinError.h: * #define ERROR_FILE_NOT_FOUND 2L * #define ERROR_PATH_NOT_FOUND 3L */ if (e.NativeErrorCode == 2 || e.NativeErrorCode == 3) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Could not find the compiler - are you sure MCS is installed?"); Console.WriteLine("On Debian, try: apt-get install mono-mcs"); Environment.Exit(2); } else { throw e; } } if (tempFile != null) File.Delete(tempFile); m_AdditionalReferences.Add(assemblyFile); if ( results.Errors.Count > 0 ) { int errorCount = 0, warningCount = 0; foreach ( CompilerError e in results.Errors ) { if ( e.IsWarning ) ++warningCount; else ++errorCount; } Console.WriteLine(); if ( errorCount > 0 ) Console.WriteLine( "failed ({0} errors, {1} warnings)", errorCount, warningCount ); else Console.WriteLine( "done ({0} errors, {1} warnings)", errorCount, warningCount ); foreach ( CompilerError e in results.Errors ) { Console.WriteLine( " - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText ); } } else { Console.Write("] "); } return results; }
private static bool Compile(string name, string path, LibraryConfig libConfig, bool debug) { DirectoryInfo cache = Core.CacheDirectoryInfo .CreateSubdirectory("lib") .CreateSubdirectory(name); if (!cache.Exists) { Console.WriteLine("Failed to create directory {0}", cache.FullName); return(false); } string oldFile = Path.Combine(cache.FullName, name + "-cs.dll"); string csFile = Path.Combine(cache.FullName, name + ".dll"); if (File.Exists(csFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", name); } else if (File.Exists(oldFile)) { /* old style file name, rename that */ File.Move(oldFile, csFile); libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", name); } else { CompilerResults results = CompileCSScripts(name, path, csFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) { return(false); } libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); } } string vbFile = Path.Combine(cache.FullName, name + "-vb.dll"); if (File.Exists(vbFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(vbFile))); m_AdditionalReferences.Add(vbFile); Console.Write("{0}/VB. ", name); } else { CompilerResults results = CompileVBScripts(name, path, vbFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) { return(false); } libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); } } return(true); }
private static CompilerResults CompileCSScripts(string name, ICollection fileColl, string assemblyFile, LibraryConfig libConfig, bool debug) { CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files; Console.Write("{0}[C#,{1}", name, fileColl.Count); string tempFile = compiler.GetType().FullName == "Mono.CSharp.CSharpCodeCompiler" ? Path.GetTempFileName() : null; if (tempFile == String.Empty) { tempFile = null; } if (tempFile == null) { files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); } else { /* to prevent an "argument list too long" error, we * write a list of file names to a temporary file * and add them with @filename */ StreamWriter w = new StreamWriter(tempFile, false); foreach (string file in fileColl) { w.Write("\"" + file + "\" "); } w.Close(); files = new string[0]; } CompilerParameters parms = new CompilerParameters(GetReferenceAssemblies(), assemblyFile, debug); if (tempFile != null) { parms.CompilerOptions += "@" + tempFile; } CompilerResults results = compiler.CompileAssemblyFromFileBatch(parms, files); if (tempFile != null) { File.Delete(tempFile); } m_AdditionalReferences.Add(assemblyFile); if (results.Errors.Count > 0) { int errorCount = 0, warningCount = 0; foreach (CompilerError e in results.Errors) { if (e.IsWarning) { ++warningCount; } else { ++errorCount; } } Console.WriteLine(); if (errorCount > 0) { Console.WriteLine("failed ({0} errors, {1} warnings)", errorCount, warningCount); } else { Console.WriteLine("done ({0} errors, {1} warnings)", errorCount, warningCount); } foreach (CompilerError e in results.Errors) { Console.WriteLine(" - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText); } } else { Console.Write("] "); } return(results); }
private static Hashtable GetScripts(LibraryConfig libConfig, string path, string type) { Hashtable list = new Hashtable(); GetScripts(libConfig, list, path, type); return list; }
private static bool Compile(string name, string path, LibraryConfig libConfig, bool debug) { DirectoryInfo cache = Core.CacheDirectoryInfo .CreateSubdirectory("lib") .CreateSubdirectory(name); if (!cache.Exists) { Console.WriteLine("Failed to create directory {0}", cache.FullName); return(false); } string csFile = Path.Combine(cache.FullName, name + ".dll"); Hashtable files = GetScripts(libConfig, path, "*.cs"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, name + ".stm"); if (File.Exists(csFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", name); } else { /* work around a serious faction bug: the factions * code (Reflector.cs) assumes alphabetical * directory entry order; simulate this by sorting * the array. See my bug report: * http://www.runuo.com/forum/showthread.php?p=373540 */ ArrayList sorted = new ArrayList(files.Keys); sorted.Sort(); CompilerResults results = CompileCSScripts(name, sorted, csFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) { return(false); } libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); WriteStampFile(stampFile, files); } } } string vbFile = Path.Combine(cache.FullName, name + "-vb.dll"); files = GetScripts(libConfig, path, "*.vb"); if (files.Count > 0) { string stampFile = Path.Combine(cache.FullName, name + "-vb.stm"); if (File.Exists(vbFile) && CheckStamps(files, stampFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(vbFile))); m_AdditionalReferences.Add(vbFile); Console.Write("{0}/VB. ", name); } else { /* workaround again */ ArrayList sorted = new ArrayList(files.Keys); sorted.Sort(); CompilerResults results = CompileVBScripts(name, sorted, vbFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) { return(false); } libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); } } } return(true); }
private void Defaults() { LibraryConfig coreConfig = new LibraryConfig("core"); libraryConfig["core"] = coreConfig; LibraryConfig legacyConfig; DirectoryInfo legacy = new DirectoryInfo(Path.Combine(Core.BaseDirectory, "Scripts")); if (legacy.Exists) { legacyConfig = new LibraryConfig("legacy", legacy); libraryConfig[legacyConfig.Name] = legacyConfig; } DirectoryInfo local = Core.BaseDirectoryInfo .CreateSubdirectory("local"); DirectoryInfo src = local .CreateSubdirectory("src"); foreach (DirectoryInfo sub in src.GetDirectories()) { string libName = sub.Name.ToLower(); if (libName == "core" || libName == "legacy") { Console.WriteLine("Warning: the library name '{0}' is invalid", libName); continue; } libraryConfig[libName] = new LibraryConfig(libName, sub); } DirectoryInfo lib = local .CreateSubdirectory("lib"); foreach (FileInfo libFile in lib.GetFiles("*.dll")) { string fileName = libFile.Name; string libName = fileName.Substring(0, fileName.Length - 4).ToLower(); if (libName == "core" || libName == "legacy") { Console.WriteLine("Warning: the library name '{0}' is invalid", libName); continue; } if (libraryConfig.ContainsKey(libName)) { Console.WriteLine("Warning: duplicate library '{0}' in '{1}'", libName, libFile); continue; } libraryConfig[libName] = new LibraryConfig(libName, libFile); } }
private static CompilerResults CompileCSScripts(ICollection fileColl, string assemblyFile, LibraryConfig libConfig, bool debug) { CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files; Console.Write("{0}[C#,{1}", libConfig.Name, fileColl.Count); string tempFile = compiler.GetType().FullName == "Mono.CSharp.CSharpCodeCompiler" ? Path.GetTempFileName() : null; if (tempFile == String.Empty) tempFile = null; if (tempFile == null) { files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); } else { /* to prevent an "argument list too long" error, we write a list of file names to a temporary file and add them with @filename */ StreamWriter w = new StreamWriter(tempFile, false); foreach (string file in fileColl) { w.Write("\"" + file + "\" "); } w.Close(); files = new string[0]; } CompilerParameters parms = new CompilerParameters( GetReferenceAssemblies(), assemblyFile, debug ); if (tempFile != null) parms.CompilerOptions += "@" + tempFile; CompilerResults results = compiler.CompileAssemblyFromFileBatch( parms, files ); if (tempFile != null) File.Delete(tempFile); m_AdditionalReferences.Add(assemblyFile); if ( results.Errors.Count > 0 ) { int errorCount = 0, warningCount = 0; foreach ( CompilerError e in results.Errors ) { if ( e.IsWarning ) ++warningCount; else ++errorCount; } Console.WriteLine(); if ( errorCount > 0 ) Console.WriteLine( "failed ({0} errors, {1} warnings)", errorCount, warningCount ); else Console.WriteLine( "done ({0} errors, {1} warnings)", errorCount, warningCount ); foreach ( CompilerError e in results.Errors ) { Console.WriteLine( " - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText ); } } else { Console.Write("] "); } return results; }
private void Load() { document = new XmlDocument(); dataDirectories = new ArrayList(); if (Exists) { XmlTextReader reader = new XmlTextReader(filename); try { document.Load(reader); } finally { reader.Close(); } } else { document.AppendChild(document.CreateElement("sunuo-config")); } // section "global" XmlElement global = GetConfiguration("global"); if (global != null) { multiThreading = GetElementBool(global, "multi-threading", false); } // section "locations" XmlElement locations = GetConfiguration("locations"); foreach (XmlElement dp in locations.GetElementsByTagName("data-path")) { string path = dp.InnerText; if (Directory.Exists(path)) dataDirectories.Add(path); } // section "libraries" XmlElement librariesEl = GetConfiguration("libraries"); foreach (XmlElement el in librariesEl.GetElementsByTagName("library")) { string name = el.GetAttribute("name"); if (name == null || name == "") { Console.WriteLine("Warning: library element without name attribute"); continue; } name = name.ToLower(); LibraryConfig libConfig = (LibraryConfig)libraryConfig[name]; if (libConfig == null) libraryConfig[name] = libConfig = new LibraryConfig(name); libConfig.Load(el); } if (!libraryConfig.ContainsKey("legacy")) libraryConfig["legacy"] = new LibraryConfig("legacy"); // section "login" XmlElement loginEl = GetConfiguration("login"); loginConfig = loginEl == null ? new LoginConfig() : new LoginConfig(loginEl); }
/** * enqueue a library for compilation, resolving all * dependencies first * * @param dst this array will receive the libraries in the correct order * @param libs source libraries * @param queue somewhat like a stack of libraries currently waiting * @param libConfig the library to be added */ private static void EnqueueLibrary(ArrayList dst, ArrayList libs, Hashtable queue, LibraryConfig libConfig) { string[] depends = libConfig.Depends; if (libConfig.Name == "core" || libConfig.Disabled) { libs.Remove(libConfig); return; } if (!libConfig.Exists) { libs.Remove(libConfig); Console.WriteLine("Warning: library {0} does not exist", libConfig.Name); return; } /* first resolve dependencies */ if (depends != null) { queue[libConfig.Name] = 1; foreach (string depend in depends) { /* if the depended library is already in the * queue, there is a circular dependency */ if (queue.ContainsKey(depend)) { Console.WriteLine("Circular library dependency {0} on {1}", libConfig.Name, depend); throw new ApplicationException(); } LibraryConfig next = Core.Config.GetLibraryConfig(depend); if (next == null || !next.Exists) { Console.WriteLine("Unresolved library dependency: {0} depends on {1}, which does not exist", libConfig.Name, depend); throw new ApplicationException(); } if (next.Disabled) { Console.WriteLine("Unresolved library dependency: {0} depends on {1}, which is disabled", libConfig.Name, depend); throw new ApplicationException(); } if (!dst.Contains(next)) EnqueueLibrary(dst, libs, queue, next); } queue.Remove(libConfig.Name); } /* then add it to 'dst' */ dst.Add(libConfig); libs.Remove(libConfig); }
private void Load() { document = new XmlDocument(); dataDirectories = new ArrayList(); if (Exists) { XmlTextReader reader = new XmlTextReader(filename); try { document.Load(reader); } finally { reader.Close(); } } else { document.AppendChild(document.CreateElement("sunuo-config")); } // section "global" XmlElement global = GetConfiguration("global"); if (global != null) { multiThreading = GetElementBool(global, "multi-threading", false); } // section "locations" XmlElement locations = GetConfiguration("locations"); foreach (XmlElement dp in locations.GetElementsByTagName("data-path")) { string path = dp.InnerText; if (Directory.Exists(path)) { dataDirectories.Add(path); } } // section "libraries" XmlElement librariesEl = GetConfiguration("libraries"); foreach (XmlElement el in librariesEl.GetElementsByTagName("library")) { string name = el.GetAttribute("name"); if (name == null || name == "") { Console.WriteLine("Warning: library element without name attribute"); continue; } name = name.ToLower(); LibraryConfig libConfig = (LibraryConfig)libraryConfig[name]; if (libConfig == null) { libraryConfig[name] = libConfig = new LibraryConfig(name); } libConfig.Load(el); } if (!libraryConfig.ContainsKey("legacy")) { libraryConfig["legacy"] = new LibraryConfig("legacy"); } // section "login" XmlElement loginEl = GetConfiguration("login"); loginConfig = loginEl == null ? new LoginConfig() : new LoginConfig(loginEl); }
private static Hashtable GetScripts(LibraryConfig libConfig, string type) { Hashtable list = new Hashtable(); GetScripts(libConfig, list, libConfig.SourcePath.FullName, type); return list; }
private static bool Compile(string name, string path, LibraryConfig libConfig, bool debug) { DirectoryInfo cache = Core.CacheDirectoryInfo .CreateSubdirectory("lib") .CreateSubdirectory(name); if (!cache.Exists) { Console.WriteLine("Failed to create directory {0}", cache.FullName); return false; } string oldFile = Path.Combine(cache.FullName, name + "-cs.dll"); string csFile = Path.Combine(cache.FullName, name + ".dll"); if (File.Exists(csFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", name); } else if (File.Exists(oldFile)) { /* old style file name, rename that */ File.Move(oldFile, csFile); libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(csFile))); m_AdditionalReferences.Add(csFile); Console.Write("{0}. ", name); } else { CompilerResults results = CompileCSScripts(name, path, csFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); } } string vbFile = Path.Combine(cache.FullName, name + "-vb.dll"); if (File.Exists(vbFile)) { libraries.Add(new Library(libConfig, name, Assembly.LoadFrom(vbFile))); m_AdditionalReferences.Add(vbFile); Console.Write("{0}/VB. ", name); } else { CompilerResults results = CompileVBScripts(name, path, vbFile, libConfig, debug); if (results != null) { if (results.Errors.HasErrors) return false; libraries.Add(new Library(libConfig, name, results.CompiledAssembly)); } } return true; }
public static void Main(string[] args) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; ParseArguments(args); SetupConsoleLogging(); m_Thread = Thread.CurrentThread; Process = Process.GetCurrentProcess(); Assembly = Assembly.GetEntryAssembly(); if (m_Thread != null) { m_Thread.Name = "Core Thread"; } if (BaseDirectory.Length > 0) { Directory.SetCurrentDirectory(BaseDirectory); } var version = Assembly.GetName().Version; CoreVersion = version; var platform = (int)Environment.OSVersion.Platform; if (platform == 4 || platform == 128) { Unix = true; } GCSettings.LatencyMode = GCLatencyMode.LowLatency; log.Info("X-RunUO Server - Version {0}.{1}.{2}, Build {3}", version.Major, version.Minor, version.Build, version.Revision); log.Info("Running on OS {0}", Environment.OSVersion); log.Info("Running on {0} {1}", Unix ? "Mono" : ".NET Framework", Environment.Version); if (MultiProcessor || Is64Bit) { log.Info("Optimizing for {0} {2}processor{1}", ProcessorCount, ProcessorCount == 1 ? "" : "s", Is64Bit ? "64-bit " : ""); } log.Info("Using GC {0} {1} mode", GCSettings.IsServerGC ? "Server" : "Workstation", GCSettings.LatencyMode); Config = new RootConfig(BaseDirectory, "x-runuo.xml"); Server.Config.Load(); #region Dependency management LibraryConfig = new LibraryConfig(BaseDirectory, "libraries.xml"); if (ForceUpdateDeps) { Directory.Delete(Path.Combine(BaseDirectory, "deps"), recursive: true); } #endregion if (!ScriptCompiler.Compile(Debug)) { log.Fatal("Compilation failed. Press any key to exit."); Console.ReadLine(); return; } ScriptCompiler.VerifyLibraries(); // This instance is shared among timer scheduler and timer executor, // and accessed from both core & timer threads. var timerQueue = new Queue <Timer>(); // Timer scheduler must be set up before world load, since world load // could schedule timers on entity deserialization. var timerScheduler = TimerScheduler.Instance = new TimerScheduler(timerQueue); m_TimerThread = new TimerThread(timerScheduler); var timerExecutor = new TimerExecutor(timerQueue); try { ScriptCompiler.Configure(); TileData.Configure(); } catch (TargetInvocationException e) { log.Fatal("Configure exception: {0}", e.InnerException); return; } SaveConfig(); Region.Load(); World.Load(); try { ScriptCompiler.Initialize(); } catch (TargetInvocationException e) { log.Fatal("Initialize exception: {0}", e.InnerException); return; } m_TimerThread.Start(); NetServer netServer = new NetServer(new Listener(Listener.Port)); netServer.Initialize(); GameServer.Instance = new GameServer(netServer); GameServer.Instance.Initialize(); EventSink.InvokeServerStarted(); PacketDispatcher.Initialize(); Now = DateTime.UtcNow; m_TotalProfile = new MainProfile(Now); m_CurrentProfile = new MainProfile(Now); try { while (!Closing) { Now = DateTime.UtcNow; Thread.Sleep(1); ClockProfile(MainProfile.TimerId.Idle); Mobile.ProcessDeltaQueue(); ClockProfile(MainProfile.TimerId.MobileDelta); Item.ProcessDeltaQueue(); ClockProfile(MainProfile.TimerId.ItemDelta); timerExecutor.Slice(); ClockProfile(MainProfile.TimerId.Timers); netServer.Slice(); ClockProfile(MainProfile.TimerId.Network); // Done with this iteration. m_TotalProfile.Next(); m_CurrentProfile.Next(); } } catch (Exception e) { HandleCrashed(e); } m_TimerThread.Stop(); }
private static CompilerResults CompileCSScripts(ICollection fileColl, string assemblyFile, LibraryConfig libConfig, bool debug) { CSharpCodeProvider provider = new CSharpCodeProvider(); ICodeCompiler compiler = provider.CreateCompiler(); string[] files; Console.Write("{0}[C#,{1}", libConfig.Name, fileColl.Count); string tempFile = compiler.GetType().FullName == "Mono.CSharp.CSharpCodeCompiler" ? Path.GetTempFileName() : null; if (tempFile == String.Empty) { tempFile = null; } if (tempFile == null) { files = new string[fileColl.Count]; fileColl.CopyTo(files, 0); } else { /* to prevent an "argument list too long" error, we * write a list of file names to a temporary file * and add them with @filename */ StreamWriter w = new StreamWriter(tempFile, false); foreach (string file in fileColl) { w.Write("\"" + file + "\" "); } w.Close(); files = new string[0]; } CompilerParameters parms = new CompilerParameters(GetReferenceAssemblies(), assemblyFile, debug); if (tempFile != null) { parms.CompilerOptions += "@" + tempFile; } if (libConfig.WarningLevel >= 0) { parms.WarningLevel = libConfig.WarningLevel; } CompilerResults results = null; try { results = compiler.CompileAssemblyFromFileBatch(parms, files); } catch (System.ComponentModel.Win32Exception e) { /* from WinError.h: * #define ERROR_FILE_NOT_FOUND 2L * #define ERROR_PATH_NOT_FOUND 3L */ if (e.NativeErrorCode == 2 || e.NativeErrorCode == 3) { Console.WriteLine(); Console.WriteLine(); Console.WriteLine("Could not find the compiler - are you sure MCS is installed?"); Console.WriteLine("On Debian, try: apt-get install mono-mcs"); Environment.Exit(2); } else { throw e; } } if (tempFile != null) { File.Delete(tempFile); } m_AdditionalReferences.Add(assemblyFile); if (results.Errors.Count > 0) { int errorCount = 0, warningCount = 0; foreach (CompilerError e in results.Errors) { if (e.IsWarning) { ++warningCount; } else { ++errorCount; } } Console.WriteLine(); if (errorCount > 0) { Console.WriteLine("failed ({0} errors, {1} warnings)", errorCount, warningCount); } else { Console.WriteLine("done ({0} errors, {1} warnings)", errorCount, warningCount); } foreach (CompilerError e in results.Errors) { Console.WriteLine(" - {0}: {1}: {2}: (line {3}, column {4}) {5}", e.IsWarning ? "Warning" : "Error", e.FileName, e.ErrorNumber, e.Line, e.Column, e.ErrorText); } } else { Console.Write("] "); } return(results); }