ocarina/libsaria/library/file.cpp

63 lines
1.2 KiB
C++

/*
* Manages the libsaria library save file
*/
#include <libsaria/library.h>
#include "library.h"
LibraryPath::LibraryPath(InFile &in, string dir)
{
unsigned int size;
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++)
file_list.push_back(TrackTag(in));
}
void LibraryPath::save(OutFile &out)
{
list<TrackTag>::iterator it;
out.write_str(path, false);
out.write_lui(file_list.size(), true);
for (it = file_list.begin(); it != file_list.end(); it++)
it->save(out);
}
namespace libsaria
{
void library::load()
{
unsigned int size;
string dir;
list<LibraryPath> *path_list = get_path_list();
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_list->push_back(LibraryPath(in, dir));
}
}
void library::save()
{
OutFile out("library.lib");
list<LibraryPath> *path_list = get_path_list();
list<LibraryPath>::iterator it;
out.write_lui(path_list->size(), true);
for (it = path_list->begin(); it != path_list->end(); it++)
it->save(out);
}
}; /* namespace: libsaria */