internal static async Task UpgradeSettingsToLatest(int version, string filePath) { await DesktopSettingsUpgrader.Version16Upgrade(version, filePath); await DesktopSettingsUpgrader.Version17Upgrade(version, filePath); await DesktopSettingsUpgrader.Version18Upgrade(version, filePath); await DesktopSettingsUpgrader.Version19Upgrade(version, filePath); await DesktopSettingsUpgrader.Version20Upgrade(version, filePath); await DesktopSettingsUpgrader.Version21Upgrade(version, filePath); await DesktopSettingsUpgrader.Version22Upgrade(version, filePath); await DesktopSettingsUpgrader.Version23Upgrade(version, filePath); await DesktopSettingsUpgrader.Version24Upgrade(version, filePath); await DesktopSettingsUpgrader.Version25Upgrade(version, filePath); await DesktopSettingsUpgrader.Version26Upgrade(version, filePath); await DesktopSettingsUpgrader.Version27Upgrade(version, filePath); DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath); settings.InitializeDB = false; await ChannelSession.Services.Settings.Initialize(settings); settings.Version = DesktopChannelSettings.LatestVersion; await ChannelSession.Services.Settings.Save(settings); }
private async Task <IChannelSettings> LoadSettings(string filePath) { string fileData = await ChannelSession.Services.FileService.ReadFile(filePath); JObject settingsJObj = JObject.Parse(fileData); int currentVersion = (int)settingsJObj["Version"]; if (currentVersion < DesktopChannelSettings.LatestVersion) { await DesktopSettingsUpgrader.UpgradeSettingsToLatest(currentVersion, filePath); } return(await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath)); }
private static async Task Version24Upgrade(int version, string filePath) { if (version < 24) { DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath); await ChannelSession.Services.Settings.Initialize(settings); foreach (CommandBase command in DesktopSettingsUpgrader.GetAllCommands(settings)) { StoreCommandUpgrader.RestructureNewOverlayActions(command.Actions); } await ChannelSession.Services.Settings.Save(settings); } }
private async Task <IChannelSettings> LoadSettings(string filePath) { string data = File.ReadAllText(filePath); if (!data.Contains("\"Version\":")) { await DesktopSettingsUpgrader.UpgradeSettingsToLatest(0, filePath); } DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath); if (settings.ShouldBeUpgraded()) { await DesktopSettingsUpgrader.UpgradeSettingsToLatest(settings.Version, filePath); settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath); } return(settings); }
private async Task <IChannelSettings> LoadSettings(string filePath) { int currentVersion = await GetSettingsVersion(filePath); if (currentVersion == -1) { // Settings file is invalid, we can't use this return(null); } else if (currentVersion > DesktopChannelSettings.LatestVersion) { // Future build, like a preview build, we can't load this return(null); } else if (currentVersion < DesktopChannelSettings.LatestVersion) { await DesktopSettingsUpgrader.UpgradeSettingsToLatest(currentVersion, filePath); } return(await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath)); }
private static async Task Version2Upgrade(int version, string filePath) { if (version < 2) { string data = File.ReadAllText(filePath); data = data.Replace("interactiveControlsInternal", "interactiveCommandsInternal"); data = data.Replace("CapsBlockCount", "ModerationCapsBlockCount"); data = data.Replace("PunctuationBlockCount", "ModerationPunctuationBlockCount"); data = data.Replace("EmoteBlockCount", "ModerationEmoteBlockCount"); data = data.Replace("BlockLinks", "ModerationBlockLinks"); data = data.Replace("Timeout1MinuteOffenseCount", "ModerationTimeout1MinuteOffenseCount"); data = data.Replace("Timeout5MinuteOffenseCount", "ModerationTimeout5MinuteOffenseCount"); File.WriteAllText(filePath, data); DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath); await ChannelSession.Services.Settings.Initialize(settings); List <CommandBase> commands = new List <CommandBase>(); commands.AddRange(settings.ChatCommands); commands.AddRange(settings.InteractiveCommands); commands.AddRange(settings.EventCommands); commands.AddRange(settings.TimerCommands); foreach (CommandBase command in commands) { foreach (ActionBase action in command.Actions) { if (action is ChatAction) { ChatAction nAction = (ChatAction)action; nAction.ChatText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion2(nAction.ChatText); } else if (action is CurrencyAction) { CurrencyAction nAction = (CurrencyAction)action; nAction.ChatText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion2(nAction.ChatText); } else if (action is OBSStudioAction) { OBSStudioAction nAction = (OBSStudioAction)action; nAction.SourceText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion2(nAction.SourceText); } else if (action is OverlayAction) { OverlayAction nAction = (OverlayAction)action; nAction.ImagePath = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion2(nAction.ImagePath); nAction.Text = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion2(nAction.Text); } else if (action is TextToSpeechAction) { TextToSpeechAction nAction = (TextToSpeechAction)action; nAction.SpeechText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion2(nAction.SpeechText); } else if (action is XSplitAction) { XSplitAction nAction = (XSplitAction)action; nAction.SourceText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion2(nAction.SourceText); } } } await ChannelSession.Services.Settings.Save(settings); } }
private static async Task Version5Upgrade(int version, string filePath) { if (version < 5) { LegacyDesktopChannelSettings legacySettings = await SerializerHelper.DeserializeFromFile <LegacyDesktopChannelSettings>(filePath); DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath); await ChannelSession.Services.Settings.Initialize(settings); foreach (string quote in legacySettings.quotesInternal) { settings.UserQuotes.Add(new UserQuoteViewModel(quote)); } List <CommandBase> commands = new List <CommandBase>(); commands.AddRange(settings.ChatCommands); commands.AddRange(settings.InteractiveCommands); commands.AddRange(settings.EventCommands); commands.AddRange(settings.TimerCommands); UserCurrencyViewModel currency = settings.Currencies.Values.FirstOrDefault(c => !c.IsRank); if (currency == null) { currency = settings.Currencies.Values.FirstOrDefault(); } foreach (CommandBase command in commands) { foreach (ActionBase action in command.Actions) { if (action is InteractiveAction) { InteractiveAction nAction = (InteractiveAction)action; #pragma warning disable CS0612 // Type or member is obsolete if (nAction.AddUserToGroup) { nAction.InteractiveType = InteractiveActionTypeEnum.MoveUserToGroup; } else { nAction.InteractiveType = InteractiveActionTypeEnum.MoveGroupToScene; } nAction.SceneID = nAction.MoveGroupToScene; #pragma warning restore CS0612 // Type or member is obsolete } if (currency != null) { if (action is ChatAction) { ChatAction nAction = (ChatAction)action; nAction.ChatText = nAction.ChatText.Replace("$usercurrencyname", currency.Name); } else if (action is CurrencyAction) { CurrencyAction nAction = (CurrencyAction)action; nAction.ChatText = nAction.ChatText.Replace("$usercurrencyname", currency.Name); } else if (action is OBSStudioAction) { OBSStudioAction nAction = (OBSStudioAction)action; if (!string.IsNullOrEmpty(nAction.SourceText)) { nAction.SourceText = nAction.SourceText.Replace("$usercurrencyname", currency.Name); } } else if (action is OverlayAction) { OverlayAction nAction = (OverlayAction)action; if (!string.IsNullOrEmpty(nAction.Text)) { nAction.Text = nAction.Text.Replace("$usercurrencyname", currency.Name); } } else if (action is TextToSpeechAction) { TextToSpeechAction nAction = (TextToSpeechAction)action; nAction.SpeechText = nAction.SpeechText.Replace("$usercurrencyname", currency.Name); } else if (action is XSplitAction) { XSplitAction nAction = (XSplitAction)action; if (!string.IsNullOrEmpty(nAction.SourceText)) { nAction.SourceText = nAction.SourceText.Replace("$usercurrencyname", currency.Name); } } } } } foreach (GameCommandBase game in settings.GameCommands) { if (game is IndividualProbabilityGameCommand) { IndividualProbabilityGameCommand individualGame = (IndividualProbabilityGameCommand)game; DesktopSettingsUpgrader.SetAllGameChatActionsToWhispers(individualGame.UserJoinedCommand); DesktopSettingsUpgrader.SetAllGameChatActionsToWhispers(individualGame.LoseLeftoverCommand); foreach (GameOutcome outcome in individualGame.Outcomes) { DesktopSettingsUpgrader.SetAllGameChatActionsToWhispers(outcome.ResultCommand); } } else if (game is OnlyOneWinnerGameCommand) { OnlyOneWinnerGameCommand oneWinnerGame = (OnlyOneWinnerGameCommand)game; DesktopSettingsUpgrader.SetAllGameChatActionsToWhispers(oneWinnerGame.UserJoinedCommand); } } await ChannelSession.Services.Settings.Save(settings); } }
private static async Task Version4Upgrade(int version, string filePath) { if (version < 4) { string data = File.ReadAllText(filePath); data = data.Replace("MixItUp.Base.Actions.RankAction", "MixItUp.Base.Actions.CurrencyAction"); data = data.Replace("\"Type\": 13\n", "\"Type\": 1\n"); File.WriteAllText(filePath, data); LegacyDesktopChannelSettings legacySettings = await SerializerHelper.DeserializeFromFile <LegacyDesktopChannelSettings>(filePath); legacySettings.InitializeDB = false; List <LegacyUserDataViewModel> legacyUsers = new List <LegacyUserDataViewModel>(); if (legacySettings.IsStreamer) { string dbPath = ((DesktopSettingsService)ChannelSession.Services.Settings).GetDatabaseFilePath(legacySettings); SQLiteDatabaseWrapper databaseWrapper = new SQLiteDatabaseWrapper(dbPath); await databaseWrapper.RunReadCommand("SELECT * FROM Users", (SQLiteDataReader dataReader) => { LegacyUserDataViewModel userData = new LegacyUserDataViewModel(dataReader); legacyUsers.Add(userData); }); File.Copy(DesktopSettingsService.SettingsTemplateDatabaseFileName, dbPath, overwrite: true); } await ChannelSession.Services.Settings.Initialize(legacySettings); DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath); settings.InitializeDB = false; await ChannelSession.Services.Settings.Initialize(settings); UserCurrencyViewModel currency = null; UserCurrencyViewModel rank = null; if (settings.IsStreamer) { if (!string.IsNullOrEmpty(legacySettings.CurrencyAcquisition.Name)) { currency = legacySettings.CurrencyAcquisition; currency.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(currency.Name); settings.Currencies.Add(legacySettings.CurrencyAcquisition.ID, legacySettings.CurrencyAcquisition); } if (!string.IsNullOrEmpty(legacySettings.RankAcquisition.Name)) { rank = legacySettings.RankAcquisition; rank.SpecialIdentifier = SpecialIdentifierStringBuilder.ConvertToSpecialIdentifier(rank.Name); rank.Ranks = legacySettings.Ranks; rank.RankChangedCommand = legacySettings.RankChangedCommand; settings.Currencies.Add(legacySettings.RankAcquisition.ID, legacySettings.RankAcquisition); } foreach (LegacyUserDataViewModel user in legacyUsers) { settings.UserData[user.ID] = user; if (rank != null) { settings.UserData[user.ID].SetCurrencyAmount(rank, user.RankPoints); } if (currency != null) { settings.UserData[user.ID].SetCurrencyAmount(currency, user.CurrencyAmount); } } if (currency != null) { if (legacySettings.GiveawayCurrencyCost > 0) { settings.GiveawayCurrencyRequirement = new UserCurrencyRequirementViewModel(currency, legacySettings.GiveawayCurrencyCost); } if (legacySettings.GameQueueCurrencyCost > 0) { settings.GameQueueCurrencyRequirement = new UserCurrencyRequirementViewModel(currency, legacySettings.GameQueueCurrencyCost); } } if (rank != null) { if (legacySettings.GiveawayUserRank != null && rank.Ranks.Any(r => r.Name.Equals(legacySettings.GiveawayUserRank))) { settings.GiveawayRankRequirement = new UserCurrencyRequirementViewModel(rank, rank.Ranks.FirstOrDefault(r => r.Name.Equals(legacySettings.GiveawayUserRank))); } if (legacySettings.GameQueueMinimumRank != null) { settings.GameQueueRankRequirement = new UserCurrencyRequirementViewModel(rank, legacySettings.GameQueueMinimumRank); } } } List <CommandBase> commands = new List <CommandBase>(); commands.AddRange(settings.ChatCommands); commands.AddRange(settings.InteractiveCommands); commands.AddRange(settings.EventCommands); commands.AddRange(settings.TimerCommands); foreach (CommandBase command in commands) { foreach (ActionBase action in command.Actions) { if (action is ChatAction) { ChatAction nAction = (ChatAction)action; nAction.ChatText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion4(nAction.ChatText, currency, rank); } else if (action is CurrencyAction) { CurrencyAction nAction = (CurrencyAction)action; nAction.ChatText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion4(nAction.ChatText, currency, rank); } else if (action is OBSStudioAction) { OBSStudioAction nAction = (OBSStudioAction)action; nAction.SourceText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion4(nAction.SourceText, currency, rank); } else if (action is OverlayAction) { OverlayAction nAction = (OverlayAction)action; nAction.ImagePath = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion4(nAction.ImagePath, currency, rank); nAction.Text = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion4(nAction.Text, currency, rank); } else if (action is TextToSpeechAction) { TextToSpeechAction nAction = (TextToSpeechAction)action; nAction.SpeechText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion4(nAction.SpeechText, currency, rank); } else if (action is XSplitAction) { XSplitAction nAction = (XSplitAction)action; nAction.SourceText = DesktopSettingsUpgrader.ReplaceSpecialIdentifiersVersion4(nAction.SourceText, currency, rank); } } } if (settings.IsStreamer) { foreach (ChatCommand command in settings.ChatCommands) { #pragma warning disable CS0612 // Type or member is obsolete if (command.CurrencyCost > 0) { command.CurrencyRequirement = new UserCurrencyRequirementViewModel(currency, command.CurrencyCost); } #pragma warning restore CS0612 // Type or member is obsolete } } await ChannelSession.Services.Settings.Save(settings); } }