Exemplo n.º 1
0
        /// <summary>
        /// This method is executed when the application has started and the
        /// message loop is running.
        /// </summary>
        private static void Bootstrap()
        {
            // Determine the other process state.
            WmOtherProcess other = new WmOtherProcess();

            other.FindOtherProcess();

            // Another KWM we own is running in our session.
            if (other.State == WmOtherProcessState.OurInCurrentSession)
            {
                // Send the other KWM a message to import the credentials.
                if (ImportKwsPath != "")
                {
                    SendMsgToOtherKwm(other, ImportKwsMsgID, ImportKwsPath);
                }

                // Show the instance of the other KWM.
                SendMsgToOtherKwm(other, ForegroundMsgID, "");

                // We're done.
                RequestAppExit();
            }

            // Warn the user.
            else if (other.State == WmOtherProcessState.NotOurInCurrentSession ||
                     other.State == WmOtherProcessState.OurInOtherSession)
            {
                String error = (other.State == WmOtherProcessState.NotOurInCurrentSession) ?
                               "A " + KwmStrings.Kwm + " started by another user is already running." :
                               "A " + KwmStrings.Kwm + " started by another user is already running.";
                WmUi.TellUser(error, "Cannot start " + KwmStrings.Kwm, MessageBoxButtons.OK, MessageBoxIcon.Error);
                RequestAppExit();
            }

            // Enter the main mode.
            else
            {
                try
                {
                    if (!EnterMainMode())
                    {
                        RequestAppExit();
                    }
                }

                catch (Exception ex)
                {
                    KBase.HandleException(ex, true);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Send the message specified to the other KWM specified, if possible.
        /// </summary>
        private static void SendMsgToOtherKwm(WmOtherProcess other, UInt32 msgID, String path)
        {
            try
            {
                // Wait 10 seconds for the other process to finish initializing,
                // then send the message.
                if (other.OtherProcess != null &&
                    other.OtherWindowHandle != IntPtr.Zero &&
                    other.OtherProcess.WaitForInputIdle(10 * 1000))
                {
                    KSyscalls.COPYDATASTRUCT cds;
                    cds.dwData = new IntPtr(msgID);
                    cds.lpData = path;
                    cds.cbData = Encoding.Default.GetBytes(path).Length + 1;
                    KSyscalls.SendMessage(other.OtherWindowHandle.ToInt32(), KSyscalls.WM_COPYDATA, 0, ref cds);
                }
            }

            catch (Exception)
            {
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Send the message specified to the other KWM specified, if possible.
        /// </summary>
        private static void SendMsgToOtherKwm(WmOtherProcess other, UInt32 msgID, String path)
        {
            try
            {
                // Wait 10 seconds for the other process to finish initializing,
                // then send the message.
                if (other.OtherProcess != null &&
                    other.OtherWindowHandle != IntPtr.Zero &&
                    other.OtherProcess.WaitForInputIdle(10 * 1000))
                {
                    KSyscalls.COPYDATASTRUCT cds;
                    cds.dwData = new IntPtr(msgID);
                    cds.lpData = path;
                    cds.cbData = Encoding.Default.GetBytes(path).Length + 1;
                    KSyscalls.SendMessage(other.OtherWindowHandle.ToInt32(), KSyscalls.WM_COPYDATA, 0, ref cds);
                }
            }

            catch (Exception)
            {
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// This method is executed when the application has started and the
        /// message loop is running.
        /// </summary>
        private static void Bootstrap()
        {
            // Determine the other process state.
            WmOtherProcess other = new WmOtherProcess();
            other.FindOtherProcess();

            // Another KWM we own is running in our session.
            if (other.State == WmOtherProcessState.OurInCurrentSession)
            {
                // Send the other KWM a message to import the credentials.
                if (ImportKwsPath != "") SendMsgToOtherKwm(other, ImportKwsMsgID, ImportKwsPath);

                // Show the instance of the other KWM.
                SendMsgToOtherKwm(other, ForegroundMsgID, "");

                // We're done.
                RequestAppExit();
            }

            // Warn the user.
            else if (other.State == WmOtherProcessState.NotOurInCurrentSession ||
                     other.State == WmOtherProcessState.OurInOtherSession)
            {
                String error = (other.State == WmOtherProcessState.NotOurInCurrentSession) ?
                    "A " + KwmStrings.Kwm + " started by another user is already running." :
                    "A " + KwmStrings.Kwm + " started by another user is already running.";
                WmUi.TellUser(error, "Cannot start " + KwmStrings.Kwm, MessageBoxButtons.OK, MessageBoxIcon.Error);
                RequestAppExit();
            }

            // Enter the main mode.
            else
            {
                try
                {
                    if (!EnterMainMode()) RequestAppExit();
                }

                catch (Exception ex)
                {
                    KBase.HandleException(ex, true);
                }
            }
        }