Ejemplo n.º 1
0
        static void addsong()
        {
            string ans = getans("Procced with adding song? y/n");
            if ((ans == "y") || (ans == "yes"))
            {
                string fileurl = getans("file url"); // might handle true cascaded directories.
                string fingerprint;
                try
                {
                    fingerprint = calcfinger.generate(fileurl);
                }
                catch (NullReferenceException) { Console.WriteLine("file not found"); return; }

                string artest = getans("artest?");
                string title = getans("song title?");
                //could get more info, but not important now.
#if CSV
                Song s = new Song();
                s.artest = artest;
                s.title = title;
                s.fingerprint = fingerprint;
                ListSong.Add(s);
#else
                // isnt completed for sql.
#endif
                Console.WriteLine("song added");
            }
            else
            {
                Console.WriteLine("not adding song");
            }
        }
Ejemplo n.º 2
0
        static void loadcsv(ref List<Song> listsong)
        {   
            TextReader tr;
            try
            {
#if VERBOSE
                Console.WriteLine("opening savefile for loading");
#endif
                tr = new StreamReader(SAVEFILE);
                string line;
                string value;
                while ((line = tr.ReadLine()) != null) //break on end of file.
                {
                    Song newsong = new Song();

                    value = line.Substring(0, line.IndexOf(","));
                    line = line.Substring(line.IndexOf(",")+1);
                    newsong.artest = value;

                    value = line.Substring(0, line.IndexOf(","));
                    line = line.Substring(line.IndexOf(",")+1);
                    newsong.title = value;

                    value = line;
                    newsong.fingerprint = value;

                    bool trig = false;
                    foreach (Song tsong in listsong) //check its not already in the list.
                    {
                        if ((tsong.artest == newsong.artest) && (tsong.title == newsong.title))
                        {
                            trig = true;
                            break;
                        }
                    }
                    if (!trig) // if not in list, add.
                    {
#if VERBOSE
                        Console.WriteLine("loaded {0} by {1}", newsong.title, newsong.artest);
#endif
                        listsong.Add(newsong);
                    }
                }
                tr.Close();

            }
            catch (FileNotFoundException)
            { Console.WriteLine("FileNotFoundException, cannot load"); return; }
            catch (FileLoadException)
            {
                Console.WriteLine("cannot load, save file in use. FileLoadException");
                return;
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("NullReference, corrupt file");//or failed math.
                return;
            }
        }
Ejemplo n.º 3
0
 public int Add( Song song ) {
   return listOfSongs.Add( song );
 }