home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1995 August / NEBULA.mdf / Apps / Utilities / Desktop / Launch1.3 / source / Launch_main.m < prev    next >
Encoding:
Text File  |  1993-12-13  |  1.9 KB  |  93 lines

  1. /*
  2.  *     Generated by the NeXT Interface Builder.
  3.  */
  4.  
  5. #import <stdlib.h>
  6. #import <appkit/Application.h>
  7. #import <appkit/Panel.h>
  8. #import <defaults.h>
  9. #import "Main.h"
  10. #import <sys/param.h>
  11. #import <string.h>
  12. #import <libc.h>
  13.  
  14. #define APPNAME "Launch"
  15.  
  16. char loginScript[MAXPATHLEN];
  17. char logoutScript[MAXPATHLEN];
  18.  
  19. // Load the interface if it isn't already loaded.
  20. void loadnib(void)
  21. {
  22.     static loaded=0;
  23.     if (loaded==0)
  24.     {
  25.         NXApp = [Application new];
  26.         [NXApp loadNibSection:"Launch.nib" owner:NXApp];        
  27.     }
  28. }
  29.  
  30. // Execute the script by overlaying our own image.
  31. void doLaunch(void)
  32. {
  33.     execl(loginScript, ".Launch", 0);
  34.     // If we ever get to here, then something went wrong with the execution.
  35.     loadnib();
  36.     NXRunAlertPanel(APPNAME, "Cannot execute script %s",
  37.         "OK", NULL, NULL, loginScript);
  38. }
  39.  
  40. void main(int argc, char *argv[])
  41. {
  42.     char const *def;
  43.     
  44.     static NXDefaultsVector Defaults = {
  45.         {"NXAutoLaunch", "NO"},
  46.         {"OnAutoLaunch", "Execute"},
  47.         {"OnLogout", "Execute"},
  48.         {NULL}
  49.         };
  50.  
  51.     // Register our defaults.
  52.     NXRegisterDefaults(APPNAME, Defaults);
  53.  
  54.     // Form the pathname of the scripts to be executed.
  55.     sprintf(loginScript, "%s/.Launch", getenv("HOME"));
  56.     sprintf(logoutScript, "%s/.Logout", getenv("HOME"));
  57.  
  58.     // Check the defaults to see if the app was auto-launched.
  59.     def = NXGetDefaultValue(APPNAME, "NXAutoLaunch");
  60.     
  61.     if (strcmp(def, "YES")==0)
  62.     {
  63.         def = NXGetDefaultValue(APPNAME, "OnAutoLaunch");
  64.  
  65.         if (strcmp(def, "ExecuteAndQuit")==0)
  66.             doLaunch();
  67.         
  68.         loadnib();
  69.         if (strcmp(def, "Ask")==0)
  70.         {
  71.             int reply;
  72.             loadnib();
  73.             reply = NXRunAlertPanel(APPNAME, "Execute Launch script?",
  74.                     "OK", "NO", NULL);
  75.             if (reply == NX_ALERTDEFAULT)
  76.                 [[NXApp delegate] executeLogin:NXApp];
  77.         }
  78.         
  79.         if (strcmp(def, "Execute")==0)
  80.         {
  81.             [[NXApp delegate] executeLogin:NXApp];
  82.         }
  83.     }
  84.     else
  85.         loadnib();
  86.  
  87.     
  88.     // If not autolaunched or if execution fails, run the application as normal 
  89.     [NXApp run];
  90.     [NXApp free];
  91.     exit(0);
  92. }
  93.