- if (!it->valid())
- continue;
- // use differnt lines to make reading easier.
- os << "<file>\n"
- // save the relative path
- << to_utf8(makeRelPath(from_utf8(it->absFilename()),
- from_utf8(files.buffer_->filePath()))) << '\n'
- << it->inzipName() << '\n'
- << it->embedded() << '\n'
- << "</file>\n";
+ if (it->embedded()) {
+ string file = it->embeddedFile();
+ if (!FileName(file).exists())
+ throw ExceptionMessage(ErrorException, _("Failed to write file"),
+ bformat(_("Embedded file %1$s does not exist. Did you tamper lyx temporary directory?"),
+ it->displayName()));
+ filenames.push_back(make_pair(file, it->inzipName()));
+ LYXERR(Debug::FILES, "Writing file " << it->outputFilename()
+ << " as " << it->inzipName() << endl);
+ }
+ }
+ // write a zip file with all these files. Write to a temp file first, to
+ // avoid messing up the original file in case something goes terribly wrong.
+ DocFileName zipfile(addName(buffer.temppath(),
+ onlyFilename(changeExtension(
+ filename.toFilesystemEncoding(), ".zip"))));
+
+ ::zipFiles(zipfile.toFilesystemEncoding(), filenames);
+ // copy file back
+ if (!zipfile.copyTo(filename)) {
+ Alert::error(_("Save failure"),
+ bformat(_("Cannot create file %1$s.\n"
+ "Please check whether the directory exists and is writeable."),
+ from_utf8(filename.absFilename())));
+ //LYXERR(Debug::DEBUG, "Fs error: " << fe.what());