public async Task StartWatchingAsync()
        {
            await this.StopWatchingAsync();

            List <Folder> folders = await this.folderRepository.GetFoldersAsync();

            foreach (Folder fol in folders)
            {
                if (Directory.Exists(fol.Path))
                {
                    try
                    {
                        // When the folder exists, but access is denied, creating the FileSystemWatcher throws an exception.
                        var watcher = new GentleFolderWatcher(fol.Path, true, 2000);
                        watcher.FolderChanged += Watcher_FolderChanged;
                        this.watchers.Add(watcher);
                        watcher.Resume();
                    }
                    catch (Exception ex)
                    {
                        LogClient.Error($"Could not watch folder '{fol.Path}', even though it exists. Please check folder permissions. Exception: {ex.Message}");
                    }
                }
            }
        }
Exemple #2
0
        public I18nService()
        {
            // Initialize the CustomLanguages directory
            // ----------------------------------------
            if (!Directory.Exists(this.customLanguagesDirectory))
            {
                Directory.CreateDirectory(System.IO.Path.Combine(this.customLanguagesDirectory));
            }

            this.LoadLanguages();

            // Watcher
            // -------
            this.watcher = new GentleFolderWatcher(this.customLanguagesDirectory, false);
            this.watcher.FolderChanged += Watcher_FolderChanged;
            this.watcher.Resume();
        }
        public PlaylistService(ITrackRepository trackRepository,
                               IFileService fileService, IContainerProvider container)
        {
            // Dependency injection
            this.trackRepository = trackRepository;
            this.fileService     = fileService;
            this.container       = container;

            // Initialize Playlists folder
            string musicFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);

            this.PlaylistFolder = Path.Combine(musicFolder, ProductInformation.ApplicationName, "Playlists");

            if (!Directory.Exists(this.PlaylistFolder))
            {
                try
                {
                    Directory.CreateDirectory(this.PlaylistFolder);
                }
                catch (Exception ex)
                {
                    LogClient.Error("Could not create Playlists folder. Exception: {0}", ex.Message);
                }
            }

            // Watcher
            this.watcher = new GentleFolderWatcher(this.PlaylistFolder, false);
            this.watcher.FolderChanged += (_, __) =>
            {
                Application.Current.Dispatcher.Invoke(() =>
                {
                    this.PlaylistFolderChanged(this, new EventArgs());
                });
            };

            this.watcher.Resume();
        }
        public AppearanceService(IPlaybackService playbackService, IMetadataService metadataService) : base()
        {
            // Services
            // --------
            this.playbackService = playbackService;
            this.metadataService = metadataService;

            playbackService.PlaybackSuccess += PlaybackService_PlaybackSuccess;

            // Initialize the ColorSchemes directory
            // -------------------------------------
            this.colorSchemesSubDirectory = Path.Combine(SettingsClient.ApplicationFolder(), ApplicationPaths.ColorSchemesFolder);

            // If the ColorSchemes subdirectory doesn't exist, create it
            if (!Directory.Exists(this.colorSchemesSubDirectory))
            {
                Directory.CreateDirectory(Path.Combine(this.colorSchemesSubDirectory));
            }

            // Create the example ColorScheme
            // ------------------------------
            string exampleColorSchemeFile = Path.Combine(this.colorSchemesSubDirectory, "Red.xml");

            if (System.IO.File.Exists(exampleColorSchemeFile))
            {
                System.IO.File.Delete(exampleColorSchemeFile);
            }

            XDocument exampleColorSchemeXml = XDocument.Parse("<ColorScheme><AccentColor>#E53935</AccentColor></ColorScheme>");

            exampleColorSchemeXml.Save(exampleColorSchemeFile);

            // Create the "How to create ColorSchemes.txt" file
            // ------------------------------------------------

            string howToFile = Path.Combine(this.colorSchemesSubDirectory, "How to create ColorSchemes.txt");

            if (System.IO.File.Exists(howToFile))
            {
                System.IO.File.Delete(howToFile);
            }

            string[] lines =
            {
                "How to create ColorSchemes?",
                "---------------------------",
                "",
                "1. Copy and rename the file Red.xml",
                "2. Open the file and edit the color code of AccentColor",
                "3. Your ColorScheme appears automatically in " + ProductInformation.ApplicationName
            };

            System.IO.File.WriteAllLines(howToFile, lines, System.Text.Encoding.UTF8);


            // Watcher
            // -------
            this.watcher = new GentleFolderWatcher(this.colorSchemesSubDirectory, false);
            this.watcher.FolderChanged += Watcher_FolderChanged;
            this.watcher.Resume();

            // Get the available ColorSchemes
            // ------------------------------
            this.GetAllColorSchemes();
        }