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-03-13 21:12:37 +0400
committerJeremie Laval <jeremie.laval@gmail.com>2012-03-13 21:12:37 +0400
commit8b1b62877edd788b9c928d3647653a2b720aa12d (patch)
tree37225af7266649d46fdf60ca93249734faeebfec /RootLauncher.cs
parent552cd23a2e24a2b10dc34ad65c9f7f8eda6ec168 (diff)
[macdoc] Propagate root launcher error and report them to the user
Diffstat (limited to 'RootLauncher.cs')
-rw-r--r--RootLauncher.cs50
1 files changed, 42 insertions, 8 deletions
diff --git a/RootLauncher.cs b/RootLauncher.cs
index d879197..8e2d8d4 100644
--- a/RootLauncher.cs
+++ b/RootLauncher.cs
@@ -1,9 +1,39 @@
using System;
+using System.IO;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace macdoc
{
+ public enum AuthorizationResultCode
+ {
+ Success = 0,
+ InvalidSet = -60001,
+ InvalidRef = -60002,
+ InvalidTag = -60003,
+ InvalidPointer = -60004,
+ Denied = -60005,
+ Canceled = -60006,
+ InteractionNotAllowed = -60007,
+ Internal = -60008,
+ ExternalizeNotAllowed = -60009,
+ InternalizeNotAllowed = -60010,
+ InvalidFlags = -60011,
+ ToolExecuteFailure = -60031,
+ ToolEnvironmentError = -60032,
+ BadAddress = -60033,
+ FileNotFound = -60035 // Addition
+ }
+
+ public class RootLauncherException : ApplicationException
+ {
+ public RootLauncherException (string message) : base (message)
+ {
+ }
+
+ public AuthorizationResultCode ResultCode { get; set; }
+ }
+
// You were in need of some harsh reality? You have come to the right place
public static class RootLauncher
{
@@ -11,20 +41,24 @@ namespace macdoc
public static void LaunchExternalTool (string toolPath)
{
+ if (!File.Exists (toolPath))
+ throw new RootLauncherException ("[Launcher] Error, the tool doesn't exist and can't be launched") { ResultCode = AuthorizationResultCode.FileNotFound };
+
IntPtr authReference = IntPtr.Zero;
- int result = AuthorizationCreate (IntPtr.Zero, IntPtr.Zero, 0, out authReference);
- if (result != 0) {
- Console.WriteLine ("Error while creating Auth Reference: {0}", result);
- return;
- }
- AuthorizationExecuteWithPrivileges (authReference, toolPath, 0, new string[] { null }, IntPtr.Zero);
+ AuthorizationResultCode result = AuthorizationCreate (IntPtr.Zero, IntPtr.Zero, 0, out authReference);
+ if (result != AuthorizationResultCode.Success)
+ throw new RootLauncherException ("[Launcher] Error while creating Auth Reference") { ResultCode = result };
+
+ result = AuthorizationExecuteWithPrivileges (authReference, toolPath, 0, new string[] { null }, IntPtr.Zero);
+ if (result != AuthorizationResultCode.Success)
+ throw new RootLauncherException ("[Launcher] Error while executing") { ResultCode = result };
}
[DllImport (SecurityFramework)]
- extern static int AuthorizationCreate (IntPtr autorizationRights, IntPtr environment, int authFlags, out IntPtr authRef);
+ extern static AuthorizationResultCode AuthorizationCreate (IntPtr autorizationRights, IntPtr environment, int authFlags, out IntPtr authRef);
[DllImport (SecurityFramework)]
- extern static int AuthorizationExecuteWithPrivileges (IntPtr authRef, string pathToTool, int authFlags, string[] args, IntPtr pipe);
+ extern static AuthorizationResultCode AuthorizationExecuteWithPrivileges (IntPtr authRef, string pathToTool, int authFlags, string[] args, IntPtr pipe);
}
public static class UrlLauncher