120 wxFFile file( aFileName, wxT(
"rb" ) );
122 if( !file.IsOpened() )
128 !=
static_cast<size_t>(
sizeof(
header ) - 1 ) )
136 if( aSection.empty() )
143 const std::string wanted =
"\n(" + aSection;
144 const std::string sibling = ( aSection ==
"pcbDesign" ) ?
"\n(schematicDesign"
147 const size_t overlap = std::max( wanted.size(), sibling.size() );
150 std::string window =
"\n";
155 size_t got = file.Read( buf,
sizeof( buf ) );
157 if( got == 0 || got ==
static_cast<size_t>( wxInvalidOffset ) )
161 window.append( buf, got );
162 window.erase( std::remove( window.begin(), window.end(),
'\r' ), window.end() );
164 if( window.find( wanted ) != std::string::npos )
167 if( window.find( sibling ) != std::string::npos )
170 if( window.size() > overlap )
171 window.erase( 0, window.size() - overlap );
179 XNODE* iNode =
nullptr, *cNode =
nullptr;
180 wxString str, propValue, content;
181 wxCSConv conv( wxT(
"windows-1251" ) );
183 wxFFile file( aFileName, wxT(
"rb" ) );
185 if( !file.IsOpened() )
186 THROW_IO_ERROR( wxString::Format(
_(
"Cannot open file '%s'." ), aFileName ) );
188 std::string fileContent;
191 wxFileOffset length = file.Length();
194 THROW_IO_ERROR( wxString::Format(
_(
"Cannot read file '%s'." ), aFileName ) );
196 fileContent.resize(
static_cast<size_t>( length ) );
198 if( file.Read( fileContent.data(), fileContent.size() ) != fileContent.size() )
199 THROW_IO_ERROR( wxString::Format(
_(
"Cannot read file '%s'." ), aFileName ) );
205 THROW_IO_ERROR( wxString::Format(
_(
"'%s' is not a P-CAD ASCII file." ), aFileName ) );
212 std::unique_ptr<XNODE> root(
new XNODE( wxXML_ELEMENT_NODE, wxT(
"www.lura.sk" ) ) );
224 THROW_IO_ERROR( wxString::Format(
_(
"Unbalanced parentheses in '%s'." ),
231 cNode =
new XNODE( wxXML_ELEMENT_NODE, wxString( lexer.
CurText(), conv ) );
232 iNode->AddChild( cNode );
237 str = wxString( lexer.
CurText(), conv );
242 if( iNode->GetAttribute( wxT(
"Name" ), &propValue ) )
244 iNode->DeleteAttribute( wxT(
"Name" ) );
245 iNode->
AddAttribute( wxT(
"Name" ), propValue + wxT(
' ' ) + str );
252 else if( str != wxEmptyString )
255 content = cNode->GetNodeContent() + wxT(
' ' ) + str;
257 if( cNode->GetChildren() )
258 cNode->GetChildren()->SetContent( content );
260 cNode->AddChild(
new wxXmlNode( wxXML_TEXT_NODE, wxEmptyString, content ) );
266 if( iNode != root.get() )
267 THROW_IO_ERROR( wxString::Format(
_(
"Unbalanced parentheses in '%s'." ), aFileName ) );
269 aXmlDoc->SetRoot( root.release() );