You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.5 KiB

#include "miniwebcam.h"
#include "inmemorytar.h"
#include "inmemoryfile.h"
InMemoryTar::InMemoryTar() {
struct archive *a;
struct archive_entry *entry;
size_t tar_size = _binary_assets_tar_end - _binary_assets_tar_start;
int r;
debug ("");
a = archive_read_new();
archive_read_support_format_tar(a);
if (a == NULL) ErrorExit("error on archive new", -1);
r = archive_read_open_memory(a, _binary_assets_tar_start, tar_size);
if (r != ARCHIVE_OK) ErrorExit("bindary asset could not been found in memory", -1);
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
debug ("found file %s\n", archive_entry_pathname(entry));
InMemoryFile *imf = new InMemoryFile();
size_t size = archive_entry_size(entry);
imf->filename = archive_entry_pathname(entry);
imf->Allocate(size);
archive_read_data(a, imf->mem, size);
files.push_back(imf);
}
archive_read_free(a);
};
InMemoryTar::~InMemoryTar() {
std::list<InMemoryFile*>::iterator f;
f = files.begin();
while (f != files.end()) {
InMemoryFile *imf = *f;
delete imf;
f = files.begin();
}
};
/// @brief
/// @param file
/// @param imf - do not free the pointer!!!!
/// @return
int InMemoryTar::FindFile(std::string file, InMemoryFile **imf) {
std::list<InMemoryFile*>::iterator f;
for (f = files.begin(); f != files.end(); f++) {
if (file.compare ((*f)->filename) == 0) {
*imf = *f;
return 1;
}
}
return 0;
}