]> git.lyx.org Git - lyx.git/blobdiff - src/exporter.C
compilation fix
[lyx.git] / src / exporter.C
index f91d98385558635e551022a38ea9cc548f68a1bc..c79f001ea2a69bc1216bf7a1599ba39aca8a5181 100644 (file)
 #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"
+
+#include <boost/filesystem/operations.hpp>
 
 using lyx::support::AddName;
 using lyx::support::bformat;
@@ -42,12 +44,14 @@ using lyx::support::MakeAbsPath;
 using lyx::support::MakeDisplayPath;
 using lyx::support::OnlyFilename;
 using lyx::support::OnlyPath;
+using lyx::support::package;
 using lyx::support::prefixIs;
 
 using std::find;
 using std::string;
 using std::vector;
 
+namespace fs = boost::filesystem;
 
 namespace {
 
@@ -64,7 +68,7 @@ vector<string> const Backends(Buffer const & buffer)
 /// ask the user what to do if a file already exists
 int checkOverwrite(string const & filename)
 {
-       if (lyx::support::FileInfo(filename, true).exist()) {
+       if (fs::exists(filename)) {
                string text = bformat(_("The file %1$s already exists.\n\n"
                                        "Do you want to over-write that file?"),
                                      MakeDisplayPath(filename));
@@ -86,14 +90,15 @@ enum CopyStatus {
 
 /** 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;
 
@@ -101,7 +106,7 @@ CopyStatus copyFile(string const & sourceFile, string const & destFile,
        // 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) {
@@ -117,7 +122,8 @@ CopyStatus copyFile(string const & sourceFile, string const & destFile,
                }
        }
 
-       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),
@@ -136,8 +142,6 @@ bool Exporter::Export(Buffer * buffer, string const & format,
        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();
@@ -200,19 +204,24 @@ bool Exporter::Export(Buffer * buffer, string const & format,
                                              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'"),
@@ -282,8 +291,8 @@ bool operator==(ExportedFile const & f1, ExportedFile const & f2)
 
 
 void ExportData::addExternalFile(string const & format,
-                                 string const & sourceName,
-                                 string const & exportName)
+                                string const & sourceName,
+                                string const & exportName)
 {
        BOOST_ASSERT(lyx::support::AbsolutePath(sourceName));
 
@@ -297,7 +306,7 @@ void ExportData::addExternalFile(string const & format,
 
 
 void ExportData::addExternalFile(string const & format,
-                                 string const & sourceName)
+                                string const & sourceName)
 {
        addExternalFile(format, sourceName, OnlyFilename(sourceName));
 }