public void RebuildCacheFromSettingsIfNotCurrent(bool forceRebuild) { EnsureLoaded(); //For somereason, the FindMountpointsToScan has some expectation of locale specific caches being loaded; // For Initializr, just get all mountpoints MountPointInfo[] mountPointsToScan = GetAllMountPoints().ToArray(); //FindMountPointsToScan(forceRebuild).ToArray(); if (!mountPointsToScan.Any()) { // Nothing to do return; } var workingCache = new InitializrTemplateCache(_environmentSettings); foreach (MountPointInfo mountPoint in mountPointsToScan) { workingCache.Scan(mountPoint.Place); } Save(workingCache); ReloadTemplates(); }
public InitializrSettingsLoader(IEngineEnvironmentSettings environmentSettings, string hivePath) { _environmentSettings = environmentSettings; _paths = new Paths(environmentSettings); _userTemplateCache = new InitializrTemplateCache(environmentSettings); _installUnitDescriptorCache = new InstallUnitDescriptorCache(environmentSettings); _hivePath = hivePath; }
private void Save(InitializrTemplateCache cacheToSave) { // When writing the template caches, we need the existing cache version to read the existing caches for before updating. // so don't update it until after the template caches are written. cacheToSave.WriteTemplateCaches(_userSettings.Version); // now it's safe to update the cache version, which is written in the settings file. _userSettings.SetVersionToCurrent(); JObject serialized = JObject.FromObject(_userSettings); _paths.WriteAllText(_paths.User.SettingsFile, serialized.ToString()); WriteInstallDescriptorCache(); if (_userTemplateCache != cacheToSave) // object equals { ReloadTemplates(); } }
// Loads from the template cache private void EnsureTemplatesLoaded() { if (_templatesLoaded) { return; } string userTemplateCache; if (_paths.Exists(_paths.User.CurrentLocaleTemplateCacheFile)) { using (Timing.Over(_environmentSettings.Host, "Read template cache")) userTemplateCache = _paths.ReadAllText(_paths.User.CurrentLocaleTemplateCacheFile, "{}"); } else if (_paths.Exists(_paths.User.CultureNeutralTemplateCacheFile)) { // clone the culture neutral cache // this should not occur if there are any langpacks installed for this culture. // when they got installed, the cache should have been created for that locale. using (Timing.Over(_environmentSettings.Host, "Clone cultural neutral cache")) { userTemplateCache = _paths.ReadAllText(_paths.User.CultureNeutralTemplateCacheFile, "{}"); _paths.WriteAllText(_paths.User.CurrentLocaleTemplateCacheFile, userTemplateCache); } } else { userTemplateCache = "{}"; } JObject parsed; using (Timing.Over(_environmentSettings.Host, "Parse template cache")) parsed = JObject.Parse(userTemplateCache); using (Timing.Over(_environmentSettings.Host, "Init template cache")) _userTemplateCache = new InitializrTemplateCache(_environmentSettings, parsed, _userSettings.Version); _templatesLoaded = true; }
private void UpdateTemplateListFromCache(InitializrTemplateCache cache, ISet <ITemplateInfo> templates) { using (Timing.Over(_environmentSettings.Host, "Enumerate infos")) templates.UnionWith(cache.TemplateInfo); }