/* $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. (V40)
**
** Revision V1.2
** --------------
** created on Freitag, 09.12.94 01:06:44  by  Lars Eilebrecht.   LogMessage :
**   - 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:06:44"
#define AUTHOR   "Lars Eilebrecht"
#define VERNUM   1
#define REVNUM   2
#define TITLE "ShadowStart "REVISION" ("REVDATE") (V40) © by "AUTHOR" (Shadowfox)"

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

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

#include <clib/exec_protos.h>
#include <clib/dos_protos.h>
#include <clib/intuition_protos.h>
#include <clib/lowlevel_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 *LowLevelBase;

    if(LowLevelBase=OpenLibrary("lowlevel.library",40))
    {
      struct Library *IntuitionBase;   

      if(IntuitionBase=OpenLibrary("intuition.library",37))
      {
        struct KeyQuery spacebar =                      // declare KeyQuery-struct
                        {
                          (UWORD)64,                    // rawkeycode for spacebar
                          FALSE,                        // not pressed yet...
                        };

        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");

        QueryKeys(&spacebar,(UBYTE)1);                  // dirty spacebar check ;-)
        if(spacebar.kq_Pressed)                         // Was it pressed? Silent exit, if not...
        {
          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...
          }
        }
        CloseLibrary(IntuitionBase);
      }
      else
        PrintFault(ERROR_INVALID_RESIDENT_LIBRARY,"intuition.library");
      CloseLibrary(LowLevelBase);
    }
    else
      PrintFault(ERROR_INVALID_RESIDENT_LIBRARY,"lowlevel.library");
    CloseLibrary(DOSBase);
  }
  return(rc);
}
