Execute() public method

Executes this external process.
public Execute ( ) : int
return int
Example #1
0
        /// <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);
            }
        }
Example #2
0
 /// <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 ();
 }
Example #3
0
 /// <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 ();
 }
Example #4
0
 /// <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 ();
 }
Example #5
0
        /// <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 ();
        }
Example #6
0
        /// <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 ();
        }
Example #7
0
 /// <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 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();
            }
        }