Пример #1
0
        private void Load()
        {
            using (var reg = new WindowRegistrySettings())
            {
                // On first startup
                if (reg.WindowHeight == 0 ||
                    reg.WindowWidth == 0)
                {
                    Save();
                    return;
                }

                WindowTop      = reg.WindowTop;
                WindowLeft     = reg.WindowLeft;
                WindowHeight   = reg.WindowHeight;
                WindowWidth    = reg.WindowWidth;
                WindowState    = reg.WindowState;
                StartMinimized = reg.StartMinimized;
                MinimizeToTray = reg.MinimizeToTray;

                using (var section = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
                {
                    if (section != null)
                    {
                        var startupLocation = section.GetValue("HearthstoneTracker");
                        if (startupLocation != null)
                        {
                            StartOnLogon = true;

                            // Verify location still correct:
                            var exeName = Assembly.GetEntryAssembly().Location;
                            var value   = String.Format("\"{0}\" -logon", exeName);
                            if (startupLocation.ToString() != value)
                            {
                                section.SetValue("HearthstoneTracker", value);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        public void Save()
        {
            if (WindowState != WindowState.Minimized &&
                !dontSave)
            {
                using (var reg = new WindowRegistrySettings())
                {
                    if (WindowState != WindowState.Maximized)
                    {
                        reg.WindowTop    = WindowTop;
                        reg.WindowLeft   = WindowLeft;
                        reg.WindowHeight = WindowHeight;
                        reg.WindowWidth  = WindowWidth;
                    }

                    reg.StartMinimized = StartMinimized;
                    reg.MinimizeToTray = MinimizeToTray;
                    reg.WindowState    = WindowState;

                    using (var section = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
                    {
                        if (section != null)
                        {
                            if (StartOnLogon)
                            {
                                var exeName = Assembly.GetEntryAssembly().Location;
                                var value   = String.Format("\"{0}\" -logon", exeName);
                                section.SetValue("HearthstoneTracker", value);
                            }
                            else if (section.GetValue("HearthstoneTracker") != null)
                            {
                                section.DeleteValue("HearthstoneTracker");
                            }
                        }
                    }
                }
            }
        }
        public void Save()
        {
            if (WindowState != WindowState.Minimized && !dontSave)
            {
                using (var reg = new WindowRegistrySettings())
                {
                    if (WindowState != WindowState.Maximized)
                    {
                        reg.WindowTop = WindowTop;
                        reg.WindowLeft = WindowLeft;
                        reg.WindowHeight = WindowHeight;
                        reg.WindowWidth = WindowWidth;
                    }

                    reg.StartMinimized = StartMinimized;
                    reg.MinimizeToTray = MinimizeToTray;
                    reg.WindowState = WindowState;

                    using (var section = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
                    {
                        if (section != null)
                        {
                            if (StartOnLogon)
                            {
                                var exeName = System.Reflection.Assembly.GetEntryAssembly().Location;
                                var value = String.Format("\"{0}\" -logon", exeName);
                                section.SetValue("HearthstoneTracker", value);
                            }
                            else if (section.GetValue("HearthstoneTracker") != null)
                            {
                                section.DeleteValue("HearthstoneTracker");
                            }
                        }
                    }
                }
            }
        }
        private void Load()
        {
            using (var reg = new WindowRegistrySettings())
            {
                // On first startup
                if (reg.WindowHeight == 0 || reg.WindowWidth == 0)
                {
                    Save();
                    return;
                }

                WindowTop = reg.WindowTop;
                WindowLeft = reg.WindowLeft;
                WindowHeight = reg.WindowHeight;
                WindowWidth = reg.WindowWidth;
                WindowState = reg.WindowState;
                StartMinimized = reg.StartMinimized;
                MinimizeToTray = reg.MinimizeToTray;

                using (var section = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
                {
                    if (section != null)
                    {
                        var startupLocation = section.GetValue("HearthstoneTracker");
                        if (startupLocation != null)
                        {
                            this.StartOnLogon = true;

                            // Verify location still correct:
                            var exeName = System.Reflection.Assembly.GetEntryAssembly().Location;
                            var value = String.Format("\"{0}\" -logon", exeName);
                            if (startupLocation.ToString() != value)
                            {
                                section.SetValue("HearthstoneTracker", value);
                            }
                        }
                    }
                }
            }
        }