2025-07-25 20:42:02 +02:00
|
|
|
#include "procfile.h"
|
|
|
|
|
#include "core/exception.h"
|
|
|
|
|
#include "logger.h"
|
|
|
|
|
#include "product_info.h"
|
|
|
|
|
#include "type.h"
|
|
|
|
|
#include "utils/file/file_iterators.h"
|
|
|
|
|
#include "utils/file/folder_file_iterators.h"
|
|
|
|
|
#include "utils/file/zip_file_iterators.h"
|
2026-05-13 19:46:42 +02:00
|
|
|
#include <H5Cpp.h>
|
|
|
|
|
#include <exception>
|
2025-07-27 18:48:34 +02:00
|
|
|
#include <memory>
|
2025-07-25 20:42:02 +02:00
|
|
|
|
|
|
|
|
namespace satdump
|
|
|
|
|
{
|
2025-08-12 13:42:31 +02:00
|
|
|
namespace firstparty
|
2025-07-25 20:42:02 +02:00
|
|
|
{
|
2025-08-12 13:42:31 +02:00
|
|
|
FirstPartyProductInfo identifyFirstPartyProductFile(std::string fpath)
|
2025-07-25 20:42:02 +02:00
|
|
|
{
|
|
|
|
|
// Identify the product to process. If a single file, just work off that
|
|
|
|
|
// and figure out if it's multi-file, if it's a zip just identify the first
|
|
|
|
|
// one we can.
|
|
|
|
|
|
2025-08-12 13:42:31 +02:00
|
|
|
FirstPartyProductInfo toproc_info;
|
2025-07-25 20:42:02 +02:00
|
|
|
|
|
|
|
|
bool is_zip = std::filesystem::path(fpath).extension() == ".zip";
|
|
|
|
|
bool is_file = std::filesystem::is_regular_file(fpath);
|
|
|
|
|
|
|
|
|
|
if (is_zip)
|
|
|
|
|
{
|
2025-08-05 19:07:45 +02:00
|
|
|
// Test if the ZIP itself is a product
|
|
|
|
|
std::shared_ptr<satdump::utils::FilesIteratorItem> _f = std::make_shared<satdump::utils::FolderFileIteratorItem>(fpath);
|
2025-08-12 13:42:31 +02:00
|
|
|
toproc_info = parseFirstPartyInfo(_f);
|
2025-07-25 20:42:02 +02:00
|
|
|
|
2025-08-11 15:04:59 +02:00
|
|
|
if (toproc_info.type == PRODUCT_NONE)
|
2025-07-25 20:42:02 +02:00
|
|
|
{
|
2025-08-05 19:07:45 +02:00
|
|
|
satdump::utils::ZipFilesIterator fit(fpath);
|
|
|
|
|
std::shared_ptr<satdump::utils::FilesIteratorItem> f;
|
|
|
|
|
|
|
|
|
|
while (fit.getNext(f))
|
2025-07-25 20:42:02 +02:00
|
|
|
{
|
2025-08-05 19:07:45 +02:00
|
|
|
if (f)
|
|
|
|
|
{
|
2025-08-12 13:42:31 +02:00
|
|
|
toproc_info = parseFirstPartyInfo(f);
|
|
|
|
|
if (toproc_info.type != PRODUCT_NONE)
|
2025-08-05 19:07:45 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2025-07-25 20:42:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (is_file)
|
|
|
|
|
{
|
2025-07-27 18:48:34 +02:00
|
|
|
std::shared_ptr<satdump::utils::FilesIteratorItem> f = std::make_shared<satdump::utils::FolderFileIteratorItem>(fpath);
|
2025-08-12 13:42:31 +02:00
|
|
|
toproc_info = parseFirstPartyInfo(f);
|
2025-07-25 20:42:02 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
logger->error("Not a file or ZIP! => " + fpath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return toproc_info;
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-12 13:42:31 +02:00
|
|
|
std::shared_ptr<products::Product> processFirstPartyProductFile(FirstPartyProductInfo toproc_info, std::string fpath)
|
2025-07-25 20:42:02 +02:00
|
|
|
{
|
|
|
|
|
// Check it is valid & setup processor
|
|
|
|
|
|
|
|
|
|
if (toproc_info.type == PRODUCT_NONE)
|
|
|
|
|
throw satdump_exception("No product present in file " + fpath + "!");
|
|
|
|
|
|
|
|
|
|
logger->debug("Processing product : " + toproc_info.name);
|
|
|
|
|
|
|
|
|
|
auto processor = getProcessorForProduct(toproc_info);
|
|
|
|
|
|
|
|
|
|
// Run all required files through.
|
|
|
|
|
bool is_zip = std::filesystem::path(fpath).extension() == ".zip";
|
|
|
|
|
|
|
|
|
|
if (toproc_info.group_id.size() || is_zip) // If we have a group, we need to iterate through all of them (also do so if we got a single one in a file)
|
|
|
|
|
{
|
|
|
|
|
logger->trace("Group : " + toproc_info.group_id);
|
|
|
|
|
|
2025-07-27 18:48:34 +02:00
|
|
|
std::shared_ptr<satdump::utils::FilesIterator> fit;
|
2025-07-25 20:42:02 +02:00
|
|
|
if (is_zip)
|
|
|
|
|
fit = std::make_unique<satdump::utils::ZipFilesIterator>(fpath);
|
|
|
|
|
else
|
2025-07-28 11:07:41 -07:00
|
|
|
fit = std::make_unique<satdump::utils::FolderFilesIterator>(std::filesystem::path(fpath).parent_path().string());
|
2025-07-25 20:42:02 +02:00
|
|
|
|
2025-07-27 18:48:34 +02:00
|
|
|
std::shared_ptr<satdump::utils::FilesIteratorItem> f;
|
2025-07-25 20:42:02 +02:00
|
|
|
while (fit->getNext(f))
|
|
|
|
|
{
|
|
|
|
|
if (!f)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-08-12 13:42:31 +02:00
|
|
|
if (toproc_info.group_id == parseFirstPartyInfo(f).group_id)
|
2025-07-25 20:42:02 +02:00
|
|
|
{
|
|
|
|
|
logger->trace(" - " + f->name);
|
2026-05-13 19:46:42 +02:00
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
processor->ingestFile(f->getPayload());
|
|
|
|
|
}
|
|
|
|
|
catch (std::exception &e)
|
|
|
|
|
{
|
|
|
|
|
logger->error("Error processing file! %s", e.what());
|
|
|
|
|
}
|
|
|
|
|
catch (H5::Exception &e)
|
|
|
|
|
{
|
|
|
|
|
logger->error("Error processing file! %s", e.getCDetailMsg());
|
|
|
|
|
}
|
2025-07-25 20:42:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::unique_ptr<satdump::utils::FilesIteratorItem> f = std::make_unique<satdump::utils::FolderFileIteratorItem>(fpath);
|
|
|
|
|
logger->trace(" - " + f->name);
|
|
|
|
|
processor->ingestFile(f->getPayload());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Finally, return product
|
2025-07-28 17:54:32 +02:00
|
|
|
auto product = processor->getProduct();
|
2025-08-12 13:42:31 +02:00
|
|
|
// product->save("/tmp/satdump_firstparty/test");
|
2025-07-28 17:54:32 +02:00
|
|
|
return product;
|
2025-07-25 20:42:02 +02:00
|
|
|
}
|
2025-08-12 13:42:31 +02:00
|
|
|
} // namespace firstparty
|
2025-07-25 20:42:02 +02:00
|
|
|
} // namespace satdump
|