| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | // Copyright 2019 Juan Palacios <[email protected]> |
| 3 | |
| 4 | #include "ccproparser.h" |
| 5 | |
| 6 | #include "zipdatasink.h" |
| 7 | #include "zipdatasource.h" |
| 8 | #include <exception> |
| 9 | #include <spdlog/spdlog.h> |
| 10 | |
| 11 | std::string CCPROParser::fileExtension() const |
| 12 | { |
| 13 | return "ccpro"; |
| 14 | } |
| 15 | |
| 16 | std::optional<std::vector<char>> |
| 17 | CCPROParser::load(std::filesystem::path const &path, |
| 18 | std::string const &internalDataName) |
| 19 | { |
| 20 | ZipDataSource dataSource(path); |
| 21 | |
| 22 | if (!internalDataName.empty()) { |
| 23 | try { |
| 24 | std::vector<char> fileData; |
| 25 | if (dataSource.read(internalDataName, fileData)) |
| 26 | return {fileData}; |
| 27 | } |
| 28 | catch (std::exception const &e) { |
| 29 | SPDLOG_DEBUG(e.what()); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | return {}; |
| 34 | } |
| 35 | |
| 36 | bool CCPROParser::save( |
| 37 | std::filesystem::path const &path, |
| 38 | std::vector<std::pair<std::string, std::vector<char>>> const &data) |
| 39 | { |
| 40 | ZipDataSink dataSink(path); |
| 41 | |
| 42 | try { |
| 43 | return dataSink.write(data); |
| 44 | } |
| 45 | catch (std::exception const &e) { |
| 46 | SPDLOG_DEBUG(e.what()); |
| 47 | } |
| 48 | |
| 49 | return false; |
| 50 | } |