public SettingsPlayerModel() { this.PlayerName = string.Empty; this.Form = new SettingsPlayerFormModel(); this.FishList = new SettingsPlayerFishListModel(); this.Fishing = new SettingsPlayerFishingModel(); this.Etc = new SettingsPlayerEtcModel(); this.History = new SettingsPlayerHistoryModel(); this.Harakiri = new SettingsPlayerHarakiriModel(); this.CaughtFishes = new SettingsPlayerCaughtFishesModel(); }
/// <summary> /// コンストラクタ /// </summary> /// <param name="iPlayerName"></param> public Settings(string iPlayerName) { this.PolProcID = 0; this.UseEnternity = false; this.UseItemizer = false; //設定読み込み if (iPlayerName.Length > 0) { Load(iPlayerName); } else { this.Global = new SettingsGlobalModel(); this.Form = new SettingsPlayerFormModel(); this.FishList = new SettingsPlayerFishListModel(); this.Fishing = new SettingsPlayerFishingModel(); this.Etc = new SettingsPlayerEtcModel(); this.History = new SettingsPlayerHistoryModel(); this.Harakiri = new SettingsPlayerHarakiriModel(); this.CaughtFishes = new SettingsPlayerCaughtFishesModel(); } }
/// <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); }