Exemple #1
0
        private async void startDownloadButton_Click(object sender, EventArgs e)
        {
            if (mediaDownloadQueue.Count == 0)
            {
                using (
                    var td = CommonTaskDialogs.Message(this, TaskDialogStandardIcon.Error, "Athame",
                                                       "No tracks are in the queue.",
                                                       "You can add tracks by copying the URL to an album, artist, track, or playlist and pasting it into Athame.",
                                                       TaskDialogStandardButtons.Ok))
                {
                    td.Show();
                }
                return;
            }

            try
            {
                LockUi();
                totalStatusLabel.Text = "Warming up...";
                await mediaDownloadQueue.StartDownloadAsync();

                currentlyDownloadingItem = null;
                SetGlobalProgress(0);
                SystemSounds.Beep.Play();
                this.Flash(FlashMethod.All | FlashMethod.TimerNoForeground, Int32.MaxValue, 0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                UnlockUi();
            }
        }
Exemple #2
0
        private void LoadAndInitPlugins()
        {
            Program.DefaultPluginManager.LoadAll();
            Program.DefaultPluginManager.InitAll();
            if (pluginLoadExceptions.Count > 0)
            {
                CommonTaskDialogs.Message("Plugin load error",
                                          "One or more errors occurred while loading plugins. Some plugins may be unavailable. Check the log for more details.",
                                          TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Warning, this).Show();
                pluginLoadExceptions.Clear();
            }
            if (!Program.DefaultPluginManager.AreAnyLoaded)
            {
#if DEBUG
                // https://youtu.be/Ki5cvEPu_e0?t=161
                var buttons = TaskDialogStandardButtons.Ok | TaskDialogStandardButtons.No;
#else
                var buttons = TaskDialogStandardButtons.Ok;
#endif
                if (CommonTaskDialogs.Message("No plugins installed",
                                              "No plugins could be found. If you have attempted to install a plugin, it may not be installed properly.",
                                              buttons, TaskDialogStandardIcon.Error, this).Show() != TaskDialogResult.No)
                {
                    Application.Exit();
                }
            }
        }
Exemple #3
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            if (Program.DefaultPluginManager.Plugins.Count == 0)
            {
                CommonTaskDialogs.Message("No plugins installed",
                                          "No plugins could be found. If you have attempted to install a plugin, it may not be installed properly.",
                                          TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Error, this).Show();
                Application.Exit();
            }

            LockUi();
            ShowStartupTaskDialog();
            UnlockUi();
        }
Exemple #4
0
 private void DefaultPluginManagerOnLoadException(object sender, PluginLoadExceptionEventArgs pluginLoadExceptionEventArgs)
 {
     if (pluginLoadExceptionEventArgs.Exception.GetType() == typeof(PluginIncompatibleException))
     {
         CommonTaskDialogs.Message("Incompatible plugin",
                                   $"The plugin \"{pluginLoadExceptionEventArgs.PluginName}\" is incompatible with this version of Athame.",
                                   icon: TaskDialogStandardIcon.Error, owner: this).Show();
     }
     else
     {
         pluginLoadExceptions.Add(pluginLoadExceptionEventArgs.Exception);
     }
     pluginLoadExceptionEventArgs.Continue = true;
 }
Exemple #5
0
        private void ShowDetails()
        {
            var tag = (MediaItemTag)mCurrentlySelectedQueueItem?.Tag;

            if (tag?.Exception == null)
            {
                return;
            }
            using (var dialog = CommonTaskDialogs.Exception(tag.Exception, "An error occurred while downloading this track",
                                                            "Check you can play this track on the web, check that you have a subscription, or try signing in and out.",
                                                            this))
            {
                dialog.Show();
            }
        }
Exemple #6
0
        private void PresentException(Exception ex)
        {
            Log.WriteException(Level.Error, Tag, ex, "PresentException");
            SetGlobalProgressState(ProgressBarState.Error);
            var th = "An unknown error occurred";

            if (ex is ResourceNotFoundException)
            {
                th = "Resource not found";
            }
            else if (ex is InvalidSessionException)
            {
                th = "Invalid session/subscription expired";
            }
            CommonTaskDialogs.Exception(ex, th, "You may need to sign into this service again.", this).Show();
        }
Exemple #7
0
        private void ShowStartupTaskDialog()
        {
            var td     = CommonTaskDialogs.Wait(this, null);
            var openCt = new CancellationTokenSource();

            td.Opened += async(o, args) =>
            {
                await Task.Factory.StartNew(async() =>
                {
                    foreach (var service in ServiceRegistry.Default)
                    {
                        if (service.Settings.Response == null)
                        {
                            continue;
                        }
                        var result         = false;
                        td.InstructionText = $"Signing into {service.Name}...";
                        td.Text            = $"Signing in as {service.Settings.Response.UserName}";
                        try
                        {
                            openCt.Token.ThrowIfCancellationRequested();
                            result = await service.RestoreSessionAsync(service.Settings.Response);
                        }
                        catch (NotImplementedException)
                        {
                            result = service.RestoreSession(service.Settings.Response);
                        }
                        finally
                        {
                            if (result)
                            {
                            }
                            else
                            {
                                MessageBox.Show($"Failed to sign in to {service.Name}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }
Exemple #8
0
        private void PresentException(Exception ex)
        {
#if DEBUG
            throw ex;
#else
            SetGlobalProgressState(ProgressBarState.Error);
            var th = "An unknown error occurred";
            if (ex is ResourceNotFoundException)
            {
                th = "Resource not found";
            }
            else if (ex is InvalidSessionException)
            {
                th = "Invalid session/subscription expired";
            }
            CommonTaskDialogs.Error(ex, th).Show();
#endif
        }
Exemple #9
0
        private void okButton_Click(object sender, EventArgs e)
        {
            var waitForm = CommonTaskDialogs.Wait($"Signing into {svc.Info.Name}...", this);

            waitForm.Opened += async(o, args) => {
                var result = await usernamePasswordService.AuthenticateAsync(emailTextBox.Text, passwordTextBox.Text, true);

                waitForm.Close();
                if (result)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    errorLabel.Text = "An error occurred while signing in. Please check your credentials and try again.";
                    SystemSounds.Hand.Play();
                }
            };
            waitForm.Show();
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            var waitForm = CommonTaskDialogs.Wait(this, $"Signing into {svc.Name}...");

            waitForm.Opened += async(o, args) => {
                Result = await svc.LoginAsync(emailTextBox.Text, passwordTextBox.Text);

                waitForm.Close();
                if (Result != null)
                {
                    svc.Settings.Response = Result;
                    Program.DefaultSettings.Save();
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    errorLabel.Text = "An error occurred while signing in. Please check your credentials and try again.";
                    SystemSounds.Hand.Play();
                }
            };
            waitForm.Show();
        }
Exemple #11
0
        private async void startDownloadButton_Click(object sender, EventArgs e)
        {
            isListViewDirty = true;
            if (mediaDownloadQueue.Count == 0)
            {
                using (
                    var td = CommonTaskDialogs.Message(owner: this, icon: TaskDialogStandardIcon.Error, caption: "No tracks are in the queue.",
                                                       message: "You can add tracks by copying the URL to an album, artist, track, or playlist and pasting it into Athame."))
                {
                    td.Show();
                }
                return;
            }

            try
            {
                LockUi();
                totalStatusLabel.Text = "Warming up...";
                await mediaDownloadQueue.StartDownloadAsync();

                totalStatusLabel.Text      = "All downloads completed";
                collectionStatusLabel.Text = GetCompletionMessage();
                currentlyDownloadingItem   = null;
                mediaDownloadQueue.Clear();
                SetGlobalProgress(0);
                SystemSounds.Beep.Play();
                this.Flash(FlashMethod.All | FlashMethod.TimerNoForeground, Int32.MaxValue, 0);
            }
            catch (Exception ex)
            {
                PresentException(ex);
            }
            finally
            {
                UnlockUi();
            }
        }
Exemple #12
0
        private void ShowStartupTaskDialog()
        {
            var td     = CommonTaskDialogs.Wait(owner: this);
            var openCt = new CancellationTokenSource();

            td.Opened += async(o, args) =>
            {
                await Task.Factory.StartNew(async() =>
                {
                    foreach (var service in Program.DefaultPluginManager.ServicesEnumerable())
                    {
                        var restorable = service.AsAuthenticatable();
                        if (restorable == null || !restorable.HasSavedSession)
                        {
                            continue;
                        }

                        var result         = false;
                        td.InstructionText = $"Signing into {service.Info.Name}...";
                        td.Text            = $"Signing in as {LocalisableAccountNameFormat.GetFormattedName(restorable.Account)}";
                        openCt.Token.ThrowIfCancellationRequested();
                        result = await restorable.RestoreAsync();
                        if (!result)
                        {
                            Log.Error(Tag, $"Failed to sign into {service.Info.Name}");
                            CommonTaskDialogs.Message(owner: this, caption: $"Failed to sign in to {service.Info.Name}",
                                                      message: null, icon: TaskDialogStandardIcon.Error).Show();
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }
Exemple #13
0
        private void MainForm_Shown(object sender, EventArgs e)
        {
            Program.DefaultPluginManager.LoadAll();
            Program.DefaultSettings.Load();
            Program.DefaultPluginManager.InitAll();
            if (pluginLoadExceptions.Count > 0)
            {
                CommonTaskDialogs.Message("Plugin load error",
                                          "One or more errors occurred while loading plugins. Some plugins may be unavailable. Check the log for more details.",
                                          TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Warning, this).Show();
                pluginLoadExceptions.Clear();
            }
            if (Program.DefaultPluginManager.Plugins.Count == 0)
            {
                CommonTaskDialogs.Message("No plugins installed",
                                          "No plugins could be found. If you have attempted to install a plugin, it may not be installed properly.",
                                          TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Error, this).Show();
                Application.Exit();
            }

            LockUi();
            ShowStartupTaskDialog();
            UnlockUi();
        }
Exemple #14
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (isListViewDirty)
            {
                collectionStatusLabel.Text  = "Ready to begin.";
                collectionProgressBar.Value = 0;
                SetGlobalProgress(0);
                SetGlobalProgressState(ProgressBarState.Normal);
                totalProgressBar.Value = 0;
                totalStatusLabel.Text  = "Ready";
                queueListView.Groups.Clear();
                queueListView.Items.Clear();
                isListViewDirty = false;
            }
#if !DEBUG
            try
            {
#endif
            // Don't add if the item is already enqueued.
            var isAlreadyInQueue = mediaDownloadQueue.ItemById(mResult.Id) != null;
            if (isAlreadyInQueue)
            {
                using (
                    var td = CommonTaskDialogs.Message(owner: this, icon: TaskDialogStandardIcon.Error,
                                                       caption: "Cannot add to download queue", message: "This item already exists in the download queue."))
                {
                    td.Show();
                    return;
                }
            }

            // Ask for the location if required before we begin retrieval
            var prefType = PreferenceForType(mResult.Type);
            var saveDir  = prefType.SaveDirectory;
            if (prefType.AskForLocation)
            {
                using (var folderSelectionDialog = new FolderBrowserDialog {
                    Description = "Select a destionation for this media:"
                })
                {
                    if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK)
                    {
                        saveDir = folderSelectionDialog.SelectedPath;
                    }
                    else
                    {
                        return;
                    }
                }
            }

            // Filter out types we can't process right now
            if (mResult.Type != MediaType.Album && mResult.Type != MediaType.Playlist &&
                mResult.Type != MediaType.Track)
            {
                using (var noTypeTd = CommonTaskDialogs.Message(owner: this, icon: TaskDialogStandardIcon.Warning,
                                                                caption: $"'{mResult.Type}' is not supported yet.",
                                                                message: "You may be able to download it in a later release."))
                {
                    noTypeTd.Show();
                    return;
                }
            }

            // Build wait dialog
            var retrievalWaitTaskDialog = new TaskDialog
            {
                Cancelable        = false,
                Caption           = "Athame",
                InstructionText   = $"Getting {mResult.Type.ToString().ToLower()} details...",
                Text              = $"{mService.Info.Name}: {mResult.Id}",
                StandardButtons   = TaskDialogStandardButtons.Cancel,
                OwnerWindowHandle = Handle,
                ProgressBar       = new TaskDialogProgressBar {
                    State = TaskDialogProgressBarState.Marquee
                }
            };
            // Open handler
            retrievalWaitTaskDialog.Opened += async(o, args) =>
            {
                LockUi();
                var pathFormat = Path.Combine(saveDir, prefType.GetPlatformSaveFormat());
                try
                {
                    switch (mResult.Type)
                    {
                    case MediaType.Album:
                        // Get album and display it in listview
                        var album = await mService.GetAlbumAsync(mResult.Id, true);

                        AddToQueue(mService, album, pathFormat);
                        break;

                    case MediaType.Playlist:
                        // Get playlist and display it in listview
                        var playlist = await mService.GetPlaylistAsync(mResult.Id);

                        AddToQueue(mService, playlist, pathFormat);
                        break;

                    case MediaType.Track:
                        var track = await mService.GetTrackAsync(mResult.Id);

                        AddToQueue(mService, track.AsCollection(), pathFormat);
                        break;
                    }
                }
                catch (ResourceNotFoundException)
                {
                    CommonTaskDialogs.Message(caption: "This media does not exist.",
                                              message: "Ensure the provided URL is valid, and try again", owner: this).Show();
                }
                catch (Exception ex)
                {
                    CommonTaskDialogs.Exception(ex,
                                                "An error occurred while trying to retrieve information for this media.",
                                                "The provided URL may be invalid or unsupported.", this).Show();
                }
                idTextBox.Clear();
                UnlockUi();
                retrievalWaitTaskDialog.Close();
            };
            // Show dialog
            retrievalWaitTaskDialog.Show();
#if !DEBUG
        }

        catch (Exception ex)
        {
            PresentException(ex);
        }
#endif
        }
Exemple #15
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                // Don't add if the item is already enqueued.
                var isAlreadyInQueue = mediaDownloadQueue.ItemById(mResult.Id) != null;
                if (isAlreadyInQueue)
                {
                    using (
                        var td = CommonTaskDialogs.Message(this, TaskDialogStandardIcon.Error, "Athame",
                                                           "Cannot add to download queue", "This item already exists in the download queue.",
                                                           TaskDialogStandardButtons.Ok))
                    {
                        td.Show();
                        return;
                    }
                }

                // Ask for the location if required before we begin retrieval
                var prefType = PreferenceForType(mResult.Type);
                var saveDir  = prefType.SaveDirectory;
                if (prefType.AskForLocation)
                {
                    using (var folderSelectionDialog = new FolderBrowserDialog {
                        Description = "Select a destionation for this media:"
                    })
                    {
                        if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK)
                        {
                            saveDir = folderSelectionDialog.SelectedPath;
                        }
                        else
                        {
                            return;
                        }
                    }
                }

                // Filter out types we can't process right now
                if (mResult.Type != MediaType.Album && mResult.Type != MediaType.Playlist &&
                    mResult.Type != MediaType.Track)
                {
                    using (var noTypeTd = CommonTaskDialogs.Message(this, TaskDialogStandardIcon.Warning,
                                                                    "Athame", $"'{mResult.Type}' is not supported yet.",
                                                                    "You may be able to download it in a later release.", TaskDialogStandardButtons.Ok))
                    {
                        noTypeTd.Show();
                        return;
                    }
                }

                // Build wait dialog
                var retrievalWaitTaskDialog = new TaskDialog
                {
                    Cancelable        = false,
                    Caption           = "Athame",
                    InstructionText   = $"Getting {mResult.Type.ToString().ToLower()} details...",
                    Text              = $"{mService.Name}: {mResult.Id}",
                    StandardButtons   = TaskDialogStandardButtons.Cancel,
                    OwnerWindowHandle = Handle,
                    ProgressBar       = new TaskDialogProgressBar {
                        State = TaskDialogProgressBarState.Marquee
                    }
                };
                // Open handler
                retrievalWaitTaskDialog.Opened += async(o, args) =>
                {
                    LockUi();
                    var pathFormat = Path.Combine(saveDir, prefType.GetPlatformSaveFormat());
                    switch (mResult.Type)
                    {
                    case MediaType.Album:
                        // Get album and display it in listview
                        var album = await mService.GetAlbumAsync(mResult.Id, true);

                        AddToQueue(mService, album, pathFormat);
                        break;

                    case MediaType.Playlist:
                        // Get playlist and display it in listview
                        var playlist = await mService.GetPlaylistAsync(mResult.Id);

                        AddToQueue(mService, playlist, pathFormat);
                        break;

                    case MediaType.Track:
                        var track = await mService.GetTrackAsync(mResult.Id);

                        AddToQueue(mService, track.AsCollection(), pathFormat);
                        break;
                    }
                    idTextBox.Clear();
                    UnlockUi();
                    retrievalWaitTaskDialog.Close();
                };
                // Show dialog
                retrievalWaitTaskDialog.Show();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }