コード例 #1
0
ファイル: TaskDialog.cs プロジェクト: ScriptBox21/mpv.net
    public static MsgResult Show(
        string mainInstruction,
        string content,
        MsgIcon icon,
        MsgButtons buttons,
        MsgResult defaultButton = MsgResult.None)
    {
        try
        {
            using (TaskDialog <MsgResult> td = new TaskDialog <MsgResult>())
            {
                td.AllowCancel   = false;
                td.DefaultButton = defaultButton;
                td.MainIcon      = icon;

                if (content == null)
                {
                    if (mainInstruction.Length < 80)
                    {
                        td.MainInstruction = mainInstruction;
                    }
                    else
                    {
                        td.Content = mainInstruction;
                    }
                }
                else
                {
                    td.MainInstruction = mainInstruction;
                    td.Content         = content;
                }
                if (buttons == MsgButtons.OkCancel)
                {
                    td.AddButton("OK", MsgResult.OK);
                    td.AddButton("Cancel", MsgResult.Cancel);
                }
                else
                {
                    td.CommonButtons = buttons;
                }
                return(td.Show());
            }
        }
        catch (Exception e)
        {
            return((MsgResult)MessageBox.Show(e.GetType().Name + "\n\n" + e.Message + "\n\n" + e,
                                              Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error));
        }
    }
コード例 #2
0
ファイル: Installer.cs プロジェクト: rikka0w0/Menu98
 public static DialogResult ShowSelectConfigFileBox(Form Parent)
 {
     if (WinVer.IsVistaOrGreater())
     {
         TaskDialog dlg = new TaskDialog();
         dlg.SetIcon(TASKDIALOG_ICON.TD_INFORMATION_ICON);
         dlg.WindowTitle     = "Open configuration file";
         dlg.MainInstruction = "You will see this dialog if the configuration file (menu.xml) is missing from your system";
         dlg.AddButton((int)DialogResult.Yes, "Create a config file").ShowShield = true;
         dlg.AddButton((int)DialogResult.No, "Open an existing config file");
         dlg.CommonButtons   = TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_CANCEL_BUTTON;
         dlg.UseCommandLinks = true;
         return((DialogResult)dlg.ShowDialog(Parent.Handle));
     }
     else
     {
         return(MessageBox.Show(Parent, "You will see this dialog if the configuration file (menu.xml) is missing from your system\n\nYes - Create a config file\nNo - Open an existing config file\nCancel - Quit", "Open configuration file", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information));
     }
 }
コード例 #3
0
        //askTask("Message", "DetailsText", , "InstructionText", "Footer")
        public static MessageBoxResult askTask(string message, string detailsText, string instructionText, string footerText)
        {
            var sync = new AutoResetEvent(false);
            MessageBoxResult result = MessageBoxResult.None;

            O2Thread.staThread(
                () => {
                var taskDialog             = new TaskDialog();
                taskDialog.DetailsText     = detailsText;
                taskDialog.FooterImage     = StockIcons.Information.SmallBitmapImage;
                taskDialog.FooterText      = footerText;
                taskDialog.Image           = StockIcons.Information.LargeBitmapImage;
                taskDialog.InstructionText = instructionText;
                taskDialog.Text            = message;
                //TaskDialog dialog = dialog2;
                taskDialog.AddButton("_Accept", MessageBoxResult.Yes, StockIcons.Shield.SmallBitmapImage);
                taskDialog.DefaultButton = taskDialog.AddButton("_Reject", MessageBoxResult.No);
                result = taskDialog.ShowDialog();
                sync.Set();
            });
            sync.WaitOne();
            return(result);
        }
コード例 #4
0
ファイル: Installer.cs プロジェクト: rikka0w0/Menu98
        public static void LaunchUninstall(Form Parent)
        {
            bool deleteConfig = false;

            if (WinVer.IsVistaOrGreater())
            {
                TaskDialog dlg = new TaskDialog();
                dlg.Icon            = Properties.Resources.Installer.Handle;
                dlg.WindowTitle     = "Uninstall";
                dlg.MainInstruction = "Uninstall this software from your system";
                dlg.Content         = "This program will not be deleted.";
                dlg.AddButton((int)DialogResult.Yes, "Uninstall now").ShowShield = true;
                dlg.CommonButtons   = TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_CANCEL_BUTTON;
                dlg.UseCommandLinks = true;
                dlg.CheckBoxText    = "Delete configuration file";
                if (dlg.ShowDialog(Parent.Handle) == (int)DialogResult.Yes)
                {
                    deleteConfig = dlg.CheckBoxChecked;
                }
                else
                {
                    return;
                }
            }
            else
            {
                switch (MessageBox.Show(Parent, "Uninstall this software from your system.\nYes - Uninstall without deleting config file\nNo - Uninstall and delete the config file", "Uninstall", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question))
                {
                case DialogResult.Yes:
                    deleteConfig = false;
                    break;

                case DialogResult.No:
                    deleteConfig = true;
                    break;

                case DialogResult.Cancel:
                    return;
                }
            }

            if (MenuControl.isMenu98ModuleLoaded())
            {
                MenuControl.Menu98_ExitHost();
            }

            try
            {
                UninstallFromSystem(deleteConfig);
            }
            catch (UnauthorizedAccessException)
            {
                UninstallWithPrivilage(deleteConfig);
            }
            catch (System.Security.SecurityException)
            {
                UninstallWithPrivilage(deleteConfig);
            }

            MessageBox.Show(Parent, "Uninstalled successfully", "Uninstall", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Application.Exit();
        }
コード例 #5
0
ファイル: Installer.cs プロジェクト: rikka0w0/Menu98
        public static void ShowInstaller(Form Parent)
        {
            string param = null;

            if (WinVer.IsVistaOrGreater())
            {
                TaskDialog dlg = new TaskDialog();
                dlg.Icon                   = Properties.Resources.Installer.Handle;
                dlg.WindowTitle            = "Install TMT & Menu98";
                dlg.MainInstruction        = "Install TMT & Menu98";
                dlg.Content                = "This tweak requires <a href=\"https://www.microsoft.com/en-us/download/details.aspx?id=49984\">VC2015 runtime</a> installed!";
                dlg.ExpandedControlText    = "Start up parameter:";
                dlg.OnRadioButtonSelected += InstallTD_OnRadioButtonSelected;
                dlg.OnHyperLinkClicked    += InstallTD_OnHyperLinkClicked;

                for (int id = 0; id <= MenuControl.OSList.Length; id++)
                {
                    dlg.AddRadioButton(id, MenuControl.GetOSFromIndex(id));
                }

                dlg.SelectedRadioButton = MenuControl.Os2ListIndex(WinVer.SystemVersion);

                param = MenuControl.GetInjectParamFromIndex(dlg.SelectedRadioButton);
                if (param == null)
                {
                    dlg.ExpandedInformation = "No startup";
                }
                else
                {
                    dlg.ExpandedInformation = param;
                }
                dlg.ExpandFooterAreaByDefault = true;

                dlg.AddButton(100, "Install Now").ShowShield = true;

                dlg.CommonButtons    = TASKDIALOG_COMMON_BUTTON_FLAGS.TDCBF_CLOSE_BUTTON;
                dlg.UseCommandLinks  = true;
                dlg.EnableHyperLinks = true;

                int ret = dlg.ShowDialog(Parent.Handle);

                if (ret != 100)
                {
                    return;
                }

                param = MenuControl.GetInjectParamFromIndex(dlg.SelectedRadioButton);
            }
            else
            {
                switch (MessageBox.Show(Parent, "Yes - Install and auto startup\nNo - Just install", "Install Menu98", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information))
                {
                case DialogResult.Yes:
                    param = "!Button";     //Hard coding here
                    break;

                case DialogResult.No:
                    param = null;     //Hard coding here
                    break;

                default:
                    return;
                }
            }


            try
            {
                InstallToSystem(WinVer.IsX64System());

                if (param == null)
                {
                    CreateRegConfig(param);
                }

                if (!System.IO.File.Exists(GetConfigPath()))
                {
                    DeployDefaultConfigFile();
                }
            }
            catch (UnauthorizedAccessException)
            {
                ProcessStartInfo startInfo = new ProcessStartInfo();
                startInfo.UseShellExecute  = true;
                startInfo.WorkingDirectory = Environment.CurrentDirectory;
                startInfo.FileName         = Application.ExecutablePath;
                startInfo.Arguments        = "INSTALL X" + (WinVer.IsX64System() ? "64" : "86") + " ";


                if (param == null)
                {
                    startInfo.Arguments += "\"?\"";
                }
                else
                {
                    startInfo.Arguments += "\"" + param + "\"";
                }

                startInfo.Verb = "runas";

                try
                {
                    System.Diagnostics.Process.Start(startInfo).WaitForExit();
                }
                catch (System.ComponentModel.Win32Exception)
                {
                    MessageBox.Show("This action requires administrative privilage!", "Fail to install", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }



            if (param != null)
            {
                MenuControl.Menu98_Inject(param);
            }
        }