示例#1
0
        /// <summary>
        /// 設定保存
        /// </summary>
        /// <param name="iPlayerName"></param>
        /// <returns></returns>
        public bool Save(string iPlayerName)
        {
            string xmlFilename = XML_FILENAME_SETTINGS;
            XmlSerializer serializer;
            SettingsModel xmlSettings = new SettingsModel();

            //設定の読み込み
            xmlSettings = new SettingsModel();
            if (File.Exists(xmlFilename))
            {
                for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++)
                {
                    try
                    {
                        using (FileStream fs = new FileStream(xmlFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            //シリアライズ
                            serializer = new XmlSerializer(typeof(SettingsModel));
                            //読み込み
                            xmlSettings = (SettingsModel)serializer.Deserialize(fs);
                            fs.Close();
                        }
                        break;
                    }
                    catch (IOException)
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                }
            }

            //保存データ設定
            xmlSettings.Global = this.Global;
            bool foundFlg = false;
            if (this.Global.SaveMode == SaveModeKind.Shared)
            {
                iPlayerName = SHARED_PLAYER_NAME;
            }
            foreach (SettingsPlayerModel v in xmlSettings.Player)
            {
                if (v.PlayerName == iPlayerName)
                {
                    foundFlg = true;
                    v.Form = this.Form;
                    v.FishList = this.FishList;
                    v.Fishing = this.Fishing;
                    v.Etc = this.Etc;
                    v.History = this.History;
                    v.Harakiri = this.Harakiri;
                    v.CaughtFishes = this.CaughtFishes;
                }
            }
            if (!foundFlg)
            {
                SettingsPlayerModel player = new SettingsPlayerModel();
                player.PlayerName = iPlayerName;
                player.Form = this.Form;
                player.FishList = this.FishList;
                player.Fishing = this.Fishing;
                player.Etc = this.Etc;
                player.History = this.History;
                player.Harakiri = this.Harakiri;
                player.CaughtFishes = this.CaughtFishes;

                xmlSettings.Player.Add(player);
            }

            //設定の保存
            for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++)
            {
                try
                {
                    using (FileStream fs = new FileStream(xmlFilename, FileMode.Create, FileAccess.Write, FileShare.None))//ファイルロック
                    {
                        StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
                        //名前空間出力抑制
                        XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                        ns.Add(String.Empty, String.Empty);
                        //シリアライズ
                        serializer = new XmlSerializer(typeof(SettingsModel));
                        serializer.Serialize(sw, xmlSettings, ns);
                        //書き込み
                        sw.Flush();
                        sw.Close();
                        sw = null;
                        fs.Close();
                    }
                    break;
                }
                catch (IOException)
                {
                    Thread.Sleep(100);
                    continue;
                }
            }
            return true;
        }
示例#2
0
        /// <summary>
        /// 設定保存
        /// </summary>
        /// <param name="iPlayerName"></param>
        /// <returns></returns>
        public bool Save(string iPlayerName)
        {
            string        xmlFilename = XML_FILENAME_SETTINGS;
            XmlSerializer serializer;
            SettingsModel xmlSettings = new SettingsModel();

            //設定の読み込み
            xmlSettings = new SettingsModel();
            if (File.Exists(xmlFilename))
            {
                for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++)
                {
                    try
                    {
                        using (FileStream fs = new FileStream(xmlFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            //シリアライズ
                            serializer = new XmlSerializer(typeof(SettingsModel));
                            //読み込み
                            xmlSettings = (SettingsModel)serializer.Deserialize(fs);
                            fs.Close();
                        }
                        break;
                    }
                    catch (IOException)
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                }
            }

            //保存データ設定
            xmlSettings.Global = this.Global;
            bool foundFlg = false;

            if (this.Global.SaveMode == SaveModeKind.Shared)
            {
                iPlayerName = SHARED_PLAYER_NAME;
            }
            foreach (SettingsPlayerModel v in xmlSettings.Player)
            {
                if (v.PlayerName == iPlayerName)
                {
                    foundFlg       = true;
                    v.Form         = this.Form;
                    v.FishList     = this.FishList;
                    v.Fishing      = this.Fishing;
                    v.Etc          = this.Etc;
                    v.History      = this.History;
                    v.Harakiri     = this.Harakiri;
                    v.CaughtFishes = this.CaughtFishes;
                }
            }
            if (!foundFlg)
            {
                SettingsPlayerModel player = new SettingsPlayerModel();
                player.PlayerName   = iPlayerName;
                player.Form         = this.Form;
                player.FishList     = this.FishList;
                player.Fishing      = this.Fishing;
                player.Etc          = this.Etc;
                player.History      = this.History;
                player.Harakiri     = this.Harakiri;
                player.CaughtFishes = this.CaughtFishes;

                xmlSettings.Player.Add(player);
            }


            //設定の保存
            for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++)
            {
                try
                {
                    using (FileStream fs = new FileStream(xmlFilename, FileMode.Create, FileAccess.Write, FileShare.None))//ファイルロック
                    {
                        StreamWriter sw = new StreamWriter(fs, new UTF8Encoding(false));
                        //名前空間出力抑制
                        XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                        ns.Add(String.Empty, String.Empty);
                        //シリアライズ
                        serializer = new XmlSerializer(typeof(SettingsModel));
                        serializer.Serialize(sw, xmlSettings, ns);
                        //書き込み
                        sw.Flush();
                        sw.Close();
                        sw = null;
                        fs.Close();
                    }
                    break;
                }
                catch (IOException)
                {
                    Thread.Sleep(100);
                    continue;
                }
            }
            return(true);
        }
示例#3
0
        /// <summary>
        /// 設定読み込み
        /// </summary>
        /// <param name="iPlayerName"></param>
        /// <returns></returns>
        public bool Load(string iPlayerName)
        {
            //xmlの読み込み
            string xmlFilename = XML_FILENAME_SETTINGS;
            SettingsModel xmlSettings = new SettingsModel();
            if (File.Exists(xmlFilename))
            {
                for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++)
                {
                    try
                    {
                        using (FileStream fs = new FileStream(xmlFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            //シリアライズ
                            XmlSerializer serializer = new XmlSerializer(typeof(SettingsModel));
                            //読み込み
                            xmlSettings = (SettingsModel)serializer.Deserialize(fs);
                            fs.Close();
                        }
                        break;
                    }
                    catch (IOException)
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                }
            }
            //メンバに設定
            //Global
            this.Global = xmlSettings.Global;
            //Player
            bool foundFlg = false;
            if (this.Global.SaveMode == SaveModeKind.Shared)
            {
                iPlayerName = SHARED_PLAYER_NAME;
            }
            foreach (SettingsPlayerModel v in xmlSettings.Player)
            {
                if (v.PlayerName == iPlayerName)
                {
                    foundFlg = true;
                    this.Form = v.Form;
                    this.FishList = v.FishList;
                    this.Fishing = v.Fishing;
                    this.Etc = v.Etc;
                    this.History = v.History;
                    this.Harakiri = v.Harakiri;
                    this.CaughtFishes = v.CaughtFishes;
                }
            }
            if (!foundFlg)
            {
                SettingsPlayerModel player = new SettingsPlayerModel();
                this.Form = player.Form;
                this.FishList = player.FishList;
                this.Fishing = player.Fishing;
                this.Etc = player.Etc;
                this.History = player.History;
                this.Harakiri = player.Harakiri;
                this.CaughtFishes = player.CaughtFishes;
            }

            return true;
        }
示例#4
0
        /// <summary>
        /// 設定読み込み
        /// </summary>
        /// <param name="iPlayerName"></param>
        /// <returns></returns>
        public bool Load(string iPlayerName)
        {
            //xmlの読み込み
            string        xmlFilename = XML_FILENAME_SETTINGS;
            SettingsModel xmlSettings = new SettingsModel();

            if (File.Exists(xmlFilename))
            {
                for (int i = 0; i < Constants.FILELOCK_RETRY_COUNT; i++)
                {
                    try
                    {
                        using (FileStream fs = new FileStream(xmlFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
                        {
                            //シリアライズ
                            XmlSerializer serializer = new XmlSerializer(typeof(SettingsModel));
                            //読み込み
                            xmlSettings = (SettingsModel)serializer.Deserialize(fs);
                            fs.Close();
                        }
                        break;
                    }
                    catch (IOException)
                    {
                        Thread.Sleep(100);
                        continue;
                    }
                }
            }
            //メンバに設定
            //Global
            this.Global = xmlSettings.Global;
            //Player
            bool foundFlg = false;

            if (this.Global.SaveMode == SaveModeKind.Shared)
            {
                iPlayerName = SHARED_PLAYER_NAME;
            }
            foreach (SettingsPlayerModel v in xmlSettings.Player)
            {
                if (v.PlayerName == iPlayerName)
                {
                    foundFlg          = true;
                    this.Form         = v.Form;
                    this.FishList     = v.FishList;
                    this.Fishing      = v.Fishing;
                    this.Etc          = v.Etc;
                    this.History      = v.History;
                    this.Harakiri     = v.Harakiri;
                    this.CaughtFishes = v.CaughtFishes;
                }
            }
            if (!foundFlg)
            {
                SettingsPlayerModel player = new SettingsPlayerModel();
                this.Form         = player.Form;
                this.FishList     = player.FishList;
                this.Fishing      = player.Fishing;
                this.Etc          = player.Etc;
                this.History      = player.History;
                this.Harakiri     = player.Harakiri;
                this.CaughtFishes = player.CaughtFishes;
            }

            return(true);
        }