From: Bo Peng Date: Wed, 22 Nov 2006 21:00:14 +0000 (+0000) Subject: * src/session.C: robustify session::read (lyx will start with corrupted session... X-Git-Tag: 1.6.10~11794 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=70cf0c49abc6bfaeed540f4d07ded548f45a67ac;p=features.git * src/session.C: robustify session::read (lyx will start with corrupted session file) git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16013 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/session.C b/src/session.C index 4372d610e8..81ac3afcf5 100644 --- a/src/session.C +++ b/src/session.C @@ -71,10 +71,14 @@ void LastFilesSection::read(istream & is) if (c == '[') break; getline(is, tmp); - // read lastfiles - if (!fs::exists(tmp) || lastfiles.size() >= num_lastfiles) + if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') continue; - lastfiles.push_back(tmp); + + // read lastfiles + if (fs::exists(tmp) && !fs::is_directory(tmp) && lastfiles.size() < num_lastfiles) + lastfiles.push_back(tmp); + else + lyxerr << "LyX: Warning: Ignore last file: " << tmp << endl; } while (is.good()); } @@ -120,9 +124,13 @@ void LastOpenedSection::read(istream & is) if (c == '[') break; getline(is, tmp); - if (!fs::exists(tmp)) + if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') continue; - lastopened.push_back(tmp); + + if (fs::exists(tmp) && !fs::is_directory(tmp)) + lastopened.push_back(tmp); + else + lyxerr << "LyX: Warning: Ignore last opened file: " << tmp << endl; } while (is.good()); } @@ -155,20 +163,28 @@ void LastFilePosSection::read(istream & is) if (c == '[') break; getline(is, tmp); - // read lastfilepos - // pos, file\n - pit_type pit; - pos_type pos; - string fname; - istringstream itmp(tmp); - itmp >> pit; - itmp.ignore(2); // ignore ", " - itmp >> pos; - itmp.ignore(2); // ignore ", " - itmp >> fname; - if (!fs::exists(fname) || lastfilepos.size() >= num_lastfilepos) + if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') continue; - lastfilepos[fname] = boost::tie(pit, pos); + + try { + // read lastfilepos + // pos, file\n + pit_type pit; + pos_type pos; + string fname; + istringstream itmp(tmp); + itmp >> pit; + itmp.ignore(2); // ignore ", " + itmp >> pos; + itmp.ignore(2); // ignore ", " + itmp >> fname; + if (fs::exists(fname) && !fs::is_directory(fname) && lastfilepos.size() < num_lastfilepos) + lastfilepos[fname] = boost::tie(pit, pos); + else + lyxerr << "LyX: Warning: Ignore pos of last file: " << fname << endl; + } catch (...) { + lyxerr << "LyX: Warning: unknown pos of last file: " << tmp << endl; + } } while (is.good()); } @@ -211,20 +227,29 @@ void BookmarksSection::read(istream & is) if (c == '[') break; getline(is, tmp); - // read bookmarks - // id, pos, file\n - unsigned int id; - pos_type pos; - string fname; - istringstream itmp(tmp); - itmp >> id; - itmp.ignore(2); // ignore ", " - itmp >> pos; - itmp.ignore(2); // ignore ", " - itmp >> fname; - // only load valid bookmarks - if (bookmarks.size() < max_bookmarks && fs::exists(fname)) - bookmarks.push_back(Bookmark(fname, id, pos)); + if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') + continue; + + try { + // read bookmarks + // id, pos, file\n + unsigned int id; + pos_type pos; + string fname; + istringstream itmp(tmp); + itmp >> id; + itmp.ignore(2); // ignore ", " + itmp >> pos; + itmp.ignore(2); // ignore ", " + itmp >> fname; + // only load valid bookmarks + if (fs::exists(fname) && !fs::is_directory(fname) && bookmarks.size() < max_bookmarks) + bookmarks.push_back(Bookmark(fname, id, pos)); + else + lyxerr << "LyX: Warning: Ignore bookmark of file: " << fname << endl; + } catch (...) { + lyxerr << "LyX: Warning: unknown Bookmark info: " << tmp << endl; + } } while (is.good()); } @@ -276,20 +301,27 @@ void ToolbarSection::read(istream & is) if (c == '[') break; getline(is, tmp); + if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') + continue; - // Read session info, saved as key/value pairs - // would better yell if pos returns npos - string::size_type pos = tmp.find_first_of(" = "); - // silently ignore lines without " = " - if (pos != string::npos) { - string key = tmp.substr(0, pos); - int state; - int location; - istringstream value(tmp.substr(pos + 3)); - value >> state; - value.ignore(1); // ignore " " - value >> location; - toolbars[key] = ToolbarInfo(state, location); + try { + // Read session info, saved as key/value pairs + // would better yell if pos returns npos + string::size_type pos = tmp.find_first_of(" = "); + // silently ignore lines without " = " + if (pos != string::npos) { + string key = tmp.substr(0, pos); + int state; + int location; + istringstream value(tmp.substr(pos + 3)); + value >> state; + value.ignore(1); // ignore " " + value >> location; + toolbars[key] = ToolbarInfo(state, location); + } else + lyxerr << "LyX: Warning: Ignore toolbar info: " << tmp << endl; + } catch (...) { + lyxerr << "LyX: Warning: unknown Toolbar info: " << tmp << endl; } } while (is.good()); } @@ -321,15 +353,22 @@ void SessionInfoSection::read(istream & is) if (c == '[') break; getline(is, tmp); + if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ') + continue; - // Read session info, saved as key/value pairs - // would better yell if pos returns npos - string::size_type pos = tmp.find_first_of(" = "); - // silently ignore lines without " = " - if (pos != string::npos) { - string key = tmp.substr(0, pos); - string value = tmp.substr(pos + 3); - sessioninfo[key] = value; + try { + // Read session info, saved as key/value pairs + // would better yell if pos returns npos + string::size_type pos = tmp.find_first_of(" = "); + // silently ignore lines without " = " + if (pos != string::npos) { + string key = tmp.substr(0, pos); + string value = tmp.substr(pos + 3); + sessioninfo[key] = value; + } else + lyxerr << "LyX: Warning: Ignore session info: " << tmp << endl; + } catch (...) { + lyxerr << "LyX: Warning: unknown Session info: " << tmp << endl; } } while (is.good()); }