///////////////////////////////////////////////////////////////////////////////
// Copyright (c) Winnov L.P., 1996.  All rights reserved
// main.c: main implementation for timer process
///////////////////////////////////////////////////////////////////////////////

#include <windows.h>
#include <stdio.h>
#include "wnv1632.h"
#include "wnvevent.h"
#include "debug.h"
#include "shell.h"
#include "srvcname.h"

/////////////////////////////////////////////////////////////////////////////////////////////////
//  <service exe> -?                to display this list
//  <service exe> -install          to install the service
//  <service exe> -remove           to remove the service
//  <service exe> -debug <params>   to run as a console app for debugging
/////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

void main(int argc, char **argv)
{
    CShell                  *pShell;

    pShell = new CShell;    // instantiate the shell command processor


    if ( (argc > 1) &&
         ((*argv[1] == '-') || (*argv[1] == '/')) )
    {
        if ( _stricmp( "install", argv[1]+1 ) == 0 )
        {
            pShell->CmdInstallService ();
        }
        else if ( _stricmp( "remove", argv[1]+1 ) == 0 )
        {
            pShell->CmdRemoveService ();
        }
        else if ( _stricmp( "debug", argv[1]+1 ) == 0 )
        {
            pShell->CmdDebugService (argc, argv);
        }
        else
        {
	     // this is just to be friendly
	    printf( "%s -install          to install the service\n", SZAPPNAME );
	    printf( "%s -remove           to remove the service\n", SZAPPNAME );
	    printf( "%s -debug <params>   to run as a console app for debugging\n", SZAPPNAME );
	    printf( "\nStartServiceCtrlDispatcher being called.\n" );
	    printf( "This may take several seconds.  Please wait.\n" );

	    pShell->CmdStartService ();
        }
    }
    else
    {
        pShell->CmdStartService ();
    }

    delete pShell;

    TraceString ("\nmain: normal termination.");
}