From de845520194eed2074dc011bbaeb47107776ea7b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 30 Dec 2018 19:45:04 -0500 Subject: [PATCH] remove support for legacy Build Endurance/Health data files --- GeneralMods/BuildEndurance/BuildEndurance.cs | 41 +------------------- GeneralMods/BuildHealth/BuildHealth.cs | 38 ------------------ 2 files changed, 1 insertion(+), 78 deletions(-) diff --git a/GeneralMods/BuildEndurance/BuildEndurance.cs b/GeneralMods/BuildEndurance/BuildEndurance.cs index bcaf75cb..d826fbc4 100644 --- a/GeneralMods/BuildEndurance/BuildEndurance.cs +++ b/GeneralMods/BuildEndurance/BuildEndurance.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Linq; using Omegasis.BuildEndurance.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; @@ -17,9 +16,6 @@ namespace Omegasis.BuildEndurance /// The relative path for the current player's data file. private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); - /// The absolute path for the current player's legacy data file. - private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "PlayerData", $"BuildEndurance_data_{Game1.player.Name}.txt"); - /// The mod settings. private ModConfig Config; @@ -38,10 +34,10 @@ namespace Omegasis.BuildEndurance /// Whether the player was eating last time we checked. private bool WasEating; - public IModHelper ModHelper; public IMonitor ModMonitor; + /********* ** Public methods *********/ @@ -128,7 +124,6 @@ namespace Omegasis.BuildEndurance this.WasEating = false; // load player data - this.MigrateLegacyData(); this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); if (this.PlayerData.OriginalMaxStamina == 0) this.PlayerData.OriginalMaxStamina = Game1.player.MaxStamina; @@ -187,40 +182,6 @@ namespace Omegasis.BuildEndurance this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); } - /// Migrate the legacy settings for the current player. - private void MigrateLegacyData() - { - // skip if no legacy data or new data already exists - if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath)) - return; - - // migrate to new file - try - { - string[] text = File.ReadAllLines(this.LegacyDataFilePath); - this.Helper.WriteJsonFile(this.DataFilePath, new PlayerData - { - CurrentLevel = Convert.ToInt32(text[3]), - CurrentExp = Convert.ToDouble(text[5]), - ExpToNextLevel = Convert.ToDouble(text[7]), - BaseStaminaBonus = Convert.ToInt32(text[9]), - CurrentLevelStaminaBonus = Convert.ToInt32(text[11]), - ClearModEffects = Convert.ToBoolean(text[14]), - OriginalMaxStamina = Convert.ToInt32(text[16]), - NightlyStamina = Convert.ToInt32(text[18]) - }); - - FileInfo file = new FileInfo(this.LegacyDataFilePath); - file.Delete(); - if (!file.Directory.EnumerateFiles().Any()) - file.Directory.Delete(); - } - catch (Exception ex) - { - this.Monitor.Log($"Error migrating data from the legacy 'PlayerData' folder for the current player. Technical details:\n {ex}", LogLevel.Error); - } - } - /// Try and emulate the old Game1.shouldFarmerPassout logic. public bool shouldFarmerPassout() { diff --git a/GeneralMods/BuildHealth/BuildHealth.cs b/GeneralMods/BuildHealth/BuildHealth.cs index 2ac4a440..bbdee068 100644 --- a/GeneralMods/BuildHealth/BuildHealth.cs +++ b/GeneralMods/BuildHealth/BuildHealth.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using System.Linq; using Omegasis.BuildHealth.Framework; using StardewModdingAPI; using StardewModdingAPI.Events; @@ -17,9 +16,6 @@ namespace Omegasis.BuildHealth /// The relative path for the current player's data file. private string DataFilePath => Path.Combine("data", $"{Constants.SaveFolderName}.json"); - /// The absolute path for the current player's legacy data file. - private string LegacyDataFilePath => Path.Combine(this.Helper.DirectoryPath, "PlayerData", $"BuildHealth_data_{Game1.player.Name}.txt"); - /// The mod settings and player data. private ModConfig Config; @@ -122,7 +118,6 @@ namespace Omegasis.BuildHealth this.WasCollapsed = false; // load player data - this.MigrateLegacyData(); this.PlayerData = this.Helper.ReadJsonFile(this.DataFilePath) ?? new PlayerData(); if (this.PlayerData.OriginalMaxHealth == 0) this.PlayerData.OriginalMaxHealth = Game1.player.maxHealth; @@ -177,39 +172,6 @@ namespace Omegasis.BuildHealth this.Helper.WriteJsonFile(this.DataFilePath, this.PlayerData); } - /// Migrate the legacy settings for the current player. - private void MigrateLegacyData() - { - // skip if no legacy data or new data already exists - if (!File.Exists(this.LegacyDataFilePath) || File.Exists(this.DataFilePath)) - return; - - // migrate to new file - try - { - string[] text = File.ReadAllLines(this.LegacyDataFilePath); - this.Helper.WriteJsonFile(this.DataFilePath, new PlayerData - { - CurrentLevel = Convert.ToInt32(text[3]), - CurrentExp = Convert.ToDouble(text[5]), - ExpToNextLevel = Convert.ToDouble(text[7]), - BaseHealthBonus = Convert.ToInt32(text[9]), - CurrentLevelHealthBonus = Convert.ToInt32(text[11]), - ClearModEffects = Convert.ToBoolean(text[14]), - OriginalMaxHealth = Convert.ToInt32(text[16]) - }); - - FileInfo file = new FileInfo(this.LegacyDataFilePath); - file.Delete(); - if (!file.Directory.EnumerateFiles().Any()) - file.Directory.Delete(); - } - catch (Exception ex) - { - this.Monitor.Log($"Error migrating data from the legacy 'PlayerData' folder for the current player. Technical details:\n {ex}", LogLevel.Error); - } - } - public bool shouldFarmerPassout() { if (Game1.player.stamina <= 0 || Game1.player.health <= 0 || Game1.timeOfDay >= 2600) return true;