Exemplo n.º 1
0
        /// <summary>
        /// Attempt to load, if failed return bindings with defaults.
        /// </summary>
        /// <returns></returns>
        public static Keybindings Load(string filepath)
        {
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading keybindings...");

            Keybindings kb;

            try
            {
                IFormatter formatter = CreateFormatter();
                Stream     stream    = CreateStream(filepath, false);

                kb = (Keybindings)formatter.Deserialize(stream);
                stream.Close();
            }
            catch (Exception e)
            {
                Logger.WriteLine(Logger.Stage.RUN_MAIN, "failed to load keybindings (first run?), using defaults.");
                Logger.WriteLine(Logger.Stage.RUN_MAIN, String.Format("load exception : {0}.", e.ToString()));
                kb = new Keybindings();
                kb.ResetToDefaults();
            }

            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading keybindings... done!");

            return(kb);
        }
Exemplo n.º 2
0
        public static void Save(Keybindings kb, string filepath)
        {
            if (kb == null)
            {
                throw new ArgumentNullException("kb");
            }

            Logger.WriteLine(Logger.Stage.RUN_MAIN, "saving keybindings...");

            IFormatter formatter = CreateFormatter();
            Stream     stream    = CreateStream(filepath, true);

            formatter.Serialize(stream, kb);
            stream.Flush();
            stream.Close();

            Logger.WriteLine(Logger.Stage.RUN_MAIN, "saving keybindings... done!");
        }