Ejemplo n.º 1
0
 public PlaylistViewModel DeserializePlaylist(string path)
 {
     //string path = Path.Combine(Directory.GetCurrentDirectory(), directoryName, name);
     if (!File.Exists(path))
     {
         Console.WriteLine("playlist doesnt exist: " + path);
         return(null);
     }
     using (StreamReader sr = File.OpenText(path))
     {
         string content = sr.ReadToEnd();
         if (content.Equals(string.Empty) || content == null)
         {
             return(null);
         }
         Console.WriteLine("playlist deserialized: " + path);
         PlaylistViewModel playlist = JsonConvert.DeserializeObject <PlaylistViewModel>(content);
         playlist.Name = GetFileNameNoExtension(path);
         for (int i = 0; i < playlist.Songs.Count; i++)
         {
             playlist.Songs[i].PlaylistName = playlist.Name;
         }
         return(playlist);
     }
 }
Ejemplo n.º 2
0
        public void Serialize(PlaylistViewModel playlist)
        {
            Directory.CreateDirectory(directoryName);

            using (StreamWriter sw = File.CreateText(Path.Combine(Directory.GetCurrentDirectory(), directoryName, playlist.Name + jsonExtension)))
            {
                sw.Write(JsonConvert.SerializeObject(playlist, Formatting.Indented));
                Console.WriteLine("serialized playlist " + playlist.Name + " to config.json");
            }
        }
Ejemplo n.º 3
0
        //moving songs from playlist to playlist
        private void AddToPlaylistButton_Click(object sender, RoutedEventArgs e)
        {
            List <SongViewModel> selectedSongs;

            switch (songListTabControl.SelectedIndex)
            {
            case 1:                         //tab 1, search tab
                selectedSongs = searchListbox.SelectedItems.Cast <SongViewModel>().ToList();
                break;

            default:                        //tab 0, song list
                selectedSongs = songListBox.SelectedItems.Cast <SongViewModel>().ToList();
                break;
            }

            if (selectedSongs.Count <= 0)
            {
                MessageBox.Show("No songs are selected", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (((PlaylistItemViewModel)targetPlaylistComboBox.SelectedItem).Name.Equals(currentPlaylist.Name))
            {
                MessageBox.Show("The source and destination playlist cannot be the same", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }



            PlaylistItemViewModel item           = PlaylistItems[targetPlaylistComboBox.SelectedIndex];
            PlaylistViewModel     targetPlaylist = serializer.DeserializePlaylist(item.Path);
            MessageBoxResult      result         = MessageBox.Show(string.Format("Would you like to copy {0} songs from {1} to {2}", selectedSongs.Count, currentPlaylist.Name, targetPlaylist.Name), "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question);

            if (result == MessageBoxResult.Yes)
            {
                int largestInd = 0;
                for (int i = 0; i < targetPlaylist.Songs.Count; i++)
                {
                    if (targetPlaylist.Songs[i].Order > largestInd)
                    {
                        largestInd = targetPlaylist.Songs[i].Order;
                    }
                }
                for (int i = 0; i < selectedSongs.Count; i++)
                {
                    SongViewModel song = new SongViewModel(selectedSongs[i]);
                    song.Order = largestInd + i + 1;
                    targetPlaylist.Songs.Add(song);
                }

                serializer.Serialize(targetPlaylist);
                Console.WriteLine("moved " + selectedSongs.Count + " to " + targetPlaylist.Name);
            }
        }
Ejemplo n.º 4
0
        private void CreatePlaylistButton_Click(object sender, RoutedEventArgs e)
        {
            if (newPlaylistTextbox.Text.Length == 0)
            {
                MessageBox.Show("Playlist must have a name", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (playlistCreator.inProgress && (bool)createConditionCheckBox.IsChecked)
            {
                MessageBox.Show("Cannot create playlist due to ongoing operation", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            for (int i = 0; i < PlaylistItems.Count; i++)
            {
                if (PlaylistItems[i].Name.Equals(newPlaylistTextbox.Text, StringComparison.InvariantCultureIgnoreCase))
                {
                    MessageBox.Show("Name already exist", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                    return;
                }
            }


            if ((bool)createConditionCheckBox.IsChecked)
            {
                playlistCreator.events += AddToPlaylistItemListFromCreator;
                playlistCreator.CreatePlaylist(newPlaylistTextbox.Text, selectedFolderPath);
                Console.WriteLine("called");
                MessageBox.Show("All songs from the osu! folder are being fetched, and the playlist will be added when operation is complete. This might take a while."
                                , "Information", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                PlaylistViewModel playlist = playlistCreator.CreatePlaylist(newPlaylistTextbox.Text);
                PlaylistItems.Add(new PlaylistItemViewModel(playlist.Name, serializer.GetPlaylistPath(playlist)));
            }
            newPlaylistTextbox.Text           = "";
            createConditionCheckBox.IsChecked = false;
        }
Ejemplo n.º 5
0
        private void PlaylistListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ReserializeCurrentPlaylist();               //checks for changes, and reserialize it
            if ((bool)ctrlShuffleCheckBox.IsChecked)
            {
                shuffleController.ClearPastValues();
            }
            int index = playlistListBox.SelectedIndex;

            if (index >= 0 && index < PlaylistItems.Count)
            {
                PlaylistItemViewModel item     = PlaylistItems[index];
                PlaylistViewModel     playlist = serializer.DeserializePlaylist(item.Path);
                if (playlist != null)
                {
                    currentPlaylist.UpdateProperties(playlist);
                }
                if (currentPlaylist.Songs.Count > 0)
                {
                    songListBox.SelectedIndex = 0;
                }
            }
        }
Ejemplo n.º 6
0
        public string GetPlaylistPath(PlaylistViewModel playlist)
        {
            string path = Path.Combine(Directory.GetCurrentDirectory(), directoryName);

            return(string.Format("{0}\\{1}{2}", path, playlist.Name, jsonExtension));
        }