Skip to content
This repository has been archived by the owner on Jan 14, 2021. It is now read-only.

Commit

Permalink
[macdoc] Update to use the new apple-doc-wizard setuid shim (no passw…
Browse files Browse the repository at this point in the history
…ord required anymore except to fix the binary). We also now show a sort-of progress window that allow to restart macdoc after the merge to pick up the new changes.
  • Loading branch information
garuma committed Nov 20, 2012
1 parent 638955f commit c8c7db2
Show file tree
Hide file tree
Showing 8 changed files with 691 additions and 30 deletions.
52 changes: 35 additions & 17 deletions samples/macdoc/AppDelegate.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
using System;
using System.IO;
using System.Linq;
using System.Drawing;
using System.Threading;
using System.Diagnostics;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;

using MonoMac.Foundation;
using MonoMac.AppKit;
using MonoMac.ObjCRuntime;

using Monodoc;
using System.IO;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Collections.Generic;

namespace macdoc
{
public partial class AppDelegate : NSApplicationDelegate
{
const string mergeToolPath = "/Developer/MonoTouch/usr/share/doc/MonoTouch/apple-doc-wizard.sh";
const string MergeToolPath = "/Developer/MonoTouch/usr/share/doc/MonoTouch/apple-doc-wizard";

static public RootTree Root;
static public string MonodocDir;
Expand Down Expand Up @@ -135,7 +139,7 @@ public override void FinishedLaunching (NSObject notification)

// Check if there is a MonoTouch documentation installed and launch accordingly
if (Root.HelpSources.Cast<HelpSource> ().Any (hs => hs != null && hs.Name != null && hs.Name.StartsWith ("MonoTouch", StringComparison.InvariantCultureIgnoreCase))
&& File.Exists (mergeToolPath)) {
&& File.Exists (MergeToolPath)) {
Task.Factory.StartNew (() => {
AppleDocHandler.AppleDocInformation infos;
bool mergeOutdated = false;
Expand Down Expand Up @@ -172,6 +176,11 @@ public static bool IsOnLion {
return isOnLion;
}
}

public static bool RestartRequested {
get;
set;
}

public override void WillFinishLaunching (NSNotification notification)
{
Expand Down Expand Up @@ -231,6 +240,12 @@ partial void HandleSearch (NSObject sender)
public override void WillTerminate (NSNotification notification)
{
BookmarkManager.SaveBookmarks ();
// Relaunch ourselves if it was requested
if (RestartRequested)
NSWorkspace.SharedWorkspace.LaunchApp (NSBundle.MainBundle.BundleIdentifier,
NSWorkspaceLaunchOptions.NewInstance | NSWorkspaceLaunchOptions.Async,
NSAppleEventDescriptor.NullDescriptor,
IntPtr.Zero);
}

void LaunchDocumentationUpdate (bool docOutdated, bool mergeOutdated)
Expand All @@ -252,17 +267,20 @@ void LaunchDocumentationUpdate (bool docOutdated, bool mergeOutdated)
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 ();
}
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 ();
}

// We use a working OpenDocument method that doesn't return anything because of MonoMac bug#3380
Expand Down
28 changes: 28 additions & 0 deletions samples/macdoc/AppleDocMergeWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

using System;
using System.Collections.Generic;
using System.Linq;
using MonoMac.Foundation;
using MonoMac.AppKit;

namespace macdoc
{
public partial class AppleDocMergeWindow : MonoMac.AppKit.NSWindow
{
public AppleDocMergeWindow (IntPtr handle) : base (handle)
{
Initialize ();
}

[Export ("initWithCoder:")]
public AppleDocMergeWindow (NSCoder coder) : base (coder)
{
Initialize ();
}

void Initialize ()
{
}
}
}

50 changes: 50 additions & 0 deletions samples/macdoc/AppleDocMergeWindow.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c8c7db2

Please sign in to comment.