- // copy file in the previous case, and a new case
- if (copyFile || (!fs::exists(ext_file) && fs::exists(emb_file))) {
- try {
- fs::copy_file(emb_file, ext_file, false);
+ return false;
+}
+
+
+bool EmbeddedFile::updateFromExternalFile(Buffer const * buf) const
+{
+ string ext_file = absFilename();
+ string emb_file = embeddedFile(buf);
+
+ if (!fs::exists(ext_file))
+ return false;
+
+ // if embedded file already exists ...
+ if (fs::exists(emb_file)) {
+ // no need to copy if the files are the same
+ if (sum(*this) == sum(FileName(emb_file)))
+ return true;
+ // other wise, ask if overwrite
+ int const ret = Alert::prompt(
+ _("Update embedded file?"),
+ bformat(_("Embeddedl file %1$s already exists, do you want to overwrite it"),
+ from_utf8(ext_file)), 1, 1, _("&Overwrite"), _("&Cancel"));
+ if (ret != 0)
+ // if the user does not want to overwrite, we still consider it
+ // a successful operation.