Beispiel #1
0
 internal static int MsiGetActiveDatabase(int hInstall)
 {
     if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hInstall))
     {
         return(NativeMethods.MsiGetActiveDatabase(hInstall));
     }
     else
     {
         int hDatabase = (int)RemotableNativeMethods.MsiFunc_III(
             RemoteMsiFunctionId.MsiGetActiveDatabase,
             RemotableNativeMethods.GetRemoteHandle(hInstall),
             0,
             0);
         return(RemotableNativeMethods.MakeRemoteHandle(hDatabase));
     }
 }
Beispiel #2
0
 internal static int MsiGetLastErrorRecord(int hAny)
 {
     // When remoting is enabled, we might need to create either a local or
     // remote record, depending on the handle it is to have an affinity with.
     // If no affinity handle is specified, create a remote record (the 99% case).
     if (!RemotingEnabled ||
         (hAny != 0 && !RemotableNativeMethods.IsRemoteHandle(hAny)))
     {
         return(NativeMethods.MsiGetLastErrorRecord());
     }
     else
     {
         int hRecord = unchecked ((int)RemotableNativeMethods.MsiFunc_III(
                                      RemoteMsiFunctionId.MsiGetLastErrorRecord, 0, 0, 0));
         return(RemotableNativeMethods.MakeRemoteHandle(hRecord));
     }
 }
Beispiel #3
0
 internal static uint MsiViewGetColumnInfo(int hView, uint eColumnInfo, out int hRecord)
 {
     if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hView))
     {
         return(NativeMethods.MsiViewGetColumnInfo(hView, eColumnInfo, out hRecord));
     }
     else
     {
         uint err = RemotableNativeMethods.MsiFunc_II_I(
             RemoteMsiFunctionId.MsiViewGetColumnInfo,
             RemotableNativeMethods.GetRemoteHandle(hView),
             (int)eColumnInfo,
             out hRecord);
         hRecord = RemotableNativeMethods.MakeRemoteHandle(hRecord);
         return(err);
     }
 }
Beispiel #4
0
 internal static uint MsiViewFetch(int hView, out int hRecord)
 {
     if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hView))
     {
         return(NativeMethods.MsiViewFetch(hView, out hRecord));
     }
     else
     {
         uint err = RemotableNativeMethods.MsiFunc_II_I(
             RemoteMsiFunctionId.MsiViewFetch,
             RemotableNativeMethods.GetRemoteHandle(hView),
             0,
             out hRecord);
         hRecord = RemotableNativeMethods.MakeRemoteHandle(hRecord);
         return(err);
     }
 }
Beispiel #5
0
 internal static uint MsiDatabaseGetPrimaryKeys(int hDatabase, string szTableName, out int hRecord)
 {
     if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hDatabase))
     {
         return(NativeMethods.MsiDatabaseGetPrimaryKeys(hDatabase, szTableName, out hRecord));
     }
     else
     {
         uint err = RemotableNativeMethods.MsiFunc_ISII_I(
             RemoteMsiFunctionId.MsiDatabaseGetPrimaryKeys,
             RemotableNativeMethods.GetRemoteHandle(hDatabase),
             szTableName,
             0,
             0,
             out hRecord);
         hRecord = RemotableNativeMethods.MakeRemoteHandle(hRecord);
         return(err);
     }
 }
Beispiel #6
0
 internal static uint MsiDatabaseOpenView(int hDatabase, string szQuery, out int hView)
 {
     if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hDatabase))
     {
         return(NativeMethods.MsiDatabaseOpenView(hDatabase, szQuery, out hView));
     }
     else
     {
         uint err = RemotableNativeMethods.MsiFunc_ISII_I(
             RemoteMsiFunctionId.MsiDatabaseOpenView,
             RemotableNativeMethods.GetRemoteHandle(hDatabase),
             szQuery,
             0,
             0,
             out hView);
         hView = RemotableNativeMethods.MakeRemoteHandle(hView);
         return(err);
     }
 }
Beispiel #7
0
 internal static uint MsiGetSummaryInformation(int hDatabase, string szDatabasePath, uint uiUpdateCount, out int hSummaryInfo)
 {
     if (!RemotingEnabled || !RemotableNativeMethods.IsRemoteHandle(hDatabase))
     {
         return(NativeMethods.MsiGetSummaryInformation(hDatabase, szDatabasePath, uiUpdateCount, out hSummaryInfo));
     }
     else
     {
         uint err = RemotableNativeMethods.MsiFunc_ISII_I(
             RemoteMsiFunctionId.MsiGetSummaryInformation,
             RemotableNativeMethods.GetRemoteHandle(hDatabase),
             szDatabasePath,
             (int)uiUpdateCount,
             0,
             out hSummaryInfo);
         hSummaryInfo = RemotableNativeMethods.MakeRemoteHandle(hSummaryInfo);
         return(err);
     }
 }
Beispiel #8
0
        public static int InvokeCustomAction(int sessionHandle, string entryPoint,
                                             IntPtr remotingDelegatePtr)
        {
            Session    session = null;
            string     assemblyName, className, methodName;
            MethodInfo method;

            try
            {
                MsiRemoteInvoke remotingDelegate = (MsiRemoteInvoke)
                                                   Marshal.GetDelegateForFunctionPointer(
                    remotingDelegatePtr, typeof(MsiRemoteInvoke));
                RemotableNativeMethods.RemotingDelegate = remotingDelegate;

                sessionHandle = RemotableNativeMethods.MakeRemoteHandle(sessionHandle);
                session       = new Session((IntPtr)sessionHandle, false);
                if (string.IsNullOrWhiteSpace(entryPoint))
                {
                    throw new ArgumentNullException("entryPoint");
                }

                if (!CustomActionProxy.FindEntryPoint(
                        session,
                        entryPoint,
                        out assemblyName,
                        out className,
                        out methodName))
                {
                    return((int)ActionResult.Failure);
                }
                session.Log("Calling custom action {0}!{1}.{2}", assemblyName, className, methodName);

                method = CustomActionProxy.GetCustomActionMethod(
                    session,
                    assemblyName,
                    className,
                    methodName);
                if (method == null)
                {
                    return((int)ActionResult.Failure);
                }
            }
            catch (Exception ex)
            {
                if (session != null)
                {
                    try
                    {
                        session.Log("Exception while loading custom action:");
                        session.Log(ex.ToString());
                    }
                    catch (Exception) { }
                }
                return((int)ActionResult.Failure);
            }

            try
            {
                // Set the current directory to the location of the extracted files.
                Environment.CurrentDirectory =
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                object[] args = new object[] { session };
                if (DebugBreakEnabled(new string[] { entryPoint, methodName }))
                {
                    string message = String.Format(CultureInfo.InvariantCulture,
                                                   "To debug your custom action, attach to process ID {0} (0x{0:x}) and click OK; otherwise, click Cancel to fail the custom action.",
                                                   System.Diagnostics.Process.GetCurrentProcess().Id
                                                   );

                    MessageResult button = NativeMethods.MessageBox(
                        IntPtr.Zero,
                        message,
                        "Custom Action Breakpoint",
                        (int)MessageButtons.OKCancel | (int)MessageIcon.Asterisk | (int)(MessageBoxStyles.TopMost | MessageBoxStyles.ServiceNotification)
                        );

                    if (MessageResult.Cancel == button)
                    {
                        return((int)ActionResult.UserExit);
                    }
                }

                ActionResult result = (ActionResult)method.Invoke(null, args);
                session.Close();
                return((int)result);
            }
            catch (InstallCanceledException)
            {
                return((int)ActionResult.UserExit);
            }
            catch (Exception ex)
            {
                session.Log("Exception thrown by custom action:");
                session.Log(ex.ToString());
                return((int)ActionResult.Failure);
            }
        }