Exemple #1
0
        /// <summary>
        /// Read package metadata from the source.properties file within the specified directory.
        /// </summary>
        /// <param name="sdkDirectory">Android SDK directory to query.</param>
        /// <param name="packageDirectory">Directory containing the package relative to
        /// sdkDirectory.</param>
        public static AndroidSdkPackage ReadFromSourceProperties(string sdkDirectory,
                                                                 string packageDirectory)
        {
            var propertiesPath = System.IO.Path.Combine(
                sdkDirectory, System.IO.Path.Combine(packageDirectory, "source.properties"));
            string propertiesText = null;

            try {
                propertiesText = File.ReadAllText(propertiesPath);
            } catch (Exception e) {
                PlayServicesResolver.Log(String.Format("Unable to read {0}\n{1}\n",
                                                       propertiesPath, e.ToString()),
                                         level: LogLevel.Verbose);
                return(null);
            }
            // Unfortunately the package name is simply based upon the path within the SDK.
            var sdkPackage = new AndroidSdkPackage {
                Path = packageDirectory
            };
            const string VERSION_FIELD_NAME     = "Pkg.Revision=";
            const string DESCRIPTION_FIELD_NAME = "Pkg.Desc=";

            foreach (var rawLine in CommandLine.SplitLines(propertiesText))
            {
                var line = rawLine.Trim();
                // Ignore comments.
                if (line.StartsWith("#"))
                {
                    continue;
                }
                // Parse fields
                if (line.StartsWith(VERSION_FIELD_NAME))
                {
                    sdkPackage.VersionString = line.Substring(VERSION_FIELD_NAME.Length);
                }
                else if (line.StartsWith(DESCRIPTION_FIELD_NAME))
                {
                    sdkPackage.Description = line.Substring(DESCRIPTION_FIELD_NAME.Length);
                }
            }
            return(sdkPackage);
        }
Exemple #2
0
        /// <summary>
        /// Use the package manager to retrieve the set of installed and available packages.
        /// </summary>
        /// <param name="toolPath">Tool to run.</param>
        /// <param name="toolArguments">Arguments to pass to the tool.</param>
        /// <param name="complete">Called when the query is complete.</param>
        public static void QueryPackages(string toolPath, string toolArguments,
                                         Action <CommandLine.Result> complete)
        {
            var window = CommandLineDialog.CreateCommandLineDialog(
                "Querying Android SDK packages");

            PlayServicesResolver.Log(String.Format("Query Android SDK packages\n" +
                                                   "\n" +
                                                   "{0} {1}\n",
                                                   toolPath, toolArguments),
                                     level: LogLevel.Verbose);
            window.summaryText = "Getting Installed Android SDK packages.";
            window.modal       = false;
            // Note: not displaying progress bar
            window.autoScrollToBottom = true;
            window.RunAsync(
                toolPath, toolArguments,
                (CommandLine.Result result) => {
                HandleProcessExited(result, window);
                complete(result);
            },
                maxProgressLines: 50);
            window.Show();
        }
Exemple #3
0
 /// <summary>
 /// Asynchronously execute a command line tool in this window, showing progress
 /// and finally calling the specified delegate on completion from the main / UI thread.
 /// </summary>
 /// <param name="toolPath">Tool to execute.</param>
 /// <param name="arguments">String to pass to the tools' command line.</param>
 /// <param name="completionDelegate">Called when the tool completes.</param>
 /// <param name="workingDirectory">Directory to execute the tool from.</param>
 /// <param name="ioHandler">Allows a caller to provide interactive input and also handle
 /// both output and error streams from a single delegate.</param>
 /// <param name="maxProgressLines">Specifies the number of lines output by the
 /// command line that results in a 100% value on a progress bar.</param>
 /// <returns>Reference to the new window.</returns>
 public void RunAsync(
     string toolPath, string arguments,
     CommandLine.CompletionHandler completionDelegate,
     string workingDirectory         = null, Dictionary <string, string> envVars = null,
     CommandLine.IOHandler ioHandler = null, int maxProgressLines                = 0)
 {
     CommandLineDialog.ProgressReporter reporter = new CommandLineDialog.ProgressReporter();
     reporter.maxProgressLines = maxProgressLines;
     // Call the reporter from the UI thread from this window.
     UpdateEvent += reporter.Update;
     // Connect the user's delegate to the reporter's completion method.
     reporter.Complete += completionDelegate;
     // Connect the caller's IoHandler delegate to the reporter.
     reporter.DataHandler += ioHandler;
     // Disconnect the reporter when the command completes.
     CommandLine.CompletionHandler reporterUpdateDisable =
         (CommandLine.Result unusedResult) => { this.UpdateEvent -= reporter.Update; };
     reporter.Complete += reporterUpdateDisable;
     PlayServicesResolver.Log(String.Format(
                                  "Executing command: {0} {1}", toolPath, arguments), level: LogLevel.Verbose);
     CommandLine.RunAsync(toolPath, arguments, reporter.CommandLineToolCompletion,
                          workingDirectory: workingDirectory, envVars: envVars,
                          ioHandler: reporter.AggregateLine);
 }