Improve fix for issue 479
This commit is contained in:
parent
a2b79e062c
commit
70cfc74ce1
|
@ -670,3 +670,9 @@ CArch::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceive
|
|||
{
|
||||
return m_appUtil->run(argc, argv, createTaskBarReceiver);
|
||||
}
|
||||
|
||||
void
|
||||
CArch::beforeAppExit()
|
||||
{
|
||||
m_appUtil->beforeAppExit();
|
||||
}
|
||||
|
|
|
@ -188,6 +188,7 @@ public:
|
|||
virtual void adoptApp(CApp* app);
|
||||
virtual CApp& app() const;
|
||||
virtual int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
|
||||
virtual void beforeAppExit();
|
||||
|
||||
private:
|
||||
static CArch* s_instance;
|
||||
|
|
|
@ -37,6 +37,7 @@ CArchAppUtil::parseArg(const int& argc, const char* const* argv, int& i)
|
|||
void
|
||||
CArchAppUtil::adoptApp(CApp* app)
|
||||
{
|
||||
app->m_bye = &exitAppStatic;
|
||||
m_app = app;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "IArchAppUtil.h"
|
||||
#include "XSynergy.h"
|
||||
|
||||
class CArchAppUtil : public IArchAppUtil {
|
||||
public:
|
||||
|
@ -24,8 +25,11 @@ public:
|
|||
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
||||
virtual void adoptApp(CApp* app);
|
||||
CApp& app() const;
|
||||
virtual void exitApp(int code) { throw XExitApp(code); }
|
||||
|
||||
static CArchAppUtil& instance();
|
||||
static void exitAppStatic(int code) { instance().exitApp(code); }
|
||||
virtual void beforeAppExit() {}
|
||||
|
||||
private:
|
||||
CApp* m_app;
|
||||
|
|
|
@ -26,7 +26,8 @@
|
|||
#include <iostream>
|
||||
#include <conio.h>
|
||||
|
||||
CArchAppUtilWindows::CArchAppUtilWindows()
|
||||
CArchAppUtilWindows::CArchAppUtilWindows() :
|
||||
m_exitMode(kExitModeNormal)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -67,13 +68,6 @@ CArchAppUtilWindows::parseArg(const int& argc, const char* const* argv, int& i)
|
|||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
CArchAppUtilWindows::adoptApp(CApp* app)
|
||||
{
|
||||
app->m_bye = &exitPause;
|
||||
CArchAppUtil::adoptApp(app);
|
||||
}
|
||||
|
||||
CString
|
||||
CArchAppUtilWindows::getServiceArgs() const
|
||||
{
|
||||
|
@ -176,23 +170,6 @@ CArchAppUtilWindows::stopService()
|
|||
LOG((CLOG_INFO "service '%s' stopping asyncronously", app().daemonName()));
|
||||
}
|
||||
|
||||
void
|
||||
exitPause(int code)
|
||||
{
|
||||
CString name;
|
||||
CArchMiscWindows::getParentProcessName(name);
|
||||
|
||||
// if the user did not launch from the command prompt (i.e. it was launched
|
||||
// by double clicking, or through a debugger), allow user to read any error
|
||||
// messages (instead of the window closing automatically).
|
||||
if (name != "cmd.exe") {
|
||||
std::cout << std::endl << "Press any key to exit..." << std::endl;
|
||||
int c = _getch();
|
||||
}
|
||||
|
||||
throw XExitApp(code);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
mainLoopStatic()
|
||||
|
@ -210,9 +187,17 @@ CArchAppUtilWindows::daemonNTMainLoop(int argc, const char** argv)
|
|||
}
|
||||
|
||||
void
|
||||
CArchAppUtilWindows::byeThrow(int x)
|
||||
CArchAppUtilWindows::exitApp(int code)
|
||||
{
|
||||
CArchMiscWindows::daemonFailed(x);
|
||||
switch (m_exitMode) {
|
||||
|
||||
case kExitModeDaemon:
|
||||
CArchMiscWindows::daemonFailed(code);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw XExitApp(code);
|
||||
}
|
||||
}
|
||||
|
||||
int daemonNTMainLoopStatic(int argc, const char** argv)
|
||||
|
@ -224,7 +209,7 @@ int
|
|||
CArchAppUtilWindows::daemonNTStartup(int, char**)
|
||||
{
|
||||
CSystemLogger sysLogger(app().daemonName(), false);
|
||||
app().m_bye = &byeThrow;
|
||||
m_exitMode = kExitModeDaemon;
|
||||
return ARCH->daemonize(app().daemonName(), daemonNTMainLoopStatic);
|
||||
}
|
||||
|
||||
|
@ -242,6 +227,21 @@ foregroundStartupStatic(int argc, char** argv)
|
|||
return CArchAppUtil::instance().app().foregroundStartup(argc, argv);
|
||||
}
|
||||
|
||||
void
|
||||
CArchAppUtilWindows::beforeAppExit()
|
||||
{
|
||||
CString name;
|
||||
CArchMiscWindows::getParentProcessName(name);
|
||||
|
||||
// if the user did not launch from the command prompt (i.e. it was launched
|
||||
// by double clicking, or through a debugger), allow user to read any error
|
||||
// messages (instead of the window closing automatically).
|
||||
if (name != "cmd.exe") {
|
||||
std::cout << std::endl << "Press any key to exit..." << std::endl;
|
||||
int c = _getch();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
CArchAppUtilWindows::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver)
|
||||
{
|
||||
|
|
|
@ -21,6 +21,11 @@
|
|||
|
||||
#define ARCH_APPUTIL CArchAppUtilWindows
|
||||
|
||||
enum AppExitMode {
|
||||
kExitModeNormal,
|
||||
kExitModeDaemon
|
||||
};
|
||||
|
||||
class CArchAppUtilWindows : public CArchAppUtil {
|
||||
public:
|
||||
CArchAppUtilWindows();
|
||||
|
@ -46,18 +51,18 @@ public:
|
|||
|
||||
bool parseArg(const int& argc, const char* const* argv, int& i);
|
||||
|
||||
void adoptApp(CApp* app);
|
||||
|
||||
int daemonNTStartup(int, char**);
|
||||
|
||||
int daemonNTMainLoop(int argc, const char** argv);
|
||||
|
||||
int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
|
||||
|
||||
static void byeThrow(int x);
|
||||
void exitApp(int code);
|
||||
|
||||
void beforeAppExit();
|
||||
|
||||
static CArchAppUtilWindows& instance();
|
||||
};
|
||||
|
||||
// TODO: move to class
|
||||
void exitPause(int code);
|
||||
private:
|
||||
AppExitMode m_exitMode;
|
||||
};
|
||||
|
|
|
@ -26,4 +26,5 @@ public:
|
|||
virtual void adoptApp(CApp* app) = 0;
|
||||
virtual CApp& app() const = 0;
|
||||
virtual int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver) = 0;
|
||||
virtual void beforeAppExit() = 0;
|
||||
};
|
||||
|
|
|
@ -256,6 +256,8 @@ CApp::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver
|
|||
|
||||
delete CLOG;
|
||||
|
||||
ARCH->beforeAppExit();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -605,12 +605,21 @@ CClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFun
|
|||
// through the task bar.
|
||||
s_taskBarReceiver = createTaskBarReceiver(logBuffer);
|
||||
|
||||
// run
|
||||
int result = startup(argc, argv);
|
||||
int result;
|
||||
try
|
||||
{
|
||||
// run
|
||||
result = startup(argc, argv);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
// done with task bar receiver
|
||||
delete s_taskBarReceiver;
|
||||
|
||||
// done with task bar receiver
|
||||
delete s_taskBarReceiver;
|
||||
delete args().m_serverAddress;
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
delete args().m_serverAddress;
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue