public FileSystemCache DeserializeCache()
        {
            if (!File.Exists(_cacheFilePath))
            {
                return(null);
            }

            FileSystemCache cache;

            lock (CacheSync)
            {
                cache = ReadCache();
                if (File.Exists(_cacheChangesFilePath))
                {
                    FileSystemChanges changes = ReadChanges();

                    foreach (FileSystemChangeEventArgs fileSystemChangeArg in changes.Changes)
                    {
                        FileSystemParser.UpdateFolders(cache.Items, fileSystemChangeArg, null);
                    }
                    cache.LastFullScanTime = changes.LastFullScanTime;

                    SerializeCache(cache);
                }
            }

            GC.Collect();

            return(cache);
        }
Example #2
0
        private IFileSystemParser CreateParser(Settings settings)
        {
            //Don't use the same file system parser for cachedParser and AsyncFileSystemParser,
            //as AsyncFileSystemParser will operate on a different thread.
            IFileSystemParser basicParser     = new FileSystemParser(new FileSystemListener());
            ICacheSerializer  cacheSerializer = new CacheSerializer();
            IFileSystemParser cachedParser    = new CachedFileSystemParser(basicParser,
                                                                           cacheSerializer,
                                                                           new FileSystemListener(),
                                                                           new RegistryService(),
                                                                           new AsyncFileSystemParser(new FileSystemParser(new FileSystemListener())),
                                                                           _appRunOnStartup);

            cachedParser.ExcludeFolderTemplates = settings.ExcludeFolderTemplates;
            cachedParser.FoldersToParse         = settings.FoldersToParse;

            return(cachedParser);
        }