3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Alfredo Braunstein
8 * \author Lars Gullik Bjønnes
9 * \author Jean Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
14 * Full author contact details are available in file CREDITS.
23 #include "frontends/alert.h"
25 #include "support/filetools.h"
26 #include "support/gettext.h"
27 #include "support/lstrings.h"
28 #include "support/Package.h"
33 using namespace lyx::support;
37 namespace Alert = frontend::Alert;
39 /// Ask the user what to do if the destination file already exists
40 /// and is different from the source file.
41 static int checkOverwrite(FileName const & src_file, FileName const & dst_file)
43 if (!dst_file.exists())
46 if (src_file.checksum() == dst_file.checksum())
49 docstring text = bformat(_("The file %1$s already exists.\n\n"
50 "Do you want to overwrite that file?"),
51 makeDisplayPath(dst_file.absFilename()));
52 return Alert::prompt(_("Overwrite file?"),
54 _("&Overwrite"), _("Overwrite &all"),
59 /** copy file \p sourceFile to \p destFile. If \p force is false, the user
60 * will be asked before existing files are overwritten.
62 * - SUCCESS if this file got copied
63 * - FORCE if subsequent calls should not ask for confirmation before
64 * overwriting files anymore.
65 * - CANCEL if the export should be cancelled
67 CopyStatus copyFile(string const & format,
68 FileName const & sourceFile, FileName const & destFile,
69 string const & latexFile, bool force)
71 CopyStatus ret = force ? FORCE : SUCCESS;
73 // Only copy files that are in our tmp dir, all other files would
74 // overwrite themselves. This check could be changed to
75 // boost::filesystem::equivalent(sourceFile, destFile) if export to
76 // other directories than the document directory is desired.
77 if (!prefixIs(onlyPath(sourceFile.absFilename()), package().temp_dir().absFilename()))
81 switch(checkOverwrite(sourceFile, destFile)) {
95 Mover const & mover = getMover(format);
96 if (!mover.copy(sourceFile, destFile, latexFile))
97 Alert::error(_("Couldn't copy file"),
98 bformat(_("Copying %1$s to %2$s failed."),
99 makeDisplayPath(sourceFile.absFilename()),
100 makeDisplayPath(destFile.absFilename())));
106 ExportedFile::ExportedFile(FileName const & s, string const & e)
107 : sourceName(s), exportName(e)
111 bool operator==(ExportedFile const & f1, ExportedFile const & f2)
113 return f1.sourceName == f2.sourceName &&
114 f1.exportName == f2.exportName;
119 void ExportData::addExternalFile(string const & format,
120 FileName const & sourceName,
121 string const & exportName)
123 // Make sure that we have every file only once, otherwise copyFile()
124 // would ask several times if it should overwrite a file.
125 vector<ExportedFile> & files = externalfiles_[format];
126 ExportedFile file(sourceName, exportName);
127 if (find(files.begin(), files.end(), file) == files.end())
128 files.push_back(file);
132 void ExportData::addExternalFile(string const & format,
133 FileName const & sourceName)
135 addExternalFile(format, sourceName, onlyFilename(sourceName.absFilename()));
139 vector<ExportedFile> const
140 ExportData::externalFiles(string const & format) const
142 FileMap::const_iterator cit = externalfiles_.find(format);
143 if (cit != externalfiles_.end())
145 return vector<ExportedFile>();