Beispiel #1
0
        //public static Dictionary<string, Track> TracksDictionary => _tracksDictionary;

        #endregion

        #region Private Methods

        private static void LoadDictionaries(string libraryLocation)
        {
            try
            {
                TunesXmlParser parser = new TunesXmlParser(libraryLocation);

                // If here then successful parse, therefore store the music folder.
                MusicFolder = parser.MusicFolder;

                // Establish if the Library Persistent ID is the one we expect.
                Setting setting = new Setting();

                // If we haven't stored this setting yet.
                if (!setting.Find(AppSetting.LibraryPersistentId))
                {
                    setting.SettingValue = parser.LibraryPersistentId;
                }
                else
                {
                    // Detect if the existing setting is different, i.e. Library connecting to is different.
                    if (setting.SettingValue != parser.LibraryPersistentId)
                    {
                        throw new Exception("This iTunes Library is different to the one you've been using previously.  To use a different iTunes Library, delete the RoadMusic Database by choosing File > Database > Reset Database...  Then restart RoadMusic.");
                    }
                }

                if (!setting.Update(AppSetting.LibraryPersistentId))
                {
                    throw new Exception("Sorry, there was a problem trying to update the Settings database.");
                }

                // Index by PersistentId and not Id, because the XML library can change Id.
                _playlistDictionary = new Dictionary <string, Playlist>();
                //_tracksDictionary = new Dictionary<string, Track>();

                foreach (Playlist playlist in parser.Playlists.Values)
                {
                    _playlistDictionary.Add(playlist.PersistentId, playlist);
                }

                // TODO: Use Tracks Dictionary?
                //foreach (Track objTrack in parser.Tracks.Values)
                //{
                //    _tracksDictionary.Add(objTrack.Id, objTrack);
                //}
            }
            catch (Exception ex)
            {
                // Throw out our own exception instead.
                throw new Exception(string.Format("Sorry, there was a problem with reading the iTunes Music Library from '{0}'.{1}{1}{2}", libraryLocation, Environment.NewLine, ex.Message));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get the default iTunes library.
        /// </summary>
        /// <returns></returns>
        private bool LoadDefaultLibraryLocation()
        {
            // Establish where the local library should be.
            string defaultLibraryLocation = TunesXmlParser.GetDefaultLibraryLocation();

            if (File.Exists(defaultLibraryLocation))
            {
                if (LoadLibrary(defaultLibraryLocation))
                {
                    EnableControls();
                    return(true);
                }

                DisableControls();
                return(false);
            }

            MessageBox.Show($"An iTunes Library file could not be found in the default location of '{defaultLibraryLocation}'.", AppGlobals.AppName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return(false);
        }