示例#1
0
        private async Task StartDownload()
        {
            isListViewDirty = true;
            if (mediaDownloadQueue.Count == 0)
            {
                TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok,
                                             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.");
                return;
            }

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

                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();
            }
        }
示例#2
0
 private void DefaultPluginManagerOnLoadException(object sender, PluginLoadExceptionEventArgs pluginLoadExceptionEventArgs)
 {
     if (pluginLoadExceptionEventArgs.Exception.GetType() == typeof(PluginIncompatibleException))
     {
         TaskDialogHelper.ShowMessage("Incompatible plugin",
                                      $"The plugin \"{pluginLoadExceptionEventArgs.PluginName}\" is incompatible with this version of Athame.",
                                      icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: Handle);
     }
     else
     {
         pluginLoadExceptions.Add(pluginLoadExceptionEventArgs.Exception);
     }
     pluginLoadExceptionEventArgs.Continue = true;
 }
示例#3
0
        public AuthProgressForm RestoreSingle(MusicService service)
        {
            if (!am.CanRestore(service))
            {
                TaskDialogHelper.ShowMessage(caption: "Cannot restore this service right now.",
                                             message: "The service is already being restored in the background. Please try again in a moment.",
                                             icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: parent.Handle);
                return(null);
            }
            var form = new AuthProgressForm(new[] { service });

            form.Show(parent);
            return(form);
        }
示例#4
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (mediaDownloadQueue.Count > 0 && Program.DefaultSettings.Settings.ConfirmExit)
            {
                var msgResult = TaskDialogHelper.ShowMessage("Are you sure you want to exit Athame?",
                                                             "You have items waiting in the download queue.", TaskDialogStandardButtons.Yes | TaskDialogStandardButtons.No, TaskDialogStandardIcon.Warning, Handle);

                if (msgResult != TaskDialogResult.Yes)
                {
                    e.Cancel = true;
                    return;
                }
            }
            Program.DefaultSettings.Save();
        }
示例#5
0
        private async void signInButton_Click(object sender, EventArgs e)
        {
            if (!authenticatable.IsAuthenticated)
            {
                if (!am.CanAuthenticate(service))
                {
                    TaskDialogHelper.ShowMessage(caption: "Cannot authenticate this service right now.",
                                                 message: "The service is already being authenticated in the background. Please try again in a moment.",
                                                 icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: Handle);
                    return;
                }
                var authenticatableAsync = service.AsAuthenticatableAsync();
                if (authenticatableAsync == null)
                {
                    var dlg = new CredentialsForm(service);
                    dlg.ShowDialog();
                }
                else
                {
                    var result = await am.Authenticate(service);

                    if (result.Result)
                    {
                        return;
                    }
                    if (result.Exception != null)
                    {
                        Log.WriteException(Level.Error, Lag, result.Exception, "AM custom auth");
                        TaskDialogHelper.ShowExceptionDialog(result.Exception,
                                                             "An error occurred while attempting to sign in.",
                                                             "Make sure you have entered the correct credentials and your device has an active internet connection.\n\n" +
                                                             "The information below may be useful to the plugin's author.", Handle);
                    }
                    else
                    {
                        TaskDialogHelper.ShowMessage("An error occurred while attempting to sign in.",
                                                     "Make sure you have entered the correct credentials and your device has an active internet connection.",
                                                     TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Error, Handle);
                    }
                }
            }
            else
            {
                authenticatable.Reset();
            }
            UpdateViews();
            servicePlugin.SettingsFile.Save();
        }
示例#6
0
        private void restoreButton_Click(object sender, EventArgs e)
        {
            if (!am.CanRestore(service))
            {
                TaskDialogHelper.ShowMessage(caption: "Cannot restore this service right now.",
                                             message: "The service is already being restored in the background. Please try again in a moment.",
                                             icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: Handle);
                return;
            }
            var form = new AuthProgressForm(new[] { service });

            form.Closed += (o, args) =>
            {
                UpdateViews();
                servicePlugin.SettingsFile.Save();
            };
            form.Show(this);
        }
        private void RestoreServices()
        {
            var am       = Program.DefaultAuthenticationManager;
            var taskList = Program.DefaultPluginManager.ServicesEnumerable()
                           .Where(am.CanRestore).Select(service => am.Restore(service));
            var td     = TaskDialogHelper.CreateWaitDialog(null, Handle);
            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}");
                            TaskDialogHelper.ShowMessage(owner: Handle, caption: $"Failed to sign in to {service.Info.Name}",
                                                         message: null, icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok);
                        }
                    }
                    td.Close();
                }, openCt.Token);
            };
            if (td.Show() == TaskDialogResult.Cancel)
            {
                openCt.Cancel(true);
            }
        }
示例#8
0
        public async Task <bool> Authenticate(MusicService service)
        {
            if (!am.CanAuthenticate(service))
            {
                TaskDialogHelper.ShowMessage(caption: "Cannot authenticate this service right now.",
                                             message: "The service is already being authenticated in the background. Please try again in a moment.",
                                             icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: parent.Handle);
                return(false);
            }
            var authenticatableAsync = service.AsAuthenticatableAsync();

            if (authenticatableAsync == null)
            {
                var dlg = new CredentialsForm(service);
                return(dlg.ShowDialog() == DialogResult.OK);
            }
            var result = await am.Authenticate(service);

            if (result.Result)
            {
                return(true);
            }
            if (result.Exception != null)
            {
                Log.WriteException(Level.Error, Tag, result.Exception, "AM custom auth");
                TaskDialogHelper.ShowExceptionDialog(result.Exception,
                                                     "An error occurred while attempting to sign in.",
                                                     "Make sure you have entered the correct credentials and your device has an active internet connection.\n\n" +
                                                     "The information below may be useful to the plugin's author.", parent.Handle);
            }
            else
            {
                TaskDialogHelper.ShowMessage("An error occurred while attempting to sign in.",
                                             "Make sure you have entered the correct credentials and your device has an active internet connection.",
                                             TaskDialogStandardButtons.Ok, TaskDialogStandardIcon.Error, parent.Handle);
            }
            return(false);
        }
示例#9
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (isListViewDirty)
            {
                CleanQueueListView();
            }
#if !DEBUG
            try
            {
#endif
            // Don't add if the item is already enqueued.
            var isAlreadyInQueue = mediaDownloadQueue.ItemById(mResult.Id) != null;
            if (isAlreadyInQueue)
            {
                TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Error,
                                             caption: "Cannot add to download queue",
                                             message: "This item already exists in the download queue.",
                                             buttons: TaskDialogStandardButtons.Ok);
            }

            // 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 destination 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)
            {
                TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Warning, buttons: TaskDialogStandardButtons.Ok,
                                             caption: $"'{mResult.Type}' is not supported yet.",
                                             message: "You may be able to download it in a later release.");
            }

            // 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 = 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, saveDir, pathFormat);
                        break;

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

                        if (playlist.Tracks == null)
                        {
                            var items = mService.GetPlaylistItems(mResult.Id, 100);
                            await items.LoadAllPagesAsync();

                            playlist.Tracks = items.AllItems;
                        }
                        AddToQueue(mService, playlist, saveDir, pathFormat);
                        break;

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

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

        catch (Exception ex)
        {
            PresentException(ex);
        }
#endif
        }
示例#10
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!resolver.HasParsedUrl)
            {
                return;
            }
            if (isListViewDirty)
            {
                CleanQueueListView();
            }
#if !DEBUG
            try
            {
#endif
            // Don't add if the item is already enqueued.
            var isAlreadyInQueue = mediaDownloadQueue.ItemById(resolver.ParseResult.Id) != null;
            if (isAlreadyInQueue)
            {
                TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Error,
                                             caption: "Cannot add to download queue",
                                             message: "This item already exists in the download queue.",
                                             buttons: TaskDialogStandardButtons.Ok);
            }

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

            // Build wait dialog
            var retrievalWaitTaskDialog = new TaskDialog
            {
                Cancelable        = false,
                Caption           = "Athame",
                InstructionText   = $"Getting {resolver.ParseResult.Type.ToString().ToLower()} details...",
                Text              = $"{resolver.Service.Info.Name}: {resolver.ParseResult.Id}",
                StandardButtons   = TaskDialogStandardButtons.Cancel,
                OwnerWindowHandle = Handle,
                ProgressBar       = new TaskDialogProgressBar {
                    State = TaskDialogProgressBarState.Marquee
                }
            };
            // Open handler
            retrievalWaitTaskDialog.Opened += async(o, args) =>
            {
                LockUi();
                var pathFormat = prefType.GetPlatformSaveFormat();
                try
                {
                    var media = await resolver.Resolve();

                    AddToQueue(resolver.Service, media, saveDir, pathFormat);
                }
                catch (ResourceNotFoundException)
                {
                    TaskDialogHelper.ShowMessage(caption: "This media does not exist.",
                                                 message: "Ensure the provided URL is valid, and try again", owner: Handle,
                                                 buttons: TaskDialogStandardButtons.Ok, icon: TaskDialogStandardIcon.Information);
                }
                catch (NotImplementedException)
                {
                    TaskDialogHelper.ShowMessage(
                        owner: Handle, icon: TaskDialogStandardIcon.Warning, buttons: TaskDialogStandardButtons.Ok,
                        caption: $"'{resolver.ParseResult.Type}' is not supported yet.",
                        message: "You may be able to download it in a later release.");
                }
                catch (Exception ex)
                {
                    Log.WriteException(Level.Error, Tag, ex, "While attempting to resolve media");
                    TaskDialogHelper.ShowExceptionDialog(ex,
                                                         "An error occurred while trying to retrieve information for this media.",
                                                         "The provided URL may be invalid or unsupported.", Handle);
                }

                idTextBox.Clear();
                UnlockUi();
                retrievalWaitTaskDialog.Close();
            };
            // Show dialog
            retrievalWaitTaskDialog.Show();
#if !DEBUG
        }

        catch (Exception ex)
        {
            PresentException(ex);
        }
#endif
        }
示例#11
0
        private void ParseAndAddUrl(UrlResolver r, bool syncMode)
        {
            if (!r.HasParsedUrl)
            {
                return;
            }
            if (isListViewDirty)
            {
                CleanQueueListView();
            }
#if !DEBUG
            try
            {
#endif
            // Don't add if the item is already enqueued.
            var isAlreadyInQueue = mediaDownloadQueue.ItemById(r.ParseResult.Id) != null;
            if (isAlreadyInQueue)
            {
                TaskDialogHelper.ShowMessage(owner: Handle, icon: TaskDialogStandardIcon.Error,
                                             caption: "Cannot add to download queue",
                                             message: "This item already exists in the download queue.",
                                             buttons: TaskDialogStandardButtons.Ok);
                return;
            }

            // Ask for the location if required before we begin retrieval
            var prefType    = PreferenceForType(r.ParseResult.Type);
            var saveDir     = prefType.SaveDirectory;
            var folderItems = new List <string>();
            if (prefType.AskForLocation || syncMode)
            {
                Shell  shell  = new Shell();
                Folder folder = shell.BrowseForFolder((int)this.Handle, "Select a destination for this media:", 0, Program.DefaultSettings.Settings.PlaylistSync.SyncDirectory);
                if (folder == null)
                {
                    return;
                }
                FolderItem fi = (folder as Folder3).Self;
                saveDir = fi.Path;
                foreach (FolderItem curr in folder.Items())
                {
                    folderItems.Add(Path.GetFileNameWithoutExtension(curr.Name));
                }


                //using (var folderSelectionDialog = new FolderBrowserDialog { Description = "Select a destination for this media:" })
                //{
                //    if (folderSelectionDialog.ShowDialog(this) == DialogResult.OK)
                //    {
                //        saveDir = folderSelectionDialog.SelectedPath;
                //    }
                //    else
                //    {
                //        return;
                //    }
                //}
            }


            // Build wait dialog
            var retrievalWaitTaskDialog = new TaskDialog
            {
                Cancelable        = false,
                Caption           = "Athame",
                InstructionText   = $"Getting {r.ParseResult.Type.ToString().ToLower()} details...",
                Text              = $"{r.Service.Info.Name}: {r.ParseResult.Id}",
                StandardButtons   = TaskDialogStandardButtons.Cancel,
                OwnerWindowHandle = Handle,
                ProgressBar       = new TaskDialogProgressBar {
                    State = TaskDialogProgressBarState.Marquee
                }
            };



            // Open handler
            retrievalWaitTaskDialog.Opened += async(o, args) =>
            {
                LockUi();
                var  pathFormat  = prefType.GetPlatformSaveFormat();
                var  finalTracks = new List <string>();
                bool isPlaylist  = false;
                try
                {
                    var media = await r.ResolveAsync(syncMode, folderItems, finalTracks);

                    isPlaylist = r.ParseResult.Type == MediaType.Playlist;
                    AddToQueue(r.Service, media, saveDir, pathFormat);
                }
                catch (ResourceNotFoundException)
                {
                    TaskDialogHelper.ShowMessage(caption: "This media does not exist.",
                                                 message: "Ensure the provided URL is valid, and try again", owner: Handle,
                                                 buttons: TaskDialogStandardButtons.Ok, icon: TaskDialogStandardIcon.Information);
                }
                catch (NotImplementedException)
                {
                    TaskDialogHelper.ShowMessage(
                        owner: Handle, icon: TaskDialogStandardIcon.Warning, buttons: TaskDialogStandardButtons.Ok,
                        caption: $"'{r.ParseResult.Type}' is not supported yet.",
                        message: "You may be able to download it in a later release.");
                }
                catch (Exception ex)
                {
                    Log.WriteException(Level.Error, Tag, ex, "While attempting to resolve media");
                    TaskDialogHelper.ShowExceptionDialog(ex,
                                                         "An error occurred while trying to retrieve information for this media.",
                                                         "The provided URL may be invalid or unsupported.", Handle);
                }

                idTextBox.Clear();
                UnlockUi();
                retrievalWaitTaskDialog.Close();
                if (syncMode && isPlaylist)
                {
                    var toDelete = new List <string>();
                    foreach (var curTrack in folderItems)
                    {
                        if (!finalTracks.Contains(curTrack))
                        {
                            toDelete.Add(curTrack);
                        }
                    }
                    if (toDelete.Count > 0)
                    {
                        DialogResult dialogResult = MessageBox.Show("Delete " + toDelete.Count + " tracks, which is not in playlist?", "Confirm delete", MessageBoxButtons.YesNo);
                        if (dialogResult == DialogResult.Yes)
                        {
                            DirectoryInfo di = new DirectoryInfo(saveDir);
                            foreach (FileInfo file in di.GetFiles())
                            {
                                if (toDelete.Contains(Path.GetFileNameWithoutExtension(file.Name)))
                                {
                                    file.Delete();
                                }
                            }
                        }
                    }
                }
                else if (!isPlaylist && syncMode)
                {
                    MessageBox.Show("Can't sync if not playlist");
                }
            };
            // Show dialog
            retrievalWaitTaskDialog.Show();
#if !DEBUG
        }

        catch (Exception ex)
        {
            PresentException(ex);
        }
#endif
        }