void LaunchDocumentationUpdate(bool docOutdated, bool mergeOutdated) { var infoDialog = new NSAlert { AlertStyle = NSAlertStyle.Informational, MessageText = "Documentation update available", InformativeText = "We have detected your MonoTouch documentation can be upgraded with Apple documentation." + Environment.NewLine + Environment.NewLine + "Would you like to update the documentation now? You can continue to browse the documentation while the update is performed." }; infoDialog.AddButton("Update now"); infoDialog.AddButton("Remind me later"); var dialogResult = infoDialog.RunModal(); // If Cancel was clicked, just return if (dialogResult == (int)NSAlertButtonReturn.Second) { return; } // Launching AppleDocWizard as root // First get the directory try { RootLauncher.LaunchExternalTool(mergeToolPath, docOutdated ? new string[] { "--force-download" } : (string[])null); } catch (RootLauncherException ex) { var alertDialog = new NSAlert { AlertStyle = NSAlertStyle.Critical, MessageText = "Documentation updater error", InformativeText = string.Format("There was an error launching the documentation updater: {0}{1}{2}", ex.ResultCode.ToString(), Environment.NewLine, ex.Message) }; alertDialog.RunModal(); } }
void LaunchDocumentationUpdate(bool docOutdated, bool mergeOutdated) { var infoDialog = new NSAlert { AlertStyle = NSAlertStyle.Informational, MessageText = "Documentation update available", InformativeText = "We have detected your MonoTouch documentation can be upgraded with Apple documentation." + Environment.NewLine + Environment.NewLine + "Would you like to update the documentation now? You can continue to browse the documentation while the update is performed." }; infoDialog.AddButton("Update now"); infoDialog.AddButton("Remind me later"); var dialogResult = infoDialog.RunModal(); // If Cancel was clicked, just return if (dialogResult == (int)NSAlertButtonReturn.Second) { return; } // Launching AppleDocWizard as root var mergerTask = Task.Factory.StartNew(() => { // If the script has its setuid bit on and user as root, then we launch it directly otherwise we first restore it if (!RootLauncher.IsRootEnabled(MergeToolPath)) { RootLauncher.LaunchExternalTool(MergeToolPath, docOutdated ? new string[] { "--self-repair" } : (string[])null); // No good way to know when the process will finish, so wait a bit. Not ideal but since this is an unlikely codepath, shouldn't matter. System.Threading.Thread.Sleep(1000); } return(ProcessUtils.StartProcess(new System.Diagnostics.ProcessStartInfo(MergeToolPath, "--force-download"), null, null, CancellationToken.None)); }).Unwrap(); var mergeController = new AppleDocMergeWindowController(); mergeController.TrackProcessTask(mergerTask); mergeController.ShowWindow(this); mergeController.Window.Center(); }
void LaunchDocumentationUpdate(Dictionary <Product, Tuple <bool, bool> > toUpdate) { var outdatedProducts = string.Join(" and ", toUpdate.Where(kvp => kvp.Value.Item1 || kvp.Value.Item2).Select(kvp => ProductUtils.GetFriendlyName(kvp.Key))); var informative = "We have detected your " + outdatedProducts + " documentation can be upgraded with Apple documentation."; // Check if we are going to be downloading stuff if (toUpdate.Any(kvp => kvp.Value.Item1)) { informative += Environment.NewLine + Environment.NewLine + "Warning: we are going to download documentation from Apple servers which can take a long time depending on your Internet connection."; } informative += Environment.NewLine + Environment.NewLine + "Would you like to update the documentation now?"; var infoDialog = new NSAlert { AlertStyle = NSAlertStyle.Informational, MessageText = "Documentation update available", InformativeText = informative }; infoDialog.AddButton("Update now"); infoDialog.AddButton("Remind me later"); var dialogResult = infoDialog.RunModal(); // If Cancel was clicked, just return if (dialogResult == (int)NSAlertButtonReturn.Second) { return; } // Launching AppleDocWizard as root var mergerTasks = toUpdate .Where(kvp => kvp.Value.Item1 || kvp.Value.Item2) .Select(kvp => Task.Factory.StartNew(() => { var mergeToolPath = ProductUtils.GetMergeToolForProduct(kvp.Key); var docOutdated = kvp.Value.Item1; // If the script has its setuid bit on and user as root, then we launch it directly otherwise we first restore it if (!RootLauncher.IsRootEnabled(mergeToolPath)) { RootLauncher.LaunchExternalTool(mergeToolPath, new string[] { "--self-repair" }); // No good way to know when the process will finish, so wait a bit. Not ideal but since this is an unlikely codepath, shouldn't matter. System.Threading.Thread.Sleep(1000); } var psi = new System.Diagnostics.ProcessStartInfo(mergeToolPath, docOutdated ? "--force-download" : null); return(ProcessUtils.StartProcess(psi, null, null, CancellationToken.None)); }).Unwrap()); // No Task.WhenAll yet var tcs = new TaskCompletionSource <int> (); Task.Factory.ContinueWhenAll(mergerTasks.ToArray(), ts => { var faulteds = ts.Where(t => t.IsFaulted); if (faulteds.Any()) { tcs.SetException(faulteds.Select(t => t.Exception)); } else { tcs.SetResult(ts.Select(t => t.Result).FirstOrDefault(r => r != 0)); } }); var mergeController = new AppleDocMergeWindowController(); mergeController.TrackProcessTask(tcs.Task); mergeController.ShowWindow(this); mergeController.Window.Center(); }