-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy patholdms_file.cpp
More file actions
90 lines (69 loc) · 2.54 KB
/
Copy patholdms_file.cpp
File metadata and controls
90 lines (69 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <odr/internal/oldms/oldms_file.hpp>
#include <odr/exceptions.hpp>
#include <odr/internal/common/path.hpp>
#include <memory>
#include <unordered_map>
namespace odr::internal::oldms {
namespace {
FileMeta parse_meta(const abstract::ReadableFilesystem &storage) {
static const std::unordered_map<common::Path, FileType> types = {
// MS-DOC: The "WordDocument" stream MUST be present in the file.
// https://msdn.microsoft.com/en-us/library/dd926131(v=office.12).aspx
{common::Path("WordDocument"), FileType::legacy_word_document},
// MS-PPT: The "PowerPoint Document" stream MUST be present in the file.
// https://msdn.microsoft.com/en-us/library/dd911009(v=office.12).aspx
{common::Path("PowerPoint Document"),
FileType::legacy_powerpoint_presentation},
// MS-XLS: The "Workbook" stream MUST be present in the file.
// https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-ppt/1fc22d56-28f9-4818-bd45-67c2bf721ccf
{common::Path("Workbook"), FileType::legacy_excel_worksheets},
};
FileMeta result;
for (auto &&t : types) {
if (storage.is_file(t.first)) {
result.type = t.second;
break;
}
}
if (result.type == FileType::unknown) {
throw UnknownFileType();
}
return result;
}
} // namespace
LegacyMicrosoftFile::LegacyMicrosoftFile(
std::shared_ptr<abstract::ReadableFilesystem> storage)
: m_storage{std::move(storage)} {
m_file_meta = parse_meta(*m_storage);
}
std::shared_ptr<abstract::File> LegacyMicrosoftFile::file() const noexcept {
return {};
}
FileType LegacyMicrosoftFile::file_type() const noexcept {
return m_file_meta.type;
}
FileMeta LegacyMicrosoftFile::file_meta() const noexcept { return m_file_meta; }
DecoderEngine LegacyMicrosoftFile::decoder_engine() const noexcept {
return DecoderEngine::odr;
}
DocumentType LegacyMicrosoftFile::document_type() const {
return m_file_meta.document_meta.value().document_type;
}
DocumentMeta LegacyMicrosoftFile::document_meta() const {
return m_file_meta.document_meta.value();
}
bool LegacyMicrosoftFile::password_encrypted() const noexcept {
return m_file_meta.password_encrypted;
}
EncryptionState LegacyMicrosoftFile::encryption_state() const noexcept {
return EncryptionState::unknown;
}
std::shared_ptr<abstract::DecodedFile>
LegacyMicrosoftFile::decrypt(const std::string &password) const {
(void)password;
return {}; // TODO throw
}
std::shared_ptr<abstract::Document> LegacyMicrosoftFile::document() const {
return {}; // TODO throw
}
} // namespace odr::internal::oldms