Exemple #1
0
        private static void OnProgressChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            if (TaskbarManager.IsPlatformSupported)
            {
                var autoDownloader = (AutoDownloader)sender;

                if (autoDownloader.IsSearching)
                {
                    TaskbarManager.Instance.SetProgressValue((int)autoDownloader.Progress, (int)autoDownloader.ProgressMax, autoDownloader);
                }
                else
                {
                    TaskbarHelper.DelayedClearProgress(autoDownloader);
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Process command args. Returns True if a new search window was shown, False if it was not.
        /// </summary>
        private bool ProcessCommandArgs(string[] args)
        {
            //valuedParameters is a list of parameters which must have values - they can not be just switches.
            string[]  valuedParameters = { "artist",   "ar", "album",   "al", "path",    "p",  "localimagespath",
                                           "sources",   "s",  "exclude", "es", "include", "i",
                                           "sort",      "o",  "group",   "g",  "minsize", "mn", "maxsize",        "mx",
                                           "covertype", "t" };
            Arguments arguments = new Arguments(args, valuedParameters);

            if (arguments.Contains("?"))
            {
                ShowCommandArgs();
                return(false);
            }

            bool?autoClose = null;
            bool showSearchWindow = false, showFileBrowser = false, showFoobarBrowser = false, showConfigFile = false;
            bool startFoobarBrowserSearch = false;
            bool showMinimized            = false;
            bool forceNewWindow           = false;

            string            artist = null, album = null, path = null, localImagesPath = null, fileBrowser = null, sortField = null;
            ListSortDirection sortDirection = ListSortDirection.Ascending;
            Grouping?         grouping = null;
            int?minSize = null, maxSize = null;
            AllowedCoverType?coverType = null;

            List <String> useSources     = new List <string>();
            List <String> excludeSources = new List <string>();
            List <String> includeSources = new List <string>();
            string        errorMessage   = null;
            bool          skipNext       = false;

            foreach (Parameter parameter in arguments)
            {
                if (skipNext)
                {
                    skipNext = false;
                    continue;
                }
                //Check un-named parameters
                if (parameter.Name == null)
                {
                    showSearchWindow = true;

                    //For un-named parameters, use compatibility mode: 3 args,  "<artist>" "<album>" "<path to save image>"
                    switch (arguments.IndexOf(parameter))
                    {
                    case 0:
                        artist = parameter.Value;
                        break;

                    case 1:
                        album = parameter.Value;
                        break;

                    case 2:
                        path = parameter.Value;
                        break;

                    default:
                        errorMessage = "Only the first three parameters may be un-named";
                        break;
                    }
                }
                else
                {
                    //Check named parameters
                    switch (parameter.Name.ToLower())                     //Case insensitive parameter names
                    {
                    case "artist":
                    case "ar":
                        artist           = parameter.Value;
                        showSearchWindow = true;
                        break;

                    case "album":
                    case "al":
                        album            = parameter.Value;
                        showSearchWindow = true;
                        break;

                    case "path":
                    case "p":
                        path = PathFix(parameter.Value);
                        //Compatibility mode: if an "f" parameter, for filename, is provided, append it to the path.
                        string filename;
                        if (arguments.TryGetParameterValue("f", out filename))
                        {
                            path = Path.Combine(path, filename);
                        }
                        showSearchWindow = true;
                        break;

                    case "f":
                        break;                                 //See case "p" for handling of this parameter

                    case "localimagespath":
                        localImagesPath  = PathFix(parameter.Value);
                        showSearchWindow = true;
                        break;

                    case "autoclose":
                    case "ac":
                        if (parameter.Value.Equals("off", StringComparison.InvariantCultureIgnoreCase))
                        {
                            autoClose = false;
                        }
                        else
                        {
                            autoClose = true;
                        }
                        break;

                    case "sources":
                    case "s":
                        useSources.AddRange(parameter.Value.Split(','));
                        showSearchWindow = true;
                        break;

                    case "exclude":
                    case "es":
                        excludeSources.AddRange(parameter.Value.Split(','));
                        showSearchWindow = true;
                        break;

                    case "ae":                             //Compatibility: Show Existing Album Art
                        excludeSources.Add("Local Files");
                        showSearchWindow = true;
                        break;

                    case "include":
                    case "i":
                        includeSources.AddRange(parameter.Value.Split(','));
                        showSearchWindow = true;
                        break;

                    case "pf":                             //Compatibility: Show pictures in folder
                        break;                             //Not currently supported

                    case "filebrowser":
                        fileBrowser     = PathFix(parameter.Value);
                        showFileBrowser = true;
                        break;

                    case "foobarbrowser":
                        startFoobarBrowserSearch = parameter.Value.Equals("search", StringComparison.InvariantCultureIgnoreCase);
                        showFoobarBrowser        = true;
                        break;

                    case "sort":
                    case "o":
                        string sortName = null;
                        if (parameter.Value.EndsWith("-"))
                        {
                            sortDirection = ListSortDirection.Descending;
                        }
                        else if (parameter.Value.EndsWith("+"))
                        {
                            sortDirection = ListSortDirection.Ascending;
                        }
                        sortName = parameter.Value.TrimEnd('-', '+');

                        switch (sortName.ToLower())
                        {
                        case "name":
                        case "n":
                            sortField = "ResultName";
                            break;

                        case "size":
                        case "s":
                            sortField = "ImageWidth";
                            break;

                        case "source":
                        case "o":
                            sortField = "SourceName";
                            break;

                        case "type":
                        case "t":
                            sortField = "CoverType";
                            break;

                        case "area":
                        case "a":
                            sortField = "ImageArea";
                            break;

                        case "page":
                        case "p":
                            sortField = "InfoUri";
                            break;

                        default:
                            errorMessage = "Unexpected sort field: " + sortName;
                            break;
                        }
                        break;

                    case "group":
                    case "g":
                        switch (parameter.Value.ToLower())
                        {
                        case "none":
                        case "n":
                            grouping = Grouping.None;
                            break;

                        case "local":
                        case "l":
                            grouping = Grouping.Local;
                            break;

                        case "source":
                        case "o":
                            grouping = Grouping.Source;
                            break;

                        case "category":
                        case "c":
                            grouping = Grouping.SourceCategory;
                            break;

                        case "type":
                        case "t":
                            grouping = Grouping.Type;
                            break;

                        case "size":
                        case "s":
                            grouping = Grouping.Size;
                            break;

                        case "page":
                        case "p":
                            grouping = Grouping.InfoUri;
                            break;

                        default:
                            errorMessage = "Unexpected grouping: " + parameter.Value;
                            break;
                        }
                        break;

                    case "minsize":
                    case "mn":
                        try
                        {
                            minSize = Int32.Parse(parameter.Value);
                        }
                        catch (Exception e)
                        {
                            errorMessage = "The /minSize parameter must be a number: " + parameter.Value + "\n  " + e.Message;
                        }
                        break;

                    case "maxsize":
                    case "mx":
                        try
                        {
                            maxSize = Int32.Parse(parameter.Value);
                        }
                        catch (Exception e)
                        {
                            errorMessage = "The /maxSize parameter must be a number: " + parameter.Value + "\n  " + e.Message;
                        }
                        break;

                    case "covertype":
                    case "t":
                        coverType = default(AllowedCoverType);
                        foreach (String allowedCoverType in parameter.Value.ToLower().Split(','))
                        {
                            switch (allowedCoverType)
                            {
                            case "front":
                            case "f":
                                coverType |= AllowedCoverType.Front;
                                break;

                            case "back":
                            case "b":
                                coverType |= AllowedCoverType.Back;
                                break;

                            case "inside":
                            case "i":
                                coverType |= AllowedCoverType.Inside;
                                break;

                            case "cd":
                            case "c":
                                coverType |= AllowedCoverType.CD;
                                break;

                            case "unknown":
                            case "u":
                                coverType |= AllowedCoverType.Unknown;
                                break;

                            case "booklet":
                            case "k":
                                coverType |= AllowedCoverType.Booklet;
                                break;

                            case "any":
                            case "a":
                                coverType |= AllowedCoverType.Any;
                                break;

                            default:
                                errorMessage = "Unrecognized cover type: " + parameter.Value;
                                break;
                            }
                        }
                        break;

                    case "update":
                        //Force an immediate check for updates
                        Updates.CheckForUpdates(true);
                        break;

                    case "getscripts":
                        //Force an immediate check for new scripts
                        Updates.ShowNewScripts();
                        break;

                    case "separateinstance":
                        //This will already have been handled earlier, in Main()
                        break;

                    case "config":
                        showConfigFile = true;
                        break;

                    case "minimized":
                        showMinimized = true;
                        break;

                    case "new":
                        forceNewWindow = true;
                        break;

                    case "minaspect":
                    case "ma":
                    case "orientation":
                    case "r":
                    case "sequence":
                    case "seq":
                    case "listsources":
                    case "l":
                        System.Diagnostics.Debug.Fail("Unexpected command line parameter (valid for aad.exe, though): " + parameter.Name);
                        break;

                    default:
                        errorMessage = "Unexpected command line parameter: " + parameter.Name;
                        break;
                    }
                }
                if (errorMessage != null)
                {
                    break;                     //Stop parsing args if there was an error
                }
            }
            if (errorMessage != null)             //Problem with the command args, so display the error, and the help
            {
                ShowCommandArgs(errorMessage);
                return(false);
            }

            if (!String.IsNullOrEmpty(sortField))
            {
                //Set the sort
                AlbumArtDownloader.Properties.Settings.Default.ResultsSorting = new SortDescription(sortField, sortDirection);
            }
            if (grouping.HasValue)
            {
                //Set the grouping
                AlbumArtDownloader.Properties.Settings.Default.ResultsGrouping = grouping.Value;
            }
            if (minSize.HasValue)
            {
                if (minSize.Value == 0)
                {
                    //0 would have no effect, so assume it means no filtering.
                    AlbumArtDownloader.Properties.Settings.Default.UseMinimumImageSize = false;
                }
                else
                {
                    //Set the minimum size
                    AlbumArtDownloader.Properties.Settings.Default.MinimumImageSize    = minSize.Value;
                    AlbumArtDownloader.Properties.Settings.Default.UseMinimumImageSize = true;
                }
            }
            if (maxSize.HasValue)
            {
                if (maxSize.Value == 0)
                {
                    //0 would result in no images at all, so assume it means no filtering.
                    AlbumArtDownloader.Properties.Settings.Default.UseMinimumImageSize = false;
                }
                else
                {
                    //Set the minimum size
                    AlbumArtDownloader.Properties.Settings.Default.MaximumImageSize    = maxSize.Value;
                    AlbumArtDownloader.Properties.Settings.Default.UseMaximumImageSize = true;
                }
            }
            if (coverType.HasValue)
            {
                AlbumArtDownloader.Properties.Settings.Default.AllowedCoverTypes = coverType.Value;
            }

            //If the setting for using system codepage for id3 tags is set, instruct TagLib to do so.
            if (AlbumArtDownloader.Properties.Settings.Default.UseSystemCodepageForID3Tags)
            {
                TagLib.ByteVector.UseBrokenLatin1Behavior = true;
            }

            if (!showFileBrowser && !showFoobarBrowser && !showSearchWindow && !showConfigFile)             //If no windows will be shown, show the search window
            {
                showSearchWindow = true;
            }

            if (showFileBrowser)
            {
                FileBrowser browserWindow = new FileBrowser();
                if (showMinimized)
                {
                    browserWindow.WindowState = WindowState.Minimized;
                }
                browserWindow.Show();

                if (!String.IsNullOrEmpty(fileBrowser))
                {
                    browserWindow.Search(fileBrowser,
                                         AlbumArtDownloader.Properties.Settings.Default.FileBrowseSubfolders,                                                //TODO: Should the browse subfolders flag be a command line parameter?
                                         AlbumArtDownloader.Properties.Settings.Default.FileBrowseImagePath,
                                         AlbumArtDownloader.Properties.Settings.Default.FileBrowseUsePathPattern ? AlbumArtDownloader.Properties.Settings.Default.FileBrowsePathPattern : null
                                         );
                }
            }

            if (showFoobarBrowser)
            {
                FoobarBrowser browserWindow = new FoobarBrowser();
                if (showMinimized)
                {
                    browserWindow.WindowState = WindowState.Minimized;
                }
                browserWindow.Show();

                if (startFoobarBrowserSearch)
                {
                    browserWindow.Search(AlbumArtDownloader.Properties.Settings.Default.FileBrowseImagePath);                     //TODO: Should foobar browser have a separate path setting?
                }
            }

            if (showSearchWindow)
            {
                ArtSearchWindow searchWindow = null;
                if ((artist != null || album != null) &&                                      //If doing a new search
                    !forceNewWindow &&                                                        //And not forcing a new window
                    !AlbumArtDownloader.Properties.Settings.Default.OpenResultsInNewWindow && //And the option is to open results in the same window
                    Windows.Count == 1)                                                       //And only one window is open
                {
                    searchWindow = Windows[0] as ArtSearchWindow;                             //And if that window is an ArtSearchWindow, then re-use it
                }

                if (searchWindow == null)
                {
                    searchWindow = new ArtSearchWindow();
                    if (showMinimized)
                    {
                        searchWindow.WindowState = WindowState.Minimized;
                    }

                    SearchQueue.EnqueueSearchWindow(searchWindow, false);                     //Don't load from settings on show, otherwise they'll override the settings specified on the command line
                }
                else
                {
                    searchWindow.Activate();                     //Bring the window to the foreground
                }

                if (autoClose.HasValue)
                {
                    searchWindow.OverrideAutoClose(autoClose.Value);
                }
                if (path != null)
                {
                    searchWindow.SetDefaultSaveFolderPattern(path);
                }
                if (localImagesPath != null)
                {
                    searchWindow.SetLocalImagesPath(localImagesPath);
                }
                if (useSources.Count > 0)
                {
                    searchWindow.UseSources(useSources);
                }
                if (excludeSources.Count > 0)
                {
                    searchWindow.ExcludeSources(excludeSources);
                }
                if (includeSources.Count > 0)
                {
                    searchWindow.IncludeSources(includeSources);
                }

                if (artist != null || album != null)
                {
                    searchWindow.Search(artist, album);
                    if (SearchQueue.Queue.Count == 1)
                    {
                        //This is the first item enqueued, so show the queue manager window
                        SearchQueue.ShowManagerWindow();
                    }
                }
                else
                {
                    //Showing a new search window without performing a search, so force show it.
                    SearchQueue.ForceSearchWindow(searchWindow);
                }
            }

            if (showConfigFile)
            {
                AlbumArtDownloader.Properties.Settings.Default.Save();
                string configName = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath;
                System.Diagnostics.Process.Start("notepad.exe", configName);

                if (!showFileBrowser && !showFoobarBrowser && !showSearchWindow)                 //If no other windows will be shown, exit now
                {
                    return(false);
                }
            }

            // Set up jumplist for taskbar button
            TaskbarHelper.CreateApplicationJumpList();

            if (AlbumArtDownloader.Properties.Settings.Default.AutoUpdateEnabled)
            {
                //Check for updates if enough time has elapsed.
                Updates.CheckForUpdates(false);
            }

            return(true);
        }