private void Reboot()
        {
            // ダイアログで確認

            // 次回起動する OS を指定
            if (BcdManager.UpdateNextBootOperatingSystem(this.SelectedOperatingSystem.Identifier))
            {
                BcdManager.Reboot();
            }
        }
Exemple #2
0
        public bool Save()
        {
            var updated = false;

            var operatingSystems = this.OperatingSystems;

            // 個々の編集結果をセーブ
            foreach (var operatingSystem in operatingSystems)
            {
                updated |= operatingSystem.Update();
            }

            // オーダーをセーブ
            updated |= BcdManager.UpdateDisplayOrder(operatingSystems.Select(model => model.Identifier));

            // 既定の OS をセーブ
            var defaultOperatingSystem = operatingSystems.FirstOrDefault(model => model.IsDefault);

            if (defaultOperatingSystem != null)
            {
                updated |= BcdManager.UpdateDefaultOperatingSystem(defaultOperatingSystem.Identifier);
            }

            // 次回起動の OS をセーブ
            var nextOperatingSystem = operatingSystems.FirstOrDefault(model => model.IsNext);

            if (nextOperatingSystem != null)
            {
                updated |= BcdManager.UpdateNextBootOperatingSystem(nextOperatingSystem.Identifier);
            }
            else
            {
                // Windows ブートマネージャーに戻す
                updated |= BcdManager.UpdateNextBootOperatingSystem();
            }

            // 表示を更新
            if (updated)
            {
                this.Refresh();
            }

            return(updated);
        }
        private void ItemOnCheckedChanged(object sender, EventArgs eventArgs)
        {
            var item = sender as ToolStripMenuItem;

            if (item == null)
            {
                return;
            }

            var operatingSystemModel = item.Tag as OperatingSystemModel;

            if (operatingSystemModel == null)
            {
                return;
            }

            var success      = false;
            var botMenuItems = this._BootMenus;

            try
            {
                // 他のアイテムのチェック変更が発動しないようイベントを解除
                foreach (var menuItem in botMenuItems)
                {
                    menuItem.CheckedChanged -= this.ItemOnCheckedChanged;
                }

                if (item.Checked)
                {
                    // 他のチェックを全て外す
                    foreach (var menuItem in botMenuItems)
                    {
                        if (menuItem != item)
                        {
                            menuItem.Checked = false;
                        }
                    }
                }
                else
                {
                    // チェックの解除は認めない
                    item.Checked = true;
                }

                success = BcdManager.UpdateNextBootOperatingSystem(operatingSystemModel.Identifier);
                if (success)
                {
                    foreach (var menuItem in botMenuItems)
                    {
                        if (menuItem == null)
                        {
                            continue;
                        }

                        var model = menuItem.Tag as OperatingSystemModel;
                        if (model == null)
                        {
                            return;
                        }

                        model.IsNext = false;
                    }

                    operatingSystemModel.IsNext = true;
                }
            }
            finally
            {
                foreach (var menuItem in botMenuItems)
                {
                    menuItem.CheckedChanged += this.ItemOnCheckedChanged;
                }
            }

            if (success)
            {
                if (this._CheckMenu.Checked && item.Checked)
                {
                    BcdManager.Reboot();
                }
            }
        }