/// <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);
        }
示例#2
0
        public static void Save(Keybindings kb, string filepath)
        {
#if DEBUG
            if (string.IsNullOrEmpty(filepath))
            {
                throw new ArgumentNullException(nameof(filepath));
            }
            if (null == kb)
            {
                throw new ArgumentNullException(nameof(kb));
            }
#endif
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "saving keybindings...");
            filepath.BinarySerialize(kb);
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "saving keybindings... done!");
        }
        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!");
        }
示例#4
0
        public static Keybindings Load(string filepath)
        {
#if DEBUG
            if (string.IsNullOrEmpty(filepath))
            {
                throw new ArgumentNullException(nameof(filepath));
            }
#endif
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading keybindings...");
            Keybindings keybindings;
            try {
                keybindings = filepath.BinaryDeserialize <Keybindings>();
            } catch (Exception ex) {
                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}.", (object)ex.ToString()));
                keybindings = new Keybindings();
            }
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading keybindings... done!");
            return(keybindings);
        }