Skip to content

Commit fa70151

Browse files
authored
test file and document meta (#434)
1 parent 7aaf6b1 commit fa70151

12 files changed

Lines changed: 92 additions & 17 deletions

File tree

src/odr/internal/odf/odf_file.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ DecoderEngine OpenDocumentFile::decoder_engine() const noexcept {
4747
}
4848

4949
DocumentType OpenDocumentFile::document_type() const {
50-
return m_file_meta.document_meta->document_type;
50+
return m_file_meta.document_meta.value().document_type;
5151
}
5252

5353
DocumentMeta OpenDocumentFile::document_meta() const {
54-
return *m_file_meta.document_meta;
54+
return m_file_meta.document_meta.value();
5555
}
5656

5757
bool OpenDocumentFile::password_encrypted() const noexcept {

src/odr/internal/oldms/oldms_file.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ DecoderEngine LegacyMicrosoftFile::decoder_engine() const noexcept {
6262
}
6363

6464
DocumentType LegacyMicrosoftFile::document_type() const {
65-
return m_file_meta.document_meta->document_type;
65+
return m_file_meta.document_meta.value().document_type;
6666
}
6767

6868
DocumentMeta LegacyMicrosoftFile::document_meta() const {
69-
return *m_file_meta.document_meta;
69+
return m_file_meta.document_meta.value();
7070
}
7171

7272
bool LegacyMicrosoftFile::password_encrypted() const noexcept {

src/odr/internal/oldms_wvware/wvware_oldms_file.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,13 @@ void WvWareLegacyMicrosoftFile::open() {
5353

5454
int ret = wvInitParser_gsf(&m_parser_state->ps, m_parser_state->gsf_input);
5555

56+
m_file_meta.type = FileType::legacy_word_document;
57+
m_file_meta.document_meta = DocumentMeta();
58+
m_file_meta.document_meta->document_type = DocumentType::text;
59+
5660
// check if encrypted
5761
if ((ret & 0x8000) != 0) {
62+
m_file_meta.password_encrypted = true;
5863
m_encryption_state = EncryptionState::encrypted;
5964
m_parser_state->encryption_flag = ret & 0x7fff;
6065

@@ -82,7 +87,7 @@ FileType WvWareLegacyMicrosoftFile::file_type() const noexcept {
8287
}
8388

8489
FileMeta WvWareLegacyMicrosoftFile::file_meta() const noexcept {
85-
return {file_type(), password_encrypted(), document_meta()};
90+
return m_file_meta;
8691
}
8792

8893
DecoderEngine WvWareLegacyMicrosoftFile::decoder_engine() const noexcept {
@@ -93,11 +98,12 @@ DocumentType WvWareLegacyMicrosoftFile::document_type() const {
9398
return DocumentType::text;
9499
}
95100

96-
DocumentMeta WvWareLegacyMicrosoftFile::document_meta() const { return {}; }
101+
DocumentMeta WvWareLegacyMicrosoftFile::document_meta() const {
102+
return m_file_meta.document_meta.value();
103+
}
97104

98105
bool WvWareLegacyMicrosoftFile::password_encrypted() const noexcept {
99-
return m_encryption_state == EncryptionState::encrypted ||
100-
m_encryption_state == EncryptionState::decrypted;
106+
return m_file_meta.password_encrypted;
101107
}
102108

103109
EncryptionState WvWareLegacyMicrosoftFile::encryption_state() const noexcept {

src/odr/internal/oldms_wvware/wvware_oldms_file.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class WvWareLegacyMicrosoftFile final : public abstract::DocumentFile {
4646
std::shared_ptr<abstract::File> m_file;
4747
std::shared_ptr<ParserState> m_parser_state;
4848

49+
FileMeta m_file_meta;
4950
EncryptionState m_encryption_state{EncryptionState::unknown};
5051

5152
void open();

src/odr/internal/ooxml/ooxml_file.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ DecoderEngine OfficeOpenXmlFile::decoder_engine() const noexcept {
4444
}
4545

4646
DocumentType OfficeOpenXmlFile::document_type() const {
47-
return m_file_meta.document_meta->document_type;
47+
return m_file_meta.document_meta.value().document_type;
4848
}
4949

5050
DocumentMeta OfficeOpenXmlFile::document_meta() const {
51-
return *m_file_meta.document_meta;
51+
return m_file_meta.document_meta.value();
5252
}
5353

5454
bool OfficeOpenXmlFile::password_encrypted() const noexcept {

src/odr/internal/ooxml/ooxml_meta.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ FileMeta parse_file_meta(abstract::ReadableFilesystem &filesystem) {
2626
};
2727

2828
FileMeta result;
29+
result.document_meta = DocumentMeta();
2930

3031
if (filesystem.is_file(common::Path("/EncryptionInfo")) &&
3132
filesystem.is_file(common::Path("/EncryptedPackage"))) {
@@ -34,8 +35,6 @@ FileMeta parse_file_meta(abstract::ReadableFilesystem &filesystem) {
3435
return result;
3536
}
3637

37-
result.document_meta.emplace();
38-
3938
for (auto &&t : types) {
4039
if (filesystem.is_file(t.first)) {
4140
result.type = t.second.file_type;

src/odr/internal/pdf/pdf_file.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
namespace odr::internal {
44

55
PdfFile::PdfFile(std::shared_ptr<abstract::File> file)
6-
: m_file{std::move(file)} {}
6+
: m_file{std::move(file)} {
7+
m_file_meta.type = FileType::portable_document_format;
8+
}
79

810
std::shared_ptr<abstract::File> PdfFile::file() const noexcept {
911
return m_file;
1012
}
1113

12-
FileMeta PdfFile::file_meta() const noexcept { return {}; }
14+
FileMeta PdfFile::file_meta() const noexcept { return m_file_meta; }
1315

1416
DecoderEngine PdfFile::decoder_engine() const noexcept {
1517
return DecoderEngine::odr;

src/odr/internal/pdf/pdf_file.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PdfFile final : public abstract::PdfFile {
2020

2121
private:
2222
std::shared_ptr<abstract::File> m_file;
23+
FileMeta m_file_meta;
2324
};
2425

2526
} // namespace odr::internal

src/odr/odr.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,34 @@ odr::file_category_by_file_type(const FileType type) noexcept {
114114
}
115115
}
116116

117+
odr::DocumentType
118+
odr::document_type_by_file_type(const FileType type) noexcept {
119+
switch (type) {
120+
case FileType::opendocument_text:
121+
return DocumentType::text;
122+
case FileType::opendocument_presentation:
123+
return DocumentType::presentation;
124+
case FileType::opendocument_spreadsheet:
125+
return DocumentType::spreadsheet;
126+
case FileType::opendocument_graphics:
127+
return DocumentType::drawing;
128+
case FileType::office_open_xml_document:
129+
return DocumentType::text;
130+
case FileType::office_open_xml_presentation:
131+
return DocumentType::presentation;
132+
case FileType::office_open_xml_workbook:
133+
return DocumentType::spreadsheet;
134+
case FileType::legacy_word_document:
135+
return DocumentType::text;
136+
case FileType::legacy_powerpoint_presentation:
137+
return DocumentType::presentation;
138+
case FileType::legacy_excel_worksheets:
139+
return DocumentType::spreadsheet;
140+
default:
141+
return DocumentType::unknown;
142+
}
143+
}
144+
117145
std::string odr::file_type_to_string(const FileType type) noexcept {
118146
switch (type) {
119147
case FileType::unknown:

src/odr/odr.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ file_type_by_file_extension(const std::string &extension) noexcept;
3939
/// @param type The file type.
4040
/// @return The file category.
4141
[[nodiscard]] FileCategory file_category_by_file_type(FileType type) noexcept;
42+
/// @brief Get the document type by the file type.
43+
/// @param type The file type.
44+
/// @return The document type.
45+
[[nodiscard]] DocumentType document_type_by_file_type(FileType type) noexcept;
4246
/// @brief Get the file type as a string.
4347
/// @param type The file type.
4448
/// @return The file type as a string.

0 commit comments

Comments
 (0)