- lyxerr << _(" Save failed! Bummer. Document is lost.") << endl;
-}
-
-
-
-Buffer * BufferList::readFile(string const & s, bool ronly)
-{
- string ts(s);
- string e = OnlyPath(s);
- string a = e;
- // File information about normal file
- FileInfo fileInfo2(s);
-
- if (!fileInfo2.exist()) {
- string const file = MakeDisplayPath(s, 50);
- string text = bformat(_("The specified document\n%1$s"
- "\ncould not be read."), file);
- Alert::error(_("Could not read document"), text);
- return 0;
- }
-
- Buffer * b = newBuffer(s, ronly);
-
- // 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()) {
- string const file = MakeDisplayPath(s, 20);
- string text = bformat(_("An emergency save of the document %1$s exists.\n"
- "\nRecover emergency save?"), file);
- int const ret = Alert::prompt(_("Load emergency save?"),
- text, 0, 1, _("&Recover"), _("&Load Original"));
-
- if (ret == 0) {
- ts = e;
- // the file is not saved if we load the
- // emergency file.
- b->markDirty();
- use_emergency = true;
- }
- }
- }
-
- 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()) {
- string const file = MakeDisplayPath(s, 20);
- string text = bformat(_("The backup of the document %1$s is newer.\n\n"
- "Load the backup instead?"), file);
- int const ret = Alert::prompt(_("Load backup?"),
- text, 0, 1, _("&Load backup"), _("Load &original"));
-
- if (ret == 0) {
- 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, ts))
- return b;
- else {
- release(b);
- return 0;
- }