/// <summary> /// Cat multiple images /// </summary> /// <param name = "mask">The permission mask.</param> /// <param name = "file">The file.</param> /// <returns>The result of the command.</returns> public static void Cat(String outputFile, String[] inputFiles, TextWriter outputWriter = null, TextWriter errorWriter = null) { if (inputFiles.Length < 2) { // TODO: I18N throw new ArgumentException ("At least 2 image files must be provided", "inputFiles"); } // Check if combination is needed bool upToDate = true; foreach (String inputFile in inputFiles) { upToDate &= FileExtensions.UpToDate (inputFile, outputFile); } if (!upToDate) { // Perform the combination String arguments = String.Format (CultureInfo.InvariantCulture, "-cathidpicheck \"{0}\" -out \"{1}\"", String.Join ("\" \"", inputFiles), outputFile); ProcessHelper helper = new ProcessHelper (Executable, arguments); helper.OutputWriter = outputWriter; helper.ErrorWriter = outputWriter; int exitCode = helper.Execute (); if (exitCode == -1) { errorWriter.WriteLine ("Error while combining {0}", inputFiles); return; } } // Remove sources foreach (String inputFile in inputFiles) { File.Delete (inputFile); } }
/// <summary> /// Applies new permissions to a file. /// </summary> /// <param name = "mask">The permission mask.</param> /// <param name = "file">The file.</param> /// <returns>The result of the command.</returns> public static void ApplyTo(String mask, String file, TextWriter outputWriter = null, TextWriter errorWriter = null) { String arguments = String.Format (CultureInfo.InvariantCulture, "{0} \"{1}\"", mask, file); ProcessHelper helper = new ProcessHelper (Executable, arguments); helper.OutputWriter = outputWriter; helper.ErrorWriter = errorWriter; helper.Execute (); }
/// <summary> /// Copy recursively the source into the destination /// </summary> /// <param name = "source">The source file or folder.</param> /// <param name = "destination">The destination file or folder.</param> /// <returns>The result of the command.</returns> public static void Recursivly(String source, String destination, TextWriter outputWriter = null, TextWriter errorWriter = null) { String arguments = String.Format(CultureInfo.InvariantCulture, "-R \"{0}\" \"{1}\"", source, destination); ProcessHelper helper = new ProcessHelper(Executable, arguments); helper.OutputWriter = outputWriter; helper.ErrorWriter = errorWriter; helper.Execute (); }
/// <summary> /// Change, TextWriter outputWriter = null, TextWriter errorWriter = null)s the id of the given library. /// </summary> /// <param name = "library">The library.</param> /// <param name = "newId">The new id.</param> public static void ChangeId(String library, String newId, TextWriter outputWriter = null, TextWriter errorWriter = null) { String arguments = String.Format(CultureInfo.InvariantCulture, "-id \"{1}\" \"{0}\"", library, newId); ProcessHelper helper = new ProcessHelper(Executable, arguments); helper.OutputWriter = outputWriter; helper.ErrorWriter = errorWriter; helper.Execute (); }
/// <summary> /// Gets the name of the install of the library. /// </summary> /// <param name = "nativeBinary">The native binary.</param> /// <returns>The install name.</returns> public static String GetInstallName(String nativeBinary) { String arguments = String.Format(CultureInfo.InvariantCulture, "-D \"{0}\"", nativeBinary); ProcessHelper helper = new ProcessHelper(Executable, arguments); String output = helper.ExecuteAndReturnOutput (); String installName = String.Empty; Match match = OTOOL_ID_REGEX.Match(output); if (match != null && match.Success) { installName = match.Result("${library}"); } return installName; }
/// <summary> /// Gets the dependencies of the native binary. /// </summary> /// <param name = "nativeBinary">The native binary.</param> /// <returns>The dependencies list</returns> public static IEnumerable<string> GetDependencies(String nativeBinary) { String arguments = String.Format(CultureInfo.InvariantCulture, "-L \"{0}\"", nativeBinary); ProcessHelper helper = new ProcessHelper(Executable, arguments); String output = helper.ExecuteAndReturnOutput (); List<String> dependencies = new List<String>(); MatchCollection matches = OTOOL_LIST_REGEX.Matches(output); if (matches.Count > 0) { dependencies.AddRange(from Match match in matches select match.Result("${library}")); } return dependencies; }
/// <summary> /// Sign the target with the following identity. /// </summary> /// <param name = "target">The path to the target.</param> /// <param name = "identity">The signing identity.</param> /// <param name = "identity">The entitlements.</param> /// <returns>The result of the command.</returns> public static void PerformSigning(String target, String identity, String entitlements, TextWriter outputWriter = null, TextWriter errorWriter = null) { StringBuilder arguments = new StringBuilder(" --verbose --force "); if (identity != null) { arguments.AppendFormat(" --sign \"{0}\" ", identity); } if (entitlements != null) { arguments.AppendFormat(" --entitlements \"{0}\" ", entitlements); } arguments.AppendFormat(" \"{0}\" ", target); ProcessHelper helper = new ProcessHelper(Executable, arguments.ToString()); helper.OutputWriter = outputWriter; helper.ErrorWriter = errorWriter; helper.Execute (); }
/// <summary> /// Returns the architectures for the given file. /// </summary> /// <param name = "file">The file.</param> /// <returns>The result of the command.</returns> public static MacOSArchitecture GetArchitecture(String file) { String arguments = String.Format (CultureInfo.InvariantCulture, "-info \"{0}\"", file); ProcessHelper helper = new ProcessHelper (Executable, arguments); String output = helper.ExecuteAndReturnOutput (); MacOSArchitecture architecture = MacOSArchitecture.None; if (output.Contains ("i386")) { architecture |= MacOSArchitecture.X86; } if (output.Contains ("x86_64")) { architecture |= MacOSArchitecture.X8664; } if (output.Contains ("ppc7400")) { architecture |= MacOSArchitecture.PPC; } return architecture; }
/// <summary> /// Archive the application bundle and sign the result with the following identity. /// </summary> /// <param name = "bundle">The path to the application bundle.</param> /// <param name = "identity">The signing identity.</param> /// <param name = "productDefinition">The product definition.</param> /// <returns>The result of the command.</returns> public static void ArchiveApplication(String bundle, String identity, String productDefinition, TextWriter outputWriter = null, TextWriter errorWriter = null) { String package = Path.ChangeExtension(bundle, ".pkg"); StringBuilder arguments = new StringBuilder(); arguments.AppendFormat(" --component \"{0}\" /Applications ", bundle); if (identity != null) { arguments.AppendFormat(" --sign \"{0}\" ", identity); } if (productDefinition != null) { arguments.AppendFormat(" --product \"{0}\" ", productDefinition); } arguments.AppendFormat(" \"{0}\" ", package); ProcessHelper helper = new ProcessHelper(Executable, arguments.ToString()); helper.OutputWriter = outputWriter; helper.ErrorWriter = errorWriter; helper.Execute (); }
/// <summary> /// Cat multiple images /// </summary> /// <param name = "mask">The permission mask.</param> /// <param name = "file">The file.</param> /// <returns>The result of the command.</returns> public static void Convert(IconUtilType inputType, String intputFile, TextWriter outputWriter = null, TextWriter errorWriter = null) { String type; switch(inputType) { case IconUtilType.Icns: type = "icns"; break; case IconUtilType.Iconset: type = "iconset"; break; default: throw new ArgumentException("Type must be either 'Icns' or 'Iconset'", "inputType"); } String arguments = String.Format (CultureInfo.InvariantCulture, "--convert {0} \"{1}\"", type, intputFile); ProcessHelper helper = new ProcessHelper (Executable, arguments); helper.OutputWriter = outputWriter; helper.ErrorWriter = errorWriter; helper.Execute (); }
/// <summary> /// Creates the static library. /// </summary> /// <param name='dataFile'> /// Data file. /// </param> /// <param name='needZeroEnd'> /// Need zero end. /// </param> public void CreateStaticLibrary(String dataFile, bool needZeroEnd) { // Generate the pretty name this.SymbolName = GetSymbolName (dataFile); // If we need a zero at the end (for text files), add 1 byte int size = (int)new FileInfo (dataFile).Length; byte[] fileBuffer = File.ReadAllBytes (dataFile); this.Logger.LogInfo ("Embedding '" + dataFile + "'..."); // Use raw file this.InputSize = size; byte[] dataBuffer = fileBuffer; if (this.Compress) { // Compress the data file if required using (MemoryStream stream = new MemoryStream()) { using (DeflaterOutputStream deflate = new DeflaterOutputStream(stream)) { int n = 0, len = 0; while (n < size) { len = Math.Min (size - n, CHUNK); deflate.Write (fileBuffer, n, len); n += CHUNK; } if (needZeroEnd) { deflate.WriteByte (0); } deflate.Finish (); } dataBuffer = stream.ToArray (); stream.Close (); } } else if (needZeroEnd) { this.InputSize = size + 1; dataBuffer = new byte[this.InputSize]; Array.Copy(fileBuffer, dataBuffer, size); dataBuffer[size] = 0; } this.OutputSize = dataBuffer.Length; if (this.Compress) { this.Logger.LogInfo ("Compression ratio: " + Math.Floor(100.0 * this.OutputSize / this.InputSize) + "%"); } // Compute the names String sFile = Path.Combine (this.OutputDirectory, this.SymbolName + ".s"); String oFile = Path.Combine (this.OutputDirectory, this.SymbolName + ".o"); String aFile = Path.Combine (this.OutputDirectory, this.SymbolName + ".a"); this.OutputFile = Path.Combine (this.OutputDirectory, "lib" + this.SymbolName + ".a"); // (1) Create the assembly source file this.Logger.LogDebug ("Create assembly file '" + Path.GetFileName (sFile) + "'..."); String content = String.Format (CultureInfo.CurrentCulture, TEMPLATE, this.SymbolName, this.OutputSize, SPACER_BYTE); File.WriteAllText (sFile, content); // (2) Create the object file this.Logger.LogDebug ("Create object file '" + Path.GetFileName (oFile) + "'..."); using (ProcessHelper helper = new ProcessHelper("cc", string.Format("{0} -c -o \"{1}\" \"{2}\"", this.ArchitectureFlags ?? String.Empty, oFile, sFile))) { helper.Logger = this.Logger; helper.Execute (); } // (3) Create the static library this.Logger.LogDebug ("Create library file '" + Path.GetFileName (aFile) + "'..."); using (ProcessHelper helper = new ProcessHelper("libtool", string.Format("-o \"{0}\" \"{1}\"", aFile, oFile))) { helper.Logger = this.Logger; helper.Execute (); } // (4) Swap binary content this.Logger.LogDebug ("Swaping content to '" + Path.GetFileName (this.OutputFile) + "'..."); // Not quite memory-efficient, but simpler to code byte[] outputBuffer = File.ReadAllBytes (aFile); // Search for the beginning and the end of the spacer zone int start = Locate (outputBuffer, new[] {SPACER_BYTE, SPACER_BYTE, SPACER_BYTE, SPACER_BYTE}); // Insert the data file content into the static library Array.Copy (dataBuffer, 0, outputBuffer, start, dataBuffer.Length); // Write the result on the disk File.WriteAllBytes (this.OutputFile, outputBuffer); }
private static String CompileInternal(String modelDir, String destinationDir) { if (FileExtensions.UpToDate(modelDir, destinationDir)) { return null; } String arguments = String.Format(CultureInfo.InvariantCulture, "\"{0}\" \"{1}\"", modelDir, destinationDir); ProcessHelper helper = new ProcessHelper(Executable, arguments); String output = helper.ExecuteAndReturnOutput(); return output; }
/// <summary> /// Generate the specified infoPlist and outputFolder. /// </summary> /// <param name='infoPlist'> /// Info plist. /// </param> /// <param name='outputFolder'> /// Output folder. /// </param> public String Generate(String infoPlist, String outputFolder) { // Load the Info.plist file PListDocument document = PListDocument.LoadFromFile (infoPlist); if (document == null) { this.Logger.LogError ("Cannot parse document: " + infoPlist); return String.Empty; } if (document.Root == null) { this.Logger.LogError ("Document has no root: " + infoPlist); return String.Empty; } if (document.Root.Dict == null) { this.Logger.LogError ("Document has no dict: " + infoPlist); return String.Empty; } // Extract bundle identifier PListString identifier = document.Root.Dict ["CFBundleIdentifier"] as PListString; if (identifier == null || String.IsNullOrWhiteSpace (identifier.Value)) { this.Logger.LogError ("Document has no 'CFBundleIdentifier': " + infoPlist); return String.Empty; } // Extract bundle version PListString version = document.Root.Dict ["CFBundleShortVersionString"] as PListString; if (version == null || String.IsNullOrWhiteSpace (version.Value)) { this.Logger.LogError ("Document has no 'CFBundleShortVersionString': " + infoPlist); return String.Empty; } // Launch the generation String file = Path.Combine (outputFolder, "receigen.h"); StringBuilder arguments = new StringBuilder (); arguments.AppendFormat (" --identifier {0} ", identifier.Value); arguments.AppendFormat (" --version {0} ", version.Value); this.Logger.LogDebug ("Calling '" + this.Executable + "' with '" + arguments + "'"); ProcessHelper helper = new ProcessHelper (this.Executable, arguments.ToString ()); String output = helper.ExecuteAndReturnOutput (); Directory.CreateDirectory(Path.GetDirectoryName(file)); File.WriteAllText(file, output); return "Done"; }
private static PListDocument CompileInternal(String xibFile, String destination) { if (FileExtensions.UpToDate(xibFile, destination)) { return null; } String arguments = String.Format(CultureInfo.InvariantCulture, "--errors --warnings --notices --compile \"{0}\" \"{1}\"", destination, xibFile); ProcessHelper helper = new ProcessHelper(Executable, arguments); String output = helper.ExecuteAndReturnOutput (); try { output = output.Trim(); PListDocument document = PListDocument.LoadFromXml(output); return document; } catch (Exception) { Console.WriteLine("XibTool cannot parse output:"); Console.WriteLine("-----"); Console.WriteLine(output); Console.WriteLine("-----"); return null; } }
private void Link(String directory, String objectFile, String outputFile, String nativeOptions, List<Dictionary<String, String>> assemblies, List<Dictionary<String, String>> configurations, Dictionary<String, String> machineConfig) { // Build the command line StringBuilder builder = new StringBuilder(); builder.AppendFormat(" {0} -L\"{1}\" ", nativeOptions, directory); builder.AppendFormat(" {0} ", this.NativeLDFLAGS ?? String.Empty); // Add the pkg-config flags for Mono String monoLibrary = this.UseSGEN ? "monosgen-2" : "mono-2"; using (ProcessHelper helper = new ProcessHelper("pkg-config", String.Format("{0} {1}", "--libs", monoLibrary))) { helper.Logger = this.Logger; String result = helper.ExecuteAndReturnOutput (); result = result.Replace("\n", String.Empty); builder.Append(result); } // Add zlib shared library if (this.Compress) { builder.Append(" -lz "); } // Add Monobjc shared library builder.AppendFormat(" -lmonobjc "); // Add all the static libraries foreach (Dictionary<string, string> dictionary in assemblies) { builder.AppendFormat(" -l{0}", dictionary[KEY_SYMBOL]); } foreach (Dictionary<string, string> dictionary in configurations) { builder.AppendFormat(" -l{0}", dictionary[KEY_SYMBOL]); } if (machineConfig != null) { builder.AppendFormat(" -l{0}", machineConfig[KEY_SYMBOL]); } // Append required framework for Receigen if (this.UseReceigen) { builder.AppendFormat(" -framework {0}", "AppKit"); builder.AppendFormat(" -framework {0}", "Foundation"); //builder.AppendFormat(" -framework {0}", "Security"); //builder.AppendFormat(" -framework {0}", "IOKit"); } builder.AppendFormat(" -o \"{0}\" \"{1}\" ", outputFile, objectFile); // TODO: I18N this.Logger.LogInfo("Linking..."); this.Logger.LogDebug(String.Format("Arguments: '{0}'", builder.ToString())); using (ProcessHelper helper = new ProcessHelper(this.NativeCompiler, builder.ToString())) { helper.Logger = this.Logger; helper.Execute(); } }
private void Compile(String directory, String sourceFile, String objectFile, String nativeOptions) { // Build the command line StringBuilder builder = new StringBuilder(); builder.AppendFormat(" -Os -gdwarf-2 {0} -I\"{1}\" ", nativeOptions, directory); builder.AppendFormat(" -c \"{0}\" -o \"{1}\" ", sourceFile, objectFile); builder.AppendFormat(" {0} ", this.NativeCFLAGS ?? String.Empty); if (this.UseReceigen) { builder.AppendFormat(" -DRECEIGEN "); } // Add the pkg-config flags for Mono String monoLibrary = this.UseSGEN ? "monosgen-2" : "mono-2"; using (ProcessHelper helper = new ProcessHelper("pkg-config", String.Format("{0} {1}", "--cflags", monoLibrary))) { helper.Logger = this.Logger; String result = helper.ExecuteAndReturnOutput (); result = result.Replace("\n", String.Empty); builder.Append(result); } // TODO: I18N this.Logger.LogInfo("Compiling..."); this.Logger.LogDebug(String.Format("Arguments: '{0}'", builder.ToString())); using (ProcessHelper helper = new ProcessHelper(this.NativeCompiler, builder.ToString())) { helper.Logger = this.Logger; helper.Execute(); } }