/* $Revision Header built automatically *************** (do not edit) ************
**
** © Copyright by Lars Eilebrecht (Shadowfox)
**
** File             : Work:Program/SC/PRG/ShadowStart/ShadowStart.c
** Created on       : Mittwoch, 16.11.94 17:23:09
** Created by       : Lars Eilebrecht
** Current revision : V1.2
**
**
** Purpose
** -------
**     Disable "WBStartup" and/or "User-Startup" during startup. (V37)
**
** Revision V1.2
** --------------
** created on Freitag, 09.12.94 01:05:03  by  Lars Eilebrecht.   LogMessage :
**   - rewrote ShadowStart for use with Kick/WB 2.0+
**     (Activation-keys are now left or right alt)
**     minor code changes
**
** Revision V1.1
** --------------
** created on Montag, 28.11.94 18:58:55  by  Lars Eilebrecht.   LogMessage :
**  -*-  changed on Samstag, 03.12.94 22:12:20  by  Lars Eilebrecht.   LogMessage :
**   - recompiled ShadowStart without startup-code
**     (results in a shorter executable)
**  -*-  created on Montag, 28.11.94 18:58:55  by  Lars Eilebrecht.   LogMessage :
**   - added NewShell-button
**     renamed other buttons, so that it fit on a lores-screen
**     removed stdio.h include (shorter executable)
**     cleaned up code a little
**
** Revision V1.0
** --------------
** created on Mittwoch, 16.11.94 17:23:09  by  Lars Eilebrecht.   LogMessage :
**     --- Initial release ---
**
*********************************************************************************/
#define REVISION "1.2"
#define REVDATE  "09.12.94"
#define REVTIME  "01:05:03"
#define AUTHOR   "Lars Eilebrecht"
#define VERNUM   1
#define REVNUM   2
#define TITLE "ShadowStart "REVISION" ("REVDATE") (V37) © by "AUTHOR" (Shadowfox)"

#include <exec/types.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <devices/inputevent.h>

#include <pragmas/exec_pragmas.h>
#include <pragmas/dos_pragmas.h>
#include <pragmas/intuition_pragmas.h>
#include <pragmas/input_pragmas.h>

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <clib/input_protos.h>
#include <clib/alib_protos.h>

static const char *ver ="$VER: "TITLE"\0";

int ShadowStart(void)
{
  LONG rc=RETURN_FAIL;

  struct Library *DOSBase;

  if(DOSBase=OpenLibrary("dos.library",37))
  {
    struct Library *IntuitionBase;   

    if(IntuitionBase=OpenLibrary("intuition.library",37))
    {
      struct MsgPort    *MsgPort;
      struct IOStdReq   *InputReq;
      struct Library    *InputBase;
       
      if(MsgPort=CreateMsgPort())
      {                                                         // create MsgPort and open input.device
        if(InputReq=CreateStdIO(MsgPort))
        {
          if(!OpenDevice("input.device",0,(struct IORequest *)InputReq,0))
          {
            rc=RETURN_OK;

            if(Rename("SYS:_WBStartup","SYS:WBStartup"))        // rename to original names...
              Rename("SYS:_WBStartup.info","SYS:WBStartup.info");
            Rename("SYS:S/_User-Startup","SYS:S/User-Startup");

            InputBase=(struct Library *)InputReq->io_Device;
            if(PeekQualifier()&IEQUALIFIER_LALT||PeekQualifier()&IEQUALIFIER_RALT)
            {                                                   // check for pressed alt-keys
              LONG result;

              struct EasyStruct shadowES =                      // declare EasyRequest-struct
                                {
                                  sizeof(struct EasyStruct),
                                  0, // no flags
                                  "ShadowStart "REVISION" ("REVDATE") © by Lars `SFX' Eilebrecht",
                                  "\nSelect startup-items that should be disabled\n\nor select `NewShell' to open a shell-window\n",
                                  "WB + User|WB|User|NewShell|Cancel",
                                };

              result=EasyRequest(NULL,&shadowES,NULL);
              switch (result)
              {                 // note: success of rename-operation isn't checked...
                case 1: 
                  Rename("SYS:S/User-Startup","SYS:S/_User-Startup");
                case 2:
                  Rename("SYS:WBStartup","SYS:_WBStartup");
                  Rename("SYS:WBStartup.info","SYS:_WBStartup.info");
                  break;
                case 3:
                  Rename("SYS:S/User-Startup","SYS:S/_User-Startup");
                  break;
                case 4:
                 if(!Execute("NewShell",0,0))                   // open a shell-window...
                   rc=RETURN_FAIL;
                 Wait(SIGBREAKF_CTRL_C);                        // 'hold' startup-sequence...
              }
            }
            CloseDevice((struct IORequest *)InputReq);
          }
          DeleteStdIO(InputReq);
        }
        DeleteMsgPort(MsgPort);
      }
      CloseLibrary(IntuitionBase);
    }
    else
      PrintFault(ERROR_INVALID_RESIDENT_LIBRARY,"intuition.library");
    CloseLibrary(DOSBase);
  }
  return(rc);
}
