public static async Task <CommandModelBase> ImportCommandFromFile() { string fileName = ChannelSession.Services.FileService.ShowOpenFileDialog(string.Format("Mix It Up Command (*{0})|*{0},*{1}|All files (*.*)|*.*", MixItUpCommandFileExtension, MixItUpOldCommandFileExtension)); if (!string.IsNullOrEmpty(fileName)) { if (Path.GetExtension(fileName).Equals(MixItUpOldCommandFileExtension)) { #pragma warning disable CS0612 // Type or member is obsolete MixItUp.Base.Commands.CommandBase command = await FileSerializerHelper.DeserializeFromFile <MixItUp.Base.Commands.CommandBase>(fileName); ActionGroupCommandModel actionGroup = new ActionGroupCommandModel(command.Name, false); foreach (MixItUp.Base.Actions.ActionBase action in command.Actions) { actionGroup.Actions.AddRange(ActionModelBase.UpgradeAction(action)); } return(actionGroup); #pragma warning restore CS0612 // Type or member is obsolete } else { return(await FileSerializerHelper.DeserializeFromFile <CommandModelBase>(fileName)); } } return(null); }
public static async Task <T> ImportCommandFromFile <T>(string filePath) where T : CommandModelBase { if (!string.IsNullOrEmpty(filePath)) { if (Path.GetExtension(filePath).Equals(MixItUpOldCommandFileExtension)) { #pragma warning disable CS0612 // Type or member is obsolete MixItUp.Base.Commands.CommandBase command = await FileSerializerHelper.DeserializeFromFile <MixItUp.Base.Commands.CommandBase>(filePath); ActionGroupCommandModel actionGroup = new ActionGroupCommandModel(command.Name, false); foreach (MixItUp.Base.Actions.ActionBase action in command.Actions) { actionGroup.Actions.AddRange(ActionModelBase.UpgradeAction(action)); } return(actionGroup as T); #pragma warning restore CS0612 // Type or member is obsolete } else { return(await FileSerializerHelper.DeserializeFromFile <T>(filePath)); } } return(null); }
public static async Task Version44Upgrade(string filePath) { SettingsV2Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV2Model>(filePath, ignoreErrors : true); await settings.Initialize(); #pragma warning disable CS0612 // Type or member is obsolete if (settings.ChatShowUserJoinLeave) { settings.AlertUserJoinLeaveColor = settings.ChatUserJoinLeaveColorScheme; } if (settings.ChatShowEventAlerts) { settings.AlertBitsCheeredColor = settings.ChatEventAlertsColorScheme; settings.AlertChannelPointsColor = settings.ChatEventAlertsColorScheme; settings.AlertFollowColor = settings.ChatEventAlertsColorScheme; settings.AlertGiftedSubColor = settings.ChatEventAlertsColorScheme; settings.AlertHostColor = settings.ChatEventAlertsColorScheme; settings.AlertMassGiftedSubColor = settings.ChatEventAlertsColorScheme; settings.AlertModerationColor = settings.ChatEventAlertsColorScheme; settings.AlertRaidColor = settings.ChatEventAlertsColorScheme; settings.AlertSubColor = settings.ChatEventAlertsColorScheme; } #pragma warning restore CS0612 // Type or member is obsolete await ChannelSession.Services.Settings.Save(settings); }
#pragma warning restore CS0612 // Type or member is obsolete public static async Task <SettingsV3Model> UpgradeSettingsToLatest(string filePath) { int currentVersion = await GetSettingsVersion(filePath); if (currentVersion < 0) { // Settings file is invalid, we can't use this return(null); } else if (currentVersion > SettingsV3Model.LatestVersion) { // Future build, like a preview build, we can't load this return(null); } else if (currentVersion < SettingsV3Model.LatestVersion) { await SettingsV3Upgrader.Version2Upgrade(currentVersion, filePath); await SettingsV3Upgrader.Version3Upgrade(currentVersion, filePath); } SettingsV3Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV3Model>(filePath, ignoreErrors : true); settings.Version = SettingsV3Model.LatestVersion; return(settings); }
public void Initialize() { this.Secrets = new SecretsService(); var mixItUpService = new MixItUpService(); this.MixItUpService = mixItUpService; this.CommunityCommandsService = mixItUpService; this.WebhookService = mixItUpService; this.User = new UserService(); this.Chat = new ChatService(); this.Events = new EventService(); this.Alerts = new AlertsService(); this.Command = new CommandService(); this.Settings = new SettingsService(); this.Statistics = new StatisticsService(); this.Database = new WindowsDatabaseService(); this.Moderation = new ModerationService(); this.FileService = new WindowsFileService(); this.InputService = new WindowsInputService(); this.Timers = new TimerService(); this.GameQueueService = new GameQueueService(); this.Image = new WindowsImageService(); this.AudioService = new WindowsAudioService(); this.GiveawayService = new GiveawayService(); this.SerialService = new SerialService(); this.DeveloperAPI = new WindowsDeveloperAPIService(); this.Telemetry = new WindowsTelemetryService(); this.Streamlabs = new StreamlabsService(new WindowsSocketIOConnection()); this.StreamElements = new StreamElementsService(new WindowsSocketIOConnection()); this.Rainmaker = new RainmakerService(new WindowsSocketIOConnection()); this.TipeeeStream = new TipeeeStreamService(new WindowsSocketIOConnection()); this.TreatStream = new TreatStreamService(new WindowsSocketIOConnection()); this.Streamloots = new StreamlootsService(); this.JustGiving = new JustGivingService(); this.Tiltify = new TiltifyService(); this.ExtraLife = new ExtraLifeService(); this.IFTTT = new IFTTTService(); this.Patreon = new PatreonService(); this.Discord = new DiscordService(); this.Twitter = new TwitterService(); this.PixelChat = new PixelChatService(); this.VTubeStudio = new VTubeStudioService(); this.Voicemod = new VoicemodEmptyService(); this.OvrStream = new WindowsOvrStreamService(); this.Overlay = new OverlayService(); this.OBSStudio = new WindowsOBSService(); this.StreamlabsOBS = new StreamlabsOBSService(); this.XSplit = new XSplitService("http://localhost:8211/"); this.TwitchStatus = new TwitchStatusService(); this.Settings.Initialize(); FileSerializerHelper.Initialize(this.FileService); }
public async Task SaveLocalBackup(SettingsV3Model settings) { Logger.Log(LogLevel.Debug, "Settings local backup save operation started"); await semaphore.WaitAndRelease(async() => { await FileSerializerHelper.SerializeToFile(settings.SettingsLocalBackupFilePath, settings); }); Logger.Log(LogLevel.Debug, "Settings local backup save operation finished"); }
public async Task Save() { try { await FileSerializerHelper.SerializeToFile(ApplicationSettingsFileName, this); } catch (Exception ex) { Logger.Log(ex); } }
public static async Task Version41Upgrade(string filePath) { SettingsV2Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV2Model>(filePath, ignoreErrors : true); // Check if the old CurrencyAmounts and InventoryAmounts tables exist bool tablesExist = false; await ChannelSession.Services.Database.Read(settings.DatabaseFilePath, "SELECT * FROM CurrencyAmounts LIMIT 1", (Dictionary <string, object> data) => { if (data.Count > 0) { tablesExist = true; } }); if (tablesExist) { await settings.Initialize(); await ChannelSession.Services.Database.Read(settings.DatabaseFilePath, "SELECT * FROM CurrencyAmounts", (Dictionary <string, object> data) => { Guid currencyID = Guid.Parse((string)data["CurrencyID"]); Guid userID = Guid.Parse((string)data["UserID"]); int amount = Convert.ToInt32(data["Amount"]); if (amount > 0 && settings.UserData.ContainsKey(userID)) { settings.UserData[userID].CurrencyAmounts[currencyID] = amount; settings.UserData.ManualValueChanged(userID); } }); await ChannelSession.Services.Database.Read(settings.DatabaseFilePath, "SELECT * FROM InventoryAmounts", (Dictionary <string, object> data) => { Guid inventoryID = Guid.Parse((string)data["InventoryID"]); Guid userID = Guid.Parse((string)data["UserID"]); Guid itemID = Guid.Parse((string)data["ItemID"]); int amount = Convert.ToInt32(data["Amount"]); if (amount > 0 && settings.UserData.ContainsKey(userID)) { if (!settings.UserData[userID].InventoryAmounts.ContainsKey(inventoryID)) { settings.UserData[userID].InventoryAmounts[inventoryID] = new Dictionary <Guid, int>(); } settings.UserData[userID].InventoryAmounts[inventoryID][itemID] = amount; settings.UserData.ManualValueChanged(userID); } }); await ChannelSession.Services.Settings.Save(settings); } }
public void Initialize() { this.Secrets = new SecretsService(); this.MixItUpService = new MixItUpService(); this.User = new UserService(); this.Chat = new ChatService(); this.Events = new EventService(); this.Alerts = new AlertsService(); this.Settings = new SettingsService(); this.Statistics = new StatisticsService(); this.Database = new WindowsDatabaseService(); this.Moderation = new ModerationService(); this.FileService = new WindowsFileService(); this.InputService = new WindowsInputService(); this.TimerService = new TimerService(); this.GameQueueService = new GameQueueService(); this.Image = new WindowsImageService(); this.AudioService = new WindowsAudioService(); this.GiveawayService = new GiveawayService(); this.TranslationService = new TranslationService(); this.SerialService = new SerialService(); this.RemoteService = new LocalStreamerRemoteService("https://mixitup-remote-server.azurewebsites.net/api/", "https://mixitup-remote-server.azurewebsites.net/RemoteHub"); this.DeveloperAPI = new WindowsDeveloperAPIService(); this.Telemetry = new WindowsTelemetryService(); this.Streamlabs = new StreamlabsService(new WindowsSocketIOConnection()); this.StreamElements = new StreamElementsService(); this.StreamJar = new StreamJarService(); this.TipeeeStream = new TipeeeStreamService(new WindowsSocketIOConnection()); this.TreatStream = new TreatStreamService(new WindowsSocketIOConnection()); this.Streamloots = new StreamlootsService(); this.JustGiving = new JustGivingService(); this.Tiltify = new TiltifyService(); this.ExtraLife = new ExtraLifeService(); this.IFTTT = new IFTTTService(); this.Patreon = new PatreonService(); this.Discord = new DiscordService(); this.Twitter = new TwitterService(); this.OvrStream = new WindowsOvrStreamService(); this.Overlay = new OverlayService(); this.OBSStudio = new WindowsOBSService(); this.StreamlabsOBS = new StreamlabsOBSService(); this.XSplit = new XSplitService("http://localhost:8211/"); this.TwitchStatus = new TwitchStatusService(); this.Settings.Initialize(); FileSerializerHelper.Initialize(this.FileService); }
#pragma warning restore CS0612 // Type or member is obsolete public async Task Save(SettingsV3Model settings) { Logger.Log(LogLevel.Debug, "Settings save operation started"); await semaphore.WaitAndRelease(async() => { settings.CopyLatestValues(); await FileSerializerHelper.SerializeToFile(settings.SettingsFilePath, settings); await settings.SaveDatabaseData(); }); Logger.Log(LogLevel.Debug, "Settings save operation finished"); }
protected override async Task OnLoadedInternal() { this.ImportActionsCommand = this.CreateCommand(async() => { try { await this.ImportActionsFromCommand(await CommandEditorWindowViewModelBase.ImportCommandFromFile(CommandEditorWindowViewModelBase.OpenCommandFileBrowser())); } catch (Exception ex) { Logger.Log(ex); await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToImportCommand + ": " + ex.ToString()); } }); this.ExportActionsCommand = this.CreateCommand(async() => { try { IEnumerable <Result> results = await this.ActionEditorList.ValidateActions(); if (results.Any(r => !r.Success)) { await DialogHelper.ShowFailedResults(results.Where(r => !r.Success)); return; } CustomCommandModel command = new CustomCommandModel(this.Name); command.Actions.AddRange(await this.ActionEditorList.GetActions()); string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(this.Name + CommandEditorWindowViewModelBase.MixItUpCommandFileExtension); if (!string.IsNullOrEmpty(fileName)) { await FileSerializerHelper.SerializeToFile(fileName, command); } } catch (Exception ex) { Logger.Log(ex); await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToExportCommand + ": " + ex.ToString()); } }); foreach (ActionModelBase subAction in subActions) { await this.ActionEditorList.AddAction(subAction); } subActions.Clear(); await base.OnLoadedInternal(); }
public static async Task <bool> ExportCommandToFile(CommandModelBase command) { if (command != null) { string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(command.Name + MixItUpCommandFileExtension); if (!string.IsNullOrEmpty(fileName)) { await FileSerializerHelper.SerializeToFile(fileName, command); return(true); } } return(false); }
private async void ExportButton_Click(object sender, RoutedEventArgs e) { await this.window.RunAsyncOperation(async() => { CommandBase command = await this.GetNewCommand(); if (command != null) { string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(command.Name + ".mixitupc"); if (!string.IsNullOrEmpty(fileName)) { await FileSerializerHelper.SerializeToFile(fileName, command); } } }); }
public static async Task Version3Upgrade(int version, string filePath) { if (version < 3) { SettingsV3Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV3Model>(filePath, ignoreErrors : true); await settings.Initialize(); if (settings.StreamingPlatformAuthentications.ContainsKey(StreamingPlatformTypeEnum.Twitch)) { settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken = null; } await settings.LoadAllUserData(); await ChannelSession.Services.Database.Write(settings.DatabaseFilePath, "ALTER TABLE Users ADD COLUMN TwitchUsername TEXT DEFAULT NULL"); await ChannelSession.Services.Database.Write(settings.DatabaseFilePath, "ALTER TABLE Users ADD COLUMN YouTubeUsername TEXT DEFAULT NULL"); await ChannelSession.Services.Database.Write(settings.DatabaseFilePath, "ALTER TABLE Users ADD COLUMN FacebookUsername TEXT DEFAULT NULL"); await ChannelSession.Services.Database.Write(settings.DatabaseFilePath, "ALTER TABLE Users ADD COLUMN TrovoUsername TEXT DEFAULT NULL"); await ChannelSession.Services.Database.Write(settings.DatabaseFilePath, "ALTER TABLE Users ADD COLUMN GlimeshUsername TEXT DEFAULT NULL"); Dictionary <Guid, string> userIDToUsername = new Dictionary <Guid, string>(); foreach (var kvp in settings.UserData) { if (kvp.Value.Platform == StreamingPlatformTypeEnum.Twitch && !string.IsNullOrEmpty(kvp.Value.TwitchUsername)) { userIDToUsername[kvp.Key] = kvp.Value.TwitchUsername; } } await ChannelSession.Services.Database.BulkWrite(settings.DatabaseFilePath, "UPDATE Users SET TwitchUsername = $TwitchUsername WHERE ID = $ID", userIDToUsername.Select(u => new Dictionary <string, object>() { { "$ID", u.Key.ToString() }, { "$TwitchUsername", u.Value.ToString() } })); await ChannelSession.Services.Settings.Save(settings); } }
public async Task SaveLocalBackup(SettingsV3Model settings) { if (settings != null) { Logger.Log(LogLevel.Debug, "Settings local backup save operation started"); if (ChannelSession.Services.FileService.GetFileSize(settings.SettingsFilePath) == 0) { Logger.Log(LogLevel.Debug, "Main settings file is empty, aborting local backup settings save operation"); return; } await semaphore.WaitAndRelease(async() => { await FileSerializerHelper.SerializeToFile(settings.SettingsLocalBackupFilePath, settings); }); Logger.Log(LogLevel.Debug, "Settings local backup save operation finished"); } }
private async void CommandEditorWindow_Drop(object sender, DragEventArgs e) { object obj = e.Data.GetData("FileNameW"); if (obj != null) { bool success = false; try { e.Handled = true; this.ActionsGrid.Visibility = Visibility.Visible; this.ImportCommandVisualGrid.Visibility = Visibility.Hidden; string filename = ((string[])obj)[0]; if (!string.IsNullOrEmpty(filename)) { CommandModelBase command = await FileSerializerHelper.DeserializeFromFile <CommandModelBase>(filename); if (command != null) { foreach (ActionModelBase action in command.Actions) { await this.viewModel.AddAction(action); } success = true; } } } catch (Exception ex) { Logger.Log(ex); } if (!success) { await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToImportCommand); } } }
public static async Task Version2Upgrade(int version, string filePath) { if (version < 2) { SettingsV3Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV3Model>(filePath, ignoreErrors : true); await settings.Initialize(); if (settings.StreamingPlatformAuthentications.ContainsKey(StreamingPlatformTypeEnum.Twitch)) { settings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken = null; } #pragma warning disable CS0612 // Type or member is obsolete if (settings.UnlockAllCommands) #pragma warning restore CS0612 // Type or member is obsolete { settings.CommandServiceLockType = CommandServiceLockTypeEnum.None; } await ChannelSession.Services.Settings.Save(settings); } }
public static async Task <ApplicationSettingsV2Model> Load() { ApplicationSettingsV2Model settings = new ApplicationSettingsV2Model(); if (ChannelSession.Services.FileService.FileExists(ApplicationSettingsFileName)) { try { settings = await FileSerializerHelper.DeserializeFromFile <ApplicationSettingsV2Model>(ApplicationSettingsFileName); } catch (Exception ex) { Logger.Log(ex); } } //if (settings.ForceResetPreviewProgram) //{ // settings.ForceResetPreviewProgram = false; // settings.PreviewProgram = false; //} return(settings); }
private async void ImportButton_Click(object sender, RoutedEventArgs e) { await this.window.RunAsyncOperation(async() => { string fileName = ChannelSession.Services.FileService.ShowOpenFileDialog("Mix It Up Command (*.mixitupc)|*.mixitupc|All files (*.*)|*.*"); if (!string.IsNullOrEmpty(fileName)) { try { ActionListContainer actionContainer = await FileSerializerHelper.DeserializeFromFile <ActionListContainer>(fileName); if (actionContainer != null && actionContainer.Actions != null) { foreach (ActionBase action in actionContainer.Actions) { ActionContainerControl actionControl = new ActionContainerControl(this.window, this, action); actionControl.Minimize(); this.actionControls.Add(actionControl); } } } catch (Exception ex) { Logger.Log(ex); } } }); }
public CommandEditorWindowViewModelBase(CommandTypeEnum type) { this.Type = type; this.SaveCommand = this.CreateCommand(async(parameter) => { CommandModelBase command = await this.ValidateAndBuildCommand(); if (command != null) { if (!command.IsEmbedded) { ChannelSession.Settings.SetCommand(command); await ChannelSession.SaveSettings(); } await this.SaveCommandToSettings(command); this.CommandSaved(this, command); } }); this.TestCommand = this.CreateCommand(async(parameter) => { if (!await this.CheckForResultErrors(await this.ValidateActions())) { IEnumerable <ActionModelBase> actions = await this.GetActions(); if (actions != null) { await CommandModelBase.RunActions(actions, CommandParametersModel.GetTestParameters(this.GetTestSpecialIdentifiers())); } } }); this.ExportCommand = this.CreateCommand(async(parameter) => { CommandModelBase command = await this.ValidateAndBuildCommand(); if (command != null) { string fileName = ChannelSession.Services.FileService.ShowSaveFileDialog(this.Name + MixItUpCommandFileExtension); if (!string.IsNullOrEmpty(fileName)) { await FileSerializerHelper.SerializeToFile(fileName, command); } } }); this.ImportCommand = this.CreateCommand(async(parameter) => { try { CommandModelBase command = await CommandEditorWindowViewModelBase.ImportCommandFromFile(); if (command != null) { // TODO Check if the imported command type matches the currently edited command. If so, import additional information. foreach (ActionModelBase action in command.Actions) { await this.AddAction(action); } } } catch (Exception ex) { Logger.Log(ex); await DialogHelper.ShowMessage(MixItUp.Base.Resources.FailedToImportCommand); } }); }
public static async Task Version43Upgrade(string filePath) { SettingsV2Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV2Model>(filePath, ignoreErrors : true); await settings.Initialize(); if (settings.IsStreamer) { List <EventCommand> eventCommandsToAdd = new List <EventCommand>(); List <EventCommand> eventCommandsToRemove = new List <EventCommand>(); foreach (EventCommand command in settings.EventCommands) { EventCommand newCommand = null; switch (command.EventCommandType) { #pragma warning disable CS0612 // Type or member is obsolete case EventTypeEnum.MixerChannelEmbersUsed: newCommand = new EventCommand(EventTypeEnum.TwitchChannelBitsCheered); break; case EventTypeEnum.MixerChannelFollowed: newCommand = new EventCommand(EventTypeEnum.TwitchChannelFollowed); break; case EventTypeEnum.MixerChannelHosted: newCommand = new EventCommand(EventTypeEnum.TwitchChannelRaided); break; case EventTypeEnum.MixerChannelResubscribed: newCommand = new EventCommand(EventTypeEnum.TwitchChannelResubscribed); break; case EventTypeEnum.MixerChannelStreamStart: newCommand = new EventCommand(EventTypeEnum.TwitchChannelStreamStart); break; case EventTypeEnum.MixerChannelStreamStop: newCommand = new EventCommand(EventTypeEnum.TwitchChannelStreamStop); break; case EventTypeEnum.MixerChannelSubscribed: newCommand = new EventCommand(EventTypeEnum.TwitchChannelSubscribed); break; case EventTypeEnum.MixerChannelSubscriptionGifted: newCommand = new EventCommand(EventTypeEnum.TwitchChannelSubscriptionGifted); break; case EventTypeEnum.MixerChannelUnfollowed: newCommand = new EventCommand(EventTypeEnum.TwitchChannelUnfollowed); break; #pragma warning restore CS0612 // Type or member is obsolete } if (newCommand != null) { eventCommandsToAdd.Add(newCommand); eventCommandsToRemove.Add(command); newCommand.Actions.AddRange(command.Actions); newCommand.Unlocked = command.Unlocked; newCommand.IsEnabled = command.IsEnabled; } } foreach (EventCommand command in eventCommandsToRemove) { settings.EventCommands.Remove(command); } foreach (EventCommand command in eventCommandsToAdd) { settings.EventCommands.Add(command); } settings.StreamElementsOAuthToken = null; settings.StreamJarOAuthToken = null; settings.StreamlabsOAuthToken = null; settings.TipeeeStreamOAuthToken = null; settings.TreatStreamOAuthToken = null; } await ChannelSession.Services.Settings.Save(settings); }
#pragma warning disable CS0612 // Type or member is obsolete public static async Task UpgradeV2ToV3(string filePath) { SettingsV2Model oldSettings = await FileSerializerHelper.DeserializeFromFile <SettingsV2Model>(filePath, ignoreErrors : true); await oldSettings.Initialize(); if (oldSettings.IsStreamer) { string settingsText = await ChannelSession.Services.FileService.ReadFile(filePath); settingsText = settingsText.Replace("MixItUp.Base.Model.Settings.SettingsV2Model, MixItUp.Base", "MixItUp.Base.Model.Settings.SettingsV3Model, MixItUp.Base"); settingsText = settingsText.Replace("MixItUp.Base.ViewModel.User.UserRoleEnum", "MixItUp.Base.Model.User.UserRoleEnum"); SettingsV3Model newSettings = JSONSerializerHelper.DeserializeFromString <SettingsV3Model>(settingsText, ignoreErrors: true); await newSettings.Initialize(); newSettings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserOAuthToken = oldSettings.TwitchUserOAuthToken; newSettings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].UserID = oldSettings.TwitchUserID; newSettings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].ChannelID = oldSettings.TwitchChannelID; newSettings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotID = (oldSettings.TwitchBotOAuthToken != null) ? string.Empty : null; newSettings.StreamingPlatformAuthentications[StreamingPlatformTypeEnum.Twitch].BotOAuthToken = oldSettings.TwitchBotOAuthToken; newSettings.PatreonTierSubscriberEquivalent = oldSettings.PatreonTierMixerSubscriberEquivalent; foreach (var kvp in oldSettings.CooldownGroups) { newSettings.CooldownGroupAmounts[kvp.Key] = kvp.Value; } foreach (var kvp in oldSettings.CommandGroups) { newSettings.CommandGroups[kvp.Key] = new CommandGroupSettingsModel(kvp.Value); } foreach (ChatCommand command in oldSettings.ChatCommands) { newSettings.SetCommand(new ChatCommandModel(command)); } foreach (EventCommand command in oldSettings.EventCommands) { newSettings.SetCommand(new EventCommandModel(command)); } foreach (TimerCommand command in oldSettings.TimerCommands) { newSettings.SetCommand(new TimerCommandModel(command)); } foreach (ActionGroupCommand command in oldSettings.ActionGroupCommands) { newSettings.SetCommand(new ActionGroupCommandModel(command)); } foreach (TwitchChannelPointsCommand command in oldSettings.TwitchChannelPointsCommands) { newSettings.SetCommand(new TwitchChannelPointsCommandModel(command)); } foreach (CustomCommand command in oldSettings.CustomCommands.Values) { newSettings.SetCommand(new CustomCommandModel(command)); } foreach (GameCommandBase command in oldSettings.GameCommands) { if (command.GetType() == typeof(BeachBallGameCommand)) { newSettings.SetCommand(new HotPotatoGameCommandModel((BeachBallGameCommand)command)); } else if (command.GetType() == typeof(BetGameCommand)) { newSettings.SetCommand(new BetGameCommandModel((BetGameCommand)command)); } else if (command.GetType() == typeof(BidGameCommand)) { newSettings.SetCommand(new BidGameCommandModel((BidGameCommand)command)); } else if (command.GetType() == typeof(CoinPusherGameCommand)) { newSettings.SetCommand(new CoinPusherGameCommandModel((CoinPusherGameCommand)command)); } else if (command.GetType() == typeof(DuelGameCommand)) { newSettings.SetCommand(new DuelGameCommandModel((DuelGameCommand)command)); } else if (command.GetType() == typeof(HangmanGameCommand)) { newSettings.SetCommand(new HangmanGameCommandModel((HangmanGameCommand)command)); } else if (command.GetType() == typeof(HeistGameCommand)) { newSettings.SetCommand(new HeistGameCommandModel((HeistGameCommand)command)); } else if (command.GetType() == typeof(HitmanGameCommand)) { newSettings.SetCommand(new HitmanGameCommandModel((HitmanGameCommand)command)); } else if (command.GetType() == typeof(HotPotatoGameCommand)) { newSettings.SetCommand(new HotPotatoGameCommandModel((HotPotatoGameCommand)command)); } else if (command.GetType() == typeof(LockBoxGameCommand)) { newSettings.SetCommand(new LockBoxGameCommandModel((LockBoxGameCommand)command)); } else if (command.GetType() == typeof(PickpocketGameCommand)) { newSettings.SetCommand(new StealGameCommandModel((PickpocketGameCommand)command)); } else if (command.GetType() == typeof(RouletteGameCommand)) { newSettings.SetCommand(new RouletteGameCommandModel((RouletteGameCommand)command)); } else if (command.GetType() == typeof(RussianRouletteGameCommand)) { newSettings.SetCommand(new RussianRouletteGameCommandModel((RussianRouletteGameCommand)command)); } else if (command.GetType() == typeof(SlotMachineGameCommand)) { newSettings.SetCommand(new SlotMachineGameCommandModel((SlotMachineGameCommand)command)); } else if (command.GetType() == typeof(SpinGameCommand)) { newSettings.SetCommand(new SpinGameCommandModel((SpinGameCommand)command)); } else if (command.GetType() == typeof(StealGameCommand)) { newSettings.SetCommand(new StealGameCommandModel((StealGameCommand)command)); } else if (command.GetType() == typeof(TreasureDefenseGameCommand)) { newSettings.SetCommand(new TreasureDefenseGameCommandModel((TreasureDefenseGameCommand)command)); } else if (command.GetType() == typeof(TriviaGameCommand)) { newSettings.SetCommand(new TriviaGameCommandModel((TriviaGameCommand)command)); } else if (command.GetType() == typeof(VendingMachineGameCommand)) { newSettings.SetCommand(new SpinGameCommandModel((VendingMachineGameCommand)command)); } else if (command.GetType() == typeof(VolcanoGameCommand)) { newSettings.SetCommand(new VolcanoGameCommandModel((VolcanoGameCommand)command)); } else if (command.GetType() == typeof(WordScrambleGameCommand)) { newSettings.SetCommand(new WordScrambleGameCommandModel((WordScrambleGameCommand)command)); } } newSettings.RemoveCommand(newSettings.GameQueueUserJoinedCommandID); newSettings.GameQueueUserJoinedCommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.GameQueueUserJoinedCommand); newSettings.RemoveCommand(newSettings.GameQueueUserSelectedCommandID); newSettings.GameQueueUserSelectedCommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.GameQueueUserSelectedCommand); newSettings.RemoveCommand(newSettings.GiveawayStartedReminderCommandID); newSettings.GiveawayStartedReminderCommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.GiveawayStartedReminderCommand); newSettings.RemoveCommand(newSettings.GiveawayUserJoinedCommandID); newSettings.GiveawayUserJoinedCommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.GiveawayUserJoinedCommand); newSettings.RemoveCommand(newSettings.GiveawayWinnerSelectedCommandID); newSettings.GiveawayWinnerSelectedCommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.GiveawayWinnerSelectedCommand); newSettings.RemoveCommand(newSettings.ModerationStrike1CommandID); newSettings.ModerationStrike1CommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.ModerationStrike1Command); newSettings.RemoveCommand(newSettings.ModerationStrike2CommandID); newSettings.ModerationStrike2CommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.ModerationStrike2Command); newSettings.RemoveCommand(newSettings.ModerationStrike3CommandID); newSettings.ModerationStrike3CommandID = SettingsV3Upgrader.ImportCustomCommand(newSettings, oldSettings.ModerationStrike3Command); foreach (UserQuoteViewModel quote in oldSettings.Quotes) { newSettings.Quotes.Add(quote.Model); } foreach (var kvp in oldSettings.UserData) { newSettings.UserData[kvp.Key] = kvp.Value; if (kvp.Value.EntranceCommand != null) { CustomCommandModel entranceCommand = new CustomCommandModel(kvp.Value.EntranceCommand); newSettings.SetCommand(entranceCommand); kvp.Value.EntranceCommandID = entranceCommand.ID; kvp.Value.EntranceCommand = null; } foreach (ChatCommand command in kvp.Value.CustomCommands) { UserOnlyChatCommandModel userCommand = new UserOnlyChatCommandModel(command, kvp.Key); newSettings.SetCommand(userCommand); kvp.Value.CustomCommandIDs.Add(userCommand.ID); } kvp.Value.CustomCommands.Clear(); } newSettings.GiveawayRequirementsSet = new RequirementsSetModel(oldSettings.GiveawayRequirements); foreach (OverlayWidgetModel widget in newSettings.OverlayWidgets.ToList()) { if (widget.Item is OverlayClipPlaybackItemModel) { newSettings.OverlayWidgets.Remove(widget); } else if (widget.Item is OverlayLeaderboardListItemModel) { if (((OverlayLeaderboardListItemModel)widget.Item).NewLeaderCommand != null) { CustomCommandModel command = new CustomCommandModel(((OverlayLeaderboardListItemModel)widget.Item).NewLeaderCommand); newSettings.SetCommand(command); ((OverlayLeaderboardListItemModel)widget.Item).LeaderChangedCommandID = command.ID; ((OverlayLeaderboardListItemModel)widget.Item).NewLeaderCommand = null; } } else if (widget.Item is OverlayProgressBarItemModel) { if (((OverlayProgressBarItemModel)widget.Item).GoalReachedCommand != null) { CustomCommandModel command = new CustomCommandModel(((OverlayProgressBarItemModel)widget.Item).GoalReachedCommand); newSettings.SetCommand(command); ((OverlayProgressBarItemModel)widget.Item).ProgressGoalReachedCommandID = command.ID; ((OverlayProgressBarItemModel)widget.Item).GoalReachedCommand = null; } } else if (widget.Item is OverlayStreamBossItemModel) { if (((OverlayStreamBossItemModel)widget.Item).NewStreamBossCommand != null) { CustomCommandModel command = new CustomCommandModel(((OverlayStreamBossItemModel)widget.Item).NewStreamBossCommand); newSettings.SetCommand(command); ((OverlayStreamBossItemModel)widget.Item).StreamBossChangedCommandID = command.ID; ((OverlayStreamBossItemModel)widget.Item).NewStreamBossCommand = null; } } else if (widget.Item is OverlayTimerItemModel) { if (((OverlayTimerItemModel)widget.Item).TimerCompleteCommand != null) { CustomCommandModel command = new CustomCommandModel(((OverlayTimerItemModel)widget.Item).TimerCompleteCommand); newSettings.SetCommand(command); ((OverlayTimerItemModel)widget.Item).TimerFinishedCommandID = command.ID; ((OverlayTimerItemModel)widget.Item).TimerCompleteCommand = null; } } } await ChannelSession.Services.Settings.Save(newSettings); } await ChannelSession.Services.FileService.CopyFile(oldSettings.SettingsFilePath, Path.Combine(SettingsV2Model.SettingsDirectoryName, "Old", oldSettings.SettingsFileName)); await ChannelSession.Services.FileService.CopyFile(oldSettings.SettingsLocalBackupFilePath, Path.Combine(SettingsV2Model.SettingsDirectoryName, "Old", oldSettings.SettingsLocalBackupFileName)); await ChannelSession.Services.FileService.CopyFile(oldSettings.DatabaseFilePath, Path.Combine(SettingsV2Model.SettingsDirectoryName, "Old", oldSettings.DatabaseFileName)); await ChannelSession.Services.FileService.DeleteFile(oldSettings.SettingsFilePath); await ChannelSession.Services.FileService.DeleteFile(oldSettings.SettingsLocalBackupFilePath); await ChannelSession.Services.FileService.DeleteFile(oldSettings.DatabaseFilePath); }
public async Task <Result <SettingsV3Model> > RestorePackagedBackup(string filePath) { try { string tempFilePath = ChannelSession.Services.FileService.GetTempFolder(); string tempFolder = Path.GetDirectoryName(tempFilePath); string settingsFile = null; string databaseFile = null; try { using (ZipArchive zipFile = ZipFile.Open(filePath, ZipArchiveMode.Read)) { foreach (ZipArchiveEntry entry in zipFile.Entries) { string extractedFilePath = Path.Combine(tempFolder, entry.Name); if (File.Exists(extractedFilePath)) { File.Delete(extractedFilePath); } if (extractedFilePath.EndsWith(SettingsV3Model.SettingsFileExtension, StringComparison.InvariantCultureIgnoreCase)) { settingsFile = extractedFilePath; } else if (extractedFilePath.EndsWith(SettingsV3Model.DatabaseFileExtension, StringComparison.InvariantCultureIgnoreCase)) { databaseFile = extractedFilePath; } } zipFile.ExtractToDirectory(tempFolder); } } catch (Exception ex) { Logger.Log(ex); } int currentVersion = -1; if (!string.IsNullOrEmpty(settingsFile)) { currentVersion = await SettingsV3Upgrader.GetSettingsVersion(settingsFile); } if (currentVersion == -1) { return(new Result <SettingsV3Model>("The backup file selected does not appear to contain Mix It Up settings.")); } if (currentVersion > SettingsV3Model.LatestVersion) { return(new Result <SettingsV3Model>("The backup file is valid, but is from a newer version of Mix It Up. Be sure to upgrade to the latest version." + Environment.NewLine + Environment.NewLine + "NOTE: This may require you to opt-in to the Preview build from the General tab in Settings if this was made in a Preview build.")); } return(new Result <SettingsV3Model>(await FileSerializerHelper.DeserializeFromFile <SettingsV3Model>(settingsFile))); } catch (Exception ex) { Logger.Log(ex); return(new Result <SettingsV3Model>(ex)); } }
public static async Task Version42Upgrade(string filePath) { SettingsV2Model settings = await FileSerializerHelper.DeserializeFromFile <SettingsV2Model>(filePath, ignoreErrors : true); if (settings.IsStreamer) { List <UserQuoteModel> quotes = new List <UserQuoteModel>(); await ChannelSession.Services.Database.Read(settings.DatabaseFilePath, "SELECT * FROM Quotes", (Dictionary <string, object> data) => { string json = (string)data["Data"]; json = json.Replace("MixItUp.Base.ViewModel.User.UserQuoteViewModel", "MixItUp.Base.Model.User.UserQuoteModel"); quotes.Add(JSONSerializerHelper.DeserializeFromString <UserQuoteModel>(json)); }); await ChannelSession.Services.Database.BulkWrite(settings.DatabaseFilePath, "REPLACE INTO Quotes(ID, Data) VALUES(@ID, @Data)", quotes.Select(q => new Dictionary <string, object>() { { "@ID", q.ID.ToString() }, { "@Data", JSONSerializerHelper.SerializeToString(q) } })); } await settings.Initialize(); #pragma warning disable CS0612 // Type or member is obsolete if (settings.DiagnosticLogging) { ChannelSession.AppSettings.DiagnosticLogging = true; } #pragma warning restore CS0612 // Type or member is obsolete #pragma warning disable CS0612 // Type or member is obsolete foreach (UserCurrencyModel oldCurrency in settings.Currencies.Values) { CurrencyModel newCurrency = new CurrencyModel(); newCurrency.ID = oldCurrency.ID; newCurrency.Name = oldCurrency.Name; newCurrency.AcquireAmount = oldCurrency.AcquireAmount; newCurrency.AcquireInterval = oldCurrency.AcquireInterval; newCurrency.MinimumActiveRate = oldCurrency.MinimumActiveRate; newCurrency.OfflineAcquireAmount = oldCurrency.OfflineAcquireAmount; newCurrency.OfflineAcquireInterval = oldCurrency.OfflineAcquireInterval; newCurrency.MaxAmount = oldCurrency.MaxAmount; newCurrency.SpecialIdentifier = oldCurrency.SpecialIdentifier; newCurrency.SubscriberBonus = oldCurrency.SubscriberBonus; newCurrency.ModeratorBonus = oldCurrency.ModeratorBonus; newCurrency.OnFollowBonus = oldCurrency.OnFollowBonus; newCurrency.OnHostBonus = oldCurrency.OnHostBonus; newCurrency.OnSubscribeBonus = oldCurrency.OnSubscribeBonus; newCurrency.ResetInterval = (Model.Currency.CurrencyResetRateEnum)((int)oldCurrency.ResetInterval); newCurrency.ResetStartCadence = oldCurrency.ResetStartCadence; newCurrency.LastReset = oldCurrency.LastReset; newCurrency.IsPrimary = oldCurrency.IsPrimary; if (oldCurrency.RankChangedCommand != null) { settings.SetCustomCommand(oldCurrency.RankChangedCommand); newCurrency.RankChangedCommandID = oldCurrency.RankChangedCommand.ID; } foreach (UserRankViewModel rank in oldCurrency.Ranks) { newCurrency.Ranks.Add(new RankModel(rank.Name, rank.MinimumPoints)); } settings.Currency[newCurrency.ID] = newCurrency; } foreach (UserInventoryModel oldInventory in settings.Inventories.Values) { InventoryModel newInventory = new InventoryModel(); newInventory.ID = oldInventory.ID; newInventory.Name = oldInventory.Name; newInventory.DefaultMaxAmount = oldInventory.DefaultMaxAmount; newInventory.SpecialIdentifier = oldInventory.SpecialIdentifier; newInventory.ShopEnabled = oldInventory.ShopEnabled; newInventory.ShopCommand = oldInventory.ShopCommand; newInventory.ShopCurrencyID = oldInventory.ShopCurrencyID; newInventory.TradeEnabled = oldInventory.TradeEnabled; newInventory.TradeCommand = oldInventory.TradeCommand; if (oldInventory.ItemsBoughtCommand != null) { settings.SetCustomCommand(oldInventory.ItemsBoughtCommand); newInventory.ItemsBoughtCommandID = oldInventory.ItemsBoughtCommand.ID; } else { CustomCommand buyCommand = new CustomCommand(InventoryWindowViewModel.ItemsBoughtCommandName); buyCommand.Actions.Add(new ChatAction("You bought $itemtotal $itemname for $itemcost $currencyname", sendAsStreamer: false)); settings.SetCustomCommand(buyCommand); newInventory.ItemsBoughtCommandID = buyCommand.ID; } if (oldInventory.ItemsSoldCommand != null) { settings.SetCustomCommand(oldInventory.ItemsSoldCommand); newInventory.ItemsSoldCommandID = oldInventory.ItemsSoldCommand.ID; } else { CustomCommand sellCommand = new CustomCommand(InventoryWindowViewModel.ItemsSoldCommandName); sellCommand.Actions.Add(new ChatAction("You sold $itemtotal $itemname for $itemcost $currencyname", sendAsStreamer: false)); settings.SetCustomCommand(sellCommand); newInventory.ItemsSoldCommandID = sellCommand.ID; } if (oldInventory.ItemsTradedCommand != null) { settings.SetCustomCommand(oldInventory.ItemsTradedCommand); newInventory.ItemsTradedCommandID = oldInventory.ItemsTradedCommand.ID; } else { CustomCommand tradeCommand = new CustomCommand(InventoryWindowViewModel.ItemsTradedCommandName); tradeCommand.Actions.Add(new ChatAction("@$username traded $itemtotal $itemname to @$targetusername for $targetitemtotal $targetitemname", sendAsStreamer: false)); settings.SetCustomCommand(tradeCommand); newInventory.ItemsTradedCommandID = tradeCommand.ID; } foreach (UserInventoryItemModel oldItem in oldInventory.Items.Values.ToList()) { InventoryItemModel newItem = new InventoryItemModel(oldItem.Name, oldItem.MaxAmount, oldItem.BuyAmount, oldItem.SellAmount); newItem.ID = oldItem.ID; newInventory.Items[newItem.ID] = newItem; } settings.Inventory[newInventory.ID] = newInventory; } #pragma warning restore CS0612 // Type or member is obsolete if (settings.GiveawayRequirements != null && settings.GiveawayRequirements.Inventory != null && settings.Inventory.ContainsKey(settings.GiveawayRequirements.Inventory.InventoryID)) { InventoryModel inventory = settings.Inventory[settings.GiveawayRequirements.Inventory.InventoryID]; #pragma warning disable CS0612 // Type or member is obsolete if (inventory != null && !string.IsNullOrEmpty(settings.GiveawayRequirements.Inventory.ItemName)) { InventoryItemModel item = inventory.GetItem(settings.GiveawayRequirements.Inventory.ItemName); if (item != null) { settings.GiveawayRequirements.Inventory.ItemID = item.ID; } settings.GiveawayRequirements.Inventory.ItemName = null; } #pragma warning restore CS0612 // Type or member is obsolete } foreach (CommandBase command in SettingsV2Upgrader.GetAllCommands(settings)) { if (command is PermissionsCommandBase) { PermissionsCommandBase pCommand = (PermissionsCommandBase)command; if (pCommand.Requirements != null && pCommand.Requirements.Inventory != null && settings.Inventory.ContainsKey(pCommand.Requirements.Inventory.InventoryID)) { InventoryModel inventory = settings.Inventory[pCommand.Requirements.Inventory.InventoryID]; #pragma warning disable CS0612 // Type or member is obsolete if (inventory != null && !string.IsNullOrEmpty(pCommand.Requirements.Inventory.ItemName)) { InventoryItemModel item = inventory.GetItem(pCommand.Requirements.Inventory.ItemName); if (item != null) { pCommand.Requirements.Inventory.ItemID = item.ID; } pCommand.Requirements.Inventory.ItemName = null; } #pragma warning restore CS0612 // Type or member is obsolete } } } List <UserDataModel> usersToRemove = new List <UserDataModel>(); foreach (UserDataModel user in settings.UserData.Values.ToList()) { if (user.MixerID <= 0) { usersToRemove.Add(user); } } foreach (UserDataModel user in usersToRemove) { settings.UserData.Remove(user.ID); } await ChannelSession.Services.Settings.Save(settings); }