예제 #1
0
        private void OnIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if ((bool)e.NewValue)
            {
                //Window is being shown. Show warning
                Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new ThreadStart(delegate
                {
                    var warning   = new AutoDownloadWarning();
                    warning.Owner = this;
                    if (warning.ShowDialog().GetValueOrDefault())
                    {
                        //User chose to enqueue normal search windows instead.
                        var cascade = new Common.WindowCascade();
                        foreach (var album in mQueueList.Albums)
                        {
                            ArtSearchWindow searchWindow = Common.NewSearchWindow(this);
                            cascade.Arrange(searchWindow);
                            searchWindow.SetDefaultSaveFolderPattern(album.ArtFile, true);                             //Default save to the location where the image was searched for.
                            searchWindow.Search(album.Artist, album.Name);
                        }

                        Close();
                    }
                }));
            }
        }
예제 #2
0
        private void NewSearchWindowExec(object sender, ExecutedRoutedEventArgs e)
        {
            IEnumerable <Album> albums;
            var albumParameter = e.Parameter as Album;

            if (albumParameter != null)
            {
                //Search for the specified album in a new search window
                albums = new Album[] { albumParameter };
            }
            else
            {
                //Search for all the selected albums in new search windows
                albums = mQueueList.SelectedItems.Cast <Album>();
            }

            var cascade = new Common.WindowCascade();

            foreach (Album album in albums)
            {
                ArtSearchWindow searchWindow = Common.NewSearchWindow(this);
                cascade.Arrange(searchWindow);
                searchWindow.SetDefaultSaveFolderPattern(album.ArtFile, true);                 //Default save to the location where the image was searched for.
                searchWindow.Search(album.Artist, album.Name);
            }
        }
예제 #3
0
        private void GetArtworkExec(object sender, ExecutedRoutedEventArgs e)
        {
            AutoDownloader autoDownloader = null;

            if (SelectedItems.Count > 1 && Properties.Settings.Default.FileBrowseAutoDownload)
            {
                autoDownloader = new AutoDownloader();
            }
            else
            {
                //Warn if there are a lot of selected items
                if (SelectedItems.Count > Properties.Settings.Default.EnqueueWarning)
                {
                    EnqueueWarning enqueueWarning = new EnqueueWarning();
                    enqueueWarning.Owner           = Window.GetWindow(this);
                    enqueueWarning.NumberToEnqueue = SelectedItems.Count;

                    if (!enqueueWarning.ShowDialog().GetValueOrDefault())
                    {
                        //Cancelled
                        return;
                    }

                    //Trim the selection back to the number to enqueue
                    while (SelectedItems.Count > enqueueWarning.NumberToEnqueue)
                    {
                        SelectedItems.RemoveAt(SelectedItems.Count - 1);
                    }
                }
            }

            //The art file search pattern is used as the default path to save the found image to, but first:
            // *In case of alternates, use the first alternate only.
            string artFileSearchPattern = ImagePathPattern.Split(new[] { '|' }, 2)[0];

            // *Don't substitute placeholders, but do substitute recursive path matching with the simplest solution to it, just putting saving to the immediate subfolder
            artFileSearchPattern = artFileSearchPattern.Replace("**\\", "").Replace("**/", "");
            // *Also replace a wildcarded extension
            if (artFileSearchPattern.EndsWith(".*"))
            {
                artFileSearchPattern = artFileSearchPattern.Substring(0, artFileSearchPattern.Length - 2) + ".%extension%";
            }
            // *If the pattern ends in just a wildcard, replace with %name%.%extension%
            else if (artFileSearchPattern.EndsWith("*"))
            {
                artFileSearchPattern = artFileSearchPattern.Substring(0, artFileSearchPattern.Length - 1) + "%name%.%extension%";
            }
            //Replace other wildcards with the %name%, so that for local files search they become wildcards again
            artFileSearchPattern = artFileSearchPattern.Replace("*", "%name%");
            var cascade = new Common.WindowCascade();

            foreach (Album album in SelectedItems)
            {
                //If the image path is relative, get an absolute path for it.
                string rootedArtFileSearchPattern;
                if (Path.IsPathRooted(artFileSearchPattern))
                {
                    rootedArtFileSearchPattern = artFileSearchPattern;
                }
                else
                {
                    rootedArtFileSearchPattern = Path.Combine(album.BasePath, artFileSearchPattern);
                }

                if (autoDownloader != null)
                {
                    album.ArtFile = rootedArtFileSearchPattern;                     //The destination filename to download to
                    autoDownloader.Add(album);
                }
                else
                {
                    ArtSearchWindow searchWindow = Common.NewSearchWindow(Window.GetWindow(this) as IAppWindow);
                    cascade.Arrange(searchWindow);

                    searchWindow.SetDefaultSaveFolderPattern(rootedArtFileSearchPattern, true); //Default save to the location where the image was searched for.
                    searchWindow.Search(album.Artist, album.Name);                              //Kick off the search.

                    //Watch for the window being closed to update the status of the artwork
                    mSearchWindowAlbumLookup.Add(searchWindow, album);
                    searchWindow.Closed += OnSearchWindowClosed;
                }
            }
            if (autoDownloader != null)
            {
                autoDownloader.Show();
            }
        }