示例#1
0
        private void OnAutomaticDownloadClick(object sender, RoutedEventArgs e)
        {
            var searchQueue = ((App)Application.Current).SearchQueue.Queue;

            if (searchQueue.Count > 0)
            {
                var autoDownloader = new AutoDownloader();

                while (searchQueue.Count > 0)
                {
                    var   window = searchQueue[0];
                    bool  ignored;
                    Album album = new Album(null, window.Artist, window.Album);
                    album.ArtFile = window.GetDefaultSaveFolderPattern(out ignored);
                    autoDownloader.Add(album);

                    RemoveFromQueue(window);
                }

                autoDownloader.Show();
            }
        }
示例#2
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();
            }
        }