public static void RestructureNewerOverlayActions(List <ActionBase> actions)
        {
            for (int i = 0; i < actions.Count; i++)
            {
                ActionBase action = actions[i];
                if (action is OverlayAction)
                {
                    OverlayAction oAction = (OverlayAction)action;
#pragma warning disable CS0612 // Type or member is obsolete
                    if (oAction.Item != null)
                    {
                        oAction.OverlayItem          = ConvertOverlayItem(oAction.Item);
                        oAction.OverlayItem.Position = new OverlayItemPositionModel((OverlayItemPositionType)oAction.Position.PositionType, oAction.Position.Horizontal, oAction.Position.Vertical, 0);
                        oAction.OverlayItem.Effects  = new OverlayItemEffectsModel((OverlayItemEffectEntranceAnimationTypeEnum)oAction.Effects.EntranceAnimation, (OverlayItemEffectVisibleAnimationTypeEnum)oAction.Effects.VisibleAnimation,
                                                                                   (OverlayItemEffectExitAnimationTypeEnum)oAction.Effects.ExitAnimation, oAction.Effects.Duration);

                        oAction.Item     = null;
                        oAction.Position = null;
                        oAction.Effects  = null;
                        oAction.Effect   = null;
                    }
#pragma warning restore CS0612 // Type or member is obsolete
                }
            }
        }
        private async void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            await this.window.RunAsyncOperation(async() =>
            {
                StoreDetailListingModel listingDetails = await ChannelSession.Services.MixItUpService.GetStoreListing(this.currentListing.ID);
                await ChannelSession.Services.MixItUpService.AddStoreListingDownload(this.currentListing);

                List <ActionBase> actions = listingDetails.GetActions();

                StoreCommandUpgrader.PerformUpgrades(actions, listingDetails.AppVersion);

                if (listingDetails.AssetsIncluded && listingDetails.AssetData != null && listingDetails.AssetData.Length > 0)
                {
                    if (await MessageBoxHelper.ShowConfirmationDialog("This command contains included assets." + Environment.NewLine + "Would you like to download them?"))
                    {
                        string folderLocation = ChannelSession.Services.FileService.ShowOpenFolderDialog();
                        if (!string.IsNullOrEmpty(folderLocation))
                        {
                            string zipFilePath = Path.Combine(ChannelSession.Services.FileService.GetTempFolder(), listingDetails.ID.ToString() + ".zip");
                            await ChannelSession.Services.FileService.SaveFileAsBytes(zipFilePath, listingDetails.AssetData);
                            await ChannelSession.Services.FileService.UnzipFiles(zipFilePath, folderLocation);

                            IEnumerable <string> assetFileNames = (await ChannelSession.Services.FileService.GetFilesInDirectory(folderLocation)).Select(s => Path.GetFileName(s));
                            foreach (ActionBase action in actions)
                            {
                                if (action.Type == ActionTypeEnum.Overlay)
                                {
                                    OverlayAction oAction = (OverlayAction)action;
                                    if (oAction.Effect is OverlayImageEffect)
                                    {
                                        OverlayImageEffect iEffect = (OverlayImageEffect)oAction.Effect;
                                        if (assetFileNames.Contains(Path.GetFileName(iEffect.FilePath)))
                                        {
                                            iEffect.FilePath = Path.Combine(folderLocation, Path.GetFileName(iEffect.FilePath));
                                        }
                                    }
                                }
                                else if (action.Type == ActionTypeEnum.Sound)
                                {
                                    SoundAction sAction = (SoundAction)action;
                                    if (assetFileNames.Contains(Path.GetFileName(sAction.FilePath)))
                                    {
                                        sAction.FilePath = Path.Combine(folderLocation, Path.GetFileName(sAction.FilePath));
                                    }
                                }
                            }
                        }
                    }
                }

                this.window.DownloadCommandFromStore(listingDetails.ID, actions);
            });
        }
        internal static void RestructureNewOverlayActions(List <ActionBase> actions)
        {
            for (int i = 0; i < actions.Count; i++)
            {
                ActionBase action = actions[i];
                if (action is OverlayAction)
                {
                    OverlayAction oAction = (OverlayAction)action;
#pragma warning disable CS0612 // Type or member is obsolete
                    if (oAction.Effect != null)
                    {
                        if (oAction.Effect is OverlayTextEffect)
                        {
                            OverlayTextEffect effect = (OverlayTextEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayTextItem(effect.Text, effect.Color, effect.Size, string.Empty, true, false, false, string.Empty);
                        }
                        else if (oAction.Effect is OverlayImageEffect)
                        {
                            OverlayImageEffect effect = (OverlayImageEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayImageItem(effect.FilePath, effect.Width, effect.Height);
                        }
                        else if (oAction.Effect is OverlayVideoEffect)
                        {
                            OverlayVideoEffect effect = (OverlayVideoEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayVideoItem(effect.FilePath, effect.Width, effect.Height, 100);
                        }
                        else if (oAction.Effect is OverlayYoutubeEffect)
                        {
                            OverlayYoutubeEffect effect = (OverlayYoutubeEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayYouTubeItem(effect.ID, effect.StartTime, effect.Width, effect.Height, 100);
                        }
                        else if (oAction.Effect is OverlayWebPageEffect)
                        {
                            OverlayWebPageEffect effect = (OverlayWebPageEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayWebPageItem(effect.URL, effect.Width, effect.Height);
                        }
                        else if (oAction.Effect is OverlayHTMLEffect)
                        {
                            OverlayHTMLEffect effect = (OverlayHTMLEffect)oAction.Effect;
                            oAction.Item = new Model.Overlay.OverlayHTMLItem(effect.HTMLText);
                        }
                        oAction.Position = new Model.Overlay.OverlayItemPosition(Model.Overlay.OverlayEffectPositionType.Percentage, oAction.Effect.Horizontal, oAction.Effect.Vertical);
                        oAction.Effects  = new Model.Overlay.OverlayItemEffects((Model.Overlay.OverlayEffectEntranceAnimationTypeEnum)oAction.Effect.EntranceAnimation,
                                                                                (Model.Overlay.OverlayEffectVisibleAnimationTypeEnum)oAction.Effect.VisibleAnimation, (Model.Overlay.OverlayEffectExitAnimationTypeEnum)oAction.Effect.ExitAnimation,
                                                                                oAction.Effect.Duration);
                        oAction.Effect = null;
                    }
#pragma warning restore CS0612 // Type or member is obsolete
                }
            }
        }
 public OverlayActionControl(ActionContainerControl containerControl, OverlayAction action) : this(containerControl) { this.action = action; }
        private async void DownloadButton_Click(object sender, RoutedEventArgs e)
        {
            await this.window.RunAsyncOperation(async() =>
            {
                StoreDetailListingModel listingDetails = await ChannelSession.Services.MixItUpService.GetStoreListing(this.currentListing.ID);
                if (listingDetails == null)
                {
                    await MessageBoxHelper.ShowMessageDialog("Failed to download command, please try again");
                    return;
                }

                Version assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;

                Version commandVersion = new Version(listingDetails.AppVersion);
                if (assemblyVersion < commandVersion)
                {
                    await MessageBoxHelper.ShowMessageDialog(string.Format("You can not download this command as it was created on version ({0}) of Mix It Up ", commandVersion));
                    return;
                }

                await ChannelSession.Services.MixItUpService.AddStoreListingDownload(listingDetails);

                List <ActionBase> actions = listingDetails.GetActions();

                StoreCommandUpgrader.PerformUpgrades(actions, listingDetails.AppVersion);

                if (listingDetails.AssetsIncluded && listingDetails.AssetData != null && listingDetails.AssetData.Length > 0)
                {
                    if (await MessageBoxHelper.ShowConfirmationDialog("This command contains included assets." + Environment.NewLine + "Would you like to download them?"))
                    {
                        string folderLocation = ChannelSession.Services.FileService.ShowOpenFolderDialog();
                        if (!string.IsNullOrEmpty(folderLocation))
                        {
                            string zipFilePath = Path.Combine(ChannelSession.Services.FileService.GetTempFolder(), listingDetails.ID.ToString() + ".zip");
                            await ChannelSession.Services.FileService.SaveFileAsBytes(zipFilePath, listingDetails.AssetData);
                            await ChannelSession.Services.FileService.UnzipFiles(zipFilePath, folderLocation);

                            IEnumerable <string> assetFileNames = (await ChannelSession.Services.FileService.GetFilesInDirectory(folderLocation)).Select(s => Path.GetFileName(s));
                            foreach (ActionBase action in actions)
                            {
                                if (action.Type == ActionTypeEnum.Overlay)
                                {
                                    OverlayAction oAction = (OverlayAction)action;
                                    if (oAction.Item is OverlayImageItem)
                                    {
                                        OverlayImageItem overlayItem = (OverlayImageItem)oAction.Item;
                                        if (assetFileNames.Contains(Path.GetFileName(overlayItem.FilePath)))
                                        {
                                            overlayItem.FilePath = Path.Combine(folderLocation, Path.GetFileName(overlayItem.FilePath));
                                        }
                                    }
                                }
                                else if (action.Type == ActionTypeEnum.Sound)
                                {
                                    SoundAction sAction = (SoundAction)action;
                                    if (assetFileNames.Contains(Path.GetFileName(sAction.FilePath)))
                                    {
                                        sAction.FilePath = Path.Combine(folderLocation, Path.GetFileName(sAction.FilePath));
                                    }
                                }
                            }
                        }
                    }
                }

                this.window.DownloadCommandFromStore(listingDetails.ID, actions);
            });
        }
        private static async Task Version11Upgrade(int version, string filePath)
        {
            if (version < 11)
            {
                string data = File.ReadAllText(filePath);
                data = data.Replace("MixItUp.Base.Actions.OverlayAction, MixItUp.Base", "MixItUp.Desktop.Services.LegacyOverlayAction, MixItUp.Desktop");
                DesktopChannelSettings legacySettings = SerializerHelper.DeserializeFromString <DesktopChannelSettings>(data);
                await ChannelSession.Services.Settings.Initialize(legacySettings);

                Dictionary <Guid, LegacyOverlayAction> legacyOverlayActions = new Dictionary <Guid, LegacyOverlayAction>();

                List <CommandBase> commands = new List <CommandBase>();
                commands.AddRange(legacySettings.ChatCommands);
                commands.AddRange(legacySettings.EventCommands);
                commands.AddRange(legacySettings.InteractiveCommands);
                commands.AddRange(legacySettings.TimerCommands);
                commands.AddRange(legacySettings.ActionGroupCommands);
                commands.AddRange(legacySettings.GameCommands);
                commands.AddRange(legacySettings.RemoteCommands);
                foreach (CommandBase command in commands)
                {
                    foreach (ActionBase action in command.Actions)
                    {
                        if (action is LegacyOverlayAction)
                        {
                            legacyOverlayActions[action.ID] = (LegacyOverlayAction)action;
                        }
                    }
                }

                DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <LegacyDesktopChannelSettings>(filePath);

                await ChannelSession.Services.Settings.Initialize(settings);

                commands.Clear();
                commands.AddRange(settings.ChatCommands);
                commands.AddRange(settings.EventCommands);
                commands.AddRange(settings.InteractiveCommands);
                commands.AddRange(settings.TimerCommands);
                commands.AddRange(settings.ActionGroupCommands);
                commands.AddRange(settings.GameCommands);
                commands.AddRange(settings.RemoteCommands);
                foreach (CommandBase command in commands)
                {
                    foreach (ActionBase action in command.Actions)
                    {
                        if (action is OverlayAction && legacyOverlayActions.ContainsKey(action.ID))
                        {
                            OverlayAction       overlayAction       = (OverlayAction)action;
                            LegacyOverlayAction legacyOverlayAction = legacyOverlayActions[action.ID];

                            OverlayEffectEntranceAnimationTypeEnum entrance = OverlayEffectEntranceAnimationTypeEnum.None;
                            OverlayEffectExitAnimationTypeEnum     exit     = OverlayEffectExitAnimationTypeEnum.None;
                            if (legacyOverlayAction.FadeDuration > 0)
                            {
                                entrance = OverlayEffectEntranceAnimationTypeEnum.FadeIn;
                                exit     = OverlayEffectExitAnimationTypeEnum.FadeOut;
                            }

                            if (!string.IsNullOrEmpty(legacyOverlayAction.ImagePath))
                            {
                                overlayAction.Effect = new OverlayImageEffect(legacyOverlayAction.ImagePath, legacyOverlayAction.ImageWidth, legacyOverlayAction.ImageHeight,
                                                                              entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.Text))
                            {
                                overlayAction.Effect = new OverlayTextEffect(legacyOverlayAction.Text, legacyOverlayAction.Color, legacyOverlayAction.FontSize,
                                                                             entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.youtubeVideoID))
                            {
                                overlayAction.Effect = new OverlayYoutubeEffect(legacyOverlayAction.youtubeVideoID, legacyOverlayAction.youtubeStartTime, legacyOverlayAction.VideoWidth,
                                                                                legacyOverlayAction.VideoHeight, entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal,
                                                                                legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.localVideoFilePath))
                            {
                                overlayAction.Effect = new OverlayVideoEffect(legacyOverlayAction.localVideoFilePath, legacyOverlayAction.VideoWidth, legacyOverlayAction.VideoHeight,
                                                                              entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration, legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                            else if (!string.IsNullOrEmpty(legacyOverlayAction.HTMLText))
                            {
                                overlayAction.Effect = new OverlayHTMLEffect(legacyOverlayAction.HTMLText, entrance, OverlayEffectVisibleAnimationTypeEnum.None, exit, legacyOverlayAction.Duration,
                                                                             legacyOverlayAction.Horizontal, legacyOverlayAction.Vertical);
                            }
                        }
                        else if (action is CounterAction)
                        {
                            CounterAction counterAction = (CounterAction)action;
                            if (counterAction.SaveToFile)
                            {
                                counterAction.ResetOnLoad = !counterAction.ResetOnLoad;
                            }
                        }
                    }
                }

                await ChannelSession.Services.Settings.Save(settings);
            }
        }
Example #7
0
 public OverlayActionControl(OverlayAction action) : this()
 {
     this.action = action;
 }
Example #8
0
        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);
            }
        }
Example #9
0
        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);
            }
        }
Example #10
0
        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);
            }
        }
Example #11
0
        private async void UploadButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            await this.RunAsyncOperation(async() =>
            {
                if (string.IsNullOrEmpty(this.NameTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("A name must be specified");
                    return;
                }

                if (this.NameTextBox.Text.Length >= 50)
                {
                    await MessageBoxHelper.ShowMessageDialog("A name must be 50 characters or less");
                    return;
                }

                if (string.IsNullOrEmpty(this.DescriptionTextBox.Text))
                {
                    await MessageBoxHelper.ShowMessageDialog("A description must be specified");
                    return;
                }

                if (!string.IsNullOrEmpty(this.DisplayImagePathTextBox.Text))
                {
                    if (!File.Exists(this.DisplayImagePathTextBox.Text))
                    {
                        await MessageBoxHelper.ShowMessageDialog("The specified display image does not exist");
                        return;
                    }

                    FileInfo info = new FileInfo(this.DisplayImagePathTextBox.Text);
                    if (info.Length >= 1000000)
                    {
                        await MessageBoxHelper.ShowMessageDialog("Display image must be smaller than 1 MB");
                        return;
                    }
                }

                HashSet <string> tags = new HashSet <string>();
                if (this.Tag1ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag1ComboBox.Text);
                }
                if (this.Tag2ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag2ComboBox.Text);
                }
                if (this.Tag3ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag3ComboBox.Text);
                }
                if (this.Tag4ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag4ComboBox.Text);
                }
                if (this.Tag5ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag5ComboBox.Text);
                }
                if (this.Tag6ComboBox.SelectedIndex > 0)
                {
                    tags.Add(this.Tag6ComboBox.Text);
                }

                if (tags.Count == 0)
                {
                    await MessageBoxHelper.ShowMessageDialog("At least 1 tag must be selected");
                    return;
                }

                JObject metadata = new JObject();

                byte[] displayImageData = null;
                if (!string.IsNullOrEmpty(this.DisplayImagePathTextBox.Text))
                {
                    displayImageData = await ChannelSession.Services.FileService.ReadFileAsBytes(this.DisplayImagePathTextBox.Text);
                }

                byte[] assetData = null;
                if (this.IncludeAssetsToggleButton.IsChecked.GetValueOrDefault())
                {
                    List <string> assetFiles = new List <string>();
                    foreach (ActionBase action in this.command.Actions)
                    {
                        if (action.Type == ActionTypeEnum.Overlay)
                        {
                            OverlayAction oAction = (OverlayAction)action;
                            if (oAction.Item is OverlayImageItem)
                            {
                                OverlayImageItem overlayItem = (OverlayImageItem)oAction.Item;
                                if (File.Exists(overlayItem.FilePath))
                                {
                                    assetFiles.Add(overlayItem.FilePath);
                                }
                            }
                        }
                        else if (action.Type == ActionTypeEnum.Sound)
                        {
                            SoundAction sAction = (SoundAction)action;
                            if (File.Exists(sAction.FilePath))
                            {
                                assetFiles.Add(sAction.FilePath);
                            }
                        }
                    }

                    if (assetFiles.Count > 0)
                    {
                        foreach (string assetFile in assetFiles)
                        {
                            FileInfo info = new FileInfo(assetFile);
                            if (info.Length >= 1000000)
                            {
                                await MessageBoxHelper.ShowMessageDialog("All asset files must be smaller than 1 MB");
                                return;
                            }
                        }

                        string zipFilePath = Path.Combine(ChannelSession.Services.FileService.GetTempFolder(), this.command.ID.ToString() + ".zip");
                        if (File.Exists(zipFilePath))
                        {
                            File.Delete(zipFilePath);
                        }
                        await ChannelSession.Services.FileService.ZipFiles(zipFilePath, assetFiles);
                        assetData = await ChannelSession.Services.FileService.ReadFileAsBytes(zipFilePath);
                    }
                }

                await ChannelSession.Services.MixItUpService.AddStoreListing(new StoreDetailListingModel(this.command, this.NameTextBox.Text, this.DescriptionTextBox.Text, tags,
                                                                                                         this.DisplayImagePathTextBox.Text, displayImageData, assetData, metadata));

                this.command.StoreID = this.command.ID;

                this.Close();
            });
        }