Пример #1
0
bool IsFullscreen()
{
	bool Result=false;
	DWORD ModeFlags=0;
	if(GetConsoleDisplayMode(&ModeFlags) && ModeFlags&CONSOLE_FULLSCREEN_HARDWARE)
	{
		Result=true;
	}
	return Result;
}
Пример #2
0
bool main_has_console() 
{
    DWORD displayMode;
    if (GetConsoleDisplayMode(&displayMode))
       return true;

        // if you need to debug service startup code
        // recompile with this code enabled, then attach the debugger
        // within 90 seconds of running "net start condor"
   #ifdef _DEBUG
    //for (int ii = 0; ii < 90*1000/500 && ! IsDebuggerPresent(); ++ii) { Sleep(500); } DebugBreak();
   #endif

    return false;
}
Пример #3
0
int main(int argc, const char * const *argv, const char * const *env)
{
    DWORD dispmode;
    nx_exception_t e;

    ASSERT(nx_init(&argc, &argv, &env) == TRUE);

    nxlog_init(&nxlog);
    _nxlog_initializer = apr_os_thread_current();

    try
    {
        // read cmd line
        parse_cmd_line(argc, argv);
        /*
        	// reload switch?
        	if ( nxlog.do_restart == TRUE )
        	{
        	    //FIXME restart service; use custom control code?
        	}
        */
        // stop switch?
        if ( nxlog.do_stop == TRUE )
        {
            nx_win32_svc_stop();
            exit(0);
        }

        if ( do_install == TRUE )
        {
            nx_win32_svc_install();
            exit(0);
        }

        if ( do_uninstall == TRUE )
        {
            nx_win32_svc_uninstall();
            exit(0);
        }

        // load and parse config
        nx_ctx_parse_cfg(nxlog.ctx, nxlog.cfgfile);

        if ( nxlog.ctx->spooldir != NULL )
        {
            CHECKERR_MSG(apr_filepath_set(nxlog.ctx->spooldir, nxlog.pool),
                         "Couldn't change to SpoolDir '%s'", nxlog.ctx->spooldir);
        }

        nx_ctx_init_logging(nxlog.ctx);

        if ( nxlog.ctx->rootdir != NULL )
        {
            throw_msg("RootDir not supported on windows");
        }

        if ( nxlog.verify_conf == TRUE )
        {
            // load DSO and read and verify module config
            nx_ctx_config_modules(nxlog.ctx);
            nx_ctx_init_routes(nxlog.ctx);
            log_info("configuration OK");
            exit(0);
        }

        if ( nxlog.foreground == TRUE )
        {
            nx_win32_svc_main(argc, argv);
        }
        else
        {
            // detect wheter we are invoked by SVM or from the console
            if ( GetConsoleDisplayMode(&dispmode) == 0 )
            {
                nx_win32_svc_dispatch();
            }
            else
            {
                nx_win32_svc_start(argc, argv);
            }
        }
    }
    catch(e)
    {
        apr_file_t *f = NULL;
        apr_pool_t *pool;
        HKEY regkey;
        uint32_t regtype = 0;
        char regvalbuf[1024];
        uint32_t regvalbufsize = 1024;
        const char *logfile = "c:\\nxlog-service-error.txt";

        pool = nx_pool_create_core();

        // TODO: log to eventlog in addition?

        if ( RegOpenKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\nxlog", &regkey) == ERROR_SUCCESS )
        {
            if ( RegQueryValueEx(regkey, "installdir", 0, &regtype,
                                 (unsigned char *) regvalbuf, &regvalbufsize) == ERROR_SUCCESS )
            {
                if ( regtype == REG_SZ )
                {
                    logfile = apr_psprintf(nxlog.pool, "%sdata\\nxlog.log", regvalbuf);
                }
            }
            RegCloseKey(regkey);
        }
        apr_file_open(&f, logfile, APR_READ | APR_WRITE | APR_CREATE | APR_APPEND,
                      APR_OS_DEFAULT, pool);
        // FXIME: check status code
        if ( f != NULL )
        {
            nx_string_t *tmpstr;
            int i;
            char errmsg[1024];

            tmpstr = nx_string_new();

            for ( i = ((int) e.num_throw) - 1; i >= 0; i-- )
            {
                if ( tmpstr->len > 0 )
                {
                    nx_string_append(tmpstr, NX_LINEFEED, -1);
                }
                nx_string_append(tmpstr, e.msgbuf + e.throwlist[i].msgoffs, -1);
            }
            nx_string_append(tmpstr, NX_LINEFEED, -1);
            if ( e.code != APR_SUCCESS )
            {
                apr_strerror(e.code, errmsg, sizeof(errmsg));
                nx_string_append(tmpstr, errmsg, -1);
                nx_string_append(tmpstr, NX_LINEFEED, -1);
            }
            apr_file_printf(f, "nxlog failed to start: %s\r\n", tmpstr->buf);
            apr_file_close(f);
            nx_string_free(tmpstr);
        }
        apr_pool_destroy(pool);
        log_exception(e);
        exit(e.code);
    }

    return ( 0 );
}