/// <summary> /// Open a install / license window and execute a command. /// </summary> /// <param name="toolPath">Tool to run.</param> /// <param name="toolArguments">Arguments to pass to the tool.</param> /// <param name="retrievingLicenses">Whether the command is retrieving licenses.</param> /// <param name="licenseResponder">Responds to license questions.</param> /// <param name="packages">List of package versions to install / upgrade.</param> /// <param name="complete">Called when installation is complete.</param> private static void DisplayInstallLicenseDialog( string toolPath, string toolArguments, bool retrievingLicenses, LicenseResponder licenseResponder, IEnumerable <AndroidSdkPackageNameVersion> packages, Action <CommandLine.Result> complete) { var summary = retrievingLicenses ? "Attempting Android SDK package installation..." : DIALOG_TITLE + "..."; var window = CommandLineDialog.CreateCommandLineDialog(DIALOG_TITLE); window.summaryText = summary; window.modal = false; window.bodyText = String.Format("{0} {1}\n\n", toolPath, toolArguments); // Note: not displaying progress bar window.autoScrollToBottom = true; CommandLine.IOHandler ioHandler = null; if (licenseResponder != null) { ioHandler = licenseResponder.AggregateLine; } PlayServicesResolver.Log(String.Format("{0} {1}", toolPath, toolArguments), level: LogLevel.Verbose); window.RunAsync( toolPath, toolArguments, (CommandLine.Result result) => { HandleProcessExited(result, window); LogInstallLicenseResult(toolPath, toolArguments, retrievingLicenses, packages, result); complete(result); }, ioHandler: ioHandler, maxProgressLines: retrievingLicenses ? 250 : 500); window.Show(); }
/// <summary> /// Create a dialog box which can display command line output. /// </summary> /// <returns>Reference to the new window.</returns> public static CommandLineDialog CreateCommandLineDialog(string title) { CommandLineDialog window = (CommandLineDialog)EditorWindow.GetWindow( typeof(CommandLineDialog), true, title); window.Initialize(); return(window); }
/// <summary> /// Called from CommandLineDialog in the context of the main / UI thread. /// </summary> public void Update(CommandLineDialog window) { if (textQueue.Count > 0) { List <string> textList = new List <string>(); while (textQueue.Count > 0) { textList.Add((string)textQueue.Dequeue()); } string bodyText = window.bodyText + String.Join("", textList.ToArray()); // Really weak handling of carriage returns. Truncates to the previous // line for each newline detected. while (true) { // Really weak handling carriage returns for progress style updates. int carriageReturn = bodyText.LastIndexOf("\r"); if (carriageReturn < 0 || bodyText.Substring(carriageReturn, 1) == "\n") { break; } string bodyTextHead = ""; int previousNewline = bodyText.LastIndexOf("\n", carriageReturn, carriageReturn); if (previousNewline >= 0) { bodyTextHead = bodyText.Substring(0, previousNewline + 1); } bodyText = bodyTextHead + bodyText.Substring(carriageReturn + 1); } window.bodyText = bodyText; if (window.autoScrollToBottom) { window.scrollPosition.y = Mathf.Infinity; } window.Repaint(); } if (maxProgressLines > 0) { window.progress = (float)linesReported / (float)maxProgressLines; } if (result != null) { window.progressTitle = ""; if (Complete != null) { Complete(result); Complete = null; } } }
/// <summary> /// Handles window behavior when the CommandLineDialog finishes, closing the window automatically if /// execution succeeded and leaving it open with a "Close" button if it failed. /// </summary> /// <param name="result">The result of the process execution.</param> /// <param name="window">The window that should be adjusted based on the process execution result.</param> private static void HandleProcessExited(CommandLine.Result result, CommandLineDialog window) { if (result.exitCode == 0) { window.Close(); } else { PlayServicesResolver.Log(string.Format(PACKAGES_MISSING, result.message)); window.noText = "Close"; // After adding the button we need to scroll down a little more. window.scrollPosition.y = Mathf.Infinity; window.Repaint(); } }
/// <summary> /// Display license dialog. /// </summary> /// <param name="licenses">String containing the licenses to display.</param> /// <param name="complete">Called when the user agrees / disagrees to the licenses.</param> private static void DisplayLicensesDialog(string licenses, Action <bool> complete) { var window = CommandLineDialog.CreateCommandLineDialog(DIALOG_TITLE); window.summaryText = "License agreement(s) required to install Android SDK packages"; window.modal = false; window.bodyText = licenses; window.yesText = "agree"; window.noText = "decline"; window.result = false; window.Repaint(); window.buttonClicked = (TextAreaDialog dialog) => { window.Close(); if (!dialog.result) { complete(false); return; } complete(true); }; window.Show(); }
/// <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(); }