public void LoadSettings() { try { var appdatpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); var setpath = Path.Combine(appdatpath, @"TLCGen\Templates\"); if (!Directory.Exists(setpath)) { Directory.CreateDirectory(setpath); } var setfile = Path.Combine(setpath, @"templates.xml"); if (File.Exists(setfile)) { Templates = TLCGenSerialization.DeSerialize <TLCGenTemplatesModel>(setfile); } else if (File.Exists(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml"))) { Templates = TLCGenSerialization.DeSerialize <TLCGenTemplatesModel>(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml")); } else { MessageBox.Show("Could not find defaults for default settings. None loaded.", "Error loading defaults"); setfile = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaultdefaults.xml"); Templates = new TLCGenTemplatesModel(); return; } } catch (Exception e) { MessageBox.Show("Error while loading templates: " + e.ToString(), "Error while loading templates"); } }
public void LoadSettings() { try { Templates = new TLCGenTemplatesModel(); _LoadedTemplates = new List <TLCGenTemplatesModelWithLocation>(); if (SettingsProvider.Default.Settings.UseFolderForTemplates) { if (!string.IsNullOrWhiteSpace(SettingsProvider.Default.Settings.TemplatesLocation) && Directory.Exists(SettingsProvider.Default.Settings.TemplatesLocation)) { var files = Directory.EnumerateFiles(SettingsProvider.Default.Settings.TemplatesLocation, "*.xml"); foreach (var f in files) { try { var t = TLCGenSerialization.DeSerialize <TLCGenTemplatesModel>(f); var twl = new TLCGenTemplatesModelWithLocation { Location = Path.GetFileNameWithoutExtension(f), Editable = true, Templates = t }; _LoadedTemplates.Add(twl); if (t.FasenTemplates != null) { foreach (var tfc in t.FasenTemplates) { Templates.FasenTemplates.Add(tfc); } } if (twl.Templates.DetectorenTemplates != null) { foreach (var td in t.DetectorenTemplates) { Templates.DetectorenTemplates.Add(td); } } if (twl.Templates.PeriodenTemplates != null) { foreach (var tp in t.PeriodenTemplates) { Templates.PeriodenTemplates.Add(tp); } } } catch { // ignored (file not right) } } } if (string.IsNullOrWhiteSpace(SettingsProvider.Default.Settings.TemplatesLocation) || !string.IsNullOrWhiteSpace(SettingsProvider.Default.Settings.TemplatesLocation) && !Directory.Exists(SettingsProvider.Default.Settings.TemplatesLocation)) { if (!string.IsNullOrWhiteSpace(SettingsProvider.Default.Settings.TemplatesLocation) && !Directory.Exists(SettingsProvider.Default.Settings.TemplatesLocation)) { MessageBox.Show("De ingestelde map met templates is niet gevonden\n\n" + $"{SettingsProvider.Default.Settings.TemplatesLocation}\n\n" + $"De default templates worden geladen", "Map met templates niet gevonden"); } if (File.Exists(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml"))) { var t = TLCGenSerialization.DeSerialize <TLCGenTemplatesModel>(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml")); var twl = new TLCGenTemplatesModelWithLocation { Location = Path.GetFileNameWithoutExtension(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml")), Editable = false, Templates = t }; _LoadedTemplates.Add(twl); if (t.FasenTemplates != null) { foreach (var tfc in t.FasenTemplates) { Templates.FasenTemplates.Add(tfc); } } if (t.DetectorenTemplates != null) { foreach (var td in t.DetectorenTemplates) { Templates.DetectorenTemplates.Add(td); } } if (t.PeriodenTemplates != null) { foreach (var tp in t.PeriodenTemplates) { Templates.PeriodenTemplates.Add(tp); } } } else { MessageBox.Show("Could not find defaults for default settings. None loaded.", "Error loading default template"); Templates = new TLCGenTemplatesModel(); return; } } } else { if (SettingsProvider.Default.Settings.TemplatesLocation != null && File.Exists(SettingsProvider.Default.Settings.TemplatesLocation)) { try { var t = TLCGenSerialization.DeSerialize <TLCGenTemplatesModel>(SettingsProvider.Default.Settings.TemplatesLocation); var twl = new TLCGenTemplatesModelWithLocation { Location = Path.GetFileNameWithoutExtension(SettingsProvider.Default.Settings.TemplatesLocation), Editable = true, Templates = t }; _LoadedTemplates.Add(twl); if (t.FasenTemplates != null) { foreach (var tfc in t.FasenTemplates) { Templates.FasenTemplates.Add(tfc); } } if (t.DetectorenTemplates != null) { foreach (var td in t.DetectorenTemplates) { Templates.DetectorenTemplates.Add(td); } } if (t.PeriodenTemplates != null) { foreach (var tp in t.PeriodenTemplates) { Templates.PeriodenTemplates.Add(tp); } } } catch { MessageBox.Show("Het ingestelde bestand voor templates heeft niet het juiste formaat:\n\n" + $"{SettingsProvider.Default.Settings.TemplatesLocation}\n\n" + $"De default templates worden geladen", "Verkeerd formaat"); } } if (string.IsNullOrWhiteSpace(SettingsProvider.Default.Settings.TemplatesLocation) || !string.IsNullOrWhiteSpace(SettingsProvider.Default.Settings.TemplatesLocation) && !File.Exists(SettingsProvider.Default.Settings.TemplatesLocation)) { if (!string.IsNullOrWhiteSpace(SettingsProvider.Default.Settings.TemplatesLocation) && !File.Exists(SettingsProvider.Default.Settings.TemplatesLocation)) { MessageBox.Show("Het ingestelde bestand voor templates is niet gevonden\n\n" + $"{SettingsProvider.Default.Settings.TemplatesLocation}\n\n" + $"De default templates worden geladen", "Bestand met templates niet gevonden"); } if (File.Exists(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml"))) { var t = TLCGenSerialization.DeSerialize <TLCGenTemplatesModel>(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml")); var twl = new TLCGenTemplatesModelWithLocation { Location = Path.GetFileNameWithoutExtension(Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "Settings\\tlcgendefaulttemplates.xml")), Editable = false, Templates = t }; _LoadedTemplates.Add(twl); if (t.FasenTemplates != null) { foreach (var tfc in t.FasenTemplates) { Templates.FasenTemplates.Add(tfc); } } if (twl.Templates.DetectorenTemplates != null) { foreach (var td in t.DetectorenTemplates) { Templates.DetectorenTemplates.Add(td); } } if (twl.Templates.PeriodenTemplates != null) { foreach (var tp in t.PeriodenTemplates) { Templates.PeriodenTemplates.Add(tp); } } } else { MessageBox.Show("Could not find defaults for templates. None loaded.", "Error loading default template"); Templates = new TLCGenTemplatesModel(); return; } } } } catch (Exception e) { MessageBox.Show("Error while loading templates: " + e.ToString(), "Error while loading templates"); } }