Ejemplo n.º 1
0
        public void Show(Updates updates)
        {
            if (updates.RestartPending)
            {
                DisplayRestartPending();
            }
            else if (updates.HasApplicationUpdate)
            {
                mLabel.Text = "A new version of Album Art Downloader XUI is available. It is recommended that you upgrade to the latest version, as new scripts may not be compatible with the current version. Click on the link below to visit the download page:";
                mApplicationDownloadLink.Content          = updates.ApplicationUpdateName;
                mApplicationDownloadLink.CommandParameter = updates.ApplicationUpdateUri.AbsoluteUri;
                mApplicationDownloadLink.ToolTip          = updates.ApplicationUpdateUri.AbsoluteUri;

                mApplicationDownloadLink.Visibility = Visibility.Visible;
                mScriptUpdatesViewer.Visibility     = Visibility.Hidden;

                mActionButton.IsEnabled = false;
                mCancelButton.Content   = "Close";
            }
            else if (!updates.AvailableScripts.Any())
            {
                //No updates available
                mLabel.Text = "No new scripts are currently available.";
                mScriptUpdatesViewer.Visibility = Visibility.Hidden;
                mActionButton.IsEnabled         = false;
                mCancelButton.Content           = "Close";
            }
            else
            {
                mScriptUpdatesViewer.ItemsSource = updates.AvailableScripts;

                mScriptUpdatesViewer.Items.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
            }

            mUpdates = updates;

            Show();
        }
Ejemplo n.º 2
0
        public void Show(Updates updates)
        {
            if (updates.RestartPending)
            {
                DisplayRestartPending();
            }
            else if (updates.HasApplicationUpdate)
            {
                mLabel.Text = "A new version of Album Art Downloader XUI is available. Click on the link below to visit the download page:";
                mApplicationDownloadLink.Content          = updates.ApplicationUpdateName;
                mApplicationDownloadLink.CommandParameter = updates.ApplicationUpdateUri.AbsoluteUri;
                mApplicationDownloadLink.ToolTip          = updates.ApplicationUpdateUri.AbsoluteUri;

                mApplicationDownloadLink.Visibility = Visibility.Visible;
                mScriptUpdatesViewer.Visibility     = Visibility.Hidden;

                mActionButton.IsEnabled = false;
                mCancelButton.Content   = "Close";
            }
            else if (!updates.ScriptUpdates.Any())
            {
                //No updates available
                mLabel.Text = "No updates are currently available.";
                mScriptUpdatesViewer.Visibility = Visibility.Hidden;
                mActionButton.IsEnabled         = false;
                mCancelButton.Content           = "Close";
            }
            else
            {
                mScriptUpdatesViewer.ItemsSource = updates.ScriptUpdates;
            }

            mUpdates = updates;

            Show();
        }
Ejemplo n.º 3
0
 private static void CheckForUpdatesExec(object sender, ExecutedRoutedEventArgs e)
 {
     //Force a check for updates now
     Updates.CheckForUpdates(true);
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Downloads the latest Updates XML file and produces an <see cref="Updates"/> list of available
        /// updates from it
        /// </summary>
        private static void PerformUpdateCheck(object state)
        {
            try
            {
                PerformUpdateCheckParameters parameters = (PerformUpdateCheckParameters)state;

                Updates updates = new Updates();

                try
                {
                    XmlDocument updatesXml = new XmlDocument();
                    updatesXml.Load(Properties.Settings.Default.UpdatesURI.AbsoluteUri);

                    Uri baseUri = new Uri(updatesXml.DocumentElement.GetAttribute("BaseURI"));

                    //Check to see if there is an application update available
                    XmlElement appUpdateXml = updatesXml.SelectSingleNode("/Updates/Application") as XmlElement;
                    if (appUpdateXml != null)
                    {
                        Version newAppVersion = new Version(appUpdateXml.GetAttribute("Version"));

                        if (newAppVersion > Assembly.GetEntryAssembly().GetName().Version)
                        {
                            //Theres a new application version, so return an update with just that
                            Uri uri = new Uri(baseUri, appUpdateXml.GetAttribute("URI"));

                            updates.SetAppUpdate(appUpdateXml.GetAttribute("Name"), uri);
                        }
                    }

                    //Create a lookup of all current scripts and their versions
                    Dictionary <String, String> scripts = new Dictionary <String, String>();
                    foreach (IScript script in ((App)Application.Current).Scripts)
                    {
                        scripts.Add(script.Name, script.Version);
                    }

                    foreach (XmlElement scriptUpdateXml in updatesXml.SelectNodes("/Updates/Script"))
                    {
                        string name       = scriptUpdateXml.GetAttribute("Name");
                        string newVersion = scriptUpdateXml.GetAttribute("Version");

                        //Check to see if there is an older version of this script to update
                        string currentVersion;
                        if (scripts.TryGetValue(name, out currentVersion))
                        {
                            if (currentVersion != newVersion)
                            {
                                updates.AddScriptUpdate(new ScriptUpdate(name, currentVersion, newVersion, GetDownloadFiles(baseUri, scriptUpdateXml)));
                            }
                        }
                        else
                        {
                            updates.AddAvailableScript(new ScriptUpdate(name, null, newVersion, GetDownloadFiles(baseUri, scriptUpdateXml)));
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.TraceError("Could not parse update xml from \"{0}\": {1}", Properties.Settings.Default.UpdatesURI.AbsoluteUri, ex.Message);
                }

                Properties.Settings.Default.NewScriptsAvailable = updates.mAvailableScripts.Count > 0;

                if (parameters.ShowUI == PerformUpdateCheckParameters.UI.NewScripts)
                {
                    parameters.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(delegate
                    {
                        if (sNewScriptsViewer != null)
                        {
                            sNewScriptsViewer.Close();
                        }
                        sNewScriptsViewer = new NewScriptsViewer();
                        sNewScriptsViewer.Show(updates);
                        sNewScriptsViewer.Closed += new EventHandler(delegate { sNewScriptsViewer = null; });
                    }));
                }
                else
                {
                    //If not showing the New Scripts UI, and no application update is available, then check for auto-downloading new scripts
                    if (sNewScriptsViewer == null &&
                        !updates.HasApplicationUpdate &&
                        updates.mAvailableScripts.Count > 0 &&
                        Properties.Settings.Default.AutoDownloadAllScripts)
                    {
                        //Automatically download all newly available scripts
                        foreach (var script in updates.mAvailableScripts)
                        {
                            script.Download();
                            sRestartPending = true;

                            parameters.Dispatcher.BeginInvoke(DispatcherPriority.DataBind, new ThreadStart(delegate
                            {
                                AutoDownloadedScripts.Add(script);
                            }));
                        }

                        Properties.Settings.Default.NewScriptsAvailable = false;
                    }

                    if (parameters.ShowUI == PerformUpdateCheckParameters.UI.Updates || //Show the updates viewer if specifically requested.
                        updates.mScriptUpdates.Count > 0 ||                             //If not requested, only show if there are updates to be shown
                        updates.HasApplicationUpdate)
                    {
                        parameters.Dispatcher.Invoke(DispatcherPriority.Normal, new ThreadStart(delegate
                        {
                            if (sUpdatesViewer != null)
                            {
                                sUpdatesViewer.Close();
                            }
                            sUpdatesViewer = new UpdatesViewer();
                            sUpdatesViewer.Show(updates);
                            sUpdatesViewer.Closed += new EventHandler(delegate { sUpdatesViewer = null; });
                        }));
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.TraceError("Check for online updates failed: {0}", ex.Message);
            }
        }
Ejemplo n.º 5
0
 private void GetMoreScriptsExec(object sender, ExecutedRoutedEventArgs e)
 {
     Updates.ShowNewScripts();
 }
Ejemplo n.º 6
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);
        }