private static async Task Version3Upgrade(int version, string filePath) { if (version < 3) { LegacyDesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <LegacyDesktopChannelSettings>(filePath); settings.InitializeDB = false; await ChannelSession.Services.Settings.Initialize(settings); IEnumerable <EventCommand> commands = settings.EventCommands.Where(c => c.Actions.Count == 0); foreach (EventCommand command in commands) { settings.EventCommands.Remove(command); } if (settings.RankChangedCommand != null && settings.RankChangedCommand.Actions.Count == 0) { settings.RankChangedCommand = null; } 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); } }