Esempio n. 1
0
        private void ApplySettings()
        {
            Settings.Refresh();

            Program.ImposterNames = new System.Collections.Specialized.StringCollection();
            Utils.UnitSpecifier   = Properties.Settings.Default.UnitSpecifier;

            foreach (string s in Properties.Settings.Default.ImposterNames.Split(','))
            {
                Program.ImposterNames.Add(s.Trim());
            }

            Program.HackerWindow.ApplyIconVisibilities();
            Program.HackerWindow.LoadFixMenuItems();
            Program.ProcessProvider.Interval = Properties.Settings.Default.RefreshInterval;
            Program.ServiceProvider.Interval = Properties.Settings.Default.RefreshInterval;
            Program.NetworkProvider.Interval = Properties.Settings.Default.RefreshInterval;

            HighlightingContext.HighlightingDuration              = Properties.Settings.Default.HighlightingDuration;
            HighlightingContext.Colors[ListViewItemState.New]     = Properties.Settings.Default.ColorNew;
            HighlightingContext.Colors[ListViewItemState.Removed] = Properties.Settings.Default.ColorRemoved;

            TreeNodeAdv.StateColors[TreeNodeAdv.NodeState.New]     = Properties.Settings.Default.ColorNew;
            TreeNodeAdv.StateColors[TreeNodeAdv.NodeState.Removed] = Properties.Settings.Default.ColorRemoved;

            Program.ProcessProvider.Interval               = Properties.Settings.Default.RefreshInterval;
            Program.ServiceProvider.Interval               = Properties.Settings.Default.RefreshInterval;
            Program.NetworkProvider.Interval               = Properties.Settings.Default.RefreshInterval;
            Program.SharedThreadProvider.Interval          = Properties.Settings.Default.RefreshInterval;
            Program.SecondarySharedThreadProvider.Interval = Properties.Settings.Default.RefreshInterval;

            Program.HackerWindow.ProcessTree.RefreshItems();
            Program.ApplyFont(Properties.Settings.Default.Font);

            if (_oldDbghelp != textDbghelpPath.Text)
            {
                PhUtils.ShowInformation("One or more options you have changed require a restart of Process Hacker.");
            }
        }
Esempio n. 2
0
        private void SaveSettings()
        {
            bool restartRequired = false;

            if (checkVerifySignatures.Checked != Settings.Instance.VerifySignatures)
            {
                restartRequired = true;
            }
            if (checkEnableKPH.Checked != Settings.Instance.EnableKPH)
            {
                restartRequired = true;
            }
            if (checkEnableExperimentalFeatures.Checked != Settings.Instance.EnableExperimentalFeatures)
            {
                restartRequired = true;
            }
            if (textDbghelpPath.Text != _oldDbghelp)
            {
                restartRequired = true;
            }

            Settings.Instance.Font                                = _font;
            Settings.Instance.SearchEngine                        = textSearchEngine.Text;
            Settings.Instance.WarnDangerous                       = checkWarnDangerous.Checked;
            Settings.Instance.ShowAccountDomains                  = checkShowProcessDomains.Checked;
            Settings.Instance.HideWhenMinimized                   = checkHideWhenMinimized.Checked;
            Settings.Instance.HideWhenClosed                      = checkHideWhenClosed.Checked;
            Settings.Instance.AllowOnlyOneInstance                = checkAllowOnlyOneInstance.Checked;
            Settings.Instance.UnitSpecifier                       = Array.IndexOf(Utils.SizeUnitNames, comboSizeUnits.SelectedItem);
            Settings.Instance.VerifySignatures                    = checkVerifySignatures.Checked;
            Settings.Instance.HideHandlesWithNoName               = checkHideHandlesWithNoName.Checked;
            Settings.Instance.ScrollDownProcessTree               = checkScrollDownProcessTree.Checked;
            Settings.Instance.StartHidden                         = checkStartHidden.Checked;
            Settings.Instance.EnableKPH                           = checkEnableKPH.Checked;
            Settings.Instance.EnableExperimentalFeatures          = checkEnableExperimentalFeatures.Checked;
            Settings.Instance.ImposterNames                       = textImposterNames.Text.ToLowerInvariant();
            Settings.Instance.HideProcessHackerNetworkConnections = checkHidePhConnections.Checked;
            Settings.Instance.ElevationLevel                      = comboElevationLevel.SelectedIndex;

            Settings.Instance.MaxSamples           = (int)textMaxSamples.Value;
            Program.ProcessProvider.HistoryMaxSize = Settings.Instance.MaxSamples;
            Settings.Instance.PlotterStep          = (int)textStep.Value;
            Plotter.GlobalMoveStep = Settings.Instance.PlotterStep;

            Settings.Instance.HighlightingDuration = (int)textHighlightingDuration.Value;
            Settings.Instance.ColorNew             = colorNewProcesses.Color;
            Settings.Instance.ColorRemoved         = colorRemovedProcesses.Color;

            foreach (ListViewItem item in listHighlightingColors.Items)
            {
                Settings.Instance[item.Name]         = item.BackColor;
                Settings.Instance["Use" + item.Name] = item.Checked;
            }

            Settings.Instance.PlotterAntialias          = checkPlotterAntialias.Checked;
            Settings.Instance.PlotterCPUKernelColor     = colorCPUKT.Color;
            Settings.Instance.PlotterCPUUserColor       = colorCPUUT.Color;
            Settings.Instance.PlotterMemoryPrivateColor = colorMemoryPB.Color;
            Settings.Instance.PlotterMemoryWSColor      = colorMemoryWS.Color;
            Settings.Instance.PlotterIOROColor          = colorIORO.Color;
            Settings.Instance.PlotterIOWColor           = colorIOW.Color;

            Settings.Instance.DbgHelpPath       = _oldDbghelp = textDbghelpPath.Text;
            Settings.Instance.DbgHelpSearchPath = textSearchPath.Text;
            Settings.Instance.DbgHelpUndecorate = checkUndecorate.Checked;

            if (optUpdateStable.Checked)
            {
                Settings.Instance.AppUpdateLevel = (int)AppUpdateLevel.Stable;
            }
            else if (optUpdateBeta.Checked)
            {
                Settings.Instance.AppUpdateLevel = (int)AppUpdateLevel.Beta;
            }
            else if (optUpdateAlpha.Checked)
            {
                Settings.Instance.AppUpdateLevel = (int)AppUpdateLevel.Alpha;
            }

            Settings.Instance.AppUpdateAutomatic = checkUpdateAutomatically.Checked;

            switch (comboToolbarStyle.SelectedIndex)
            {
            case 0:
                Settings.Instance.ToolStripDisplayStyle = 0;
                break;

            case 1:
                Settings.Instance.ToolStripDisplayStyle = 1;
                break;

            case 2:
                Settings.Instance.ToolStripDisplayStyle = 2;
                break;

            default:
                Settings.Instance.ToolStripDisplayStyle = 0;
                break;
            }

            Settings.Instance.Save();
            // We manually set settings, so we must invalidate.
            Settings.Instance.Invalidate();

            if (checkReplaceTaskManager.Enabled)
            {
                try
                {
                    string fileName = ProcessHandle.Current.MainModule.FileName;

                    using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(
                               "Software\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\taskmgr.exe",
                               true
                               ))
                    {
                        if (checkReplaceTaskManager.Checked)
                        {
                            key.SetValue("Debugger", "\"" + fileName + "\"");
                            // In case the user presses Apply and then OK.
                            _oldTaskMgrDebugger = "\"" + fileName + "\"";
                        }
                        else
                        {
                            // If we were replacing Task Manager and the user unchecked the box,
                            // don't replace Task Manager anymore.
                            if (_oldTaskMgrDebugger.Trim('"').Equals(fileName, StringComparison.OrdinalIgnoreCase))
                            {
                                key.DeleteValue("Debugger");
                                _oldTaskMgrDebugger = string.Empty;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    PhUtils.ShowException("Unable to replace Task Manager with Process Hacker", ex);
                }
            }

            if (restartRequired)
            {
                PhUtils.ShowInformation("One or more settings you have changed require a restart of Process Hacker.");
            }
        }