public static Configuration Create() { Configuration c = new Configuration(); XmlSerializer xs = new XmlSerializer(typeof(Configuration)); bool portable = File.Exists(Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "portable"); string configPath = portable ? Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) : Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData), "EvImSync"); configPath = Path.Combine(configPath, "EvImSync.xml"); if (File.Exists(configPath)) { using (FileStream fs = File.OpenRead(configPath)) { c = (Configuration)xs.Deserialize(fs); } SimpleAES simpleAES = new SimpleAES(); foreach (SyncPairSettings sps in c.SyncPairs) { sps.IMAPPassword = simpleAES.DecryptString(sps.IMAPPassword); } } return c; }
private void ConfigFrm_Load(object sender, EventArgs e) { config = Configuration.Create(); if (config.ENScriptPath.Length > 0) { enscriptPath.Text = config.ENScriptPath; } else { // try to find the ENScript path ourselves string path = System.Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86); path = Path.Combine(path, "Evernote"); if (Directory.Exists(path)) { foreach (string d in Directory.GetDirectories(path)) { string everPath = Path.Combine(path, d); string enscrPath = Path.Combine(everPath, "ENScript.exe"); if (File.Exists(enscrPath)) { enscriptPath.Text = enscrPath; break; } } } } // now fill all the pairs in the list control foreach (SyncPairSettings sps in config.SyncPairs) { pairList.Items.Add(sps.EvernoteNotebook); } deletePairButton.Enabled = pairList.SelectedItems.Count != 0; }