Beispiel #1
0
        /// <summary>
        /// Log a message that describes the installation / license fetching operation.
        /// </summary>
        /// <param name="toolPath">Tool that was executed.</param>
        /// <param name="toolArguments">Arguments to passed to the tool.</param>
        /// <param name="retrievingLicenses">Whether the command is retrieving licenses.</param>
        /// <param name="packages">List of package versions to install / upgrade..</param>
        /// <param name="toolResult">Result of the tool's execution.</param>
        private static void LogInstallLicenseResult(
            string toolPath, string toolArguments, bool retrievingLicenses,
            IEnumerable <AndroidSdkPackageNameVersion> packages,
            CommandLine.Result toolResult)
        {
            bool succeeded = toolResult.exitCode == 0;

            if (!retrievingLicenses || !succeeded)
            {
                var failedMessage = retrievingLicenses ?
                                    "Failed to retrieve Android SDK package licenses.\n\n" +
                                    "Aborted installation of the following packages:\n" :
                                    "Android package installation failed.\n\n" +
                                    "Failed when installing the following packages:\n";
                PlayServicesResolver.Log(
                    String.Format(
                        "{0}\n" +
                        "{1}\n\n" +
                        "{2}\n",
                        succeeded ? "Successfully installed Android packages.\n\n" : failedMessage,
                        AndroidSdkPackageNameVersion.ListToString(packages),
                        toolResult.message),
                    level: succeeded ? LogLevel.Info : LogLevel.Warning);
            }
        }
        /// <summary>
        /// Install a set of packages.
        /// </summary>
        /// <param name="packages">List of package versions to install / upgrade.</param>
        /// <param name="complete">Called when installation is complete.</param>
        public void InstallPackages(HashSet <AndroidSdkPackageNameVersion> packages,
                                    Action <bool> complete)
        {
            var packagesString = AndroidSdkPackageNameVersion.ListToString(packages);
            // TODO: Remove this dialog when the package manager provides feedback while
            // downloading.
            bool installPackage = UnityEditor.EditorUtility.DisplayDialog(
                "Missing Android SDK packages",
                String.Format(
                    "Android SDK packages need to be installed:\n" +
                    "{0}\n" +
                    "\n" +
                    "The install process can be *slow* and does not provide any feedback " +
                    "which may lead you to think Unity has hung / crashed.  Would you like " +
                    "to wait for these package to be installed?",
                    packagesString),
                "Yes", cancel: "No");

            if (!installPackage)
            {
                PlayServicesSupport.Log("User cancelled installation of Android SDK tools package.",
                                        level: PlayServicesSupport.LogLevel.Warning);
                complete(false);
                return;
            }
            var packageNames = new List <string>();

            foreach (var pkg in packages)
            {
                packageNames.Add(pkg.Name);
            }
            SdkManagerUtil.InstallPackages(toolPath, String.Join(" ", packageNames.ToArray()),
                                           packages, "Accept? (y/N):", "y", "N",
                                           new Regex("^License\\W+[^ ]+:"), complete);
        }