]> git.lyx.org Git - lyx.git/blobdiff - src/EmbeddedFiles.cpp
* support/FileName:
[lyx.git] / src / EmbeddedFiles.cpp
index bc7ab0b1006c1afd9947e41eb8330ba1753746c3..2d2aef8c37b842a1c93d4f2340528fc9191529d2 100644 (file)
 
 #include "frontends/alert.h"
 
-#include <boost/filesystem/operations.hpp>
-
 #include "support/filetools.h"
-#include "support/fs_extras.h"
 #include "support/convert.h"
 #include "support/lyxlib.h"
 #include "support/lstrings.h"
@@ -53,7 +50,6 @@ using std::istringstream;
 
 namespace lyx {
 
-namespace fs = boost::filesystem;
 namespace Alert = frontend::Alert;
 
 using support::FileName;
@@ -133,11 +129,14 @@ bool EmbeddedFile::extract(Buffer const * buf) const
        string ext_file = absFilename();
        string emb_file = embeddedFile(buf);
 
-       if (!fs::exists(emb_file))
+       FileName emb(emb_file);
+       FileName ext(ext_file);
+
+       if (!emb.exists())
                return false;
 
        // if external file already exists ...
-       if (fs::exists(ext_file)) {
+       if (ext.exists()) {
                // no need to copy if the files are the same
                if (sum(*this) == sum(FileName(emb_file)))
                        return true;
@@ -152,20 +151,18 @@ bool EmbeddedFile::extract(Buffer const * buf) const
                        return true;
        }
        // copy file
-       try {
-               // need to make directory?
-               string path = support::onlyPath(ext_file);
-               if (!fs::is_directory(path))
-                       makedir(const_cast<char*>(path.c_str()), 0755);
-               fs::copy_file(emb_file, ext_file, false);
+
+       // need to make directory?
+       FileName path = ext.onlyPath();
+       if (!path.isDirectory())
+               makedir(const_cast<char*>(path.absFilename().c_str()), 0755);
+       if (emb.copyTo(ext))
                return true;
-       } catch (fs::filesystem_error const & fe) {
-               Alert::error(_("Copy file failure"),
-                        bformat(_("Cannot copy file %1$s to %2$s.\n"
-                                  "Please check whether the directory exists and is writeable."),
-                                       from_utf8(emb_file), from_utf8(ext_file)));
-               LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
-       }
+       Alert::error(_("Copy file failure"),
+                bformat(_("Cannot copy file %1$s to %2$s.\n"
+                                "Please check whether the directory exists and is writeable."),
+                               from_utf8(emb_file), from_utf8(ext_file)));
+       //LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
        return false;
 }
 
@@ -175,11 +172,14 @@ bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const
        string ext_file = absFilename();
        string emb_file = embeddedFile(buf);
 
-       if (!fs::exists(ext_file))
+       FileName emb(emb_file);
+       FileName ext(ext_file);
+
+       if (!ext.exists())
                return false;
        
        // if embedded file already exists ...
-       if (fs::exists(emb_file)) {
+       if (emb.exists()) {
                // no need to copy if the files are the same
                if (sum(*this) == sum(FileName(emb_file)))
                        return true;
@@ -194,20 +194,17 @@ bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const
                        return true;
        }
        // copy file
-       try {
-               // need to make directory?
-               string path = support::onlyPath(emb_file);
-               if (!fs::is_directory(path))
-                       makedir(const_cast<char*>(path.c_str()), 0755);
-               fs::copy_file(ext_file, emb_file, false);
+       // need to make directory?
+       FileName path = emb.onlyPath();
+       if (!path.isDirectory())
+               makedir(const_cast<char*>(path.absFilename().c_str()), 0755);
+       if (ext.copyTo(emb))
                return true;
-       } catch (fs::filesystem_error const & fe) {
-               Alert::error(_("Copy file failure"),
-                        bformat(_("Cannot copy file %1$s to %2$s.\n"
-                                  "Please check whether the directory exists and is writeable."),
-                                       from_utf8(ext_file), from_utf8(emb_file)));
-               LYXERR(Debug::DEBUG) << "Fs error: " << fe.what() << endl;
-       }
+       Alert::error(_("Copy file failure"),
+                bformat(_("Cannot copy file %1$s to %2$s.\n"
+                          "Please check whether the directory exists and is writeable."),
+                               from_utf8(ext_file), from_utf8(emb_file)));
+       //LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
        return false;
 }
 
@@ -304,20 +301,19 @@ bool EmbeddedFiles::writeFile(DocFileName const & filename)
 
        ::zipFiles(zipfile.toFilesystemEncoding(), filenames);
        // copy file back
-       try {
-               fs::copy_file(zipfile.toFilesystemEncoding(), filename.toFilesystemEncoding(), false);
-       } catch (fs::filesystem_error const & fe) {
+       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() << endl;
+               //LYXERR(Debug::DEBUG, "Fs error: " << fe.what());
        }
        return true;
 }
 
 
-EmbeddedFiles::EmbeddedFileList::const_iterator EmbeddedFiles::find(std::string filename) const
+EmbeddedFiles::EmbeddedFileList::const_iterator
+EmbeddedFiles::find(std::string filename) const
 {
        EmbeddedFileList::const_iterator it = file_list_.begin();
        EmbeddedFileList::const_iterator it_end = file_list_.end();