Inheritance: Banshee.Sources.PrimarySource
        public SourceWatcher (LibrarySource library)
        {
            this.library = library;
            handle = new ManualResetEvent(false);
            string path = library.BaseDirectoryWithSeparator;
            string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar;
            if (path == home) {
                throw new Exception ("Will not create LibraryWatcher for the entire home directory");
            }

            import_manager = ServiceManager.Get<LibraryImportManager> ();

            watcher = new FileSystemWatcher (path);
            watcher.IncludeSubdirectories = true;
            watcher.Changed += OnChanged;
            watcher.Created += OnChanged;
            watcher.Deleted += OnChanged;
            watcher.Renamed += OnChanged;

            active = true;
            watch_thread = new Thread (new ThreadStart (Watch));
            watch_thread.Name = String.Format ("LibraryWatcher for {0}", library.Name);
            watch_thread.IsBackground = true;
            watch_thread.Start ();
        }
Beispiel #2
0
        internal DapLibrarySync(DapSync sync, LibrarySource library)
        {
            this.sync = sync;
            this.library = library;

            BuildPreferences ();
            BuildSyncLists ();
        }
Beispiel #3
0
        public SourceWatcher(LibrarySource library)
        {
            this.library = library;
            handle = new ManualResetEvent(false);
            string path = library.BaseDirectoryWithSeparator;
            if (String.IsNullOrEmpty (path)) {
                throw new Exception ("Will not create LibraryWatcher for the blank directory");
            }

            string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar;
            if (path == home) {
                throw new Exception ("Will not create LibraryWatcher for the entire home directory");
            }

            string root = Path.GetPathRoot (Environment.CurrentDirectory);
            if (path == root || path == root + Path.DirectorySeparatorChar) {
                throw new Exception ("Will not create LibraryWatcher for the entire root directory");
            }

            if (!Banshee.IO.Directory.Exists (path)) {
                throw new Exception ("Will not create LibraryWatcher for non-existent directory");
            }

            import_manager = ServiceManager.Get<LibraryImportManager> ();

            watcher = new FileSystemWatcher (path);
            watcher.IncludeSubdirectories = true;
            watcher.Changed += OnModified;
            watcher.Created += OnModified;
            watcher.Deleted += OnModified;
            watcher.Renamed += OnModified;

            active = true;
            watch_thread = new Thread (new ThreadStart (Watch));
            watch_thread.Name = String.Format ("LibraryWatcher for {0}", library.Name);
            watch_thread.IsBackground = true;
            watch_thread.Start ();
        }
        public SourceWatcher (LibrarySource library)
        {
            this.library = library;
            handle = new ManualResetEvent(false);
            string path = library.BaseDirectoryWithSeparator;
            string home = Environment.GetFolderPath (Environment.SpecialFolder.Personal) + Path.DirectorySeparatorChar;
            if (path == home) {
                throw new Exception ("Will not create LibraryWatcher for the entire home directory");
            }

            import_manager = ServiceManager.Get<LibraryImportManager> ();

            FileSystemWatcher master_watcher = new FileSystemWatcher (path);
            master_watcher.IncludeSubdirectories = true;
            master_watcher.Changed += OnChanged;
            master_watcher.Created += OnChanged;
            master_watcher.Deleted += OnChanged;
            master_watcher.Renamed += OnChanged;
            watcher.Add (master_watcher);

            foreach (string additional_path in ServiceManager.SourceManager.ActiveSource.Properties.Get<string[]> ("AdditionalWatchedDirectories")) {
                Hyena.Log.DebugFormat ("Watcher: additional LibraryWatcher for {0}", additional_path);
                FileSystemWatcher additional_watcher = new FileSystemWatcher (additional_path);
                additional_watcher.IncludeSubdirectories = true;
                additional_watcher.Changed += OnChanged;
                additional_watcher.Created += OnChanged;
                additional_watcher.Deleted += OnChanged;
                additional_watcher.Renamed += OnChanged;
                watcher.Add (additional_watcher);
            }

            active = true;
            watch_thread = new Thread (new ThreadStart (Watch));
            watch_thread.Name = String.Format ("LibraryWatcher for {0}", library.Name);
            watch_thread.IsBackground = true;
            watch_thread.Start ();
        }
        /*
        private void OnSourceAdded (SourceAddedArgs args)
        {
            var library = args.Source as LibrarySource;
            if (library != null) {
                AddLibrary (library);
            }
        }

        private void OnSourceRemoved (SourceEventArgs args)
        {
            var library = args.Source as LibrarySource;
            if (library != null) {
                RemoveLibrary (library);
            }
        }
        */

        private void AddLibrary (LibrarySource library)
        {
            if (!Banshee.IO.Directory.Exists(library.BaseDirectoryWithSeparator)) {
                Hyena.Log.DebugFormat ("Will not watch library {0} because its folder doesn't exist: {1}",
                    library.Name, library.BaseDirectoryWithSeparator);
                return;
            }
            lock (watchers) {
                if (!watchers.ContainsKey (library)) {
                    try {
                        var dir = library.BaseDirectoryWithSeparator;
                        if (!Banshee.IO.Directory.Exists (dir)) {
                            Hyena.Log.DebugFormat ("Skipped LibraryWatcher for {0} ({1})", library.Name, dir);
                        } else {
                            watchers[library] = new SourceWatcher (library);
                            Hyena.Log.DebugFormat ("Started LibraryWatcher for {0} ({1})", library.Name, dir);
                        }
                    } catch (Exception e) {
                        Hyena.Log.Exception (e);
                    }
                }
            }
        }
        private void UnmonitorLibrary(LibrarySource library)
        {
            if (library == null || !libraries.Contains (library)) {
                return;
            }

            library.TracksAdded -= OnLibraryChanged;
            library.TracksDeleted -= OnLibraryChanged;
            library.TracksChanged -= OnLibraryChanged;

            libraries.Remove (library);
        }
        private void MonitorLibrary(LibrarySource library)
        {
            if (library == null || !library.Indexable || libraries.Contains (library)) {
                return;
            }

            libraries.Add (library);

            library.TracksAdded += OnLibraryChanged;
            library.TracksDeleted += OnLibraryChanged;
            library.TracksChanged += OnLibraryChanged;
        }