Esempio n. 1
0
        public ChorusSongListBoxItem(MainWindow mainWindow, Song song)
        {
            Content = song.artist + " - " + song.name + " (" + song.charter + ")";
            RemoteSongContextMenu contextMenu = new RemoteSongContextMenu();

            contextMenu.Download += () =>
            {
                string songsDirectory = mainWindow.SongsDirectory.Text;
                mainWindow.StatusLabel.Content = "Downloading...";
                Task.Run(() =>
                {
                    string link         = song.directLinks.archive ?? song.link;
                    bool downloadFailed = false;
                    try
                    {
                        SongDownloader.DownloadSong(songsDirectory, link, song.artist, song.name, song.charter, (status) =>
                        {
                            Dispatcher.Invoke(() => mainWindow.StatusLabel.Content = status);
                        });
                    }
                    catch (Win32Exception exception)
                    {
                        Dispatcher.Invoke(() => MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error));
                        downloadFailed = true;
                    }
                    catch (Exception e)
                    {
                        string message;
                        if (e is WebException)
                        {
                            message = e.InnerException?.Message ?? e.Message;
                        }
                        else
                        {
                            message = "Link could not be downloaded.";
                        }
                        downloadFailed = true;
                        Dispatcher.Invoke(() =>
                        {
                            var result = MessageBox.Show(string.Format("{0} Open in browser instead?", message), "Warning", MessageBoxButton.YesNo, MessageBoxImage.Warning);
                            if (result == MessageBoxResult.Yes)
                            {
                                Process.Start(link);
                            }
                        });
                    }
                    Dispatcher.Invoke(() =>
                    {
                        mainWindow.ScanSongs();
                        if (!downloadFailed)
                        {
                            mainWindow.StatusLabel.Content = "Download complete.";
                        }
                    });
                });
            };
            ContextMenu = contextMenu;
        }
Esempio n. 2
0
        private async void UIDownloadBtn_Click(object sender, RoutedEventArgs e)
        {
            UISongsList.IsEnabled = false;

            await songDownloader.DownloadSong(GetSelectedSong());

            UISongsList.IsEnabled = true;

            UpdateSongInstalledUI(true);
        }
Esempio n. 3
0
        public SongListItem(GameplayParameters parameters)
        {
            this.parameters   = parameters;
            cancellationToken = new CancellationTokenSource();

            if (OstHelper.IsOst(parameters.Beatmap.LevelId) || SongUtils.masterLevelList.Any(x => x.levelID == parameters.Beatmap.LevelId))
            {
                downloadState = DownloadState.Complete;
                level         = SongUtils.masterLevelList.First(x => x.levelID == parameters.Beatmap.LevelId);
            }
            else
            {
                SongDownloader.DownloadSong(parameters.Beatmap.LevelId, true, OnSongDownloaded, OnDownloadProgress);
            }
        }