private void ShowDetails() { var tag = (MediaItemTag)mCurrentlySelectedQueueItem?.Tag; if (tag?.Exception == null) { return; } TaskDialogHelper.ShowExceptionDialog(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.", Handle); }
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(); }
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"; } TaskDialogHelper.ShowExceptionDialog(ex, th, "You may need to sign into this service again.", Handle); }
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); }
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 }
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 }
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 }