public static FileSharperSettings Load() { FileSharperSettings settings = null; try { EnsureSettingsDirectoryPath(); } catch (Exception) { } try { string json = File.ReadAllText(SettingsPath); settings = JsonConvert.DeserializeObject <FileSharperSettings>(json); settings.Loaded = true; } catch (Exception) { settings = new FileSharperSettings(); } try { SyncTemplatesToFilesystem(settings); } catch (Exception) { } return(settings); }
public static void SyncTemplatesToFilesystem(FileSharperSettings settings) { EnsureTemplatesDirectoryPath(); IEnumerable <FileInfo> templateFiles; DirectoryInfo dir; dir = new DirectoryInfo(StockTemplatesDirectoryPath); templateFiles = dir.GetFiles("*.fsh").OrderBy(f => f.Name); foreach (FileInfo file in templateFiles) { if (!settings.Templates.Any(t => t.Stock && file.Name.Equals(t.FileName))) { string displayName = Path.GetFileNameWithoutExtension(file.Name); displayName = Regex.Replace(displayName, @"^\d+\s*", string.Empty); settings.Templates.Add(new SearchTemplateInfo(file.Name, displayName, true)); } } dir = new DirectoryInfo(UserTemplatesDirectoryPath); templateFiles = dir.GetFiles("*.fsh").OrderBy(f => f.Name); foreach (FileInfo file in templateFiles) { if (!settings.Templates.Any(t => !t.Stock && file.Name.Equals(t.FileName))) { settings.Templates.Add(new SearchTemplateInfo(file.Name, Path.GetFileNameWithoutExtension(file.Name))); } } List <SearchTemplateInfo> toRemove = new List <SearchTemplateInfo>(); foreach (SearchTemplateInfo template in settings.Templates) { if (!File.Exists(template.FileFullName)) { toRemove.Add(template); } } foreach (SearchTemplateInfo template in toRemove) { settings.Templates.Remove(template); } }