KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easypc_file.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
21
22#ifndef EASYPC_FILE_H
23#define EASYPC_FILE_H
24
25#include <cstdint>
26#include <map>
27#include <memory>
28#include <string>
29#include <vector>
30
31#include <wx/string.h>
32
33namespace CFB
34{
35class CompoundFileReader;
36}
37
38
39namespace EASYPC
40{
41
51
52
53const char* FileKindString( FILE_KIND aKind );
54
55
57wxString UnescapeItemName( const std::u16string& aName );
58
59
61std::vector<uint8_t> ReadWholeFile( const wxString& aPath );
62
63
65{
66 uint32_t Id = 0;
67 std::u16string Name;
68 uint8_t Type = 0;
69
70 bool IsStorage() const { return Type == 1 || Type == 5; }
71 bool IsStream() const { return Type == 2; }
72
74 bool IsAppStream() const { return !Name.empty() && Name[0] == 5; }
75};
76
77
80{
81public:
82 explicit COMPOUND_FILE( const wxString& aPath );
84
85 const SOURCE_FB_ENTRY& Root() const { return m_entries.at( 0 ); }
86
88 std::vector<const SOURCE_FB_ENTRY*> Children( const SOURCE_FB_ENTRY& aStorage ) const;
89
90 const SOURCE_FB_ENTRY* FindChild( const SOURCE_FB_ENTRY& aStorage, const std::u16string& aName ) const;
91 std::vector<uint8_t> ReadStream( const SOURCE_FB_ENTRY& aStream ) const;
92
93 FILE_KIND FileKind() const;
94
96 int32_t LibraryProduct() const;
97
98private:
99 std::vector<uint8_t> m_image;
100 std::unique_ptr<CFB::CompoundFileReader> m_reader;
101 std::map<uint32_t, SOURCE_FB_ENTRY> m_entries;
102 std::map<uint32_t, std::vector<uint32_t>> m_children;
103};
104
105} // namespace EASYPC
106
107#endif // EASYPC_FILE_H
std::map< uint32_t, std::vector< uint32_t > > m_children
storage id to member ids in tree order
std::unique_ptr< CFB::CompoundFileReader > m_reader
std::vector< uint8_t > ReadStream(const SOURCE_FB_ENTRY &aStream) const
const SOURCE_FB_ENTRY & Root() const
Definition easypc_file.h:85
int32_t LibraryProduct() const
The LibFormat product, 1 when missing, short or 0.
FILE_KIND FileKind() const
std::vector< const SOURCE_FB_ENTRY * > Children(const SOURCE_FB_ENTRY &aStorage) const
The members of a storage in directory-tree order.
std::vector< uint8_t > m_image
Definition easypc_file.h:99
COMPOUND_FILE(const wxString &aPath)
std::map< uint32_t, SOURCE_FB_ENTRY > m_entries
const SOURCE_FB_ENTRY * FindChild(const SOURCE_FB_ENTRY &aStorage, const std::u16string &aName) const
std::vector< uint8_t > ReadWholeFile(const wxString &aPath)
The whole content of a file; throws IO_ERROR when it cannot be read.
const char * FileKindString(FILE_KIND aKind)
FILE_KIND
The FileType strings the importer reads.
Definition easypc_file.h:44
wxString UnescapeItemName(const std::u16string &aName)
Undo the item name escaping, which stores # ! \ / : * ? " < > | as 0x06..0x10.
Definition easypc_file.h:65
uint8_t Type
1 storage, 2 stream, 5 root
Definition easypc_file.h:68
bool IsAppStream() const
FileType, LibFormat and SummaryInformation start with 0x05 and are never items.
Definition easypc_file.h:74
std::u16string Name
without the terminator
Definition easypc_file.h:67
uint32_t Id
Definition easypc_file.h:66
bool IsStorage() const
Definition easypc_file.h:70
bool IsStream() const
Definition easypc_file.h:71