Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/xamarin/macdoc.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Laval <jeremie.laval@gmail.com>2012-11-20 22:11:42 +0400
committerJeremie Laval <jeremie.laval@gmail.com>2012-11-20 22:11:42 +0400
commit29e95b76d844c76cd3ccffc991e57604339c39ee (patch)
treebfffe2f8223880bc11ec23c90a7d536df6d6529f
parente798cd51f95f2ea0c1982bb55edbed8396f07186 (diff)
[macdoc] Update to use the new apple-doc-wizard setuid shim (no password 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.
-rw-r--r--AppDelegate.cs52
-rw-r--r--AppleDocMergeWindow.cs28
-rw-r--r--AppleDocMergeWindow.designer.cs50
-rw-r--r--AppleDocMergeWindow.xib378
-rw-r--r--AppleDocMergeWindowController.cs84
-rw-r--r--ProcessUtils.cs86
-rw-r--r--RootLauncher.cs7
-rw-r--r--macdoc.csproj36
8 files changed, 691 insertions, 30 deletions
diff --git a/AppDelegate.cs b/AppDelegate.cs
index 0f56d9e..ca8559d 100644
--- a/AppDelegate.cs
+++ b/AppDelegate.cs
@@ -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;
@@ -135,7 +139,7 @@ namespace macdoc
// 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;
@@ -172,6 +176,11 @@ namespace macdoc
return isOnLion;
}
}
+
+ public static bool RestartRequested {
+ get;
+ set;
+ }
public override void WillFinishLaunching (NSNotification notification)
{
@@ -231,6 +240,12 @@ namespace macdoc
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)
@@ -252,17 +267,20 @@ namespace macdoc
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
diff --git a/AppleDocMergeWindow.cs b/AppleDocMergeWindow.cs
new file mode 100644
index 0000000..c4f4d95
--- /dev/null
+++ b/AppleDocMergeWindow.cs
@@ -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 ()
+ {
+ }
+ }
+}
+
diff --git a/AppleDocMergeWindow.designer.cs b/AppleDocMergeWindow.designer.cs
new file mode 100644
index 0000000..1a11538
--- /dev/null
+++ b/AppleDocMergeWindow.designer.cs
@@ -0,0 +1,50 @@
+// WARNING
+//
+// This file has been generated automatically by MonoDevelop to store outlets and
+// actions made in the Xcode designer. If it is removed, they will be lost.
+// Manual changes to this file may not be handled correctly.
+//
+using MonoMac.Foundation;
+
+namespace macdoc
+{
+ [Register ("AppleDocMergeWindowController")]
+ partial class AppleDocMergeWindowController
+ {
+ [Outlet]
+ MonoMac.AppKit.NSProgressIndicator ProgressWidget { get; set; }
+
+ [Outlet]
+ MonoMac.AppKit.NSTextField WizardText { get; set; }
+
+ [Outlet]
+ MonoMac.AppKit.NSButton WizardButton { get; set; }
+
+ void ReleaseDesignerOutlets ()
+ {
+ if (ProgressWidget != null) {
+ ProgressWidget.Dispose ();
+ ProgressWidget = null;
+ }
+
+ if (WizardText != null) {
+ WizardText.Dispose ();
+ WizardText = null;
+ }
+
+ if (WizardButton != null) {
+ WizardButton.Dispose ();
+ WizardButton = null;
+ }
+ }
+ }
+
+ [Register ("AppleDocMergeWindow")]
+ partial class AppleDocMergeWindow
+ {
+
+ void ReleaseDesignerOutlets ()
+ {
+ }
+ }
+}
diff --git a/AppleDocMergeWindow.xib b/AppleDocMergeWindow.xib
new file mode 100644
index 0000000..b2ad448
--- /dev/null
+++ b/AppleDocMergeWindow.xib
@@ -0,0 +1,378 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
+ <data>
+ <int key="IBDocument.SystemTarget">1070</int>
+ <string key="IBDocument.SystemVersion">11G63</string>
+ <string key="IBDocument.InterfaceBuilderVersion">2840</string>
+ <string key="IBDocument.AppKitVersion">1138.51</string>
+ <string key="IBDocument.HIToolboxVersion">569.00</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string key="NS.object.0">2840</string>
+ </object>
+ <object class="NSArray" key="IBDocument.IntegratedClassDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSButton</string>
+ <string>NSButtonCell</string>
+ <string>NSCustomObject</string>
+ <string>NSProgressIndicator</string>
+ <string>NSTextField</string>
+ <string>NSTextFieldCell</string>
+ <string>NSView</string>
+ <string>NSWindowTemplate</string>
+ </object>
+ <object class="NSArray" key="IBDocument.PluginDependencies">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ <object class="NSMutableDictionary" key="IBDocument.Metadata">
+ <string key="NS.key.0">PluginDependencyRecalculationVersion</string>
+ <integer value="1" key="NS.object.0"/>
+ </object>
+ <object class="NSMutableArray" key="IBDocument.RootObjects" id="1000">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSCustomObject" id="1001">
+ <string key="NSClassName">AppleDocMergeWindowController</string>
+ </object>
+ <object class="NSCustomObject" id="1003">
+ <string key="NSClassName">FirstResponder</string>
+ </object>
+ <object class="NSCustomObject" id="1004">
+ <string key="NSClassName">NSApplication</string>
+ </object>
+ <object class="NSWindowTemplate" id="748157544">
+ <int key="NSWindowStyleMask">1</int>
+ <int key="NSWindowBacking">2</int>
+ <string key="NSWindowRect">{{131, 74}, {426, 105}}</string>
+ <int key="NSWTFlags">611844096</int>
+ <string key="NSWindowTitle">MacDoc Wizard</string>
+ <string key="NSWindowClass">AppleDocMergeWindow</string>
+ <nil key="NSViewClass"/>
+ <nil key="NSUserInterfaceItemIdentifier"/>
+ <object class="NSView" key="NSWindowView" id="312036702">
+ <reference key="NSNextResponder"/>
+ <int key="NSvFlags">256</int>
+ <object class="NSMutableArray" key="NSSubviews">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSTextField" id="392246965">
+ <reference key="NSNextResponder" ref="312036702"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{17, 68}, {392, 17}}</string>
+ <reference key="NSSuperview" ref="312036702"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="925472382"/>
+ <string key="NSReuseIdentifierKey">_NS:1535</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSTextFieldCell" key="NSCell" id="812466593">
+ <int key="NSCellFlags">68157504</int>
+ <int key="NSCellFlags2">138413056</int>
+ <string key="NSContents">Merging Apple documentation...</string>
+ <object class="NSFont" key="NSSupport" id="754317893">
+ <string key="NSName">LucidaGrande</string>
+ <double key="NSSize">13</double>
+ <int key="NSfFlags">1044</int>
+ </object>
+ <string key="NSCellIdentifier">_NS:1535</string>
+ <reference key="NSControlView" ref="392246965"/>
+ <object class="NSColor" key="NSBackgroundColor">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">controlColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
+ </object>
+ </object>
+ <object class="NSColor" key="NSTextColor">
+ <int key="NSColorSpace">6</int>
+ <string key="NSCatalogName">System</string>
+ <string key="NSColorName">controlTextColor</string>
+ <object class="NSColor" key="NSColor">
+ <int key="NSColorSpace">3</int>
+ <bytes key="NSWhite">MAA</bytes>
+ </object>
+ </object>
+ </object>
+ </object>
+ <object class="NSProgressIndicator" id="925472382">
+ <reference key="NSNextResponder" ref="312036702"/>
+ <int key="NSvFlags">268</int>
+ <string key="NSFrame">{{86, 68}, {16, 16}}</string>
+ <reference key="NSSuperview" ref="312036702"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="1045547612"/>
+ <string key="NSReuseIdentifierKey">_NS:945</string>
+ <int key="NSpiFlags">20746</int>
+ <double key="NSMaxValue">100</double>
+ </object>
+ <object class="NSButton" id="1045547612">
+ <reference key="NSNextResponder" ref="312036702"/>
+ <int key="NSvFlags">-2147483380</int>
+ <string key="NSFrame">{{274, 12}, {138, 32}}</string>
+ <reference key="NSSuperview" ref="312036702"/>
+ <reference key="NSWindow"/>
+ <string key="NSReuseIdentifierKey">_NS:9</string>
+ <bool key="NSEnabled">YES</bool>
+ <object class="NSButtonCell" key="NSCell" id="1003732266">
+ <int key="NSCellFlags">67108864</int>
+ <int key="NSCellFlags2">134217728</int>
+ <string key="NSContents">Restart MacDoc</string>
+ <reference key="NSSupport" ref="754317893"/>
+ <string key="NSCellIdentifier">_NS:9</string>
+ <reference key="NSControlView" ref="1045547612"/>
+ <int key="NSButtonFlags">-2038284288</int>
+ <int key="NSButtonFlags2">129</int>
+ <string key="NSAlternateContents"/>
+ <string key="NSKeyEquivalent"/>
+ <int key="NSPeriodicDelay">200</int>
+ <int key="NSPeriodicInterval">25</int>
+ </object>
+ </object>
+ </object>
+ <string key="NSFrameSize">{426, 105}</string>
+ <reference key="NSSuperview"/>
+ <reference key="NSWindow"/>
+ <reference key="NSNextKeyView" ref="392246965"/>
+ </object>
+ <string key="NSScreenRect">{{0, 0}, {2560, 1418}}</string>
+ <string key="NSMaxSize">{10000000000000, 10000000000000}</string>
+ <bool key="NSWindowIsRestorable">YES</bool>
+ </object>
+ </object>
+ <object class="IBObjectContainer" key="IBDocument.Objects">
+ <object class="NSMutableArray" key="connectionRecords">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">window</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="748157544"/>
+ </object>
+ <int key="connectionID">6</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">ProgressWidget</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="925472382"/>
+ </object>
+ <int key="connectionID">12</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">WizardText</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="392246965"/>
+ </object>
+ <int key="connectionID">13</int>
+ </object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">WizardButton</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="1045547612"/>
+ </object>
+ <int key="connectionID">14</int>
+ </object>
+ </object>
+ <object class="IBMutableOrderedSet" key="objectRecords">
+ <object class="NSArray" key="orderedObjects">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBObjectRecord">
+ <int key="objectID">0</int>
+ <object class="NSArray" key="object" id="0">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ </object>
+ <reference key="children" ref="1000"/>
+ <nil key="parent"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-2</int>
+ <reference key="object" ref="1001"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">File's Owner</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-1</int>
+ <reference key="object" ref="1003"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">First Responder</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">-3</int>
+ <reference key="object" ref="1004"/>
+ <reference key="parent" ref="0"/>
+ <string key="objectName">Application</string>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">2</int>
+ <reference key="object" ref="748157544"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="312036702"/>
+ </object>
+ <reference key="parent" ref="0"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">3</int>
+ <reference key="object" ref="312036702"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="392246965"/>
+ <reference ref="1045547612"/>
+ <reference ref="925472382"/>
+ </object>
+ <reference key="parent" ref="748157544"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">7</int>
+ <reference key="object" ref="392246965"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="812466593"/>
+ </object>
+ <reference key="parent" ref="312036702"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">8</int>
+ <reference key="object" ref="812466593"/>
+ <reference key="parent" ref="392246965"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">9</int>
+ <reference key="object" ref="925472382"/>
+ <reference key="parent" ref="312036702"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">10</int>
+ <reference key="object" ref="1045547612"/>
+ <object class="NSMutableArray" key="children">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference ref="1003732266"/>
+ </object>
+ <reference key="parent" ref="312036702"/>
+ </object>
+ <object class="IBObjectRecord">
+ <int key="objectID">11</int>
+ <reference key="object" ref="1003732266"/>
+ <reference key="parent" ref="1045547612"/>
+ </object>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="flattenedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>-1.IBPluginDependency</string>
+ <string>-2.IBPluginDependency</string>
+ <string>-3.IBPluginDependency</string>
+ <string>10.IBPluginDependency</string>
+ <string>11.IBPluginDependency</string>
+ <string>2.IBPluginDependency</string>
+ <string>2.IBWindowTemplateEditedContentRect</string>
+ <string>2.NSWindowTemplate.visibleAtLaunch</string>
+ <string>3.IBPluginDependency</string>
+ <string>7.IBPluginDependency</string>
+ <string>8.IBPluginDependency</string>
+ <string>9.IBPluginDependency</string>
+ </object>
+ <object class="NSArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>{{319, 371}, {606, 354}}</string>
+ <boolean value="YES"/>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="unlocalizedProperties">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <reference key="dict.values" ref="0"/>
+ </object>
+ <nil key="activeLocalization"/>
+ <object class="NSMutableDictionary" key="localizations">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <reference key="dict.sortedKeys" ref="0"/>
+ <reference key="dict.values" ref="0"/>
+ </object>
+ <nil key="sourceID"/>
+ <int key="maxID">14</int>
+ </object>
+ <object class="IBClassDescriber" key="IBDocument.Classes">
+ <object class="NSMutableArray" key="referencedPartialClassDescriptions">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBPartialClassDescription">
+ <string key="className">AppleDocMergeWindow</string>
+ <string key="superclassName">NSWindow</string>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/AppleDocMergeWindow.h</string>
+ </object>
+ </object>
+ <object class="IBPartialClassDescription">
+ <string key="className">AppleDocMergeWindowController</string>
+ <string key="superclassName">NSWindowController</string>
+ <object class="NSMutableDictionary" key="outlets">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>ProgressWidget</string>
+ <string>WizardButton</string>
+ <string>WizardText</string>
+ </object>
+ <object class="NSArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>NSProgressIndicator</string>
+ <string>NSButton</string>
+ <string>NSTextField</string>
+ </object>
+ </object>
+ <object class="NSMutableDictionary" key="toOneOutletInfosByName">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="NSArray" key="dict.sortedKeys">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <string>ProgressWidget</string>
+ <string>WizardButton</string>
+ <string>WizardText</string>
+ </object>
+ <object class="NSArray" key="dict.values">
+ <bool key="EncodedWithXMLCoder">YES</bool>
+ <object class="IBToOneOutletInfo">
+ <string key="name">ProgressWidget</string>
+ <string key="candidateClassName">NSProgressIndicator</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">WizardButton</string>
+ <string key="candidateClassName">NSButton</string>
+ </object>
+ <object class="IBToOneOutletInfo">
+ <string key="name">WizardText</string>
+ <string key="candidateClassName">NSTextField</string>
+ </object>
+ </object>
+ </object>
+ <object class="IBClassDescriptionSource" key="sourceIdentifier">
+ <string key="majorKey">IBProjectSource</string>
+ <string key="minorKey">./Classes/AppleDocMergeWindowController.h</string>
+ </object>
+ </object>
+ </object>
+ </object>
+ <int key="IBDocument.localizationMode">0</int>
+ <string key="IBDocument.TargetRuntimeIdentifier">IBCocoaFramework</string>
+ <object class="NSMutableDictionary" key="IBDocument.PluginDeclaredDevelopmentDependencies">
+ <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3</string>
+ <integer value="3000" key="NS.object.0"/>
+ </object>
+ <bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
+ <int key="IBDocument.defaultPropertyAccessControl">3</int>
+ </data>
+</archive>
diff --git a/AppleDocMergeWindowController.cs b/AppleDocMergeWindowController.cs
new file mode 100644
index 0000000..d0c8e47
--- /dev/null
+++ b/AppleDocMergeWindowController.cs
@@ -0,0 +1,84 @@
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using MonoMac.Foundation;
+using MonoMac.AppKit;
+
+namespace macdoc
+{
+ public partial class AppleDocMergeWindowController : MonoMac.AppKit.NSWindowController
+ {
+ public AppleDocMergeWindowController (IntPtr handle) : base (handle)
+ {
+ Initialize ();
+ }
+
+ [Export ("initWithCoder:")]
+ public AppleDocMergeWindowController (NSCoder coder) : base (coder)
+ {
+ Initialize ();
+ }
+
+ public AppleDocMergeWindowController () : base ("AppleDocMergeWindow")
+ {
+ Initialize ();
+ }
+
+ void Initialize ()
+ {
+ }
+
+ public override void WindowDidLoad ()
+ {
+ ProgressWidget.StartAnimation (this);
+ }
+
+ public void TrackProcessTask (Task<int> task)
+ {
+ task.ContinueWith (t => {
+ var faulted = t.IsFaulted;
+
+ if (faulted)
+ Console.WriteLine ("Merger exception: " + t.Exception.ToString ());
+
+ BeginInvokeOnMainThread (() => Finish (faulted || t.Result > 0, faulted ? 99 : t.Result));
+ });
+ }
+
+ void Finish (bool errored, int code)
+ {
+ ProgressWidget.Hidden = true;
+ WizardButton.Hidden = false;
+
+ if (errored) {
+ WizardText.StringValue = string.Format ("There was a problem running the update (code {0}).", code);
+ WizardButton.Title = "Close";
+ WizardButton.Activated += CloseCallback;
+ } else {
+ WizardText.StringValue = "Update successful. Restart MacDoc for changes to take effect.";
+ WizardButton.Title = "Restart MacDoc";
+ WizardButton.Activated += RestartCallback;
+ }
+ }
+
+ void CloseCallback (object sender, EventArgs e)
+ {
+ Close ();
+ }
+
+ void RestartCallback (object sender, EventArgs e)
+ {
+ AppDelegate.RestartRequested = true;
+ NSApplication.SharedApplication.Terminate (this);
+ }
+
+ public new AppleDocMergeWindow Window {
+ get {
+ return (AppleDocMergeWindow)base.Window;
+ }
+ }
+ }
+}
+
diff --git a/ProcessUtils.cs b/ProcessUtils.cs
new file mode 100644
index 0000000..39906bd
--- /dev/null
+++ b/ProcessUtils.cs
@@ -0,0 +1,86 @@
+//
+// ProcessUtils.cs
+//
+// Author:
+// Jérémie Laval <jeremie.laval@xamarin.com>
+//
+// Copyright (c) 2012 Xamarin, Inc.
+
+using System;
+using System.IO;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace macdoc
+{
+ public static class ProcessUtils
+ {
+ public static Task<int> StartProcess (ProcessStartInfo psi, TextWriter stdout, TextWriter stderr, CancellationToken cancellationToken)
+ {
+ var tcs = new TaskCompletionSource<int> ();
+ if (cancellationToken.CanBeCanceled && cancellationToken.IsCancellationRequested) {
+ tcs.SetCanceled ();
+ return tcs.Task;
+ }
+
+ psi.UseShellExecute = false;
+ if (stdout != null) {
+ psi.RedirectStandardOutput = true;
+ }
+ if (stderr != null) {
+ psi.RedirectStandardError = true;
+ }
+ var p = Process.Start (psi);
+ if (cancellationToken.CanBeCanceled)
+ cancellationToken.Register (() => {
+ try {
+ if (!p.HasExited) {
+ p.Kill ();
+ }
+ } catch (InvalidOperationException ex) {
+ if (ex.Message.IndexOf ("already exited") < 0)
+ throw;
+ }
+ });
+ p.EnableRaisingEvents = true;
+ if (psi.RedirectStandardOutput) {
+ bool stdOutInitialized = false;
+ p.OutputDataReceived += (sender, e) => {
+ try {
+ if (stdOutInitialized)
+ stdout.WriteLine ();
+ stdout.Write (e.Data);
+ stdOutInitialized = true;
+ } catch (Exception ex) {
+ tcs.SetException (ex);
+ }
+ };
+ p.BeginOutputReadLine ();
+ }
+ if (psi.RedirectStandardError) {
+ bool stdErrInitialized = false;
+ p.ErrorDataReceived += (sender, e) => {
+ try {
+ if (stdErrInitialized)
+ stderr.WriteLine ();
+ stderr.Write (e.Data);
+ stdErrInitialized = true;
+ } catch (Exception ex) {
+ tcs.SetException (ex);
+ }
+ };
+ p.BeginErrorReadLine ();
+ }
+ p.Exited += (sender, e) => tcs.SetResult (p.ExitCode);
+
+ return tcs.Task;
+ }
+
+ public static void StartRelaunchProcess ()
+ {
+
+ }
+ }
+}
+
diff --git a/RootLauncher.cs b/RootLauncher.cs
index 35e1db4..a4851a5 100644
--- a/RootLauncher.cs
+++ b/RootLauncher.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using Mono.Unix;
namespace macdoc
{
@@ -40,6 +41,12 @@ namespace macdoc
public static class RootLauncher
{
const string SecurityFramework = "/System/Library/Frameworks/Security.framework/Versions/Current/Security";
+
+ public static bool IsRootEnabled (string toolPath)
+ {
+ var stat = new UnixFileInfo (toolPath);
+ return stat.IsSetUser && stat.IsSetGroup && stat.OwnerUserId == 0;
+ }
public static void LaunchExternalTool (string toolPath, string[] args)
{
diff --git a/macdoc.csproj b/macdoc.csproj
index cf776a4..e883c54 100644
--- a/macdoc.csproj
+++ b/macdoc.csproj
@@ -12,30 +12,32 @@
<AssemblyName>macdoc</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <DebugSymbols>true</DebugSymbols>
+ <DebugSymbols>True</DebugSymbols>
<DebugType>full</DebugType>
- <Optimize>false</Optimize>
+ <Optimize>False</Optimize>
<OutputPath>bin\Debug</OutputPath>
<DefineConstants>DEBUG</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <ConsolePause>false</ConsolePause>
- <EnableCodeSigning>false</EnableCodeSigning>
- <CreatePackage>false</CreatePackage>
- <EnablePackageSigning>false</EnablePackageSigning>
- <IncludeMonoRuntime>false</IncludeMonoRuntime>
+ <ConsolePause>False</ConsolePause>
+ <EnableCodeSigning>False</EnableCodeSigning>
+ <CreatePackage>False</CreatePackage>
+ <EnablePackageSigning>False</EnablePackageSigning>
+ <IncludeMonoRuntime>False</IncludeMonoRuntime>
+ <UseSGen>False</UseSGen>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>none</DebugType>
- <Optimize>false</Optimize>
+ <Optimize>False</Optimize>
<OutputPath>bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
- <ConsolePause>false</ConsolePause>
- <EnableCodeSigning>false</EnableCodeSigning>
- <CreatePackage>false</CreatePackage>
- <EnablePackageSigning>false</EnablePackageSigning>
- <IncludeMonoRuntime>false</IncludeMonoRuntime>
+ <ConsolePause>False</ConsolePause>
+ <EnableCodeSigning>False</EnableCodeSigning>
+ <CreatePackage>False</CreatePackage>
+ <EnablePackageSigning>False</EnablePackageSigning>
+ <IncludeMonoRuntime>False</IncludeMonoRuntime>
+ <UseSGen>False</UseSGen>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
@@ -49,6 +51,7 @@
<Reference Include="monodoc">
<HintPath>lib\monodoc.dll</HintPath>
</Reference>
+ <Reference Include="Mono.Posix" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyDocument.cs">
@@ -96,6 +99,12 @@
<DependentUpon>FindBarExtraordinaire.cs</DependentUpon>
</Compile>
<Compile Include="AppleDocHandler.cs" />
+ <Compile Include="ProcessUtils.cs" />
+ <Compile Include="AppleDocMergeWindow.cs" />
+ <Compile Include="AppleDocMergeWindowController.cs" />
+ <Compile Include="AppleDocMergeWindow.designer.cs">
+ <DependentUpon>AppleDocMergeWindow.cs</DependentUpon>
+ </Compile>
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="MyDocument.xib" xmlns="" />
@@ -103,6 +112,7 @@
<InterfaceDefinition Include="BookmarkPopover.xib" />
<InterfaceDefinition Include="BookmarkAssistant.xib" />
<InterfaceDefinition Include="FindBarExtraordinaire.xib" />
+ <InterfaceDefinition Include="AppleDocMergeWindow.xib" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />