libsaria: Load a saved library
No point in saving a library if I can't make use of the save file later.
This commit is contained in:
parent
1d1ecc8d8c
commit
1a7b8a5ae9
|
@ -39,4 +39,20 @@ class OutFile
|
|||
void write_ino(ino_t, bool);
|
||||
};
|
||||
|
||||
class InFile
|
||||
{
|
||||
private:
|
||||
ifstream in;
|
||||
|
||||
public:
|
||||
InFile(string);
|
||||
~InFile();
|
||||
bool good();
|
||||
string read_str();
|
||||
int read_int();
|
||||
unsigned int read_ui();
|
||||
long unsigned int read_lui();
|
||||
ino_t read_ino();
|
||||
};
|
||||
|
||||
#endif /* LIBSARIA_FILES_H */
|
||||
|
|
|
@ -12,5 +12,6 @@ void libsaria_refresh_library();
|
|||
void libsaria_library_list(list<Track> &);
|
||||
void libsaria_play_id(ino_t);
|
||||
void libsaria_library_save();
|
||||
void libsaria_library_load();
|
||||
|
||||
#endif /* LIBSARIA_LIBRARY_H */
|
||||
|
|
|
@ -29,6 +29,7 @@ class TrackTag
|
|||
TrackTag();
|
||||
TrackTag(const TrackTag &);
|
||||
TrackTag(string);
|
||||
TrackTag(InFile &);
|
||||
~TrackTag();
|
||||
void save(OutFile &);
|
||||
|
||||
|
|
|
@ -33,3 +33,8 @@ void libsaria_library_save()
|
|||
{
|
||||
library.save();
|
||||
}
|
||||
|
||||
void libsaria_library_load()
|
||||
{
|
||||
library.load();
|
||||
}
|
||||
|
|
|
@ -36,6 +36,24 @@ void Library::save()
|
|||
it->second.save(out);
|
||||
}
|
||||
|
||||
void Library::load()
|
||||
{
|
||||
unsigned int size;
|
||||
string dir;
|
||||
InFile in("library.lib");
|
||||
|
||||
if (!in.good())
|
||||
return;
|
||||
size = in.read_lui();
|
||||
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
dir = in.read_str();
|
||||
path_map.insert(
|
||||
pair<string, LibraryPath>(dir, LibraryPath(in, dir))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void LibraryPath::save(OutFile &out)
|
||||
{
|
||||
map<ino_t, TrackTag>::iterator it;
|
||||
|
@ -47,3 +65,20 @@ void LibraryPath::save(OutFile &out)
|
|||
it->second.save(out);
|
||||
}
|
||||
}
|
||||
|
||||
LibraryPath::LibraryPath(InFile &in, string dir)
|
||||
{
|
||||
unsigned int size;
|
||||
ino_t inode;
|
||||
|
||||
path = dir;
|
||||
size = in.read_lui();
|
||||
println("Library path dir: " + path);
|
||||
print("Library path size: ");
|
||||
println(size);
|
||||
|
||||
for (unsigned int i = 0; i < size; i++) {
|
||||
inode = in.read_ino();
|
||||
file_map[inode] = TrackTag(in);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ class Library
|
|||
void list_all(list<Track> &);
|
||||
void play_id(ino_t);
|
||||
void save();
|
||||
void load();
|
||||
};
|
||||
|
||||
#endif /* LIBSARIA_LIBRARY_SOURCE_H */
|
||||
|
|
|
@ -20,6 +20,7 @@ class LibraryPath
|
|||
|
||||
public:
|
||||
LibraryPath(string);
|
||||
LibraryPath(InFile &, string);
|
||||
~LibraryPath();
|
||||
|
||||
void update();
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
#include <libsaria/audio.h>
|
||||
#include <libsaria/path.h>
|
||||
#include <libsaria/print.h>
|
||||
#include <libsaria/library.h>
|
||||
|
||||
void libsaria_init(int argc, char **argv)
|
||||
{
|
||||
|
@ -11,6 +12,7 @@ void libsaria_init(int argc, char **argv)
|
|||
print("saria dir: ");
|
||||
println(get_saria_dir());
|
||||
make_saria_dir();
|
||||
libsaria_library_load();
|
||||
}
|
||||
|
||||
void libsaria_quit()
|
||||
|
|
|
@ -78,3 +78,64 @@ void OutFile::write_ino(ino_t inode, bool end)
|
|||
out << inode;
|
||||
end_write(end);
|
||||
}
|
||||
|
||||
InFile::InFile(string path)
|
||||
{
|
||||
string in_file = get_saria_dir() + "/" + path;
|
||||
in.open(in_file.c_str());
|
||||
if (in.good())
|
||||
println("Reading save file: " + in_file);
|
||||
}
|
||||
|
||||
InFile::~InFile()
|
||||
{
|
||||
in.close();
|
||||
}
|
||||
|
||||
bool InFile::good()
|
||||
{
|
||||
return in.good();
|
||||
}
|
||||
|
||||
string InFile::read_str()
|
||||
{
|
||||
int len;
|
||||
string str = "";
|
||||
|
||||
in >> len;
|
||||
if (len == 0)
|
||||
return str;
|
||||
len++;
|
||||
in.get();
|
||||
char c[len];
|
||||
in.get(c, len);
|
||||
return c;
|
||||
}
|
||||
|
||||
int InFile::read_int()
|
||||
{
|
||||
int i;
|
||||
in >> i;
|
||||
return i;
|
||||
}
|
||||
|
||||
unsigned int InFile::read_ui()
|
||||
{
|
||||
unsigned int i;
|
||||
in >> i;
|
||||
return i;
|
||||
}
|
||||
|
||||
long unsigned int InFile::read_lui()
|
||||
{
|
||||
long unsigned int i;
|
||||
in >> i;
|
||||
return i;
|
||||
}
|
||||
|
||||
ino_t InFile::read_ino()
|
||||
{
|
||||
ino_t i;
|
||||
in >> i;
|
||||
return i;
|
||||
}
|
||||
|
|
|
@ -60,6 +60,23 @@ TrackTag::TrackTag(string file)
|
|||
make_lenstr();
|
||||
}
|
||||
|
||||
TrackTag::TrackTag(InFile &in)
|
||||
{
|
||||
filepath = in.read_str();
|
||||
title = in.read_str();
|
||||
artist = in.read_str();
|
||||
album = in.read_str();
|
||||
comment = in.read_str();
|
||||
genre = in.read_str();
|
||||
lenstr = in.read_str();
|
||||
year = in.read_ui();
|
||||
track = in.read_ui();
|
||||
length = in.read_int();
|
||||
bitrate = in.read_int();
|
||||
sample = in.read_int();
|
||||
channels = in.read_int();
|
||||
}
|
||||
|
||||
TrackTag::~TrackTag()
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue