- lyxerr << _(" Save failed! Bummer. Document is lost.") << endl;
-}
-
-
-
-Buffer * BufferList::readFile(string const & s, bool ronly)
-{
- Buffer * b = bstore.newBuffer(s, ronly);
-
- string ts = s;
- string e = OnlyPath(s);
- string a = e;
- // File information about normal file
- FileInfo fileInfo2(s);
-
- if (!fileInfo2.exist()) {
- WriteAlert(_("Error!"), _("Cannot open file"),
- MakeDisplayPath(s));
- return 0;
- }
-
- // Check if emergency save file exists and is newer.
- e += OnlyFilename(s) + ".emergency";
- FileInfo fileInfoE(e);
-
- bool use_emergency = false;
-
- if (fileInfoE.exist() && fileInfo2.exist()) {
- if (fileInfoE.getModificationTime()
- > fileInfo2.getModificationTime()) {
- if (AskQuestion(_("An emergency save of this document exists!"),
- MakeDisplayPath(s, 50),
- _("Try to load that instead?"))) {
- ts = e;
- // the file is not saved if we load the
- // emergency file.
- b->markDirty();
- use_emergency = true;
- } else {
- // Here, we should delete the emergency save
- lyx::unlink(e);
- }
- }
- }
-
- if (!use_emergency) {
- // Now check if autosave file is newer.
- a += '#';
- a += OnlyFilename(s);
- a += '#';
- FileInfo fileInfoA(a);
- if (fileInfoA.exist() && fileInfo2.exist()) {
- if (fileInfoA.getModificationTime()
- > fileInfo2.getModificationTime()) {
- if (AskQuestion(_("Autosave file is newer."),
- MakeDisplayPath(s, 50),
- _("Load that one instead?"))) {
- ts = a;
- // the file is not saved if we load the
- // autosave file.
- b->markDirty();
- } else {
- // Here, we should delete the autosave
- lyx::unlink(a);
- }
- }
- }
- }
- // not sure if this is the correct place to begin LyXLex
- LyXLex lex(0, 0);
- lex.setFile(ts);
- if (b->readFile(lex))
- return b;
- else {
- bstore.release(b);
- return 0;
- }