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 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); }); }