예제 #1
0
 /// <summary>
 /// Stops this instance of Krento and dispose Krento context.
 /// </summary>
 internal void Stop()
 {
     TraceDebug.Trace("Stop Krento");
     if (context != null)
     {
         try
         {
             if (splashScreen != null)
             {
                 splashScreen.Dispose();
                 splashScreen = null;
             }
             context.StopServer();
             context.UnloadKrentoPlugins();
             context.UnloadKrentoToys();
             context.UnloadKrentoDocklets();
             context.UnloadRingImage();
             context.Dispose();
             context = null;
         }
         catch (Exception ex)
         {
             TraceDebug.Trace("Exception in Startup.Stop: " + ex.Message);
             context = null;
         }
     }
 }
예제 #2
0
 internal void UnloadAll()
 {
     try
     {
         SaveAll();
     }
     catch (Exception ex)
     {
         //do not raise an exception here because Krento wants to shutdown
         TraceDebug.Trace(ex);
     }
     UnloadMouseHook();
     UnloadKeyboardHook();
     context.FreeAllResources();
 }
예제 #3
0
        private void Load()
        {
            try
            {
                iniFile = new MemIniFile(FileName);
                try
                {
                    iniFile.Load();
                    LoadIniFileData();
                }
                finally
                {
                    iniFile.Dispose();
                    iniFile = null;
                }

                LoadLogo(logoFile);
            }
            catch (Exception ex)
            {
                TraceDebug.Trace(ex);
            }
        }
예제 #4
0
 /// <summary>
 /// Stops this instance of Krento and dispose Krento context.
 /// </summary>
 internal void Stop()
 {
     TraceDebug.Trace("Stop Krento");
     if (context != null)
     {
         try
         {
             context.StopServer();
             context.UnloadKrentoPlugins();
             context.UnloadKrentoToys();
             context.UnloadKrentoDocklets();
             context.UnloadRingImage();
             context.Dispose();
             context = null;
         }
         catch (Exception ex)
         {
             TraceDebug.Trace("Exception in Startup.Stop: " + ex.Message);
             context = null;
         }
     }
     CentralPoint.Shutdown();
 }
예제 #5
0
        internal static void UnhandledException(Exception ex)
        {
            if (!busyException)
            {
                try
                {
                    busyException = true;

#if !DEBUG
                    try
                    {
#endif
                    InteropHelper.OutputDebugString(ex.Message);

                    BroadcastShutdownMessage();
                    string message = string.Empty;

                    ErrorHandleDialog ehd = new ErrorHandleDialog();
                    try
                    {
                        if (ex is HookException)
                        {
                            ehd.ErrorText.Text = SR.KrentoHookMissing;
                        }
                        else
                        {
                            while (ex.InnerException != null)
                            {
                                message = message + ex.Message + Environment.NewLine;
                                ex      = ex.InnerException;
                            }
                            message = message + ex.Message + Environment.NewLine;

                            StackTrace st = new StackTrace(ex);
                            message            = message + "Call stack:";
                            ehd.ErrorText.Text = message + Environment.NewLine + st.ToString();
                            InteropHelper.OutputDebugString(ehd.ErrorText.Text);
                        }

                        DialogResult ok = DialogResult.Cancel;

                        ThreadWindows threadWindows;
                        threadWindows = DisableTaskWindows();
                        try
                        {
                            ok = ehd.ShowDialog(MainForm);
                        }
                        finally
                        {
                            EnableTaskWindows(threadWindows);
                        }
                        if (ok == DialogResult.OK)
                        {
#if DEBUG
                            if (Debugger.IsAttached)
                            {
                                throw ex;
                            }
                            else
                            {
                                Killer.KillSelf();
                            }
#else
                            Killer.KillSelf();
#endif
                        }
                        else
                        {
#if DEBUG
                            if (Debugger.IsAttached)
                            {
                                throw ex;
                            }
                            else
                            {
                                Killer.KillSelf();
                            }
#else
                            Application.Restart();
                            Killer.KillSelf();
#endif
                        }
                    }
                    finally
                    {
                        ehd.Dispose();
                    }
#if !DEBUG
                }

                catch
                {
                    //Exception happens in exception handler
                    //Can't do anything now
                    TraceDebug.Trace(ex.Message);
                    MessageBox.Show(ex.ToString());
                    Killer.KillSelf();
                }
            }
#endif
                }
예제 #6
0
 private static void HandleApplicationException(object sender, ThreadExceptionEventArgs e)
 {
     TraceDebug.Trace("DEBUG: Application thread exception");
     UnhandledException(e.Exception);
 }
예제 #7
0
 private static void HandleDomainException(object sender, UnhandledExceptionEventArgs e)
 {
     TraceDebug.Trace("DEBUG: Current Domain unhandled exception");
     UnhandledException((Exception)e.ExceptionObject);
 }
예제 #8
0
        internal void Start()
        {
            string ApplicationPrefix = GlobalConfig.ProductName.ToUpperInvariant();

            TraceDebug.Trace("Start {0}", GlobalConfig.ProductName);
#if PORTABLE
            Environment.SetEnvironmentVariable(ApplicationPrefix + "_PORTABLE", GlobalConfig.MainFolder, EnvironmentVariableTarget.Process);
            Environment.SetEnvironmentVariable(ApplicationPrefix + "_DRIVE", GlobalConfig.ApplicationDrive, EnvironmentVariableTarget.Process);
#endif

            Environment.SetEnvironmentVariable(ApplicationPrefix + "_DATA", GlobalConfig.MainFolder, EnvironmentVariableTarget.Process);

            messageID = NativeMethods.RegisterWindowMessage("KrentoStop"); //Do not localize!!!
            NativeMethods.AddRemoveMessageFilter(messageID, ChangeWindowMessageFilterFlags.Add);


            PrepareStandardProperties();

            showSplashScreen = true;

            ApplyGUILanguage();

            GlobalSettings.LoadGlobalSettings();
            GlobalSettings.ManagerLeft = Settings.Default.ManagerLeft;
            GlobalSettings.ManagerTop  = Settings.Default.ManagerTop;



            #region Parse command line
            foreach (string param in args)
            {
                if (TextHelper.SameText(param, @"/low"))
                {
                    GlobalConfig.LowMemory = true;
                }

                if (TextHelper.SameText(param, @"/ns"))
                {
                    showSplashScreen = false;
                }

                if (TextHelper.SameText(param, @"/nd"))
                {
                    KrentoContext.SkipDocklets = true;
                }

                if (TextHelper.SameText(param, @"/nt"))
                {
                    KrentoContext.SkipToys = true;
                }

                if (TextHelper.SameText(param, @"/desktop"))
                {
                    KrentoContext.CreateDesktopCircle = true;
                }

                if (param.IndexOf(@".circle", StringComparison.OrdinalIgnoreCase) > 0)
                {
                    KrentoContext.CircleParameter = param;
                }

                if (FileOperations.IsKrentoPackage(param))
                {
                    KrentoContext.PackageParameter = param;
                }
            }
            #endregion

            this.context = new KrentoContext();

            #region FirstRun
            if (NativeMethods.GlobalCheckAtom("krento_first_run"))
            {
                KrentoContext.FirstRun = true;
                NativeMethods.GlobalKillAtom("krento_first_run");
            }
#if PORTABLE
            string firstRunFile = Path.Combine(GlobalConfig.ApplicationFolder, "first.run");
            if (NativeMethods.FileExists(firstRunFile))
            {
                KrentoContext.FirstRun = true;
                NativeMethods.FileDelete(firstRunFile);
            }
#endif
            if (KrentoContext.FirstRun)
            {
                GlobalSettings.SaveGlobalSettings();
            }
            #endregion

            #region First Instance
            if (context.FirstInstance)
            {
                if ((showSplashScreen) && GlobalSettings.ShowSplashScreen)
                {
                    splashScreen = new SplashScreen();
                }
                else
                {
                    splashScreen = null;
                }



                this.mainForm            = new MainForm(context);
                mainForm.Text            = GlobalConfig.ProductName;
                InteropHelper.MainWindow = mainForm.Handle;

                if (showSplashScreen)
                {
                    if (splashScreen != null)
                    {
                        mainForm.SplashScreen = splashScreen;
                    }
                }


                if (NativeMethods.StartEngineEx(mainForm.Handle))
                {
                    if (GlobalSettings.ActivateServer)
                    {
                        if (NetworkOperations.PortAvailable(GlobalSettings.PortNumber))
                        {
                            context.StartServer();
                        }
                    }


                    appContext = new ApplicationContext();

                    //Load plugins. If the instance is the first instance and
                    //engine is activated, then plugins are loaded

                    try
                    {
                        context.LoadKrentoPlugins();
                    }
                    catch (Exception)
                    {
                        //do not stop on wrong plugins
                        TraceDebug.Trace("Exception on loading Krento plugin");
                    }

                    try
                    {
                        context.LoadKrentoToys();
                    }
                    catch (Exception)
                    {
                        //do not stop on wrong plugins
                        TraceDebug.Trace("Exception on loading Krento toy");
                    }
                    try
                    {
                        context.LoadKrentoDocklets();
                    }
                    catch
                    {
                        //do not stop on wrong docklet
                        TraceDebug.Trace("Exception on loading docklet");
                    }

                    NativeThemeManager.MakeSound("#110");
                    Application.Run(appContext);
                }
            }
            #endregion
        }
예제 #9
0
        internal void InstallKrentoPart(string fileName)
        {
            string destination    = null;
            bool   compressed     = false;
            bool   loadNewToy     = false;
            bool   loadNewDocklet = false;
            bool   reloadStones   = false;
            string mainFolderName = null;

            string ext = Path.GetExtension(fileName);

            if (TextHelper.SameText(ext, ".toy"))
            {
                destination = GlobalConfig.ToysFolder;
                compressed  = true;
                loadNewToy  = true;
            }
            else
            if (TextHelper.SameText(ext, ".kmenu"))
            {
                destination = GlobalConfig.MenusFolder;
                compressed  = true;
            }
            else
            if (TextHelper.SameText(ext, ".kskin"))
            {
                destination = GlobalConfig.SkinsFolder;
                compressed  = true;
            }
            else
            if (TextHelper.SameText(ext, ".stone"))
            {
                destination  = GlobalConfig.StoneClasses;
                compressed   = true;
                reloadStones = true;
            }
            else
            if (TextHelper.SameText(ext, ".lng"))
            {
                destination = GlobalConfig.LanguagesFolder;
                compressed  = false;
            }
            else
            if (TextHelper.SameText(ext, ".kadd"))
            {
                destination = GlobalConfig.AddInRootFolder;
                compressed  = true;
            }
            else
            if (TextHelper.SameText(ext, ".docklet"))
            {
                destination    = GlobalConfig.DockletsFolder;
                compressed     = true;
                loadNewDocklet = true;
            }
            else
            if (TextHelper.SameText(ext, ".circle"))
            {
                destination = GlobalConfig.RollingStonesFolder;
                compressed  = false;
            }

            if (string.IsNullOrEmpty(destination))
            {
                return;
            }

            if (!compressed)
            {
                string destinationName = Path.Combine(destination, Path.GetFileName(fileName));
                try
                {
                    FileOperations.CopyFile(fileName, destinationName);
                    if (TextHelper.SameText(destination, GlobalConfig.RollingStonesFolder))
                    {
                        if (FileOperations.FileExists(destinationName))
                        {
                            Manager.HistoryAdd(destinationName);
                        }
                    }
                }
                catch (Exception ex)
                {
                    TraceDebug.Trace(ex);
                }
            }
            else
            {
                try
                {
                    destination = Path.Combine(destination, Path.GetFileNameWithoutExtension(fileName));
                    if (!Directory.Exists(destination))
                    {
                        Directory.CreateDirectory(destination);
                    }
                }
                catch (Exception ex)
                {
                    TraceDebug.Trace(ex);
                }

                NativeMethods.ExtractArchive(fileName, destination);
                FileOperations.CopyFile(fileName, Path.Combine(GlobalConfig.DownloadsFolder, Path.GetFileName(fileName)));

                if (reloadStones)
                {
                    try
                    {
                        string newStonePath;
                        if (!string.IsNullOrEmpty(mainFolderName))
                        {
                            newStonePath = Path.Combine(destination, mainFolderName);
                        }
                        else
                        {
                            newStonePath = destination;
                        }
                        Language.Merge(Path.Combine(newStonePath, GlobalSettings.Language + ".lng"));
                    }
                    catch (Exception ex)
                    {
                        //Toy load error happens
                        TraceDebug.Trace(ex);
                    }

                    //Loading of the new stone must be AFTER merging of the language
                    Manager.LoadStoneClasses();
                }
                else
                if (loadNewToy)
                {
                    try
                    {
                        string newToyPath;
                        if (!string.IsNullOrEmpty(mainFolderName))
                        {
                            newToyPath = Path.Combine(destination, mainFolderName);
                        }
                        else
                        {
                            newToyPath = destination;
                        }
                        context.LoadKrentoToys(newToyPath);
                    }
                    catch (Exception ex)
                    {
                        //Toy load error happens
                        TraceDebug.Trace(ex);
                    }
                }
                else
                if (loadNewDocklet)
                {
                    try
                    {
                        string newDockletPath;

                        if (!string.IsNullOrEmpty(mainFolderName))
                        {
                            newDockletPath = Path.Combine(destination, mainFolderName);
                        }
                        else
                        {
                            newDockletPath = destination;
                        }
                        context.LoadKrentoDocklets(newDockletPath);
                    }
                    catch (Exception ex)
                    {
                        //Toy load error happens
                        TraceDebug.Trace(ex);
                    }
                }
            }
        }
예제 #10
0
        internal void PrepareKeyboardHook()
        {
            KeyModifiers mod = KeyModifiers.None;

            try
            {
                if (hotKeys != null)
                {
                    hotKeys.Dispose();
                    hotKeys = null;
                }

                if (ringKeys != null)
                {
                    ringKeys.Dispose();
                    ringKeys = null;
                }

                if (GlobalSettings.UseKeyboardActivation)
                {
                    try
                    {
                        if ((GlobalSettings.Modifiers & Keys.LWin) != 0)
                        {
                            mod |= KeyModifiers.Windows;
                        }
                        if ((GlobalSettings.Modifiers & Keys.Shift) != 0)
                        {
                            mod |= KeyModifiers.Shift;
                        }
                        if ((GlobalSettings.Modifiers & Keys.Alt) != 0)
                        {
                            mod |= KeyModifiers.Alt;
                        }
                        if ((GlobalSettings.Modifiers & Keys.Control) != 0)
                        {
                            mod |= KeyModifiers.Control;
                        }
                        hotKeys = new Hotkeys(mod, GlobalSettings.Shortcut, this);
                    }
                    catch (ArgumentException)
                    {
                        hotKeys = null;
                        RtlAwareMessageBox.Show(SR.HotkeyCollision(HotKeyMessage), SR.KrentoShortName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }

                    if (GlobalSettings.CircleSelector)
                    {
                        try
                        {
                            ringKeys = new Hotkeys(KeyModifiers.Windows, Keys.N, this);
                        }
                        catch
                        {
                            ringKeys = null;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TraceDebug.Trace("PrepareKeyboardHook: ", ex);
                throw;
            }
        }
예제 #11
0
        public void ActivateEngine()
        {
            TraceDebug.Trace("Activate Engine");

            bool doCheck      = GlobalSettings.CheckUpdate;
            bool disableCheck = false;

            Visible = false;
            NativeMethods.ShowWindow(this.Handle, 0);
            NativeMethods.RemoveSystemMenu(this.Handle);


            #region First Instance Execution
            if (context.FirstInstance)
            {
                if (!string.IsNullOrEmpty(GlobalSettings.IconName))
                {
                    Icon customIcon = null;

                    if (FileOperations.FileExists(GlobalSettings.IconName))
                    {
                        Icon loadIcon = new Icon(FileOperations.StripFileName(GlobalSettings.IconName));
                        try
                        {
                            customIcon = (Icon)loadIcon.Clone();
                        }
                        finally
                        {
                            loadIcon.Dispose();
                            loadIcon = null;
                        }

                        notifyIcon.Icon = customIcon;
                        //this.Icon = customIcon;
                    }
                }

                if (splashScreen != null)
                {
                    splashScreen.Show();
                }

                if (!string.IsNullOrEmpty(GlobalSettings.GlyphName))
                {
                    if (FileOperations.FileExists(GlobalSettings.GlyphName))
                    {
                        Bitmap tmp = FastBitmap.FromFile(GlobalSettings.GlyphName);
                        notifier.Glyph = BitmapPainter.ResizeBitmap(tmp, notifier.GlyphSize, notifier.GlyphSize, true);
                    }
                }

                if (notifier.Glyph == null)
                {
                    notifier.Glyph = NativeThemeManager.Load("BigKrento.png");
                }

                context.Manager.SetHookMessage(context);

                ReloadAll();


                PreparePulsar();


                context.Manager.Rotate(0);
                if (!GlobalSettings.ShowManagerButtons)
                {
                    context.Manager.DrawText(SR.KrentoWelcome);
                }
                context.Manager.Update();
                context.Manager.Visible = false;


                notifyIcon.Visible = GlobalSettings.ShowTrayIcon;


                if (splashScreen != null)
                {
                    if (KrentoContext.FirstRun)
                    {
                        splashScreen.Hide();
                        NativeMethods.PostMessage(InteropHelper.MainWindow, NativeMethods.CM_SPLASHCLOSE, IntPtr.Zero, IntPtr.Zero);
                    }
                    else
                    {
                        splashScreen.Close(200);
                    }
                }

                systemReady = true;

                string keyMessage = HotKeyMessage;



                notifier.Caption = SR.KrentoWelcome;

                if (GlobalSettings.MouseHook == MouseHookButton.None)
                {
                    notifier.Text = SR.WelcomeMessage(keyMessage, "", "");
                }
                else
                {
                    string mouseText = "";
                    switch (GlobalSettings.MouseHook)
                    {
                    case MouseHookButton.Wheel:
                        mouseText = MouseKeyMessage + SR.MouseWheelButton;
                        break;

                    case MouseHookButton.XButton1:
                        mouseText = MouseKeyMessage + SR.MouseXButton1;
                        break;

                    case MouseHookButton.XButton2:
                        mouseText = MouseKeyMessage + SR.MouseXButton2;
                        break;

                    default:
                        mouseText = "";
                        break;
                    }

                    notifier.Text = SR.WelcomeMessage(keyMessage, SR.OrClick, mouseText);
                }

                //Only show popup window when asked
                if (GlobalSettings.ShowPopupAlerts)
                {
                    if (GlobalConfig.LowMemory)
                    {
                        notifyIcon.BalloonTipTitle = notifier.Caption;
                        notifyIcon.BalloonTipText  = notifier.Text;
                        notifyIcon.BalloonTipIcon  = ToolTipIcon.Info;
                        notifyIcon.ShowBalloonTip(5000);
                    }
                    else
                    {
                        notifier.Show();
                    }
                }


                Manager.ClearUnusedMemory();

                #region manage autoupdate
                DateTime lastCheck = Settings.Default.LastCheck;
                TimeSpan ts        = DateTime.Now - lastCheck;
                if (ts.Days >= 7)
                {
                    Settings.Default.LastCheck = DateTime.Now;
                    Settings.Default.Save();
                    if (Settings.Default.AskForCheck)
                    {
                        UpdateDialog upd = new UpdateDialog();
                        try
                        {
                            upd.ShowDialog();
                            doCheck      = (upd.DialogResult == DialogResult.OK);
                            disableCheck = (upd.btnDisable.Checked);
                            if (disableCheck)
                            {
                                GlobalSettings.CheckUpdate   = doCheck;
                                Settings.Default.AskForCheck = false;
                                Settings.Default.Save();
                            }
                        }
                        finally
                        {
                            upd.Dispose();
                        }
                    }

                    if ((GlobalSettings.CheckUpdate) && (doCheck))
                    {
                        checker.CheckNewVersion();
                    }
                }
                #endregion

                if (GlobalSettings.StartVisible || KrentoContext.FirstRun)
                {
                    InteropHelper.ShowDesktop();
                    if (!Manager.Visible)
                    {
                        if (KrentoContext.FirstRun)
                        {
                            Manager.ShowAndExecute(Manager.SimulateWheelRotation);
                        }
                        else
                        {
                            ChangeVisibility();
                        }
                    }
                }
            }
            #endregion
            else
            {
                systemReady           = false;
                context.FirstInstance = false;
            }
        }
예제 #12
0
        protected override void WndProc(ref Message m)
        {
            try
            {
                if (wasException)
                {
                    base.WndProc(ref m);
                    return;
                }


                if (!systemReady)
                {
                    if (m.Msg == NativeMethods.CM_STARTENGINE)
                    {
                        ActivateEngine();
                        return;
                    }

                    if ((m.Msg == NativeMethods.WM_CLOSE) || (m.Msg == NativeMethods.WM_QUIT) || (m.Msg == NativeMethods.WM_QUERYENDSESSION))
                    {
                        UnloadAll();
                    }
                    base.WndProc(ref m);
                    return;
                }
                else //do it only if the system is ready
                {
                    if (context.Dispatch(ref m))
                    {
                        return;
                    }

                    int code = m.Msg;
                    switch (code)
                    {
                    case NativeMethods.WM_ACTIVATEAPP:
                        // The WParam value identifies what is occurring.
                        bool appActive = (((int)m.WParam != 0));
                        {
                            if (GlobalSettings.HideOnClick)
                            {
                                if (!appActive)
                                {
                                    if (Manager.Visible && (!Manager.Fading))
                                    {
                                        if (!context.HookActive)
                                        {
                                            ChangeVisibility();
                                        }
                                    }
                                }
                            }
                        }
                        break;

                    case NativeMethods.WM_CLOSE:
                    case NativeMethods.WM_QUIT:
                        this.UnloadAll();
                        break;

                    case NativeMethods.WM_QUERYENDSESSION:
                        this.UnloadAll();
                        break;

                    case NativeMethods.CM_CHECKUPDATE:
                        ShowNewVersion();
                        break;

                    case NativeMethods.WM_POWERBROADCAST:
                        if (m.WParam == (IntPtr)NativeMethods.PBT_APMRESUMEAUTOMATIC)
                        {
                            context.HidePulsar();
                            if (Settings.Default.ShowPulsar)
                            {
                                Pulsar.RestoreAlpha();
                                Pulsar.Alpha = 60;
                                context.ShowPulsar();
                                Pulsar.DeactivatePulsar();
                            }
                        }
                        break;

                    case NativeMethods.CM_RBUTTONDOWN:
                    {
                        if (GlobalSettings.UseMouseActivation)
                        {
                            if (GlobalSettings.UseRightClick)
                            {
                                TraceDebug.Trace("CM_RBUTTONDOWN");
                                if (!trackRightDown)
                                {
                                    trackRightDown = true;
                                    if (!context.Manager.Visible)
                                    {
                                        timerIntercept.Enabled = true;
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case NativeMethods.CM_RBUTTONUP:
                    {
                        if (GlobalSettings.UseMouseActivation)
                        {
                            if (GlobalSettings.UseRightClick)
                            {
                                TraceDebug.Trace("CM_RBUTTONUP");
                                timerIntercept.Enabled = false;

                                if (trackRightDown)
                                {
                                    trackRightDown = false;
                                    if (!trackRightUp)
                                    {
                                        trackRightUp = true;
                                        MouseHook.PauseIntercept();
                                        VirtualMouse.RightClick();
                                    }
                                    else
                                    {
                                        trackRightUp = false;
                                        MouseHook.ResumeIntercept();
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case NativeMethods.CM_MBUTTONUP:
                    case NativeMethods.CM_XBUTTONUP:

                        if (GlobalSettings.UseMouseActivation)
                        {
                            int             xButton    = (int)m.WParam;
                            MouseHookButton hookButton = MouseHookButton.None;

                            if (m.Msg == NativeMethods.CM_MBUTTONUP)
                            {
                                hookButton = MouseHookButton.Wheel;
                            }
                            else
                            {
                                switch (xButton)
                                {
                                case NativeMethods.XBUTTON1:
                                    hookButton = MouseHookButton.XButton1;
                                    break;

                                case NativeMethods.XBUTTON2:
                                    hookButton = MouseHookButton.XButton2;
                                    break;

                                default:
                                    hookButton = MouseHookButton.None;
                                    break;
                                }
                            }

                            if (GlobalSettings.MouseHook != hookButton)
                            {
                                return;
                            }

                            Keys modifiers = (Keys)m.LParam;

                            if (GlobalSettings.MouseModifiers != modifiers)
                            {
                                return;
                            }

                            ActivateUsingMouse(true);
                        }
                        return;

                    case NativeMethods.CM_DESKTOPCLICK:
                        if (GlobalSettings.UseMouseActivation)
                        {
                            if (Manager != null)
                            {
                                if (context.HookActive)
                                {
                                    return;
                                }

                                if (GlobalSettings.DesktopClick)
                                {
                                    ActivateUsingMouse(true);
                                }
                            }
                        }
                        return;

                    case NativeMethods.WM_HOTKEY:
                        if (NativeMethods.IsMetroActive())
                        {
                            return;
                        }
                        if (GlobalSettings.UseKeyboardActivation)
                        {
                            if (Manager != null)
                            {
                                if (context.HookActive)
                                {
                                    return;
                                }

                                if (GlobalSettings.CircleSelector)
                                {
                                    if (ringKeys != null)
                                    {
                                        if (((int)m.WParam) == (ringKeys.Id))
                                        {
                                            Manager.SwitchRing();
                                        }
                                    }
                                }

                                if (hotKeys != null)
                                {
                                    if (((int)m.WParam) == (hotKeys.Id))
                                    {
                                        if (Manager.Visible)
                                        {
                                            if (NativeMethods.GetForegroundWindow() != Manager.Handle)
                                            {
                                                Manager.Visible = false;
                                                Manager.Rotate(0);
                                                ChangeVisibility();
                                                return;
                                            }
                                        }
                                        ChangeVisibility();
                                    }
                                }
                            }
                        }
                        return;

                    case NativeMethods.CM_SPLASHCLOSE:
                        if (splashScreen != null)
                        {
                            splashScreen.Dispose();
                            splashScreen = null;
                        }
                        break;

                    default:
                        break;
                    }
                    base.WndProc(ref m);
                }
            }
            catch (Exception ex)
            {
                TraceDebug.Trace(ex);
                if (!wasException)
                {
                    wasException = true;
                    throw new KrentoEngineException("Krento Engine Error: ", ex);
                }
            }
        }
예제 #13
0
        private void ExecuteAsync()
        {
            Version clientVersion;

            try
            {
                AssemblyName krentoName = new AssemblyName(Assembly.GetEntryAssembly().FullName);
                if (krentoName != null)
                {
                    clientVersion = krentoName.Version;
                }
                else
                {
                    clientVersion = new Version(Application.ProductVersion);
                }
            }
            catch
            {
                clientVersion = new Version("3.0");
                TraceDebug.Trace("Error in getting the Krento assembly version. By default assume 3.0");
            }
            Version serverVersion = null;

#if DEBUG
            string configFile = "http://localhost:8080";
#else
            string configFile = Settings.Default.Website;
#endif
            if (!configFile.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                configFile = configFile + "/";
            }
            configFile = configFile + "app_version.xml";

            XmlTextReader reader = null;
            try
            {
                try
                {
                    // provide the XmlTextReader with the URL of
                    // our xml document
                    string xmlURL = configFile;
                    reader = new XmlTextReader(xmlURL);
                    // simply (and easily) skip the junk at the beginning
                    reader.MoveToContent();
                    // internal - as the XmlTextReader moves only
                    // forward, we save current xml element name
                    // in elementName variable. When we parse a
                    // text node, we refer to elementName to check
                    // what was the node name
                    string elementName = "";
                    // we check if the xml starts with a proper
                    // "ourfancyapp" element node
                    if ((reader.NodeType == XmlNodeType.Element) &&
                        (reader.Name == "krento"))
                    {
                        while (reader.Read())
                        {
                            // when we find an element node,
                            // we remember its name
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                elementName = reader.Name;
                            }
                            else
                            {
                                // for text nodes...
                                if ((reader.NodeType == XmlNodeType.Text) &&
                                    (reader.HasValue))
                                {
                                    // we check what the name of the node was
                                    switch (elementName)
                                    {
                                    case "version":
                                        // thats why we keep the version info
                                        // in xxx.xxx.xxx.xxx format
                                        // the Version class does the
                                        // parsing for us
                                        serverVersion = new Version(reader.Value);
                                        break;

                                    case "url":
                                        url = reader.Value;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }

                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
            }
            catch
            {
                serverVersion = null;
            }

            if (serverVersion != null)
            {
                version = serverVersion.ToString();
                if (clientVersion < serverVersion)
                {
                    NativeMethods.PostMessage(InteropHelper.MainWindow, NativeMethods.CM_CHECKUPDATE, IntPtr.Zero, IntPtr.Zero);
                }
            }
        }