+void LyX::prepareExit()
+{
+ // Set a flag that we do quitting from the program,
+ // so no refreshes are necessary.
+ quitting = true;
+
+ // close buffers first
+ pimpl_->buffer_list_.closeAll();
+
+ // do any other cleanup procedures now
+ lyxerr[Debug::INFO] << "Deleting tmp dir " << package().temp_dir() << endl;
+
+ // Prevent the deletion of /tmp if LyX was called with invalid
+ // arguments. Does not work on windows.
+ // FIXME: Fix the real bug instead.
+ if (package().temp_dir() == "/tmp") {
+ lyxerr << "Not deleting /tmp." << endl;
+ return;
+ }
+
+ if (!destroyDir(package().temp_dir())) {
+ docstring const msg =
+ bformat(_("Unable to remove the temporary directory %1$s"),
+ from_utf8(package().temp_dir()));
+ Alert::warning(_("Unable to remove temporary directory"), msg);
+ }
+
+ if (use_gui) {
+ if (pimpl_->session_)
+ pimpl_->session_->writeFile();
+ pimpl_->session_.reset();
+ pimpl_->lyx_server_.reset();
+ pimpl_->lyx_socket_.reset();
+ }
+
+ // Kill the application object before exiting. This avoids crashes
+ // when exiting on Linux.
+ if (pimpl_->application_)
+ pimpl_->application_.reset();
+}
+
+
+void LyX::earlyExit(int status)
+{
+ BOOST_ASSERT(pimpl_->application_.get());
+ // LyX::pimpl_::application_ is not initialised at this
+ // point so it's safe to just exit after some cleanup.
+ prepareExit();
+ exit(status);
+}
+
+
+int LyX::loadFiles(int & argc, char * argv[],
+ vector<FileName> & files)