From a91c42b7dbc9fb8737fbbd4788906a795bb69006 Mon Sep 17 00:00:00 2001 From: Enrico Forestieri Date: Tue, 18 Aug 2009 11:49:00 +0000 Subject: [PATCH] Fix the dataloss problem when shutting down Windows (part of bug #5525). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@31114 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/client/client.cpp | 4 ++++ src/support/os_cygwin.cpp | 19 ++++++++++++++++++- src/support/os_win32.cpp | 17 +++++++++++++++++ src/tex2lyx/tex2lyx.cpp | 5 +++++ status.16x | 2 ++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index e62ef5f390..365498f2cc 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -65,6 +65,10 @@ using ::boost::scoped_ptr; namespace lyx { +// Keep the linker happy on Windows +void emergencyCleanup() +{} + namespace support { string itoa(unsigned int i) diff --git a/src/support/os_cygwin.cpp b/src/support/os_cygwin.cpp index d90ebcf7c2..99cf75171e 100644 --- a/src/support/os_cygwin.cpp +++ b/src/support/os_cygwin.cpp @@ -33,6 +33,9 @@ using namespace std; namespace lyx { + +void emergencyCleanup(); + namespace support { namespace os { @@ -122,15 +125,29 @@ string convert_path_list(string const & p, PathStyle const & target) return subst(p, '\\', '/'); } + +BOOL terminate_handler(DWORD event) +{ + if (event == CTRL_CLOSE_EVENT + || event == CTRL_LOGOFF_EVENT + || event == CTRL_SHUTDOWN_EVENT) { + lyx::emergencyCleanup(); + return TRUE; + } + return FALSE; +} + } // namespace anon void init(int, char *[]) { // Make sure that the TEMP variable is set // and sync the Windows environment. - setenv("TEMP", "/tmp", false); cygwin_internal(CW_SYNC_WINENV); + + // Catch shutdown events. + SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE); } diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp index f9f1112df7..ceae3651c8 100644 --- a/src/support/os_win32.cpp +++ b/src/support/os_win32.cpp @@ -71,6 +71,9 @@ using namespace std; namespace lyx { + +void emergencyCleanup(); + namespace support { namespace os { @@ -80,6 +83,17 @@ bool windows_style_tex_paths_ = true; string cygdrive = "/cygdrive"; +BOOL terminate_handler(DWORD event) +{ + if (event == CTRL_CLOSE_EVENT + || event == CTRL_LOGOFF_EVENT + || event == CTRL_SHUTDOWN_EVENT) { + lyx::emergencyCleanup(); + return TRUE; + } + return FALSE; +} + } // namespace anon void init(int /* argc */, char * argv[]) @@ -161,6 +175,9 @@ void init(int /* argc */, char * argv[]) if ((retVal == ERROR_SUCCESS) && (bufSize <= MAX_PATH)) cygdrive = rtrim(string(buf), "/"); } + + // Catch shutdown events. + SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE); } diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 1ac32c40ff..603f5d5b9d 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -41,6 +41,11 @@ using namespace lyx::support::os; namespace lyx { +// Keep the linker happy on Windows +void emergencyCleanup() +{} + + string const trim(string const & a, char const * p) { // LASSERT(p, /**/); diff --git a/status.16x b/status.16x index 998ac92203..d866268ee1 100644 --- a/status.16x +++ b/status.16x @@ -179,6 +179,8 @@ What's new - Enable document margin settings and hyperref settings in the article (beamer) class. + +- Fix data loss when shutting down Windows (part of bug 5525). * USER INTERFACE