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);
|
return m_appUtil->run(argc, argv, createTaskBarReceiver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
CArch::beforeAppExit()
|
||||||
|
{
|
||||||
|
m_appUtil->beforeAppExit();
|
||||||
|
}
|
||||||
|
|
|
@ -188,6 +188,7 @@ public:
|
||||||
virtual void adoptApp(CApp* app);
|
virtual void adoptApp(CApp* app);
|
||||||
virtual CApp& app() const;
|
virtual CApp& app() const;
|
||||||
virtual int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
|
virtual int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
|
||||||
|
virtual void beforeAppExit();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CArch* s_instance;
|
static CArch* s_instance;
|
||||||
|
|
|
@ -37,6 +37,7 @@ CArchAppUtil::parseArg(const int& argc, const char* const* argv, int& i)
|
||||||
void
|
void
|
||||||
CArchAppUtil::adoptApp(CApp* app)
|
CArchAppUtil::adoptApp(CApp* app)
|
||||||
{
|
{
|
||||||
|
app->m_bye = &exitAppStatic;
|
||||||
m_app = app;
|
m_app = app;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "IArchAppUtil.h"
|
#include "IArchAppUtil.h"
|
||||||
|
#include "XSynergy.h"
|
||||||
|
|
||||||
class CArchAppUtil : public IArchAppUtil {
|
class CArchAppUtil : public IArchAppUtil {
|
||||||
public:
|
public:
|
||||||
|
@ -24,8 +25,11 @@ public:
|
||||||
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
virtual bool parseArg(const int& argc, const char* const* argv, int& i);
|
||||||
virtual void adoptApp(CApp* app);
|
virtual void adoptApp(CApp* app);
|
||||||
CApp& app() const;
|
CApp& app() const;
|
||||||
|
virtual void exitApp(int code) { throw XExitApp(code); }
|
||||||
|
|
||||||
static CArchAppUtil& instance();
|
static CArchAppUtil& instance();
|
||||||
|
static void exitAppStatic(int code) { instance().exitApp(code); }
|
||||||
|
virtual void beforeAppExit() {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CApp* m_app;
|
CApp* m_app;
|
||||||
|
|
|
@ -26,7 +26,8 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <conio.h>
|
#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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
CArchAppUtilWindows::adoptApp(CApp* app)
|
|
||||||
{
|
|
||||||
app->m_bye = &exitPause;
|
|
||||||
CArchAppUtil::adoptApp(app);
|
|
||||||
}
|
|
||||||
|
|
||||||
CString
|
CString
|
||||||
CArchAppUtilWindows::getServiceArgs() const
|
CArchAppUtilWindows::getServiceArgs() const
|
||||||
{
|
{
|
||||||
|
@ -176,23 +170,6 @@ CArchAppUtilWindows::stopService()
|
||||||
LOG((CLOG_INFO "service '%s' stopping asyncronously", app().daemonName()));
|
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
|
static
|
||||||
int
|
int
|
||||||
mainLoopStatic()
|
mainLoopStatic()
|
||||||
|
@ -210,9 +187,17 @@ CArchAppUtilWindows::daemonNTMainLoop(int argc, const char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
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)
|
int daemonNTMainLoopStatic(int argc, const char** argv)
|
||||||
|
@ -224,7 +209,7 @@ int
|
||||||
CArchAppUtilWindows::daemonNTStartup(int, char**)
|
CArchAppUtilWindows::daemonNTStartup(int, char**)
|
||||||
{
|
{
|
||||||
CSystemLogger sysLogger(app().daemonName(), false);
|
CSystemLogger sysLogger(app().daemonName(), false);
|
||||||
app().m_bye = &byeThrow;
|
m_exitMode = kExitModeDaemon;
|
||||||
return ARCH->daemonize(app().daemonName(), daemonNTMainLoopStatic);
|
return ARCH->daemonize(app().daemonName(), daemonNTMainLoopStatic);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,6 +227,21 @@ foregroundStartupStatic(int argc, char** argv)
|
||||||
return CArchAppUtil::instance().app().foregroundStartup(argc, 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
|
int
|
||||||
CArchAppUtilWindows::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver)
|
CArchAppUtilWindows::run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver)
|
||||||
{
|
{
|
||||||
|
|
|
@ -21,6 +21,11 @@
|
||||||
|
|
||||||
#define ARCH_APPUTIL CArchAppUtilWindows
|
#define ARCH_APPUTIL CArchAppUtilWindows
|
||||||
|
|
||||||
|
enum AppExitMode {
|
||||||
|
kExitModeNormal,
|
||||||
|
kExitModeDaemon
|
||||||
|
};
|
||||||
|
|
||||||
class CArchAppUtilWindows : public CArchAppUtil {
|
class CArchAppUtilWindows : public CArchAppUtil {
|
||||||
public:
|
public:
|
||||||
CArchAppUtilWindows();
|
CArchAppUtilWindows();
|
||||||
|
@ -46,18 +51,18 @@ public:
|
||||||
|
|
||||||
bool parseArg(const int& argc, const char* const* argv, int& i);
|
bool parseArg(const int& argc, const char* const* argv, int& i);
|
||||||
|
|
||||||
void adoptApp(CApp* app);
|
|
||||||
|
|
||||||
int daemonNTStartup(int, char**);
|
int daemonNTStartup(int, char**);
|
||||||
|
|
||||||
int daemonNTMainLoop(int argc, const char** argv);
|
int daemonNTMainLoop(int argc, const char** argv);
|
||||||
|
|
||||||
int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
|
int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver);
|
||||||
|
|
||||||
static void byeThrow(int x);
|
void exitApp(int code);
|
||||||
|
|
||||||
|
void beforeAppExit();
|
||||||
|
|
||||||
static CArchAppUtilWindows& instance();
|
static CArchAppUtilWindows& instance();
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: move to class
|
private:
|
||||||
void exitPause(int code);
|
AppExitMode m_exitMode;
|
||||||
|
};
|
||||||
|
|
|
@ -26,4 +26,5 @@ public:
|
||||||
virtual void adoptApp(CApp* app) = 0;
|
virtual void adoptApp(CApp* app) = 0;
|
||||||
virtual CApp& app() const = 0;
|
virtual CApp& app() const = 0;
|
||||||
virtual int run(int argc, char** argv, CreateTaskBarReceiverFunc createTaskBarReceiver) = 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;
|
delete CLOG;
|
||||||
|
|
||||||
|
ARCH->beforeAppExit();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -605,12 +605,21 @@ CClientApp::runInner(int argc, char** argv, ILogOutputter* outputter, StartupFun
|
||||||
// through the task bar.
|
// through the task bar.
|
||||||
s_taskBarReceiver = createTaskBarReceiver(logBuffer);
|
s_taskBarReceiver = createTaskBarReceiver(logBuffer);
|
||||||
|
|
||||||
// run
|
int result;
|
||||||
int result = startup(argc, argv);
|
try
|
||||||
|
{
|
||||||
|
// run
|
||||||
|
result = startup(argc, argv);
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
// done with task bar receiver
|
||||||
|
delete s_taskBarReceiver;
|
||||||
|
|
||||||
// done with task bar receiver
|
delete args().m_serverAddress;
|
||||||
delete s_taskBarReceiver;
|
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
delete args().m_serverAddress;
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue