summaryrefslogtreecommitdiff
path: root/src/SongUpdate.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2016-02-26 14:53:37 +0100
committerMax Kellermann <max@duempel.org>2016-02-26 14:53:37 +0100
commit35567e6507f513f8b945e918255e36656198ec38 (patch)
tree32af1998aa51164c637661c03b8c84d7786eef09 /src/SongUpdate.cxx
parentae37e254526d707eb5bcdafe6c9846f6055b16a8 (diff)
SongUpdate: add UpdateFileInArchive(ArchiveFile&)
Diffstat (limited to 'src/SongUpdate.cxx')
-rw-r--r--src/SongUpdate.cxx41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/SongUpdate.cxx b/src/SongUpdate.cxx
index a18209048..71e5ba3b1 100644
--- a/src/SongUpdate.cxx
+++ b/src/SongUpdate.cxx
@@ -106,6 +106,47 @@ Song::UpdateFile(Storage &storage)
#ifdef ENABLE_ARCHIVE
+Song *
+Song::LoadFromArchive(ArchiveFile &archive, const char *name_utf8,
+ Directory &parent)
+{
+ assert(!uri_has_scheme(name_utf8));
+ assert(strchr(name_utf8, '\n') == nullptr);
+
+ Song *song = NewFile(name_utf8, parent);
+
+ if (!song->UpdateFileInArchive(archive)) {
+ song->Free();
+ return nullptr;
+ }
+
+ return song;
+}
+
+bool
+Song::UpdateFileInArchive(ArchiveFile &archive)
+{
+ assert(parent != nullptr);
+ assert(parent->device == DEVICE_INARCHIVE);
+
+ std::string path_utf8(uri);
+
+ for (const Directory *directory = parent;
+ directory->parent != nullptr &&
+ directory->parent->device == DEVICE_INARCHIVE;
+ directory = directory->parent) {
+ path_utf8.insert(path_utf8.begin(), '/');
+ path_utf8.insert(0, directory->GetName());
+ }
+
+ TagBuilder tag_builder;
+ if (!tag_archive_scan(archive, path_utf8.c_str(), tag_builder))
+ return false;
+
+ tag_builder.Commit(tag);
+ return true;
+}
+
bool
Song::UpdateFileInArchive(const Storage &storage)
{