コード例 #1
0
        /// <inheritdoc />
        protected override void LoadPlugins(PluginCallback pluginCallback, IProgressMonitor progressMonitor)
        {
            // Attempt to read the old cache.
            string cacheFilePath;
            try
            {
                Hash64 hash = new Hash64();
                foreach (string pluginPath in PluginPaths)
                    hash = hash.Add(pluginPath);
                foreach (string constant in InitialPreprocessorConstants)
                    hash = hash.Add(constant);
                hash = hash.Add(InstallationId.ToString());

                string cacheDirPath = GetCurrentUserPluginCacheDir();
                string cacheFileName = hash + ".xml";
                cacheFilePath = Path.Combine(cacheDirPath, cacheFileName);

                if (Directory.Exists(cacheDirPath))
                {
                    if (File.Exists(cacheFilePath))
                    {
                        Cache oldCache = ReadCacheFile(cacheFilePath);
                        if (oldCache != null)
                        {
                            foreach (var pluginInfo in oldCache.PluginInfos)
                                pluginCallback(pluginInfo.Plugin, new DirectoryInfo(pluginInfo.BaseDirectory), pluginInfo.PluginFile);
                            return;
                        }
                    }
                }
                else
                {
                    Directory.CreateDirectory(cacheDirPath);
                }
            }
            catch (Exception)
            {
                // Fallback on any failure.
                // There can be all sorts of weird security exceptions that will prevent
                // us from manipulating the local application data directory.
                base.LoadPlugins(pluginCallback, progressMonitor);
                return;
            }

            // Load plugin metadata.
            var newCache = new Cache
            {
                InstallationId = InstallationId.ToString()
            };

            base.LoadPlugins((plugin, baseDirectory, pluginFile) =>
            {
                newCache.PluginInfos.Add(new CachePluginInfo
                {
                    Plugin = plugin,
                    BaseDirectory = baseDirectory.FullName,
                    PluginFile = pluginFile,
                    PluginFileModificationTime = File.GetLastWriteTimeUtc(pluginFile)
                });

                pluginCallback(plugin, baseDirectory, pluginFile);
            }, progressMonitor);

            // Attempt to store it in the cache.
            try
            {
                WriteCacheFile(cacheFilePath, newCache);
            }
            catch (Exception)
            {
                // Ignore any failure.
            }
        }
コード例 #2
0
 private void WriteCacheFile(string cacheFilePath, Cache cache)
 {
     using (var xmlWriter = XmlWriter.Create(cacheFilePath))
     {
         CacheXmlSerializer.Serialize(xmlWriter, cache);
     }
 }