Defines configuration options for showing a task dialog.
Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskDialogViewModel"/> class.
        /// </summary>
        /// <param name="options">Options to use.</param>
        public TaskDialogViewModel(TaskDialogOptions options)
            : this()
        {
            this.options = options;

            _expandedInfoVisible = options.ExpandedByDefault;
            _verificationChecked = options.VerificationByDefault;

            if (options.EnableCallbackTimer)
            {
                // By default it will run on the default dispatcher and with Background priority
                _callbackTimer = new System.Windows.Threading.DispatcherTimer();

                _callbackTimer.Interval = CallbackTimerInterval;
                _callbackTimer.Tick    += new EventHandler(CallbackTimer_Tick);
            }

            FixAllButtonLabelAccessKeys();

            // If radio buttons are defined, set the radio result to the default selected radio
            if (RadioButtons.Count > 0)
            {
                _radioResult = RadioButtons[DefaultButtonIndex].ID;
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskDialogMessage"/> class.
        /// </summary>
        /// <param name="options">The configuration options for the task dialog.</param>
        /// <param name="callback">A callback method that should be executed to deliver the result
        /// of the task dialog to the object that sent the message.</param>
        public TaskDialogMessage(
			TaskDialogOptions options,
			Action<TaskDialogResult> callback)
        {
            this.Options = options;
            this.Callback = callback;
        }
Пример #3
0
        private static TaskDialogResult ShowEmulatedTaskDialog(TaskDialogOptions options)
        {
            TaskDialog          td   = new TaskDialog();
            TaskDialogViewModel tdvm = new TaskDialogViewModel(options);

            td.DataContext = tdvm;

            if (options.Owner != null)
            {
                td.Owner = options.Owner;
            }

            td.ShowDialog();

            TaskDialogResult result           = null;
            int diagResult                    = -1;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked          = false;
            int  radioButtonResult            = -1;
            int? commandButtonResult          = null;
            int? customButtonResult           = null;

            diagResult          = tdvm.DialogResult;
            radioButtonResult   = tdvm.RadioResult - RadioButtonIDOffset;
            verificationChecked = tdvm.VerificationChecked;

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult          = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            //else if (diagResult >= RadioButtonIDOffset)
            //{
            //    simpResult = (TaskDialogSimpleResult)diagResult;
            //    radioButtonResult = diagResult - RadioButtonIDOffset;
            //}
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult         = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            // This occurs usually when the red X button is clicked
            else if (diagResult == -1)
            {
                simpResult = TaskDialogSimpleResult.Cancel;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return(result);
        }
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskDialogViewModel"/> class.
        /// </summary>
        /// <param name="options">Options to use.</param>
        public TaskDialogViewModel(TaskDialogOptions options)
            : this()
        {
            this.options = options;

            _expandedInfoVisible = options.ExpandedByDefault;
            _verificationChecked = options.VerificationByDefault;

            if (options.EnableCallbackTimer)
            {
                // By default it will run on the default dispatcher and with Background priority
                _callbackTimer = new System.Windows.Threading.DispatcherTimer();

                _callbackTimer.Interval = CallbackTimerInterval;
                _callbackTimer.Tick += new EventHandler(CallbackTimer_Tick);
            }

            FixAllButtonLabelAccessKeys();

            // If radio buttons are defined, set the radio result to the default selected radio
            if (RadioButtons.Count > 0)
            {
                _radioResult = RadioButtons[DefaultButtonIndex].ID;
            }
        }
Пример #5
0
        /// <summary>
        /// Displays a task dialog with the given configuration options.
        /// </summary>
        /// <param name="options">
        /// A <see cref="T:TaskDialogInterop.TaskDialogOptions"/> that specifies the
        /// configuration options for the dialog.
        /// </param>
        /// <returns>
        /// A <see cref="T:TaskDialogInterop.TaskDialogResult"/> value that specifies
        /// which button is clicked by the user.
        /// </returns>
        public static TaskDialogResult Show(TaskDialogOptions options)
        {
            TaskDialogResult result = null;

            // Make a copy since we'll let Showing event possibly modify them
            TaskDialogOptions configOptions = options;

            OnShowing(new TaskDialogShowingEventArgs(ref configOptions));

            if (VistaTaskDialog.IsAvailableOnThisOS && !ForceEmulationMode)
            {
                try
                {
                    result = ShowTaskDialog(configOptions);
                }
                catch (EntryPointNotFoundException)
                {
                    // This can happen on some machines, usually when running Vista/7 x64
                    // When it does, we'll work around the issue by forcing emulated mode
                    // http://www.codeproject.com/Messages/3257715/How-to-get-it-to-work-on-Windows-7-64-bit.aspx
                    ForceEmulationMode = true;
                    result = ShowEmulatedTaskDialog(configOptions);
                }
            }
            else
            {
                result = ShowEmulatedTaskDialog(configOptions);
            }

            OnClosed(new TaskDialogClosedEventArgs(result));

            return result;
        }
Пример #6
0
        /// <summary>
        /// Displays a task dialog with the given configuration options.
        /// </summary>
        /// <param name="options">
        /// A <see cref="T:TaskDialogInterop.TaskDialogOptions"/> that specifies the
        /// configuration options for the dialog.
        /// </param>
        /// <returns>
        /// A <see cref="T:TaskDialogInterop.TaskDialogResult"/> value that specifies
        /// which button is clicked by the user.
        /// </returns>
        public static TaskDialogResult Show(TaskDialogOptions options)
        {
            TaskDialogResult result = null;

            // Make a copy since we'll let Showing event possibly modify them
            TaskDialogOptions configOptions = options;

            OnShowing(new TaskDialogShowingEventArgs(ref configOptions));

            if (VistaTaskDialog.IsAvailableOnThisOS && !ForceEmulationMode)
            {
                try
                {
                    result = ShowTaskDialog(configOptions);
                }
                catch (EntryPointNotFoundException)
                {
                    // This can happen on some machines, usually when running Vista/7 x64
                    // When it does, we'll work around the issue by forcing emulated mode
                    // http://www.codeproject.com/Messages/3257715/How-to-get-it-to-work-on-Windows-7-64-bit.aspx
                    ForceEmulationMode = true;
                    result             = ShowEmulatedTaskDialog(configOptions);
                }
            }
            else
            {
                result = ShowEmulatedTaskDialog(configOptions);
            }

            OnClosed(new TaskDialogClosedEventArgs(result));

            return(result);
        }
Пример #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskDialogMessage"/> class.
        /// </summary>
        /// <param name="sender">The message's original sender.</param>
        /// <param name="options">The configuration options for the task dialog.</param>
        /// <param name="callback">A callback method that should be executed to deliver the result
        /// of the task dialog to the object that sent the message.</param>
        public TaskDialogMessage(
			object sender,
			TaskDialogOptions options,
			Action<TaskDialogResult> callback)
            : this(options, callback)
        {
            this.Sender = sender;
        }
Пример #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskDialogMessage"/> class.
        /// </summary>
        /// <param name="sender">The message's original sender.</param>
        /// <param name="target">The message's intended target. This parameter can be used
        /// to give an indication as to whom the message was intended for. Of course
        /// this is only an indication, and may be null.</param>
        /// <param name="options">The configuration options for the task dialog.</param>
        /// <param name="callback">A callback method that should be executed to deliver the result
        /// of the task dialog to the object that sent the message.</param>
        public TaskDialogMessage(
			object sender,
			object target,
			TaskDialogOptions options,
			Action<TaskDialogResult> callback)
            : this(sender, options, callback)
        {
            this.Target = target;
        }
Пример #9
0
        /// <summary>
        /// Displays a task dialog that has a message and that returns a result.
        /// </summary>
        /// <param name="owner">
        /// The <see cref="T:System.Windows.Window"/> that owns this dialog.
        /// </param>
        /// <param name="messageText">
        /// A <see cref="T:System.String"/> that specifies the text to display.
        /// </param>
        /// <returns>
        /// A <see cref="T:TaskDialogInterop.TaskDialogSimpleResult"/> value that
        /// specifies which button is clicked by the user.
        /// </returns>
        public static TaskDialogSimpleResult ShowMessage(Window owner, string messageText)
        {
            TaskDialogOptions options = TaskDialogOptions.Default;

            options.Owner         = owner;
            options.Content       = messageText;
            options.CommonButtons = TaskDialogCommonButtons.Close;

            return(Show(options).Result);
        }
Пример #10
0
        /// <summary>
        /// Displays a task dialog that has a message and that returns a result.
        /// </summary>
        /// <param name="owner">
        /// The <see cref="T:System.Windows.Window"/> that owns this dialog.
        /// </param>
        /// <param name="messageText">
        /// A <see cref="T:System.String"/> that specifies the text to display.
        /// </param>
        /// <param name="caption">
        /// A <see cref="T:System.String"/> that specifies the title bar
        /// caption to display.
        /// </param>
        /// <param name="buttons">
        /// A <see cref="T:TaskDialogInterop.TaskDialogCommonButtons"/> value that
        /// specifies which button or buttons to display.
        /// </param>
        /// <param name="icon">
        /// A <see cref="T:TaskDialogInterop.VistaTaskDialogIcon"/> that specifies the
        /// icon to display.
        /// </param>
        /// <returns>
        /// A <see cref="T:TaskDialogInterop.TaskDialogSimpleResult"/> value that
        /// specifies which button is clicked by the user.
        /// </returns>
        public static TaskDialogSimpleResult ShowMessage(Window owner, string messageText, string caption, TaskDialogCommonButtons buttons, VistaTaskDialogIcon icon)
        {
            TaskDialogOptions options = TaskDialogOptions.Default;

            options.Owner         = owner;
            options.Title         = caption;
            options.Content       = messageText;
            options.CommonButtons = buttons;
            options.MainIcon      = icon;

            return(Show(options).Result);
        }
Пример #11
0
 private void Application_DispatcherUnhandledException_1(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
 {
     TaskDialogOptions o = new TaskDialogOptions
     {
         Title = "Error",
         MainInstruction = "An error has occurred.",
         ExpandedByDefault = true,
         Content = e.Exception.ToString(),
         FooterText = "Please report this error by sending an email to [email protected] with [MCL-EXCEPTION] in the subject line containing the stack trace above."
     };
     TaskDialog.Show(o);
 }
        public void CloseGame(object ignored)
        {
            var opts = new TaskDialogOptions
            {
                Title = Translator.GetInstance().GetString("MessageBox", "1003"),
                MainInstruction = Translator.GetInstance().GetString("MessageBox", "1003", "message"),
                MainIcon = VistaTaskDialogIcon.Warning,
                CommonButtons = TaskDialogCommonButtons.YesNo
            };

            _taskDialog.ShowTaskDialog(opts, ExitResults);
        }
Пример #13
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TaskDialogViewModel"/> class.
        /// </summary>
        /// <param name="options">Options to use.</param>
        public TaskDialogViewModel(TaskDialogOptions options)
            : this()
        {
            this.options = options;

            FixAllButtonLabelAccessKeys();

            // If radio buttons are defined, set the dialog result to the default selected radio
            if (RadioButtons.Count > 0)
            {
                _dialogResult = RadioButtons[DefaultButtonIndex].ID;
            }
        }
        private void ExitGame(Window window)
        {
            _parent = window;

            var opts = new TaskDialogOptions
            {
                Owner = window,
                Title = Translator.GetInstance().GetString("MessageBox", "1003"),
                MainInstruction = Translator.GetInstance().GetString("MessageBox", "1003", "message"),
                MainIcon = VistaTaskDialogIcon.Warning,
                CommonButtons = TaskDialogCommonButtons.YesNo
            };

            _taskDialog.ShowTaskDialog(opts, ExitResult);
        }
Пример #15
0
        private void PassToExceptionHandler(Exception exception, string @event)
        {
            TaskDialogOptions config = new TaskDialogOptions();

            config.Owner = this.MainWindow;
            config.Title = "Task Dialog Title";
            config.MainInstruction = "The main instruction text for the TaskDialog goes here";
            config.Content = "The content text for the task dialog is shown here and the text will automatically wrap as needed.";
            config.ExpandedInfo = "Any expanded content text for the task dialog is shown here and the text will automatically wrap as needed.";
            config.VerificationText = "Don't show me this message again";
            config.CustomButtons = new string[] { "&Save", "Do&n't save", "&Cancel" };
            config.MainIcon = VistaTaskDialogIcon.Shield;
            config.FooterText = "Optional footer text with an icon or <a href=\"testUri\">hyperlink</a> can be included.";
            config.FooterIcon = VistaTaskDialogIcon.Warning;
            config.AllowDialogCancellation = true;

            TaskDialogResult res = TaskDialog.Show(config);
        }
Пример #16
0
        /// <summary>
        /// Shows a task dialog.
        /// </summary>
        /// <param name="sender">The owner of the dialog, or null.
        /// Should either be a window instance or the data context object of one.</param>
        /// <param name="options">A <see cref="T:TaskDialogOptions"/> config object.</param>
        /// <param name="callback">An optional callback method.</param>
        public void ShowTaskDialog(object sender, TaskDialogOptions options, Action<TaskDialogResult> callback)
        {
            MessageBoxButton buttons = MessageBoxButton.OK;

            if (options.AllowDialogCancellation
                || (options.CommonButtons == TaskDialogCommonButtons.OKCancel
                    || options.CommonButtons == TaskDialogCommonButtons.RetryCancel
                    || options.CommonButtons == TaskDialogCommonButtons.YesNo
                    || options.CommonButtons == TaskDialogCommonButtons.YesNoCancel))
                buttons = MessageBoxButton.OKCancel;

            MessageBoxResult mbResult =
                MessageBox.Show(
                    String.IsNullOrEmpty(options.MainInstruction) ? options.Content : options.MainInstruction,
                    options.Title,
                    buttons);

            TaskDialogResult tdResult = new TaskDialogResult((TaskDialogSimpleResult)mbResult);
        }
Пример #17
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            TaskDialogOptions config = new TaskDialogOptions();

            config.Owner = this;
            config.Title = "Task Dialog Title";
            config.MainInstruction = "The main instruction text for the TaskDialog goes here";
            config.Content = "The content text for the task dialog is shown here and the text will automatically wrap as needed.";
            config.ExpandedInfo = "Any expanded content text for the task dialog is shown here and the text will automatically wrap as needed.";
            config.VerificationText = "Don't show me this message again";
            config.CustomButtons = new string[] { "&Save", "Do&n't save", "&Cancel" };
            config.MainIcon = VistaTaskDialogIcon.Shield;
            config.FooterText = "Optional footer text with an icon can be included.";
            config.FooterIcon = VistaTaskDialogIcon.Warning;
            config.AllowDialogCancellation = true;

            TaskDialogResult res =
                TaskDialog.Show(config);

            UpdateResult(res);
        }
Пример #18
0
        public static async Task LaunchSequence(this MainWindow window,string username, string password)
        {
            window.LoadingBox.Visibility = Visibility.Visible;
            window.LoadingText.Content = "Logging in...";
            string[] AuthenticationString = await AuthenticatePlayer(username, password);
            if (!(AuthenticationString.Length >= 3))
            {
                TaskDialogOptions o = new TaskDialogOptions();
                o.Title = "Unexpected Login Server Response";
                o.Owner = window;
                o.MainInstruction = "A login error has occurred.";
                o.Content = String.Join(":", AuthenticationString);
                o.MainIcon = VistaTaskDialogIcon.Warning;

                TaskDialog.Show(o);
                //MessageBox.Show(AuthenticationString[0], "Unexpected Login Server Response", MessageBoxButton.OK);
                window.LoadingBox.Visibility = Visibility.Collapsed;
                return;
            }
            await window.BeginDownloadMinecraft();
            await Run(window, AuthenticationString[2], AuthenticationString[3]);
        }
Пример #19
0
        /// <summary>
        /// Displays a task dialog that has a message and that returns a result.
        /// </summary>
        /// <param name="owner">
        /// The <see cref="T:System.Windows.Window"/> that owns this dialog.
        /// </param>
        /// <param name="title">
        /// A <see cref="T:System.String"/> that specifies the title bar
        /// caption to display.
        /// </param>
        /// <param name="mainInstruction">
        /// A <see cref="T:System.String"/> that specifies the main text to display.
        /// </param>
        /// <param name="content">
        /// A <see cref="T:System.String"/> that specifies the body text to display.
        /// </param>
        /// <param name="expandedInfo">
        /// A <see cref="T:System.String"/> that specifies the expanded text to display when toggled.
        /// </param>
        /// <param name="verificationText">
        /// A <see cref="T:System.String"/> that specifies the text to display next to a checkbox.
        /// </param>
        /// <param name="footerText">
        /// A <see cref="T:System.String"/> that specifies the footer text to display.
        /// </param>
        /// <param name="buttons">
        /// A <see cref="T:TaskDialogInterop.TaskDialogCommonButtons"/> value that
        /// specifies which button or buttons to display.
        /// </param>
        /// <param name="mainIcon">
        /// A <see cref="T:TaskDialogInterop.VistaTaskDialogIcon"/> that specifies the
        /// main icon to display.
        /// </param>
        /// <param name="footerIcon">
        /// A <see cref="T:TaskDialogInterop.VistaTaskDialogIcon"/> that specifies the
        /// footer icon to display.
        /// </param>
        /// <returns></returns>
        public static TaskDialogSimpleResult ShowMessage(Window owner, string title, string mainInstruction, string content, string expandedInfo, string verificationText, string footerText, TaskDialogCommonButtons buttons, VistaTaskDialogIcon mainIcon, VistaTaskDialogIcon footerIcon)
        {
            TaskDialogOptions options = TaskDialogOptions.Default;

            if (owner != null)
            {
                options.Owner = owner;
            }
            if (!String.IsNullOrEmpty(title))
            {
                options.Title = title;
            }
            if (!String.IsNullOrEmpty(mainInstruction))
            {
                options.MainInstruction = mainInstruction;
            }
            if (!String.IsNullOrEmpty(content))
            {
                options.Content = content;
            }
            if (!String.IsNullOrEmpty(expandedInfo))
            {
                options.ExpandedInfo = expandedInfo;
            }
            if (!String.IsNullOrEmpty(verificationText))
            {
                options.VerificationText = verificationText;
            }
            if (!String.IsNullOrEmpty(footerText))
            {
                options.FooterText = footerText;
            }
            options.CommonButtons = buttons;
            options.MainIcon      = mainIcon;
            options.FooterIcon    = footerIcon;

            return(Show(options).Result);
        }
        public void Close(DocumentPaneViewModel fileToClose)
        {
            if (fileToClose.IsModified.Value)
            {
                var dialog = new TaskDialog.TaskDialogOptions();
                dialog.Owner           = App.MainView;
                dialog.Title           = "保存の確認";
                dialog.MainInstruction = "ドキュメントを保存しますか?";
                dialog.Content         = "保存しない場合、現在の変更は失われます";
                dialog.CustomButtons   = new[] { "保存 (&S)", "保存しない (&N)", "キャンセル (&C)" };

                var result = TaskDialog.TaskDialog.Show(dialog);
                switch (result.CustomButtonResult)
                {
                case 0:
                    this.Save(fileToClose);
                    if (fileToClose.IsModified.Value)
                    {
                        return;
                    }
                    break;

                case 1:
                    break;

                case 2:
                    return;
                }
            }

            this.Files.Remove(fileToClose);
            this.ToggleStartPage();
            if (this.ActiveDocument.Value == fileToClose)
            {
                this.ActiveDocument.Value = this.Files.FirstOrDefault();
            }
        }
Пример #21
0
 public TaskDialogMessage(TaskDialogOptions options, Action<TaskDialogResult> resultHandler = null)
 {
     this.Options = options;
     this.ResultHandler = resultHandler;
 }
        /// <summary>
        /// Shows a task dialog.
        /// </summary>
        /// <param name="options">A <see cref="T:TaskDialogOptions"/> config object.</param>
        /// <param name="callback">An optional callback method.</param>
        public void ShowTaskDialog(TaskDialogOptions options, Action<TaskDialogResult> callback)
        {
            TaskDialogResult result = TaskDialog.Show(options);

            callback?.Invoke(result);
        }
        /// <summary>
        /// Downloads the specified link near the specified video.
        /// </summary>
        /// <param name="file">The path to the archive.</param>
        public void OpenArchive(string file)
        {
            _file = file;

            var res = TaskDialog.Show(new TaskDialogOptions
                {
                    Title                   = "Open archive",
                    MainInstruction         = Path.GetFileName(file),
                    Content                 = "The episode you are trying to play is compressed.",
                    AllowDialogCancellation = true,
                    CommandButtons          = new[]
                        {
                            "Open archive with default video player\nSome video players are be able to open files inside archives.", 
                            "Decompress archive before opening", 
                            "None of the above"
                        }
                });

            if (!res.CommandButtonResult.HasValue)
            {
                return;
            }
            
            switch (res.CommandButtonResult.Value)
            {
                case 0:
                    var apps = Utils.GetDefaultVideoPlayers();

                    if (apps.Length == 0)
                    {
                        TaskDialog.Show(new TaskDialogOptions
                            {
                                MainIcon                = VistaTaskDialogIcon.Error,
                                Title                   = "No associations found",
                                MainInstruction         = "No associations found",
                                Content                 = "No application is registered to open any of the known video types.",
                                AllowDialogCancellation = true,
                                CustomButtons           = new[] { "OK" }
                            });

                        return;
                    }

                    Utils.Run(apps[0], _file);
                    break;

                case 1:
                    SevenZipBase.SetLibraryPath(Path.Combine(Signature.InstallPath, @"libs\7z" + (Environment.Is64BitProcess ? "64" : string.Empty) + ".dll"));

                    using (var archive = new SevenZipExtractor(_file))
                    {
                        var files = archive.ArchiveFileData.Where(f => !f.IsDirectory && ShowNames.Regexes.KnownVideo.IsMatch(f.FileName) && !ShowNames.Regexes.SampleVideo.IsMatch(f.FileName)).ToList();

                        if (files.Count == 1)
                        {
                            ExtractFile(files[0]);
                        }
                        else if (files.Count == 0)
                        {
                            TaskDialog.Show(new TaskDialogOptions
                                {
                                    MainIcon                = VistaTaskDialogIcon.Error,
                                    Title                   = "No files found",
                                    MainInstruction         = "No files found",
                                    Content                 = "The archive doesn't contain any video files.",
                                    AllowDialogCancellation = true,
                                    CustomButtons           = new[] {"OK"}
                                });
                        }
                        else
                        {
                            var seltd = new TaskDialogOptions
                                {
                                    Title                   = "Open archive",
                                    MainInstruction         = Path.GetFileName(_file),
                                    Content                 = "The archive contains more than one video files.\r\nSelect the one to decompress and open:",
                                    AllowDialogCancellation = true,
                                    CommandButtons          = new string[files.Count + 1]
                                };

                            var i = 0;
                            foreach (var c in files)
                            {
                                seltd.CommandButtons[i] = c.FileName + "\n" + Utils.GetFileSize((long)c.Size) + "   –   " + c.LastWriteTime;
                                i++;
                            }

                            seltd.CommandButtons[i] = "None of the above";

                            var rez = TaskDialog.Show(seltd);

                            if (rez.CommandButtonResult.HasValue && rez.CommandButtonResult.Value < files.Count)
                            {
                                ExtractFile(files[rez.CommandButtonResult.Value]);
                            }
                        }
                    }
                    break;
            }
        }
Пример #24
0
        /// <summary>
        /// Shows a message box.
        /// </summary>
        /// <param name="message">
        /// A <see cref="T:DialogMessage"/> that defines the message box.
        /// </param>
        public void ShowMessageBox(DialogMessage message)
        {
            TaskDialogOptions options = new TaskDialogOptions();

            options.Owner = DialogHelper.TryGetOwnerFromSender(message.Sender);
            options.MainInstruction = message.Content;
            options.Title = message.Caption;

            switch (message.Button)
            {
                case MessageBoxButton.OK:
                    options.CommonButtons = TaskDialogCommonButtons.Close;
                    options.DefaultButtonIndex = 0;
                    break;
                case MessageBoxButton.OKCancel:
                    options.CommonButtons = TaskDialogCommonButtons.OKCancel;
                    if (message.DefaultResult == MessageBoxResult.OK)
                        options.DefaultButtonIndex = 0;
                    else
                        options.DefaultButtonIndex = 1;
                    break;
                case MessageBoxButton.YesNo:
                    options.CommonButtons = TaskDialogCommonButtons.YesNo;
                    if (message.DefaultResult == MessageBoxResult.Yes)
                        options.DefaultButtonIndex = 0;
                    else
                        options.DefaultButtonIndex = 1;
                    break;
                case MessageBoxButton.YesNoCancel:
                    options.CommonButtons = TaskDialogCommonButtons.YesNoCancel;
                    if (message.DefaultResult == MessageBoxResult.Yes)
                        options.DefaultButtonIndex = 0;
                    else if (message.DefaultResult == MessageBoxResult.No)
                        options.DefaultButtonIndex = 1;
                    else
                        options.DefaultButtonIndex = 2;
                    break;
            }

            switch (message.Icon)
            {
                default:
                case MessageBoxImage.None:
                case MessageBoxImage.Question:
                    break;
                case MessageBoxImage.Information:
                    options.MainIcon = VistaTaskDialogIcon.Information;
                    break;
                case MessageBoxImage.Warning:
                    options.MainIcon = VistaTaskDialogIcon.Warning;
                    break;
                case MessageBoxImage.Error:
                    options.MainIcon = VistaTaskDialogIcon.Error;
                    break;
            }

            TaskDialogResult result = TaskDialog.Show(options);

            // TaskDialogSimpleResult is directly convertable to DialogResult (WinForms) and MessageBoxResult (WPF)
            message.ProcessCallback((MessageBoxResult)result.Result);
        }
        /// <summary>
        /// Handles the DownloadFileCompleted event of the HTTPDownloader control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void NearVideoDownloadFileCompletedOld(object sender, EventArgs<string, string, string> e)
        {
            _active = false;

            Utils.Win7Taskbar(state: TaskbarProgressBarState.NoProgress);

            if (e.First == null && e.Second == null)
            {
                TaskDialog.Show(new TaskDialogOptions
                    {
                        MainIcon                = VistaTaskDialogIcon.Error,
                        Title                   = "Download error",
                        MainInstruction         = _link.Release,
                        Content                 = "There was an error while downloading the requested file." + Environment.NewLine + "Try downloading another file from the list.",
                        AllowDialogCancellation = true,
                        CustomButtons           = new[] { "OK" }
                    });

                return;
            }

            var dlsnvtd = new TaskDialogOptions
                {
                    Title                   = "Download subtitle near video",
                    MainInstruction         = _link.Release,
                    Content                 = "The following files were found for {0} S{1:00}E{2:00}.\r\nSelect the desired video file and the subtitle will be placed in the same directory with the same name.".FormatWith(_ep.Show.Title, _ep.Season, _ep.Number),
                    AllowDialogCancellation = true,
                    CommandButtons          = new string[_files.Count + 1],
                    VerificationText        = "Play video after subtitle is downloaded",
                    VerificationByDefault   = Settings.Get("Play Video After Subtitle Download", false)
                };
            
            var i = 0;
            for (; i < _files.Count; i++)
            {
                var fi      = new FileInfo(_files[i]);
                var quality = Parser.ParseQuality(_files[i]);
                var instr   = fi.Name + "\n";

                if (quality != Parsers.Downloads.Qualities.Unknown)
                {
                    instr += quality.GetAttribute<DescriptionAttribute>().Description + "   –   ";
                }

                dlsnvtd.CommandButtons[i] = instr + Utils.GetFileSize(fi.Length) + "\n" + fi.DirectoryName;
            }

            dlsnvtd.CommandButtons[i] = "None of the above";

            var res = TaskDialog.Show(dlsnvtd);

            if (res.VerificationChecked.HasValue)
            {
                Settings.Set("Play Video After Subtitle Download", _play = res.VerificationChecked.Value);
            }

            if (res.CommandButtonResult.HasValue && res.CommandButtonResult.Value < _files.Count)
            {
                new Thread(() =>
                    {
                        NearVideoFinishMoveOld(_files[res.CommandButtonResult.Value], e.First, e.Second);

                        if (_play)
                        {
                            if (OpenArchiveTaskDialog.SupportedArchives.Contains(Path.GetExtension(_files[res.CommandButtonResult.Value]).ToLower()))
                            {
                                new OpenArchiveTaskDialog().OpenArchive(_files[res.CommandButtonResult.Value]);
                            }
                            else
                            {
                                Utils.Run(_files[res.CommandButtonResult.Value]);
                            }
                        }
                    }).Start();
            }
        }
        /// <summary>
        /// Called when the online search has encountered an error.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void OnlineSearchError(object sender, EventArgs<string, string, Tuple<string, string, string>> e)
        {
            _active = false;

            Utils.Win7Taskbar(state: TaskbarProgressBarState.NoProgress);
            
            var nvftd = new TaskDialogOptions
                {
                    MainIcon                = VistaTaskDialogIcon.Error,
                    Title                   = "No videos found",
                    MainInstruction         = e.First,
                    AllowDialogCancellation = true,
                    Content                 = e.Second
                };

            if (!string.IsNullOrWhiteSpace(e.Third.Item3))
            {
                nvftd.ExpandedInfo = e.Third.Item3;
            }

            if (!string.IsNullOrEmpty(e.Third.Item1))
            {
                nvftd.CommandButtons = new[] { e.Third.Item1, "Close" };
            }
            else
            {
                nvftd.CustomButtons = new[] { "OK" };
            }

            var res = TaskDialog.Show(nvftd);

            if (res.CommandButtonResult.HasValue && res.CommandButtonResult.Value == 0)
            {
                Utils.Run(e.Third.Item2);
            }
        }
Пример #27
0
        private static TaskDialogResult ShowEmulatedTaskDialog(TaskDialogOptions options)
        {
            TaskDialog td = new TaskDialog();
            TaskDialogViewModel tdvm = new TaskDialogViewModel(options);

            td.DataContext = tdvm;

            if (options.Owner != null)
            {
                td.Owner = options.Owner;
            }

            td.ShowDialog();

            TaskDialogResult result = null;
            int diagResult = -1;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked = false;
            int radioButtonResult = -1;
            int? commandButtonResult = null;
            int? customButtonResult = null;

            diagResult = tdvm.DialogResult;
            radioButtonResult = tdvm.RadioResult - RadioButtonIDOffset;
            verificationChecked = tdvm.VerificationChecked;

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            //else if (diagResult >= RadioButtonIDOffset)
            //{
            //    simpResult = (TaskDialogSimpleResult)diagResult;
            //    radioButtonResult = diagResult - RadioButtonIDOffset;
            //}
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            // This occurs usually when the red X button is clicked
            else if (diagResult == -1)
            {
                simpResult = TaskDialogSimpleResult.Cancel;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return result;
        }
Пример #28
0
        private static TaskDialogResult ShowTaskDialog(TaskDialogOptions options)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

            vtd.WindowTitle = options.Title;
            vtd.MainInstruction = options.MainInstruction;
            vtd.Content = options.Content;
            vtd.ExpandedInformation = options.ExpandedInfo;
            vtd.Footer = options.FooterText;

            if (options.CommandButtons != null && options.CommandButtons.Length > 0)
            {
                List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                for (int i = 0; i < options.CommandButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId = GetButtonIdForCommandButton(i);
                        button.ButtonText = options.CommandButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex >= 0
                    && options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
            }
            else if (options.RadioButtons != null && options.RadioButtons.Length > 0)
            {
                List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                for (int i = 0; i < options.RadioButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId = GetButtonIdForRadioButton(i);
                        button.ButtonText = options.RadioButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.RadioButtons = lst.ToArray();
                vtd.NoDefaultRadioButton = (!options.DefaultButtonIndex.HasValue || options.DefaultButtonIndex.Value == -1);
                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex >= 0
                    && options.DefaultButtonIndex.Value < vtd.RadioButtons.Length)
                    vtd.DefaultButton = vtd.RadioButtons[options.DefaultButtonIndex.Value].ButtonId;
            }

            bool hasCustomCancel = false;

            if (options.CustomButtons != null && options.CustomButtons.Length > 0)
            {
                List<VistaTaskDialogButton> lst = new List<VistaTaskDialogButton>();
                for (int i = 0; i < options.CustomButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId = GetButtonIdForCustomButton(i);
                        button.ButtonText = options.CustomButtons[i];

                        if (!hasCustomCancel)
                        {
                            hasCustomCancel =
                                (button.ButtonText == "Close"
                                || button.ButtonText == "Cancel");
                        }

                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }

                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex.Value >= 0
                    && options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                vtd.CommonButtons = VistaTaskDialogCommonButtons.None;
            }
            else
            {
                vtd.CommonButtons = ConvertCommonButtons(options.CommonButtons);

                if (options.DefaultButtonIndex.HasValue
                    && options.DefaultButtonIndex >= 0)
                    vtd.DefaultButton = GetButtonIdForCommonButton(options.CommonButtons, options.DefaultButtonIndex.Value);
            }

            vtd.MainIcon = options.MainIcon;
            vtd.CustomMainIcon = options.CustomMainIcon;
            vtd.FooterIcon = options.FooterIcon;
            vtd.CustomFooterIcon = options.CustomFooterIcon;
            vtd.EnableHyperlinks = DetectHyperlinks(options.Content, options.ExpandedInfo, options.FooterText);
            vtd.AllowDialogCancellation =
                (options.AllowDialogCancellation
                || hasCustomCancel
                || options.CommonButtons == TaskDialogCommonButtons.Close
                || options.CommonButtons == TaskDialogCommonButtons.OKCancel
                || options.CommonButtons == TaskDialogCommonButtons.YesNoCancel);
            vtd.CallbackTimer = options.EnableCallbackTimer;
            vtd.ExpandedByDefault = options.ExpandedByDefault;
            vtd.ExpandFooterArea = options.ExpandToFooter;
            vtd.PositionRelativeToWindow = true;
            vtd.RightToLeftLayout = false;
            vtd.NoDefaultRadioButton = false;
            vtd.CanBeMinimized = false;
            vtd.ShowProgressBar = options.ShowProgressBar;
            vtd.ShowMarqueeProgressBar = options.ShowMarqueeProgressBar;
            vtd.UseCommandLinks = (options.CommandButtons != null && options.CommandButtons.Length > 0);
            vtd.UseCommandLinksNoIcon = false;
            vtd.VerificationText = options.VerificationText;
            vtd.VerificationFlagChecked = options.VerificationByDefault;
            vtd.ExpandedControlText = "Hide details";
            vtd.CollapsedControlText = "Show details";
            vtd.Callback = options.Callback;
            vtd.CallbackData = options.CallbackData;
            vtd.Config = options;

            TaskDialogResult result = null;
            int diagResult = 0;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked = false;
            int radioButtonResult = -1;
            int? commandButtonResult = null;
            int? customButtonResult = null;

            diagResult = vtd.Show((vtd.CanBeMinimized ? null : options.Owner), out verificationChecked, out radioButtonResult);

            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            else if (radioButtonResult >= RadioButtonIDOffset)
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
                radioButtonResult -= RadioButtonIDOffset;
            }
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return result;
        }
        /// <summary>
        /// Event handler for <c>FileSearch.FileSearchDone</c>.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="RoliSoft.TVShowTracker.EventArgs&lt;System.Collections.Generic.List&lt;System.String&gt;&gt;"/> instance containing the event data.</param>
        private void FileSearchDone(object sender, EventArgs<List<string>> e)
        {
            _active = false;

            Utils.Win7Taskbar(state: TaskbarProgressBarState.NoProgress);

            if (e.Data == null)
            {
                return;
            }

            switch (e.Data.Count)
            {
                case 0:
                    TaskDialog.Show(new TaskDialogOptions
                        {
                            MainIcon                = VistaTaskDialogIcon.Error,
                            Title                   = "No files found",
                            MainInstruction         = string.Format("{0} S{1:00}E{2:00}", _ep.Show.Title, _ep.Season, _ep.Number),
                            Content                 = "No files were found for this episode.",
                            ExpandedInfo            = "If you have the episode in the specified download folder but the search fails, it might be because the file name slightly differs.\r\nIf this is the case, click on the 'Guides' tab, select this show, click on the wrench icon and then follow the instructions under the 'Custom release name' section.",
                            AllowDialogCancellation = true,
                            CustomButtons           = new[] { "OK" }
                        });
                    break;

                case 1:
                    if (OpenArchiveTaskDialog.SupportedArchives.Contains(Path.GetExtension(e.Data[0]).ToLower()))
                    {
                        new OpenArchiveTaskDialog().OpenArchive(e.Data[0]);
                    }
                    else
                    {
                        Utils.Run(e.Data[0]);
                    }
                    break;

                default:
                    var mfftd = new TaskDialogOptions
                        {
                            Title                   = "Multiple files found",
                            MainInstruction         = string.Format("{0} S{1:00}E{2:00}", _ep.Show.Title, _ep.Season, _ep.Number),
                            Content                 = "Multiple files were found for this episode:",
                            AllowDialogCancellation = true,
                            CommandButtons          = new string[e.Data.Count + 1]
                        };

                    var i = 0;
                    for (; i < e.Data.Count; i++)
                    {
                        var fi      = new FileInfo(e.Data[i]);
                        var quality = Parser.ParseQuality(e.Data[i]);
                        var instr   = fi.Name + "\n";

                        if (quality != Parsers.Downloads.Qualities.Unknown)
                        {
                            instr += quality.GetAttribute<DescriptionAttribute>().Description + "   –   ";
                        }

                        mfftd.CommandButtons[i] = instr + Utils.GetFileSize(fi.Length) + "\n" + fi.DirectoryName;
                    }

                    mfftd.CommandButtons[i] = "None of the above";

                    var res = TaskDialog.Show(mfftd);

                    if (res.CommandButtonResult.HasValue && res.CommandButtonResult.Value < e.Data.Count)
                    {
                        if (OpenArchiveTaskDialog.SupportedArchives.Contains(Path.GetExtension(e.Data[res.CommandButtonResult.Value]).ToLower()))
                        {
                            new OpenArchiveTaskDialog().OpenArchive(e.Data[res.CommandButtonResult.Value]);
                        }
                        else
                        {
                            Utils.Run(e.Data[res.CommandButtonResult.Value]);
                        }
                    }
                    break;
            }
        }
Пример #30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskDialogShowingEventArgs"/> class.
 /// </summary>
 /// <param name="configOptions">The configuration options for the TaskDialog.</param>
 internal TaskDialogShowingEventArgs(ref TaskDialogOptions configOptions)
 {
     ConfigurationOptions = configOptions;
 }
        /// <summary>
        /// Handles the Click event of the grabButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        private void GrabButtonClick(object sender, RoutedEventArgs e)
        {
            Cookies = _webBrowser.Document.Cookie ?? string.Empty;

            if (Engine.RequiredCookies != null && Engine.RequiredCookies.Length != 0 && !((string[])Engine.RequiredCookies).All(req => Regex.IsMatch(Cookies, @"(?:^|[\s;]){0}=".FormatWith(req), RegexOptions.IgnoreCase)))
            {
                var td = new TaskDialogOptions
                    {
                        MainIcon                = VistaTaskDialogIcon.Error,
                        Title                   = "Required cookies not found",
                        MainInstruction         = Engine.Name,
                        Content                 = "Couldn't catch the required cookies for authentication.\r\nYou need to manually extract the following cookies from your browser:\r\n\r\n-> " + string.Join("\r\n-> ", Engine.RequiredCookies) + "\r\n\r\nAnd enter them in this way:\r\n\r\n" + string.Join("=VALUE; ", Engine.RequiredCookies) + "=VALUE",
                        AllowDialogCancellation = true,
                        CommandButtons          = new[] { "How to extract cookies manually", "Close" }
                    };

                var res = TaskDialog.Show(td);

                if (res.CommandButtonResult.HasValue && res.CommandButtonResult == 0)
                {
                    Utils.Run("http://lab.rolisoft.net/tvshowtracker/extract-cookies.html");
                }
            }

            DialogResult = true;
        }
Пример #32
0
        private void mnuRecentItem_Click(object sender, RoutedEventArgs e)
        {
            if (!UndoManager.IsSavedState())
            {
                TaskDialogOptions tdOptions = new TaskDialogOptions();
                tdOptions.Title = "Circuit Diagram";
                tdOptions.MainInstruction = "Do you want to save changes to " + m_documentTitle + "?";
                tdOptions.CustomButtons = new string[] { "&Save", "Do&n't Save", "Cancel" };
                tdOptions.Owner = this;
                TaskDialogResult result = TaskDialog.Show(tdOptions);

                bool saved = false;
                if (result.CustomButtonResult == 0)
                    SaveDocument(out saved);

                if (result.CustomButtonResult == 2 || result.Result == TaskDialogSimpleResult.Cancel || (result.CustomButtonResult == 0 && !saved))
                    return; // Don't create new document
            }

            // Load the clicked item
            if ((e.OriginalSource as MenuItem).Header is string && System.IO.File.Exists((e.OriginalSource as MenuItem).Header as string))
                OpenDocument((e.OriginalSource as MenuItem).Header as string);
        }
        /// <summary>
        /// Moves the downloaded subtitle near the video.
        /// </summary>
        /// <param name="video">The location of the video.</param>
        /// <param name="temp">The location of the downloaded subtitle.</param>
        /// <param name="subtitle">The original file name of the subtitle.</param>
        private void NearVideoFinishMoveOld(string video, string temp, string subtitle)
        {
            if (OpenArchiveTaskDialog.SupportedArchives.Contains(Path.GetExtension(subtitle).ToLower()))
            {
                var archive = ArchiveFactory.Open(temp);
                var files   = archive.Entries.Where(f => !f.IsDirectory && Regexes.KnownSubtitle.IsMatch(f.FilePath)).ToList();

                if (files.Count == 1)
                {
                    using (var mstream = new MemoryStream())
                    {
                        subtitle = Utils.SanitizeFileName(files.First().FilePath.Split('\\').Last());
                        files.First().WriteTo(mstream);
                        
                        try { archive.Dispose(); } catch { }
                        try { File.Delete(temp); } catch { }
                        File.WriteAllBytes(temp, mstream.ToArray());
                    }
                }
                else
                {
                    var dlsnvtd = new TaskDialogOptions
                        {
                            Title                   = "Download subtitle near video",
                            MainInstruction         = _link.Release,
                            Content                 = "The downloaded subtitle was a ZIP package with more than one files.\r\nSelect the matching subtitle file to extract it from the package:",
                            AllowDialogCancellation = true,
                            CommandButtons          = new string[files.Count + 1],
                        };

                    var i = 0;
                    for (; i < files.Count; i++)
                    {
                        dlsnvtd.CommandButtons[i] = files[i].FilePath + "\n" + Utils.GetFileSize(files[i].Size) + "   –   " + files[i].LastModifiedTime;
                    }

                    dlsnvtd.CommandButtons[i] = "None of the above";

                    var res = TaskDialog.Show(dlsnvtd);

                    if (res.CommandButtonResult.HasValue && res.CommandButtonResult.Value < files.Count)
                    {
                        using (var mstream = new MemoryStream())
                        {
                            subtitle = Utils.SanitizeFileName(files[res.CommandButtonResult.Value].FilePath.Split('\\').Last());
                            files[res.CommandButtonResult.Value].WriteTo(mstream);

                            try { archive.Dispose(); } catch { }
                            try { File.Delete(temp); } catch { }
                            File.WriteAllBytes(temp, mstream.ToArray());
                        }

                        NearVideoFinishMoveOld(video, temp, subtitle);
                    }
                    else
                    {
                        _play = false;
                    }

                    return;
                }
            }

            var ext = new FileInfo(subtitle).Extension;

            if (Settings.Get<bool>("Append Language to Subtitle") && Languages.List.ContainsKey(_link.Language))
            {
                ext = "." + Languages.List[_link.Language].Substring(0, 3).ToLower() + ext;
            }

            var dest = Path.ChangeExtension(video, ext);

            if (File.Exists(dest))
            {
                try { File.Delete(dest); } catch { }
            }

            File.Move(temp, dest);
        }
Пример #34
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TaskDialogShowingEventArgs"/> class.
 /// </summary>
 /// <param name="configOptions">The configuration options for the TaskDialog.</param>
 internal TaskDialogShowingEventArgs(ref TaskDialogOptions configOptions)
 {
     ConfigurationOptions = configOptions;
 }
Пример #35
0
        private void DownloadClick(object sender, RoutedEventArgs e)
        {
            TaskDialogOptions o = new TaskDialogOptions
            {
                ShowMarqueeProgressBar = true,
                MainInstruction = "Press OK to download selected release... (MCLauncher will freeze! Do not close!)",
                MainIcon = VistaTaskDialogIcon.Information,
                EnableCallbackTimer = true,
                CustomButtons = new [] { "Cancel", "OK" }
            };
            string SecretKey = null;
            string PublicKey = null;
            Release Selected = (Release)JarList.SelectedItem;

            AmazonS3Client Client = new AmazonS3Client(PublicKey, SecretKey);

            GetObjectRequest Request = new GetObjectRequest
            {
                BucketName = "assets.minecraft.net",
                Key = Selected.Key
            };

            GetObjectResponse Result;
            TaskDialogResult tdr = TaskDialog.Show(o);
            if (tdr.CustomButtonResult == 0) return;
            Result = Client.GetObject(Request);
            Directory.CreateDirectory(Globals.LauncherDataPath + "/Minecraft/bin/");
            try
            {
                File.Copy(Globals.LauncherDataPath + "/Minecraft/bin/minecraft.jar", Globals.LauncherDataPath + "/Minecraft/OldMinecraft.jar", true);
                File.Delete(Globals.LauncherDataPath + "/Minecraft/bin/minecraft.jar");
            }
            catch (FileNotFoundException ex) { }
            Result.WriteResponseStreamToFile(Globals.LauncherDataPath + "/Minecraft/bin/minecraft.jar");
        }
        /// <summary>
        /// Searches for the specified show on the specified guide.
        /// </summary>
        /// <param name="guide">The guide.</param>
        /// <param name="show">The show.</param>
        /// <param name="lang">The language.</param>
        /// <param name="done">The method to call when finished.</param>
        public void Search(Guide guide, string show, string lang, Action<string, string, string> done)
        {
            _g = guide;

            var showmbp = false;
            var mthd = new Thread(() => TaskDialog.Show(new TaskDialogOptions
                {
                    Title                   = "Searching...",
                    MainInstruction         = show.ToUppercaseWords(),
                    Content                 = "Searching on " + guide.Name + "...",
                    CustomButtons           = new[] { "Cancel" },
                    ShowMarqueeProgressBar  = true,
                    EnableCallbackTimer     = true,
                    AllowDialogCancellation = true,
                    Callback                = (dialog, args, data) =>
                        {
                            if (!showmbp)
                            {
                                dialog.SetProgressBarMarquee(true, 0);
                                showmbp = true;
                            }

                            if (args.ButtonId != 0)
                            {
                                if (_thd != null && _thd.IsAlive && !_cancel)
                                {
                                    _thd.Abort();
                                }

                                return false;
                            }

                            if (_cancel)
                            {
                                dialog.ClickButton(500);
                                return false;
                            }

                            return true;
                        }
                }));
            mthd.SetApartmentState(ApartmentState.STA);
            mthd.Start();

            _thd = new Thread(() =>
                {
                    try
                    {
                        _ids = _g.GetID(show, lang).ToList();
                    }
                    catch (Exception ex)
                    {
                        _cancel = true;

                        TaskDialog.Show(new TaskDialogOptions
                            {
                                MainIcon        = VistaTaskDialogIcon.Error,
                                Title           = "Search error",
                                MainInstruction = show.ToUppercaseWords(),
                                Content         = "Error while searching on " + _g.Name + ".",
                                ExpandedInfo    = ex.Message,
                                CustomButtons   = new[] { "OK" }
                            });

                        done(null, null, null);
                        return;
                    }

                    _cancel = true;

                    if (_ids.Count == 0)
                    {
                        TaskDialog.Show(new TaskDialogOptions
                            {
                                MainIcon        = VistaTaskDialogIcon.Warning,
                                Title           = "Search result",
                                MainInstruction = show.ToUppercaseWords(),
                                Content         = "Couldn't find the specified show on " + _g.Name + ".",
                                CustomButtons   = new[] { "OK" }
                            });

                        done(null, null, null);
                        return;
                    }

                    if (_ids.Count == 1)
                    {
                        done(_ids[0].ID, _ids[0].Title, _ids[0].Language);
                        return;
                    }

                    if (_ids.Count > 1)
                    {
                        if (_ids.Count > 5)
                        {
                            _ids = _ids.Take(5).ToList();
                        }

                        var td = new TaskDialogOptions
                            {
                                Title           = "Search result",
                                MainInstruction = show.ToUppercaseWords(),
                                Content         = "More than one show matched the search criteria on " + _g.Name + ":",
                                CommandButtons  = new string[_ids.Count + 1]
                            };

                        var i = 0;
                        for (; i < _ids.Count; i++)
                        {
                            td.CommandButtons[i] = _ids[i].Title;
                        }

                        td.CommandButtons[i] = "None of the above";

                        var res = TaskDialog.Show(td);

                        if (res.CommandButtonResult.HasValue && res.CommandButtonResult.Value < _ids.Count)
                        {
                            done(_ids[res.CommandButtonResult.Value].ID, _ids[res.CommandButtonResult.Value].Title, _ids[res.CommandButtonResult.Value].Language);
                        }
                        else
                        {
                            done(null, null, null);
                        }
                    }
                });
            _thd.SetApartmentState(ApartmentState.STA);
            _thd.Start();
        }
Пример #37
0
        private static TaskDialogResult ShowTaskDialog(TaskDialogOptions options)
        {
            VistaTaskDialog vtd = new VistaTaskDialog();

            vtd.WindowTitle         = options.Title;
            vtd.MainInstruction     = options.MainInstruction;
            vtd.Content             = options.Content;
            vtd.ExpandedInformation = options.ExpandedInfo;
            vtd.Footer = options.FooterText;

            if (options.CommandButtons != null && options.CommandButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.CommandButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForCommandButton(i);
                        button.ButtonText = options.CommandButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                {
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }
            else if (options.RadioButtons != null && options.RadioButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.RadioButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForRadioButton(i);
                        button.ButtonText = options.RadioButtons[i];
                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }
                vtd.RadioButtons         = lst.ToArray();
                vtd.NoDefaultRadioButton = (!options.DefaultButtonIndex.HasValue || options.DefaultButtonIndex.Value == -1);
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.RadioButtons.Length)
                {
                    vtd.DefaultButton = vtd.RadioButtons[options.DefaultButtonIndex.Value].ButtonId;
                }
            }

            bool hasCustomCancel = false;

            if (options.CustomButtons != null && options.CustomButtons.Length > 0)
            {
                List <VistaTaskDialogButton> lst = new List <VistaTaskDialogButton>();
                for (int i = 0; i < options.CustomButtons.Length; i++)
                {
                    try
                    {
                        VistaTaskDialogButton button = new VistaTaskDialogButton();
                        button.ButtonId   = GetButtonIdForCustomButton(i);
                        button.ButtonText = options.CustomButtons[i];

                        if (!hasCustomCancel)
                        {
                            hasCustomCancel =
                                (button.ButtonText == "Close" ||
                                 button.ButtonText == "Cancel");
                        }

                        lst.Add(button);
                    }
                    catch (FormatException)
                    {
                    }
                }

                vtd.Buttons = lst.ToArray();
                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex.Value >= 0 &&
                    options.DefaultButtonIndex.Value < vtd.Buttons.Length)
                {
                    vtd.DefaultButton = vtd.Buttons[options.DefaultButtonIndex.Value].ButtonId;
                }
                vtd.CommonButtons = VistaTaskDialogCommonButtons.None;
            }
            else
            {
                vtd.CommonButtons = ConvertCommonButtons(options.CommonButtons);

                if (options.DefaultButtonIndex.HasValue &&
                    options.DefaultButtonIndex >= 0)
                {
                    vtd.DefaultButton = GetButtonIdForCommonButton(options.CommonButtons, options.DefaultButtonIndex.Value);
                }
            }

            vtd.MainIcon                = options.MainIcon;
            vtd.CustomMainIcon          = options.CustomMainIcon;
            vtd.FooterIcon              = options.FooterIcon;
            vtd.CustomFooterIcon        = options.CustomFooterIcon;
            vtd.EnableHyperlinks        = DetectHyperlinks(options.Content, options.ExpandedInfo, options.FooterText);
            vtd.AllowDialogCancellation =
                (options.AllowDialogCancellation ||
                 hasCustomCancel ||
                 options.CommonButtons == TaskDialogCommonButtons.Close ||
                 options.CommonButtons == TaskDialogCommonButtons.OKCancel ||
                 options.CommonButtons == TaskDialogCommonButtons.YesNoCancel);
            vtd.CallbackTimer            = options.EnableCallbackTimer;
            vtd.ExpandedByDefault        = options.ExpandedByDefault;
            vtd.ExpandFooterArea         = options.ExpandToFooter;
            vtd.PositionRelativeToWindow = true;
            vtd.RightToLeftLayout        = false;
            vtd.NoDefaultRadioButton     = false;
            vtd.CanBeMinimized           = false;
            vtd.ShowProgressBar          = options.ShowProgressBar;
            vtd.ShowMarqueeProgressBar   = options.ShowMarqueeProgressBar;
            vtd.UseCommandLinks          = (options.CommandButtons != null && options.CommandButtons.Length > 0);
            vtd.UseCommandLinksNoIcon    = false;
            vtd.VerificationText         = options.VerificationText;
            vtd.VerificationFlagChecked  = options.VerificationByDefault;
            vtd.ExpandedControlText      = "Hide details";
            vtd.CollapsedControlText     = "Show details";
            vtd.Callback     = options.Callback;
            vtd.CallbackData = options.CallbackData;
            vtd.Config       = options;

            TaskDialogResult result           = null;
            int diagResult                    = 0;
            TaskDialogSimpleResult simpResult = TaskDialogSimpleResult.None;
            bool verificationChecked          = false;
            int  radioButtonResult            = -1;
            int? commandButtonResult          = null;
            int? customButtonResult           = null;

            //diagResult = vtd.Show((vtd.CanBeMinimized ? null : options.Owner), out verificationChecked, out radioButtonResult);

            IntPtr ownerHandle = options.OwnerHandle;

            if (options.Owner != null)
            {
                WindowInteropHelper helper = new WindowInteropHelper(options.Owner);
                ownerHandle = helper.Owner;
            }
            diagResult = vtd.Show((vtd.CanBeMinimized ? IntPtr.Zero : ownerHandle), out verificationChecked, out radioButtonResult);


            if (diagResult >= CommandButtonIDOffset)
            {
                simpResult          = TaskDialogSimpleResult.Command;
                commandButtonResult = diagResult - CommandButtonIDOffset;
            }
            else if (radioButtonResult >= RadioButtonIDOffset)
            {
                simpResult         = (TaskDialogSimpleResult)diagResult;
                radioButtonResult -= RadioButtonIDOffset;
            }
            else if (diagResult >= CustomButtonIDOffset)
            {
                simpResult         = TaskDialogSimpleResult.Custom;
                customButtonResult = diagResult - CustomButtonIDOffset;
            }
            else
            {
                simpResult = (TaskDialogSimpleResult)diagResult;
            }

            result = new TaskDialogResult(
                simpResult,
                (String.IsNullOrEmpty(options.VerificationText) ? null : (bool?)verificationChecked),
                ((options.RadioButtons == null || options.RadioButtons.Length == 0) ? null : (int?)radioButtonResult),
                ((options.CommandButtons == null || options.CommandButtons.Length == 0) ? null : commandButtonResult),
                ((options.CustomButtons == null || options.CustomButtons.Length == 0) ? null : customButtonResult));

            return(result);
        }
        private RefreshMode GetMode([NotNull] Window mainWindow)
        {
            Assert.ArgumentNotNull(mainWindow, "mainWindow");

              if (this.mode != RefreshMode.Undefined)
              {
            return this.mode;
              }

              var config = new TaskDialogOptions
              {
            Owner = mainWindow,
            Title = "Refresh",
            MainInstruction = "Choose what would you like to refresh.",
            Content = "The application has three kinds of storages that you can refresh.",
            CommandButtons = new[]
            {
              // 0
              "Refresh sites list\nReading IIS metabase to find Sitecore instances",

              // 1
              "Refresh installer\nLooking for *.zip files in your local repository",

              // 2
              "Refresh caches\nFlushing internal caches",

              // 3
              "Refresh everything\nFlushing internal caches and refreshing instances and installer",
            },
            MainIcon = VistaTaskDialogIcon.Information
              };

              var res = TaskDialog.Show(config);
              if (res == null)
              {
            return RefreshMode.Undefined;
              }

              var result = res.CommandButtonResult;
              if (result == null)
              {
            return RefreshMode.Undefined;
              }

              return (RefreshMode)((int)result);
        }
Пример #39
0
        /// <summary>
        /// Shows a task dialog.
        /// </summary>
        /// <param name="sender">The owner of the dialog, or null.
        /// Should either be a window instance or the data context object of one.</param>
        /// <param name="options">A <see cref="T:TaskDialogOptions"/> config object.</param>
        /// <param name="callback">An optional callback method.</param>
        public void ShowTaskDialog(object sender, TaskDialogOptions options, Action<TaskDialogResult> callback)
        {
            if (options.Owner == null)
            {
                options.Owner = DialogHelper.TryGetOwnerFromSender(sender);
            }

            TaskDialogResult result = TaskDialog.Show(options);

            if (callback != null)
                callback(result);
        }