christian@0: /* christian@0: * Postarc christian@0: * christian@0: * Author: christian@0: * Christian Lins christian@0: * christian@0: * Copyright: christian@0: * Copyright (C) 2012 Intevation GmbH christian@0: * christian@0: * This program is free software: you can redistribute it and/or modify christian@0: * it under the terms of the GNU Lesser General Public License as published by christian@0: * the Free Software Foundation, either version 3 of the License, or christian@0: * (at your option) any later version. christian@0: * christian@0: * This program is distributed in the hope that it will be useful, christian@0: * but WITHOUT ANY WARRANTY; without even the implied warranty of christian@0: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the christian@0: * GNU General Public License for more details. christian@0: * christian@0: * You should have received a copy of the GNU Lesser General Public License christian@0: * along with this program. If not, see . christian@0: */ christian@0: christian@0: using System; christian@0: using System.Collections.Generic; christian@0: using System.Linq; christian@0: using System.Text; christian@0: using System.Windows.Forms; christian@0: using System.IO; christian@0: using System.Runtime.Serialization.Formatters.Binary; christian@0: using System.Runtime.Serialization; christian@0: using System.Reflection; christian@0: christian@0: namespace Postarc christian@0: { christian@0: public class Settings christian@0: { christian@0: public class Binder : SerializationBinder christian@0: { christian@0: public override Type BindToType(string assemblyName, string typeName) christian@0: { christian@0: Type type = null; christian@0: string shortAssem = assemblyName.Split(',')[0]; christian@0: Assembly[] assemblies = christian@0: AppDomain.CurrentDomain.GetAssemblies(); christian@0: christian@0: foreach (Assembly assem in assemblies) christian@0: { christian@0: if (shortAssem == assem.FullName.Split(',')[0]) christian@0: { christian@0: type = assem.GetType(typeName); christian@0: break; christian@0: } christian@0: christian@0: } christian@0: return type; christian@0: } christian@0: christian@0: } christian@0: christian@0: public static List LoadSavedProfiles() christian@0: { christian@0: List profiles = new List(); christian@0: string path = Application.UserAppDataPath + "\\postarc\\"; christian@0: christian@0: string[] files = Directory.GetFiles(path, "*.connprof"); christian@0: foreach(string file in files) christian@0: { christian@0: FileStream fs = new FileStream(file, FileMode.Open); christian@0: BinaryFormatter formatter = new BinaryFormatter(); christian@0: formatter.Binder = new Settings.Binder(); christian@0: PostGISConnection conn = (PostGISConnection)formatter.Deserialize(fs); christian@0: fs.Close(); christian@0: profiles.Add(conn); christian@0: } christian@0: christian@0: return profiles; christian@0: } christian@0: } christian@0: }