Esempio n. 1
0
        public static GameHintsStatus Load(string filepath)
        {
#if DEBUG
            if (string.IsNullOrEmpty(filepath))
            {
                throw new ArgumentNullException(nameof(filepath));
            }
#endif
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading hints...");
            GameHintsStatus gameHintsStatus;
            try {
#if LINUX
                filepath = filepath.Replace("\\", "/");
#endif
                gameHintsStatus = filepath.BinaryDeserialize <GameHintsStatus>();
            } catch (Exception ex) {
                Logger.WriteLine(Logger.Stage.RUN_MAIN, "failed to load hints (first run?).");
                Logger.WriteLine(Logger.Stage.RUN_MAIN, string.Format("load exception : {0}.", (object)ex.ToString()));
                Logger.WriteLine(Logger.Stage.RUN_MAIN, "resetting.");
                gameHintsStatus = new GameHintsStatus();
                gameHintsStatus.ResetAllHints();
            }
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "loading options... done!");
            return(gameHintsStatus);
        }
        /// <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);
        }
Esempio n. 3
0
        public static void Save(GameHintsStatus hints, string filepath)
        {
#if DEBUG
            if (string.IsNullOrEmpty(filepath))
            {
                throw new ArgumentNullException(nameof(filepath));
            }
#endif
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "saving hints...");
            filepath.BinarySerialize(hints);
            Logger.WriteLine(Logger.Stage.RUN_MAIN, "saving hints... done!");
        }
        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!");
        }