void __add_children_to_database(V3::File_Entry *fe, PasswordDatabase &pdb, const EntryId &parent_id, int &entry_ctr, function<void(int)> progress_cb) { GASSERT(fe->getType() == V3::File_Entry::directory); for(uint i = 0; i < fe->getContents().size(); ++i) { progress_cb(++entry_ctr); V3::File_Entry *cur = fe->getContents()[i]; Entry e; e.SetParentId(parent_id); e.SetRow(cur->getRow()); e.SetName(cur->getLabel().getContent()); e.SetDescription(cur->getDescription().getContent()); e.SetFavoriteIndex(cur->getFavorite()); e.SetModifyDate(*cur->getModifyDate()); if(V3::File_Entry::password == cur->getType()){ for(const V3::Attribute &a : cur->getAttributes()){ SecretValue sv; sv.SetName(a.getLabel()); sv.SetValue(a.getContent().toUtf8()); sv.SetIsHidden(a.secret); sv.SetNotes(a.notes); e.Values().append(sv); } } pdb.AddEntry(e, true); // We want to show true progress, which means waiting // after each item until the background thread is done adding it pdb.WaitForThreadIdle(); if(V3::File_Entry::directory == cur->getType()) __add_children_to_database(cur, pdb, e.GetId(), entry_ctr, progress_cb); } }
status_t PackageSettingsItem::AddEntry(const char* path, Entry*& _entry) { Entry* parent = NULL; while (*path != '\0') { while (*path == '/') { path++; continue; } const char* componentEnd = strchr(path, '/'); if (componentEnd == NULL) componentEnd = path + strlen(path); const char* name = path; size_t nameLength = componentEnd - path; Entry* entry = FindEntry(parent, name, nameLength); if (entry == NULL) { entry = new(std::nothrow) Entry(parent); if (entry == NULL || !entry->SetName(name, nameLength)) { delete entry; return B_NO_MEMORY; } AddEntry(entry); } path = componentEnd; parent = entry; } if (parent == NULL) return B_BAD_VALUE; _entry = parent; return B_OK; }