- for_each(bstore.begin(), bstore.end(),
- bind(&BufferList::emergencyWrite, this, _1));
-}
-
-
-void BufferList::emergencyWrite(Buffer * buf)
-{
- // Use ::assert to avoid a loop, BOOST_ASSERT ends up calling ::assert
- // compare with 0 to avoid pointer/interger comparison
- // ::assert(buf != 0);
- if (!buf)
- return;
-
- // No need to save if the buffer has not changed.
- if (buf->isClean())
- return;
-
- string const doc = buf->isUnnamed()
- ? onlyFilename(buf->fileName()) : buf->fileName();
-
- lyxerr << to_utf8(
- bformat(_("LyX: Attempting to save document %1$s"), from_utf8(doc)))
- << endl;
-
- // We try to save three places:
- // 1) Same place as document. Unless it is an unnamed doc.
- if (!buf->isUnnamed()) {
- string s = buf->fileName();
- s += ".emergency";
- lyxerr << " " << s << endl;
- if (buf->writeFile(FileName(s))) {
- buf->markClean();
- lyxerr << to_utf8(_(" Save seems successful. Phew.")) << endl;
- return;
- } else {
- lyxerr << to_utf8(_(" Save failed! Trying...")) << endl;
- }
- }
-
- // 2) In HOME directory.
- string s = addName(package().home_dir().absFilename(), buf->fileName());
- s += ".emergency";
- lyxerr << ' ' << s << endl;
- if (buf->writeFile(FileName(s))) {
- buf->markClean();
- lyxerr << to_utf8(_(" Save seems successful. Phew.")) << endl;
- return;
- }
-
- lyxerr << to_utf8(_(" Save failed! Trying...")) << endl;
-
- // 3) In "/tmp" directory.
- // MakeAbsPath to prepend the current
- // drive letter on OS/2
- s = addName(package().temp_dir().absFilename(), buf->fileName());
- s += ".emergency";
- lyxerr << ' ' << s << endl;
- if (buf->writeFile(FileName(s))) {
- buf->markClean();
- lyxerr << to_utf8(_(" Save seems successful. Phew.")) << endl;
- return;
- }
- lyxerr << to_utf8(_(" Save failed! Bummer. Document is lost.")) << endl;