Beispiel #1
0
		/// <summary>
		/// Remove a source from the collection
		/// </summary>
		/// <param name="source">The source to be removed</param>
		public static void RemoveSource(SourceData source)
		{
			if (!SettingsManager.Sources.Contains(source))
			{
				U.L(LogLevel.Warning, "FILESYSTEM", "Trying to remove non-existing source " + source.Data);
				return;
			}
			DispatchSourceRemoved(source);
			ScanSources();
		}
Beispiel #2
0
		/// <summary>
		/// Scans for system specific folders of music and adds them to the source collection.
		/// </summary>
		/// <remarks>
		/// The following will be added for supported platforms:
		/// Windows: Libraries of type "Music"
		/// </remarks>
		/// <param name="ScanSourcesWhenDone">Set to true to scan the folders afterwards</param>
		/// <param name="InBackground">Set to true to perform the scan in a background thread</param>
		public static void AddSystemFolders(bool ScanSourcesWhenDone = false, bool InBackground = true)
		{
			WaitForInitialization();

			ThreadStart ScanThread = delegate()
			{
#if (Windows)
				String librariesPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
					+ @"\AppData\Roaming\Microsoft\Windows\Libraries\";

				// remove non-existing libraries from sources
				for (int i = 0; i < SettingsManager.Sources.Count; i++)
					if (SettingsManager.Sources[i].Type == SourceType.Library &&
						!System.IO.File.Exists(librariesPath + SettingsManager.Sources[i].Data + ".library-ms"))
						SettingsManager.Sources.RemoveAt(i--);

				// add newly created libraries
				DirectoryInfo librariesInfo = new DirectoryInfo(librariesPath);
				FileInfo[] libraries = librariesInfo.GetFiles("*.library-ms");
				foreach (FileInfo libraryInfo in libraries)
				{
					String libraryName = System.IO.Path.GetFileNameWithoutExtension(libraryInfo.FullName);
					ShellLibrary library = ShellLibrary.Load(libraryName, librariesPath, true);

					// newly created libraries will not get a LibraryType so we get an exception here
					try
					{
						// make sure that the library is added
						if (library.LibraryType == LibraryFolderType.Music)
						{
							bool AlreadyAdded = false;
							foreach (SourceData src in SettingsManager.Sources)
							{
								if (src.Data == libraryName && src.Type == SourceType.Library)
								{
									AlreadyAdded = true;
									break;
								}
							}
							if (!AlreadyAdded)
							{
								SourceData s = new SourceData();
								s.Data = libraryName;
								s.Automatic = true;
								s.Type = SourceType.Library;
								s.Include = true;
								s.Icon = "pack://*****:*****@"\AppData\Roaming\Microsoft\Windows\Libraries\";
					fsw.Filter = "*.library-ms";
					fsw.IncludeSubdirectories = false;
					fsw.NotifyFilter = NotifyFilters.Attributes | NotifyFilters.CreationTime | NotifyFilters.DirectoryName | NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
					fsw.Changed += Janitor_LibraryChanged;
					fsw.Created += Janitor_LibraryChanged;
					fsw.Deleted += Janitor_LibraryChanged;
					fsw.Renamed += Janitor_LibraryRenamed;
					fsw.EnableRaisingEvents = true;
					janitors.Add(fsw);
				}
				if (ScanSourcesWhenDone) ScanSources();
#else
				SettingsManager.Sources.Add(new SourceData
				{
					HumanType = U.T("SourcesTypeFolder"),
					Type = SourceType.Folder,
					Automatic = true,
					Data = @"C:\Users\ephracis\Music\",
					Include = true,
					Icon = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/Folder.ico"
				});
#endif
			};

			Thread thread = new Thread(ScanThread);
			thread.Name = "Scan libraries";
			thread.Priority = ThreadPriority.BelowNormal;
			thread.Start();
			if (!InBackground)
				thread.Join();
		}
Beispiel #3
0
		/// <summary>
		/// Add a source to the collection
		/// </summary>
		/// <param name="source">The source to be added</param>
		/// <param name="callback">A function that will be sent along with the SourceModified event</param>
		/// <param name="callbackParams">The parameters for the callback function</param>
		public static void AddSource(SourceData source, ScannerCallback callback = null, object callbackParams = null)
		{
			U.L(LogLevel.Information, "FILESYSTEM", String.Format("{0} the {1} {2}", 
				(source.Include ? "Adding" : "Ignoring"), source.Type, source.Data));

			SourceTree s = GetSourceTree(source.Data, sourceForest);

			if (s != null)
			{
				U.L(LogLevel.Warning, "FILESYSTEM", String.Format("Removing currently {0} {1} {2}",
					(source.Include ? "added" : "ignored"), source.Type, source.Data));
				RemoveSource(source);
			}

			DispatchSourceAdded(source);
			ScanSourcesWithDelay(callback, callbackParams);
		}
Beispiel #4
0
		/// <summary>
		/// Add a source to the collection
		/// </summary>
		/// <param name="path">The path of source to be added</param>
		/// <param name="callback">A function that will be sent along with the SourceModified event</param>
		/// <param name="callbackParams">The parameters for the callback function</param>
		public static void AddSource(string path, ScannerCallback callback = null, object callbackParams = null)
		{
			SourceData s = null;
			if (File.Exists(path))
			{
				s = new SourceData()
				{
					Data = path,
					Type = SourceType.File,
					Icon = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/FileAudio.ico",
					Include = true
				};
			}
			else if (Directory.Exists(path))
			{
				s = new SourceData()
				{
					Data = path,
					Type = SourceType.Folder,
					Icon = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/Folder.ico",
					Include = true
				};
			}
			else
			{
				s = new SourceData()
				{
					Data = path,
					Type = SourceType.Library,
					Icon = "pack://application:,,,/Platform/Windows 7/GUI/Images/Icons/Library.ico",
					Include = true
				};
			}
			if (s != null)
				AddSource(s, callback, callbackParams);
		}
Beispiel #5
0
		/// <summary>
		/// Toggle a source between Include and Ignore
		/// </summary>
		/// <param name="source">The source to toggle</param>
		public static void ToggleSource(SourceData source)
		{
			source.Include = !source.Include;
			ScanSources();
		}
Beispiel #6
0
		/// <summary>
		/// Initializes a new instance of the <see cref="SourcesModifiedEventArgs"/> class
		/// </summary>
		/// <param name="source">The source that was modified</param>
		public SourcesModifiedEventArgs(SourceData source)
		{
			Source = source;
		}
Beispiel #7
0
		/// <summary>
		/// The dispatcher of the <see cref="SourceRemoved"/> event
		/// </summary>
		/// <param name="source">The source that was removed</param>
		private static void DispatchSourceRemoved(SourceData source)
		{
			if (SourceRemoved != null)
				SourceRemoved(null, new SourcesModifiedEventArgs(source));
		}