Esempio n. 1
0
        private void OnMusicListColumnClick(object sender, ColumnClickEventArgs e)
        {
            if (MusicList.ListViewItemSorter == null)
            {
                MusicList.ListViewItemSorter = new ListViewColumnSorter();
            }

            var sorter      = MusicList.ListViewItemSorter as ListViewColumnSorter;
            var chartSorter = new ChartSorter();

            chartSorter.SortType = (ChartSortType)e.Column;
            if (e.Column != sorter.SortColumn)
            {
                sorter.SortColumn = e.Column;
                chartSorter.Order = sorter.Order = SortOrder.Ascending;
            }
            else
            {
                chartSorter.Order = sorter.Order = sorter.Order == SortOrder.Descending || sorter.Order == SortOrder.None ?
                                                   SortOrder.Ascending :
                                                   SortOrder.Descending;
            }

            MusicList.Sort();
            charts?.Sort(chartSorter);
        }
Esempio n. 2
0
        private void AddChart(string[] filenames)
        {
            bool initial = MusicList.Items.Count == 0;
            var  err     = new List <string>();

            MusicList.BeginUpdate();
            {
                LoadingForm loader = null;
                loader = new LoadingForm(async() =>
                {
                    float progress = 0;
                    foreach (string filename in filenames)
                    {
                        Chart chart = null;
                        try
                        {
                            if (charts.FirstOrDefault((existing) => existing.Filename == filename) == null)
                            {
                                chart = await ChartDecoder.DecodeHeaderAsync(filename, (int)OJN.Difficulty.HX);
                                charts.Add(chart);

                                var item = new ListViewItem(new string[] {
                                    chart.Title,
                                    chart.Artist,
                                    chart.Pattern,
                                    chart.Duration.ToString(@"mm\:ss")
                                });

                                MusicList.Items.Add(item);
                            }
                        }
                        catch (Exception ex)
                        {
                            err.Add(string.Format("{0}: {1}", Path.GetFileName(filename), ex.Message));
                        }

                        progress++;
                        if (loader.IsHandleCreated)
                        {
                            loader.SetStatus(string.Format("Processing {0} - {1}", Path.GetFileName(filename), chart?.Title));
                            loader.SetProgress((progress / filenames.Length) * 100f);
                        }
                    }

                    loader.Close();
                });

                loader.ShowDialog();
                if (MusicList.ListViewItemSorter == null)
                {
                    var listSorter = new ListViewColumnSorter();
                    listSorter.Order = SortOrder.Ascending;

                    MusicList.ListViewItemSorter = listSorter;
                }

                var sorter      = MusicList.ListViewItemSorter as ListViewColumnSorter;
                var chartSorter = new ChartSorter();
                chartSorter.SortType = (ChartSortType)sorter.SortColumn;
                chartSorter.Order    = sorter.Order;

                MusicList.Sort();
                charts?.Sort(chartSorter);
            }
            MusicList.EndUpdate();

            if (err.Count > 0)
            {
                string errfn = "";
                foreach (string fn in err)
                {
                    errfn += fn + Environment.NewLine;
                }

                MessageBox.Show("Failed to decode following charts: " + Environment.NewLine + errfn, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            if (charts.Count > 0 && initial)
            {
                playback.Track = 0;
                GenerateOJNListMenu.Enabled   = SavePlaylistMenu.Enabled =
                    RenderMenu.Enabled        = OpenMenu.Enabled =
                        GroupPlayback.Enabled = PlaybackMenu.Enabled = true;
            }
        }