GetRegistryValue() public static method

public static GetRegistryValue ( string Name, string DefaultValue ) : Object
Name string
DefaultValue string
return Object
Esempio n. 1
0
        private void InitializeInitialTabs()
        {
            var InitialTabs = Utilities.GetRegistryValue("OpenedTabs", "").ToString().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);

            if (InitialTabs.Length == 0 || !_IsrestoreTabs)
            {
                var sho = FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, tcMain.StartUpLocation.ToShellParsingName());

                if (tcMain.Items.OfType <Wpf.Controls.TabItem>().Any())
                {
                    NavigationController(sho);
                }
                else
                {
                    var tab = tcMain.NewTab(sho, true);
                    this.SelectTab(tab);
                }
            }
            if (_IsrestoreTabs)
            {
                isOnLoad = true;
                int i = 0;
                foreach (string str in InitialTabs)
                {
                    try {
                        i++;
                        if (str.ToLowerInvariant() == "::{22877a6d-37a1-461a-91b0-dbda5aaebc99}")
                        {
                            continue;
                        }
                        var tab = tcMain.NewTab(FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, str.ToShellParsingName()), i == InitialTabs.Length);
                        if (i == InitialTabs.Length)
                        {
                            this.SelectTab(tab);
                            bcbc.SetPathWithoutNavigate(str);
                        }
                    } catch {
                        //AddToLog(String.Format("Unable to load {0} into a tab!", str));
                        MessageBox.Show("BetterExplorer is unable to load one of the tabs from your last session. Your other tabs are perfectly okay though! \r\n\r\nThis location was unable to be loaded: " + str, "Unable to Create New Tab", MessageBoxButton.OK, MessageBoxImage.Error);
                    }
                }

                if (tcMain.Items.Count == 0)
                {
                    tcMain.NewTab();

                    string idk = tcMain.StartUpLocation.StartsWith("::") ? tcMain.StartUpLocation.ToShellParsingName() : tcMain.StartUpLocation.Replace("\"", "");
                    NavigationController(FileSystemListItem.ToFileSystemItem(this._ShellListView.LVHandle, idk));
                    (tcMain.SelectedItem as Wpf.Controls.TabItem).ShellObject = _ShellListView.CurrentFolder;
                    (tcMain.SelectedItem as Wpf.Controls.TabItem).ToolTip     = _ShellListView.CurrentFolder.ParsingName.Replace("%20", " ").Replace("%3A", ":").Replace("%5C", @"\");
                }

                isOnLoad = false;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Single instance callback handler.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="SingleInstanceApplication.InstanceCallbackEventArgs"/> instance containing the event data.</param>
        ///
        private void SingleInstanceCallback(Object sender, InstanceCallbackEventArgs args)
        {
            if (args == null || Dispatcher == null)
            {
                return;
            }
            var startUpLocation = Utilities.GetRegistryValue("StartUpLoc", KnownFolders.Libraries.ParsingName).ToString();

            Action <Boolean> d = x => {
                var win             = MainWindow as MainWindow;
                var windowsActivate = new CombinedWindowActivator();
                if (!x)
                {
                    return;
                }
                if (win == null)
                {
                    return;
                }
                win.StateChanged += Win_StateChanged;
                if (args?.CommandLineArgs == null || !args.CommandLineArgs.Any())
                {
                    return;
                }
                if (args.CommandLineArgs.Length == 1)
                {
                    win.Visibility = Visibility.Visible;
                    //if (win.WindowState == WindowState.Minimized) {
                    //	User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle, User32.ShowWindowCommands.Restore);
                    //}
                    //User32.ForceForegroundWindow(win);
                    windowsActivate.ActivateForm(win, null, IntPtr.Zero);
                }
                else
                {
                    if (args.CommandLineArgs[1] == "/nw")
                    {
                        new MainWindow()
                        {
                            IsMultipleWindowsOpened = true
                        }.Show();
                    }
                    else
                    {
                        IListItemEx sho = null;
                        if (args.CommandLineArgs[1] == "t")
                        {
                            win.Visibility = Visibility.Visible;
                            //if (win.WindowState == WindowState.Minimized)
                            //	User32.ShowWindow((PresentationSource.FromVisual(win) as HwndSource).Handle,
                            //		User32.ShowWindowCommands.Restore);
                            windowsActivate.ActivateForm(win, null, IntPtr.Zero);

                            sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, startUpLocation.ToShellParsingName());
                        }
                        else
                        {
                            sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, args.CommandLineArgs[1].ToShellParsingName());
                        }

                        if (!IsStartMinimized || win.tcMain.Items.Count == 0)
                        {
                            CreateInitialTab(win, sho);
                        }
                        else if ((Int32)Utilities.GetRegistryValue("IsRestoreTabs", "1") == 0)
                        {
                            win.tcMain.Items.Clear();
                            CreateInitialTab(win, sho);
                        }
                        else if (args.CommandLineArgs.Length > 1 && args.CommandLineArgs[1] != null)
                        {
                            if (args.CommandLineArgs[1] == "t")
                            {
                                CreateInitialTab(win, sho);
                            }
                            else
                            {
                                var cmd = args.CommandLineArgs[1];
                                sho = FileSystemListItem.ToFileSystemItem(IntPtr.Zero, cmd.ToShellParsingName());
                                CreateInitialTab(win, sho);
                            }
                        }
                        else
                        {
                            CreateInitialTab(win, sho);
                        }
                    }
                    //User32.ForceForegroundWindow(win);

                    windowsActivate.ActivateForm(win, null, IntPtr.Zero);
                }
            };

            Dispatcher.BeginInvoke(d, true);
        }
Esempio n. 3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            System.Diagnostics.Process process = System.Diagnostics.Process.GetCurrentProcess();
            process.PriorityClass = System.Diagnostics.ProcessPriorityClass.Normal;

            // Set the current thread to run at 'Highest' Priority
            Thread thread = System.Threading.Thread.CurrentThread;

            thread.Priority = ThreadPriority.Highest;

            string locale = ""; bool dmi = true;

            Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);
            AppDomain.CurrentDomain.UnhandledException       += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            //System.AppDomain.CurrentDomain.BaseDirectory

            if (!File.Exists(Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer\Settings.sqlite")))
            {
                File.Copy(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings.sqlite"), Path.Combine(KnownFolders.RoamingAppData.ParsingName, @"BExplorer\Settings.sqlite"));
            }

            RegistryKey rk = Registry.CurrentUser, rks = rk.OpenSubKey(@"Software\BExplorer", true);

            if (rks == null)
            {
                rk.CreateSubKey(@"Software\BExplorer");
                rks = rk.OpenSubKey(@"Software\BExplorer", true);
            }

            //// loads current Ribbon color theme
            try {
                var Color = Convert.ToString(rks.GetValue("CurrentTheme", "Blue"));
                var owner = Application.Current.MainWindow;
                if (owner != null)
                {
                    owner.Resources.BeginInit();

                    if (owner.Resources.MergedDictionaries.Count > 0)
                    {
                        owner.Resources.MergedDictionaries.RemoveAt(0);
                    }

                    if (string.IsNullOrEmpty(Color) == false)
                    {
                        owner.Resources.MergedDictionaries.Add(new ResourceDictionary {
                            Source = new Uri(Color)
                        });
                    }

                    owner.Resources.EndInit();
                }
                Application.Current.Resources.BeginInit();

                Application.Current.Resources.MergedDictionaries.RemoveAt(1);

                switch (Color)
                {
                case "Blue":
                case "Silver":
                case "Black":
                case "Green":
                    Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary()
                    {
                        Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{Color}.xaml")
                    });
                    break;

                case "Metro":
                    Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary()
                    {
                        Source = new Uri("pack://application:,,,/Fluent;component/Themes/Office2013/Generic.xaml")
                    });
                    break;

                default:
                    Application.Current.Resources.MergedDictionaries.Insert(1, new ResourceDictionary()
                    {
                        Source = new Uri($"pack://application:,,,/Fluent;component/Themes/Office2010/{Color}.xaml")
                    });
                    break;
                }
                Application.Current.Resources.EndInit();

                if (owner is RibbonWindow)
                {
                    owner.Style = null;
                    owner.Style = owner.FindResource("RibbonWindowStyle") as Style;
                    owner.Style = null;

                    // Resize Window to work around alignment issues caused by theme change
                    ++owner.Width;
                    --owner.Width;
                }
            } catch (Exception ex) {
                //MessageBox.Show(String.Format("An error occurred while trying to load the theme data from the Registry. \n\r \n\r{0}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/", ex.Message), "RibbonTheme Error - " + ex.ToString());
                MessageBox.Show($"An error occurred while trying to load the theme data from the Registry. \n\r \n\rRibbonTheme Error - {ex.ToString()}\n\r \n\rPlease let us know of this issue at http://bugtracker.better-explorer.com/", ex.Message);
            }

            rks.Close();
            rk.Close();

            if (e.Args.Any())
            {
                dmi = e.Args.Length >= 1;
                IsStartWithStartupTab = e.Args.Contains("/norestore");

                if (e.Args[0] != "-minimized")
                {
                    this.Properties["cmd"] = e.Args[0];
                }
                else
                {
                    IsStartMinimized = true;
                }
            }

            if (dmi && !ApplicationInstanceManager.CreateSingleInstance(Assembly.GetExecutingAssembly().GetName().Name, SingleInstanceCallback))
            {
                return;                 // exit, if same app. is running
            }
            base.OnStartup(e);

            try {
                var regLocale = Utilities.GetRegistryValue("Locale", "").ToString();
                locale = String.IsNullOrEmpty(regLocale) ? CultureInfo.CurrentUICulture.Name : regLocale;
                SelectCulture(locale);
            } catch {
                //MessageBox.Show(String.Format("A problem occurred while loading the locale from the Registry. This was the value in the Registry: \r\n \r\n {0}\r\n \r\nPlease report this issue at http://bugtracker.better-explorer.com/.", Locale));
                MessageBox.Show($"A problem occurred while loading the locale from the Registry. This was the value in the Registry: \r\n \r\n {locale}\r\n \r\nPlease report this issue at http://bugtracker.better-explorer.com/.");

                Shutdown();
            }
        }