public static string GetProtocPath(out string folder) { const string Name = "protoc.exe"; string lazyPath = InputFileLoader.CombinePathFromAppRoot(Name); if (File.Exists(lazyPath)) { // use protoc.exe from the existing location (faster) folder = null; return(lazyPath); } folder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("n")); Directory.CreateDirectory(folder); string path = Path.Combine(folder, Name); UnityEngine.Debug.Log("---" + typeof(InputFileLoader).Namespace + "." + Name); // look inside ourselves... using (Stream resStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( typeof(InputFileLoader).Namespace + "." + Name)) using (Stream outFile = File.OpenWrite(path)) { long len = 0; int bytesRead; byte[] buffer = new byte[4096]; while ((bytesRead = resStream.Read(buffer, 0, buffer.Length)) > 0) { outFile.Write(buffer, 0, bytesRead); len += bytesRead; } outFile.SetLength(len); } return(path); }
private static string LoadFilesAsXml(CommandLineOptions options) { FileDescriptorSet set = new FileDescriptorSet(); foreach (string inPath in options.InPaths) { InputFileLoader.Merge(options.OutCPath, set, inPath, options.ErrorWriter, options.Arguments.ToArray()); } ProtoParseGen.Gen(set); ProcessFileDescriptorSet(set, options); XmlSerializer xser = new XmlSerializer(typeof(FileDescriptorSet)); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineHandling = NewLineHandling.Entitize; StringBuilder sb = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(sb, settings)) { xser.Serialize(writer, set); } return(sb.ToString()); }
public static string GetProtocPath(out string folder) { if (IsUnix) { folder = null; // protogen.exe can be run with mono on Mac/Unix (cool mono) // but the embedded protoc.exe cannot be executed, as it's not a .net exe // workaround 1: ln -s /opt/local/bin/protoc protoc.exe // workaround 2: search the protoc in following bin folder string[] UnixProtoc = { "/usr/bin/protoc", "/usr/local/bin/protoc", "/opt/local/bin/protoc" }; for (int i = 0; i < UnixProtoc.Length; i++) { if (File.Exists(UnixProtoc[i])) { return(UnixProtoc[i]); } } return(UnixProtoc[0]); } const string Name = "protoc.exe"; string lazyPath = InputFileLoader.CombinePathFromAppRoot(Name); if (File.Exists(lazyPath)) { // use protoc.exe from the existing location (faster) folder = null; return(lazyPath); } folder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("n")); Directory.CreateDirectory(folder); string path = Path.Combine(folder, Name); // look inside ourselves... using (Stream resStream = Assembly.GetExecutingAssembly().GetManifestResourceStream( typeof(InputFileLoader).Namespace + "." + Name)) using (Stream outFile = File.OpenWrite(path)) { long len = 0; int bytesRead; byte[] buffer = new byte[4096]; while ((bytesRead = resStream.Read(buffer, 0, buffer.Length)) > 0) { outFile.Write(buffer, 0, bytesRead); len += bytesRead; } outFile.SetLength(len); } return(path); }
public static FileDescriptorSet LoadFilesAsFileDescription(params string[] files) { FileDescriptorSet set = new FileDescriptorSet(); foreach (string inPath in files) { InputFileLoader.Merge(set, inPath, Console.Error); } return(set); }
private static ProcessStartInfo GetProtocStartInfo() { string workingDirectory; string protoFile = InputFileLoader.GetProtocPath(out workingDirectory); ProcessStartInfo procStartInfo = new ProcessStartInfo { WorkingDirectory = workingDirectory, FileName = protoFile, CreateNoWindow = true }; return(procStartInfo); }
private static string ApplyTransform(CommandLineOptions options, string xml) { XmlWriterSettings settings = new XmlWriterSettings(); settings.ConformanceLevel = ConformanceLevel.Auto; settings.CheckCharacters = false; StringBuilder sb = new StringBuilder(); using (XmlReader reader = XmlReader.Create(new StringReader(xml))) using (TextWriter writer = new StringWriter(sb)) { XslCompiledTransform xslt = new XslCompiledTransform(); string xsltTemplate = Path.ChangeExtension(options.Template, "xslt"); if (!File.Exists(xsltTemplate)) { string localXslt = InputFileLoader.CombinePathFromAppRoot(xsltTemplate); if (File.Exists(localXslt)) { xsltTemplate = localXslt; } } try { xslt.Load(xsltTemplate); } catch (Exception ex) { throw new InvalidOperationException("Unable to load tranform: " + options.Template, ex); } options.XsltOptions.RemoveParam("defaultNamespace", ""); if (options.DefaultNamespace != null) { options.XsltOptions.AddParam("defaultNamespace", "", options.DefaultNamespace); } if (options.DefaultEnumPassthru) { options.XsltOptions.AddParam("defaultEnumPassthru", "", options.DefaultEnumPassthru); } xslt.Transform(reader, options.XsltOptions, writer); } return(sb.ToString()); }
private static string LoadFilesAsXml(List <string> fileList) { FileDescriptorSet set = new FileDescriptorSet(); foreach (string inPath in fileList) { InputFileLoader.Merge(set, inPath, Console.Error); } XmlSerializer xser = new XmlSerializer(typeof(FileDescriptorSet)); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = " "; settings.NewLineHandling = NewLineHandling.Entitize; StringBuilder sb = new StringBuilder(); using (XmlWriter writer = XmlWriter.Create(sb, settings)) { xser.Serialize(writer, set); } return(sb.ToString()); }
private static string ApplyTransform(XsltArgumentList xsltArgs, string xml) { XmlWriterSettings settings = new XmlWriterSettings(); settings.ConformanceLevel = ConformanceLevel.Auto; settings.CheckCharacters = false; StringBuilder sb = new StringBuilder(); using (XmlReader reader = XmlReader.Create(new StringReader(xml))) using (TextWriter writer = new StringWriter(sb)) { XslCompiledTransform xslt = new XslCompiledTransform(); string xsltTemplate = "csharp.xslt"; if (!File.Exists(xsltTemplate)) { string localXslt = InputFileLoader.CombinePathFromAppRoot(xsltTemplate); if (File.Exists(localXslt)) { xsltTemplate = localXslt; } } try { xslt.Load(xsltTemplate); } catch (Exception ex) { throw new InvalidOperationException("Unable to load tranform: " + "CSharp.xslt", ex); } xsltArgs.AddParam("defaultNamespace", "", "FiddlerProtos"); xslt.Transform(reader, xsltArgs, writer); } return(sb.ToString()); }