-
-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);
-#if USE_BOOST_FORMAT
- boost::format fmt(_("The specified document\n%1$s\ncould not be read."));
- fmt % file;
- string text = fmt.str();
-#else
- string text = _("The specified document\n");
- text += file + _(" could not be read.");
-#endif
- 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);
-#if USE_BOOST_FORMAT
- boost::format fmt(_("An emergency save of the document %1$s exists.\n\nRecover emergency save?"));
- fmt % file;
- string text = fmt.str();
-#else
- string text = _("An emergency save of the document ");
- text += file + _(" exists.\n\nRecover emergency save?");
-#endif
- int const ret = Alert::prompt(_("Load emergency save?"),
- text, 0, _("&Recover"), _("&Load original"));
-
- if (ret == 0) {
- 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()) {
- string const file = MakeDisplayPath(s, 20);
-#if USE_BOOST_FORMAT
- boost::format fmt(_("The backup of the document %1$s is newer.\n\nLoad the backup instead?"));
- fmt % file;
- string text = fmt.str();
-#else
- string text = _("The backup of the document ");
- text += file + _(" is newer.\n\nLoad the backup instead?");
-#endif
- int const ret = Alert::prompt(_("Load backup?"),
- text, 0, _("&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;
- }
-}
-
-