From 06856e170d2a878ecc79c450868cb4c900c8f4d6 Mon Sep 17 00:00:00 2001 From: crs Date: Sat, 14 Sep 2002 12:03:43 +0000 Subject: [PATCH] Fixed backend mode. Now reports log messages and, if any are serious, shows a message box before exiting. --- cmd/synergyc/resource.h | 6 +- cmd/synergyc/synergyc.cpp | 26 ++++- cmd/synergyc/synergyc.rc | 188 ++++++++++++++++------------------- cmd/synergys/resource.h | 10 +- cmd/synergys/synergys.cpp | 26 ++++- cmd/synergys/synergys.rc | 201 ++++++++++++++++---------------------- 6 files changed, 219 insertions(+), 238 deletions(-) diff --git a/cmd/synergyc/resource.h b/cmd/synergyc/resource.h index 9c299850..c5887fb2 100644 --- a/cmd/synergyc/resource.h +++ b/cmd/synergyc/resource.h @@ -3,15 +3,13 @@ // Used by synergyc.rc // #define IDS_FAILED 1 -#define IDD_SYNERGY 101 -#define IDI_SYNERGY 103 -#define IDC_LOG 1000 +#define IDI_SYNERGY 101 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 104 +#define _APS_NEXT_RESOURCE_VALUE 102 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 diff --git a/cmd/synergyc/synergyc.cpp b/cmd/synergyc/synergyc.cpp index d2e45f31..aa7906d3 100644 --- a/cmd/synergyc/synergyc.cpp +++ b/cmd/synergyc/synergyc.cpp @@ -447,16 +447,26 @@ parse(int argc, const char** argv) #include "CMSWindowsScreen.h" +static bool s_hasImportantLogMessages = false; + static bool logMessageBox(int priority, const char* msg) { - if (priority <= (s_backend ? CLog::kERROR : CLog::kFATAL)) { + // note any important messages the user may need to know about + if (priority <= CLog::kWARNING) { + s_hasImportantLogMessages = true; + } + + // FATAL and PRINT messages get a dialog box if not running as + // backend. if we're running as a backend the user will have + // a chance to see the messages when we exit. + if (!s_backend && priority <= CLog::kFATAL) { MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING); return true; } else { - return s_backend; + return false; } } @@ -487,6 +497,9 @@ daemonStartup(IPlatform* iplatform, int argc, const char** argv) // parse command line parse(argc, argv); + // cannot run as backend if running as a service + s_backend = false; + // run as a service return platform->runDaemon(realMain, daemonStop); } @@ -560,6 +573,15 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int) CNetwork::cleanup(); + // let user examine any messages if we're running as a backend + // by putting up a dialog box before exiting. + if (s_backend && s_hasImportantLogMessages) { + char msg[1024]; + msg[0] = '\0'; + LoadString(instance, IDS_FAILED, msg, sizeof(msg) / sizeof(msg[0])); + MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING); + } + return result; } diff --git a/cmd/synergyc/synergyc.rc b/cmd/synergyc/synergyc.rc index f1523300..74ecee37 100644 --- a/cmd/synergyc/synergyc.rc +++ b/cmd/synergyc/synergyc.rc @@ -1,106 +1,82 @@ -//Microsoft Developer Studio generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_SYNERGY DIALOG DISCARDABLE 0, 0, 329, 158 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Synergy" -FONT 8, "MS Sans Serif" -BEGIN - EDITTEXT IDC_LOG,7,7,315,144,ES_MULTILINE | ES_AUTOHSCROLL | - ES_READONLY | WS_VSCROLL | WS_HSCROLL -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO DISCARDABLE -BEGIN - IDD_SYNERGY, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 322 - TOPMARGIN, 7 - BOTTOMMARGIN, 151 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_SYNERGY ICON DISCARDABLE "synergyc.ico" -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_SYNERGY ICON DISCARDABLE "synergyc.ico" +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE DISCARDABLE +BEGIN + IDS_FAILED "Synergy is about to quit with errors or warnings. Please check the log then click OK." +END + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/cmd/synergys/resource.h b/cmd/synergys/resource.h index 6142fc38..6bfc7486 100644 --- a/cmd/synergys/resource.h +++ b/cmd/synergys/resource.h @@ -1,19 +1,17 @@ //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. -// Used by synergyd.rc +// Used by synergys.rc // #define IDS_FAILED 1 -#define IDD_SYNERGY 101 -#define IDI_SYNERGY 102 -#define IDC_LOG 1000 +#define IDI_SYNERGY 101 // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 103 +#define _APS_NEXT_RESOURCE_VALUE 102 #define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1002 +#define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif diff --git a/cmd/synergys/synergys.cpp b/cmd/synergys/synergys.cpp index 496cf5a7..4f60ff9e 100644 --- a/cmd/synergys/synergys.cpp +++ b/cmd/synergys/synergys.cpp @@ -579,16 +579,26 @@ loadConfig() #include "CMSWindowsScreen.h" +static bool s_hasImportantLogMessages = false; + static bool logMessageBox(int priority, const char* msg) { - if (priority <= (s_backend ? CLog::kERROR : CLog::kFATAL)) { + // note any important messages the user may need to know about + if (priority <= CLog::kWARNING) { + s_hasImportantLogMessages = true; + } + + // FATAL and PRINT messages get a dialog box if not running as + // backend. if we're running as a backend the user will have + // a chance to see the messages when we exit. + if (!s_backend && priority <= CLog::kFATAL) { MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING); return true; } else { - return s_backend; + return false; } } @@ -619,6 +629,9 @@ daemonStartup(IPlatform* iplatform, int argc, const char** argv) // parse command line parse(argc, argv); + // cannot run as backend if running as a service + s_backend = false; + // load configuration loadConfig(); @@ -698,6 +711,15 @@ WinMain(HINSTANCE instance, HINSTANCE, LPSTR, int) CNetwork::cleanup(); + // let user examine any messages if we're running as a backend + // by putting up a dialog box before exiting. + if (s_backend && s_hasImportantLogMessages) { + char msg[1024]; + msg[0] = '\0'; + LoadString(instance, IDS_FAILED, msg, sizeof(msg) / sizeof(msg[0])); + MessageBox(NULL, msg, pname, MB_OK | MB_ICONWARNING); + } + return result; } diff --git a/cmd/synergys/synergys.rc b/cmd/synergys/synergys.rc index b24adecc..61bb42f1 100644 --- a/cmd/synergys/synergys.rc +++ b/cmd/synergys/synergys.rc @@ -1,118 +1,83 @@ -//Microsoft Developer Studio generated resource script. -// -#include "resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (U.S.) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -#ifdef _WIN32 -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) -#endif //_WIN32 - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE DISCARDABLE -BEGIN - "resource.h\0" -END - -2 TEXTINCLUDE DISCARDABLE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE DISCARDABLE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_SYNERGY DIALOG DISCARDABLE 0, 0, 531, 159 -STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU -CAPTION "Synergy" -FONT 8, "MS Sans Serif" -BEGIN - LISTBOX IDC_LOG,7,7,517,145,NOT LBS_NOTIFY | - LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | - WS_TABSTOP -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO DISCARDABLE -BEGIN - IDD_SYNERGY, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 524 - TOPMARGIN, 7 - BOTTOMMARGIN, 152 - END -END -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Icon -// - -// Icon with lowest ID value placed first to ensure application icon -// remains consistent on all systems. -IDI_SYNERGY ICON DISCARDABLE "synergys.ico" - -///////////////////////////////////////////////////////////////////////////// -// -// String Table -// - -STRINGTABLE DISCARDABLE -BEGIN - IDS_FAILED "Synergy is about to quit with an error. Please check the log for error messages then click OK." -END - -#endif // English (U.S.) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - +//Microsoft Developer Studio generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (U.S.) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +#ifdef _WIN32 +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) +#endif //_WIN32 + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE DISCARDABLE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE DISCARDABLE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE DISCARDABLE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Icon +// + +// Icon with lowest ID value placed first to ensure application icon +// remains consistent on all systems. +IDI_SYNERGY ICON DISCARDABLE "synergys.ico" + +///////////////////////////////////////////////////////////////////////////// +// +// String Table +// + +STRINGTABLE DISCARDABLE +BEGIN + IDS_FAILED "Synergy is about to quit with errors or warnings. Please check the log then click OK." +END + +#endif // English (U.S.) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED +