+
+Session::Session(unsigned int num) :
+ last_files(num)
+{
+ // locate the session file
+ // note that the session file name 'session' is hard-coded
+ session_file = FileName(addName(package().user_support(), "session"));
+ //
+ readFile();
+}
+
+
+void Session::readFile()
+{
+ // we will not complain if we can't find session_file nor will
+ // we issue a warning. (Lgb)
+ ifstream is(session_file.toFilesystemEncoding().c_str());
+ string tmp;
+
+ while (getline(is, tmp)) {
+ // Ignore comments, empty line or line stats with ' '
+ if (tmp == "" || tmp[0] == '#' || tmp[0] == ' ')
+ continue;
+
+ // Determine section id
+ if (tmp == sec_lastfiles)
+ lastFiles().read(is);
+ else if (tmp == sec_lastopened)
+ lastOpened().read(is);
+ else if (tmp == sec_lastfilepos)
+ lastFilePos().read(is);
+ else if (tmp == sec_bookmarks)
+ bookmarks().read(is);
+ else if (tmp == sec_toolbars)
+ toolbars().read(is);
+ else if (tmp == sec_session)
+ sessionInfo().read(is);
+ else
+ lyxerr[Debug::INIT] << "LyX: Warning: unknown Session section: " << tmp << endl;
+ }
+}
+
+
+void Session::writeFile() const
+{
+ ofstream os(session_file.toFilesystemEncoding().c_str());
+ if (os) {
+ os << "## Automatically generated lyx session file \n"
+ << "## Editing this file manually may cause lyx to crash.\n";
+
+ lastFiles().write(os);
+ lastOpened().write(os);
+ lastFilePos().write(os);
+ bookmarks().write(os);
+ toolbars().write(os);
+ sessionInfo().write(os);
+ } else
+ lyxerr[Debug::INIT] << "LyX: Warning: unable to save Session: "
+ << session_file << endl;
+}
+