On Thu, May 08, 2008 at 11:20:56PM -0500, Bo Peng wrote: > +void FileName::decodeFrom(string const & encoded) const > +{ > + QByteArray text(encoded.c_str()); > + QByteArray decoded = QByteArray::fromBase64(text); > + > +/* NOTE: The following is supposed to work but it does not. > + * Some strange bytes 0x0000 0x1902 are written to the output > + * before the content is written. QT experts should know what is > + * happening here. > + */ > +/* > + QFile file(d->fi.absoluteFilePath()); > + if (!file.open(QFile::WriteOnly | QFile::Truncate)) { > + LYXERR0("File '" << *this > + << "' could not be opened in write only mode!"); > + return; > + } > + > + QDataStream out(&file); > + out << decoded; > +*/ > + ofstream ofs(toFilesystemEncoding().c_str()); > + char * data = decoded.data(); > + for (int i = 0; i < decoded.size(); ++i) > + ofs << data[i]; > + ofs.close(); > +}
I am not sure why this is "supposed to work". QDataStream serializes data in a fashion that can be deserialized by QDataStream again. This typically involves some metainfo in =the serialized data like type information and length. QDataStream is _not_ the same as "QTextStream opened in binary mode" or such. > Index: src/EmbeddedFiles.h > =================================================================== > --- src/EmbeddedFiles.h (revision 0) > +++ src/EmbeddedFiles.h (revision 0) > @@ -0,0 +1,79 @@ > +// -*- C++ -*- > +/** > + * \file EmbeddedFiles.h > + * This file is part of LyX, the document processor. > + * Licence details can be found in the file COPYING. > + * > + * \author Bo Peng > + * > + * Full author contact details are available in file CREDITS. > + */ > + > +#ifndef EMBEDDED_FILES_H > +#define EMBEDDED_FILES_H > + > +#include <string> > + > +using namespace std; Do not use 'using namespace' on file scope in headers. > +namespace lyx { > + > +namespace support { > +class DocFileName; > +class FileName; > +} > + > + > +class EmbeddedFiles { > +public: > + /// > + EmbeddedFiles(); > + ~EmbeddedFiles(); > + > + /// embedded files are put under the temp_path of a buffer > + void setTempPath(std::string const & temp_path); > + > + /** Copy \c file to a random new file under the buffer temporary > directory. > + * > + * \param file external file to be embedded > + * \result an embedded file with random filename > + */ > + support::DocFileName embed(support::DocFileName const & file); > + > + /** Link \c file to file \c name under the buffer temporary directory. > + * The content of \c file will not be copied to \c name. > + * \param file external file > + * \param name name (filename only) of the embedded file > + */ > + support::DocFileName link(support::DocFileName const & file, > std::string const & name); > + > + /** Look up original filename from an embedded file. An empty filename > will > + * be returned if the embedded file can not be found, but this should > not happen. > + * > + * \param file embedded file > + * \return the original filename of the embedded file > + */ > + support::DocFileName lookup(support::DocFileName const & file); > + > + /** register file as writable to .lyx file > + * \param file embedded file that will be written to .lyx file > + */ > + void registerFile(support::DocFileName const & file) const; > + > + /// clear 'write to .lyx file' list, this should be done before > + /// write a .lyx file. > + void clearWriteList() const; > + > + /// write embedded files in base64 encoding > + void write(ostream & ofs); > + > +private: > + > + class Impl; > + Impl * const d; > +}; > + > + > +} // namespace lyx #include "support/strfwd.h" might do. Andre'