예제 #1
0
        /// <summary>
        /// Try to load, null if failed.
        /// </summary>
        /// <returns></returns>
        public static GameHintsStatus Load(string filepath)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading hints...");

            GameHintsStatus hints;

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

                hints = (GameHintsStatus)formatter.Deserialize(stream);
                stream.Close();
            }
            catch (Exception e)
            {
                Logger.WriteLine(Logger.Stage.RUN_MAIN, "failed to load hints (first run?).");
                Logger.WriteLine(Logger.Stage.RUN_MAIN, String.Format("load exception : {0}.", e.ToString()));
                Logger.WriteLine(Logger.Stage.RUN_MAIN, "resetting.");
                hints = new GameHintsStatus();
                hints.ResetAllHints();
            }

            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading options... done!");
            return(hints);
        }
예제 #2
0
        public static void Save(GameHintsStatus hints, string filepath)
        {
            if (filepath == null)
            {
                throw new ArgumentNullException("filepath");
            }

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

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

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

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