#include "format.h"
#include "gettext.h"
#include "lyxrc.h"
+#include "mover.h"
#include "output_plaintext.h"
#include "outputparams.h"
#include "frontends/Alert.h"
#include "support/FileInfo.h"
#include "support/filetools.h"
#include "support/lyxlib.h"
-#include "support/os.h"
+#include "support/package.h"
using lyx::support::AddName;
using lyx::support::bformat;
using lyx::support::MakeDisplayPath;
using lyx::support::OnlyFilename;
using lyx::support::OnlyPath;
+using lyx::support::package;
using lyx::support::prefixIs;
using std::find;
/** copy file \p sourceFile to \p destFile. If \p force is false, the user
* will be asked before existing files are overwritten.
- * \return
+ * \return
* - SUCCESS if this file got copied
* - FORCE if subsequent calls should not ask for confirmation before
* overwriting files anymore.
* - CANCEL if the export should be cancelled
*/
-CopyStatus copyFile(string const & sourceFile, string const & destFile,
- bool force)
+CopyStatus copyFile(string const & format,
+ string const & sourceFile, string const & destFile,
+ string const & latexFile, bool force)
{
CopyStatus ret = force ? FORCE : SUCCESS;
// overwrite themselves. This check could be changed to
// boost::filesystem::equivalent(sourceFile, destFile) if export to
// other directories than the document directory is desired.
- if (!prefixIs(OnlyPath(sourceFile), lyx::support::os::getTmpDir()))
+ if (!prefixIs(OnlyPath(sourceFile), package().temp_dir()))
return ret;
if (!force) {
}
}
- if (!lyx::support::copy(sourceFile, destFile))
+ Mover const & mover = movers(format);
+ if (!mover.copy(sourceFile, destFile, latexFile))
Alert::error(_("Couldn't copy file"),
bformat(_("Copying %1$s to %2$s failed."),
MakeDisplayPath(sourceFile),
OutputParams runparams;
runparams.flavor = OutputParams::LATEX;
runparams.linelen = lyxrc.ascii_linelen;
- ExportData exportdata;
- runparams.exportdata = &exportdata;
vector<string> backends = Backends(*buffer);
if (find(backends.begin(), backends.end(), format) == backends.end()) {
for (vector<string>::const_iterator it = backends.begin();
formats.extension(format));
// We need to copy referenced files (e. g. included graphics
// if format == "dvi") to the result dir.
- vector<ExportedFile> const files = exportdata.externalFiles(format);
+ vector<ExportedFile> const files =
+ runparams.exportdata->externalFiles(format);
string const dest = OnlyPath(result_file);
CopyStatus status = SUCCESS;
for (vector<ExportedFile>::const_iterator it = files.begin();
- it != files.end() && status != CANCEL; ++it)
- status = copyFile(it->sourceName,
+ it != files.end() && status != CANCEL; ++it) {
+ string const fmt =
+ formats.getFormatFromFile(it->sourceName);
+ status = copyFile(fmt, it->sourceName,
MakeAbsPath(it->exportName, dest),
- status == FORCE);
+ it->exportName, status == FORCE);
+ }
if (status == CANCEL) {
buffer->message(_("Document export cancelled."));
} else {
// Finally copy the main file
- status = copyFile(tmp_result_file, result_file,
+ status = copyFile(format, tmp_result_file,
+ result_file, result_file,
status == FORCE);
buffer->message(bformat(_("Document exported as %1$s"
"to file `%2$s'"),
void ExportData::addExternalFile(string const & format,
- string const & sourceName,
- string const & exportName)
+ string const & sourceName,
+ string const & exportName)
{
BOOST_ASSERT(lyx::support::AbsolutePath(sourceName));
void ExportData::addExternalFile(string const & format,
- string const & sourceName)
+ string const & sourceName)
{
addExternalFile(format, sourceName, OnlyFilename(sourceName));
}