private static async Task Version22Upgrade(int version, string filePath)
        {
            if (version < 22)
            {
                DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath);

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

                PreMadeChatCommandSettings cSetting = settings.PreMadeChatCommandSettings.FirstOrDefault(c => c.Name.Equals("Ban"));
                if (cSetting != null)
                {
                    cSetting.IsEnabled = false;
                }

                List <CommandBase> commands = new List <CommandBase>();
                commands.AddRange(settings.ChatCommands);
                commands.AddRange(settings.EventCommands);
                commands.AddRange(settings.InteractiveCommands);
                commands.AddRange(settings.TimerCommands);
                commands.AddRange(settings.ActionGroupCommands);
                commands.AddRange(settings.GameCommands);
                foreach (CommandBase command in commands)
                {
                    StoreCommandUpgrader.ChangeCounterActionsToUseSpecialIdentifiers(command.Actions);
                }

                await ChannelSession.Services.Settings.Save(settings);
            }
        }
        private static async Task Version35Upgrade(int version, string filePath)
        {
            if (version < 35)
            {
                DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath);

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

                foreach (CommandBase command in GetAllCommands(settings))
                {
                    StoreCommandUpgrader.RestructureNewerOverlayActions(command.Actions);
                }

#pragma warning disable CS0612 // Type or member is obsolete
                foreach (OverlayWidget widget in settings.overlayWidgetsInternal)
                {
                    OverlayItemModelBase newItem = StoreCommandUpgrader.ConvertOverlayItem(widget.Item);
                    newItem.ID       = widget.Item.ID;
                    newItem.Position = new OverlayItemPositionModel((OverlayItemPositionType)widget.Position.PositionType, widget.Position.Horizontal, widget.Position.Vertical, 0);
                    OverlayWidgetModel newWidget = new OverlayWidgetModel(widget.Name, widget.OverlayName, newItem, 0);
                    settings.OverlayWidgets.Add(newWidget);
                    if (newWidget.SupportsRefreshUpdating && !widget.DontRefresh)
                    {
                        newWidget.RefreshTime = settings.OverlayWidgetRefreshTime;
                    }
                }
                settings.overlayWidgetsInternal.Clear();
#pragma warning restore CS0612 // Type or member is obsolete

                await ChannelSession.Services.Settings.Save(settings);
            }
        }
        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);
            });
        }
        private static async Task Version24Upgrade(int version, string filePath)
        {
            if (version < 24)
            {
                DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath);

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

                foreach (CommandBase command in DesktopSettingsUpgrader.GetAllCommands(settings))
                {
                    StoreCommandUpgrader.RestructureNewOverlayActions(command.Actions);
                }

                await ChannelSession.Services.Settings.Save(settings);
            }
        }
        private static async Task Version36Upgrade(int version, string filePath)
        {
            if (version < 36)
            {
                DesktopChannelSettings settings = await SerializerHelper.DeserializeFromFile <DesktopChannelSettings>(filePath);

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

                foreach (CommandBase command in GetAllCommands(settings))
                {
                    StoreCommandUpgrader.ReplaceActionGroupAction(command.Actions);
                }

                await ChannelSession.Services.Settings.Save(settings);
            }
        }
        private static async Task Version18Upgrade(int version, string filePath)
        {
            if (version < 18)
            {
                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.EventCommands);
                commands.AddRange(settings.InteractiveCommands);
                commands.AddRange(settings.TimerCommands);
                commands.AddRange(settings.ActionGroupCommands);
                commands.AddRange(settings.GameCommands);
                foreach (CommandBase command in commands)
                {
                    StoreCommandUpgrader.SeperateChatFromCurrencyActions(command.Actions);
                }

                await ChannelSession.Services.Settings.Save(settings);
            }
        }
Exemplo n.º 7
0
        protected override async Task PerformInternal(UserViewModel user, IEnumerable <string> arguments)
        {
            if (this.WidgetID != Guid.Empty)
            {
                OverlayWidgetModel widget = ChannelSession.Settings.OverlayWidgets.FirstOrDefault(w => w.Item.ID.Equals(this.WidgetID));
                if (widget != null)
                {
                    if (this.ShowWidget)
                    {
                        await widget.Initialize(user, arguments, this.extraSpecialIdentifiers);
                    }
                    else
                    {
                        await widget.Disable();
                    }
                }
            }
            else
            {
#pragma warning disable CS0612 // Type or member is obsolete
                if (this.Item != null)
                {
                    StoreCommandUpgrader.RestructureNewerOverlayActions(new List <ActionBase>()
                    {
                        this
                    });
                }
#pragma warning restore CS0612 // Type or member is obsolete

                string          overlayName = (string.IsNullOrEmpty(this.OverlayName)) ? ChannelSession.Services.OverlayServers.DefaultOverlayName : this.OverlayName;
                IOverlayService overlay     = ChannelSession.Services.OverlayServers.GetOverlay(overlayName);
                if (overlay != null)
                {
                    await overlay.ShowItem(this.OverlayItem, user, arguments, this.extraSpecialIdentifiers);
                }
            }
        }
        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);
            });
        }
        public override Task OnLoaded()
        {
            if (ChannelSession.Settings.EnableOverlay)
            {
                if (ChannelSession.Services.OverlayServers.GetOverlayNames().Count() > 1)
                {
                    this.OverlayNameComboBox.IsEnabled   = true;
                    this.OverlayNameComboBox.ItemsSource = ChannelSession.Services.OverlayServers.GetOverlayNames();
                }
                else
                {
                    this.OverlayNameComboBox.IsEnabled   = false;
                    this.OverlayNameComboBox.ItemsSource = new List <string>()
                    {
                        ChannelSession.Services.OverlayServers.DefaultOverlayName
                    };
                }
                this.OverlayNameComboBox.SelectedItem = ChannelSession.Services.OverlayServers.DefaultOverlayName;
            }
            else
            {
                this.OverlayNotEnabledWarningTextBlock.Visibility = Visibility.Visible;
            }

            List <string> typeOptions = new List <string>(EnumHelper.GetEnumNames <OverlayItemModelTypeEnum>(new List <OverlayItemModelTypeEnum>()
            {
                OverlayItemModelTypeEnum.Text, OverlayItemModelTypeEnum.Image, OverlayItemModelTypeEnum.Video,
                OverlayItemModelTypeEnum.YouTube, OverlayItemModelTypeEnum.WebPage, OverlayItemModelTypeEnum.HTML
            }));

            typeOptions.Add(ShowHideWidgetOption);

            this.TypeComboBox.ItemsSource = typeOptions;

            this.WidgetNameComboBox.ItemsSource = ChannelSession.Settings.OverlayWidgets.ToList();

            this.EntranceAnimationComboBox.ItemsSource   = EnumHelper.GetEnumNames <OverlayItemEffectEntranceAnimationTypeEnum>();
            this.EntranceAnimationComboBox.SelectedIndex = 0;
            this.VisibleAnimationComboBox.ItemsSource    = EnumHelper.GetEnumNames <OverlayItemEffectVisibleAnimationTypeEnum>();
            this.VisibleAnimationComboBox.SelectedIndex  = 0;
            this.ExitAnimationComboBox.ItemsSource       = EnumHelper.GetEnumNames <OverlayItemEffectExitAnimationTypeEnum>();
            this.ExitAnimationComboBox.SelectedIndex     = 0;

            if (this.action != null)
            {
                if (!string.IsNullOrEmpty(this.action.OverlayName))
                {
                    this.OverlayNameComboBox.SelectedItem = this.action.OverlayName;
                }

                if (this.action.WidgetID != Guid.Empty)
                {
                    this.TypeComboBox.SelectedItem        = ShowHideWidgetOption;
                    this.WidgetNameComboBox.SelectedItem  = ChannelSession.Settings.OverlayWidgets.FirstOrDefault(w => w.Item.ID.Equals(this.action.WidgetID));
                    this.ShowHideWidgetCheckBox.IsChecked = this.action.ShowWidget;
                }
                else
                {
#pragma warning disable CS0612 // Type or member is obsolete
                    if (this.action.Item != null)
                    {
                        StoreCommandUpgrader.RestructureNewerOverlayActions(new List <ActionBase>()
                        {
                            this.action
                        });
                    }
#pragma warning restore CS0612 // Type or member is obsolete

                    if (this.action.OverlayItem != null)
                    {
                        if (this.action.OverlayItem.Effects != null)
                        {
                            this.DurationTextBox.Text = this.action.OverlayItem.Effects.Duration.ToString();
                            this.EntranceAnimationComboBox.SelectedItem = EnumHelper.GetEnumName(this.action.OverlayItem.Effects.EntranceAnimation);
                            this.VisibleAnimationComboBox.SelectedItem  = EnumHelper.GetEnumName(this.action.OverlayItem.Effects.VisibleAnimation);
                            this.ExitAnimationComboBox.SelectedItem     = EnumHelper.GetEnumName(this.action.OverlayItem.Effects.ExitAnimation);
                        }

                        if (this.action.OverlayItem.Position != null)
                        {
                            this.ItemPosition.SetPosition(this.action.OverlayItem.Position);
                        }

                        if (this.action.OverlayItem is OverlayImageItemModel)
                        {
                            this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayItemModelTypeEnum.Image);
                            this.ImageItem.SetItem(this.action.OverlayItem);
                        }
                        else if (this.action.OverlayItem is OverlayTextItemModel)
                        {
                            this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayItemModelTypeEnum.Text);
                            this.TextItem.SetItem(this.action.OverlayItem);
                        }
                        else if (this.action.OverlayItem is OverlayYouTubeItemModel)
                        {
                            this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayItemModelTypeEnum.YouTube);
                            this.YouTubeItem.SetItem(this.action.OverlayItem);
                        }
                        else if (this.action.OverlayItem is OverlayVideoItemModel)
                        {
                            this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayItemModelTypeEnum.Video);
                            this.VideoItem.SetItem(this.action.OverlayItem);
                        }
                        else if (this.action.OverlayItem is OverlayWebPageItemModel)
                        {
                            this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayItemModelTypeEnum.WebPage);
                            this.WebPageItem.SetItem(this.action.OverlayItem);
                        }
                        else if (this.action.OverlayItem is OverlayHTMLItemModel)
                        {
                            this.TypeComboBox.SelectedItem = EnumHelper.GetEnumName(OverlayItemModelTypeEnum.HTML);
                            this.HTMLItem.SetItem(this.action.OverlayItem);
                        }
                    }
                }
            }
            return(Task.FromResult(0));
        }