libsaria: Add a new field to the Track class

I plan on using this to track if the user has banned a track or not.
This patch introduces the new field and handles the library version
upgrade.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-05-17 11:51:42 -04:00
parent ea7b66ae6d
commit e8e8589614
3 changed files with 21 additions and 6 deletions

View File

@ -30,6 +30,7 @@ namespace libsaria
int bitrate;
int sample;
int channels;
bool banned;
string *artist_lc;
string *album_lc;
@ -40,7 +41,7 @@ namespace libsaria
Track();
Track(string);
Track(string, library::Path *);
Track(ifstream &, library::Path *);
Track(ifstream &, library::Path *, unsigned int);
~Track();
void save(ofstream &);

View File

@ -28,7 +28,7 @@ static void do_save_path(ofstream &stream, void *data)
list<libsaria::Track>::iterator it;
println("Saving library path: %d", path->id);
stream << 1 << "\n"; /* Save file version: 1 */
stream << 2 << "\n"; /* Save file version: 2 */
stream << path->path << "\n";
stream << path->id << " " << path->visible << " ";
stream << path->next_track << " " << path->tracks.size() << "\n";
@ -55,7 +55,7 @@ void read_path(ifstream &stream)
getline(stream, tmp);
s << tmp;
s >> version;
if (version != 1)
if (version > 2)
return;
getline(stream, path.path);
@ -72,10 +72,15 @@ void read_path(ifstream &stream)
path_ptr = push_path(path);
for (unsigned int i = 0; i < size; i++) {
path_ptr->tracks.push_back(libsaria::Track(stream, path_ptr));
path_ptr->tracks.push_back(libsaria::Track(stream, path_ptr, version));
tracks.push_back(&path_ptr->tracks.back());
}
if (version != 2) {
path_ptr->data_state = DIRTY;
libsaria::library::save_path(path_ptr);
}
notify_path_updated(path_ptr);
lib_playlist.add_tracks(tracks);
}

View File

@ -82,6 +82,7 @@ namespace libsaria
Track::Track(string file)
{
filepath = file;
banned = false;
read_tags();
}
@ -93,6 +94,7 @@ namespace libsaria
last_day = 0;
last_month = 0;
last_year = 0;
banned = false;
read_tags();
@ -102,7 +104,8 @@ namespace libsaria
make_lenstr(length, lenstr);
}
Track::Track(ifstream &in, struct library::Path *lib_path)
Track::Track(ifstream &in, struct library::Path *lib_path,
unsigned int version)
{
string tmp;
stringstream s;
@ -132,6 +135,11 @@ namespace libsaria
s >> sample;
s >> channels;
if (version >= 2)
s >> banned;
else
banned = false;
artist_lc = lowercase(artist);
album_lc = lowercase(album);
}
@ -197,7 +205,8 @@ namespace libsaria
out << length << " ";
out << bitrate << " ";
out << sample << " ";
out << channels << "\n";
out << channels << " ";
out << banned << "\n";
}
} /* Namespace: libsaria */