home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / OTL-MC7.DMS / in.adf / classsource.lha / ClassSource / Exec / Libraries / Libraries.c
Encoding:
C/C++ Source or Header  |  1995-02-12  |  3.6 KB  |  150 lines

  1. #include <classes/Exec/Libraries.h>
  2.  
  3. #include <intuition/intuition.h>
  4.  
  5. #pragma -
  6. #include <pragma/exec_lib.h>
  7. #include <pragma/dos_lib.h>
  8. #include <pragma/intuition_lib.h>
  9. #include <clib/alib_stdio_protos.h>
  10. #include <string.h>
  11. #pragma +
  12.  
  13. extern struct Library *IntuitionBase;
  14. extern struct Library *DosBase;
  15.  
  16. LibraryBaseC::LibraryBaseC(STRPTR name, ULONG version)
  17. {
  18.     if (!(Base = OpenLibrary(name,version)))
  19.         not_open = TRUE;
  20. };
  21.  
  22. LibraryBaseC::~LibraryBaseC()
  23. {
  24.     if (Base)
  25.     {
  26.         CloseLibrary(Base);
  27.         Base = NULL;
  28.     };
  29. };
  30.  
  31. UWORD LibraryBaseC::version() const
  32. {
  33.     if (Base)
  34.         return Base->lib_Version;
  35.     return 0;
  36. };
  37.  
  38. BOOL LibraryBaseC::not_open = FALSE;
  39.  
  40. // **********************************************************
  41.  
  42. LibraryBaseErrC::LibraryBaseErrC(STRPTR name, ULONG version)
  43.     : LibraryBaseC(name,version)
  44. {
  45.     if (!isOpen())
  46.     {
  47.         BOOL close_intuition = FALSE;
  48.         if (!IntuitionBase)
  49.         {
  50.             IntuitionBase = OpenLibrary("intuition.library",33);
  51.             close_intuition = TRUE;
  52.         };
  53.         if (IntuitionBase)
  54.         {
  55.             ULONG actual;
  56.             actual = 0;
  57.             struct Library *l = OpenLibrary(name,0);
  58.             if (l)
  59.                 actual = l->lib_Version;
  60.             if (IntuitionBase->lib_Version >= 37)
  61.             {
  62.                 char programname[80];
  63.                 if (DosBase)
  64.                 {
  65.                     if (!GetProgramName(programname,80))
  66.                         sprintf(programname,"Application")
  67.                 }
  68.                 else {
  69.                     sprintf(programname,"Application")
  70.                 };
  71.                 if (actual)
  72.                 {
  73.                     struct EasyStruct myES =
  74.                         { sizeof(struct EasyStruct),0,"Application Request",
  75.                           "\"%s\" version %ld expected.\n"
  76.                           "Found only version %ld.\n"
  77.                           "Unable to run \"%s\".",
  78.                           "OK"
  79.                         };
  80.                     EasyRequest(NULL,&myES,NULL,name,version,actual,programname);
  81.                 }
  82.                 else {
  83.                     struct EasyStruct myES =
  84.                         { sizeof(struct EasyStruct),0,"Application Request",
  85.                           "Cannot open \"%s\".\n"
  86.                           "Unable to run \"%s\".",
  87.                           "OK"
  88.                         };
  89.                     EasyRequest(NULL,&myES,NULL,name,programname);
  90.                 }
  91.             }
  92.             else {
  93.                 if (actual)
  94.                 {
  95.                     char bodytext1[80];
  96.                     char bodytext2[80];
  97.                     struct TextAttr TopazFont8 =
  98.                         { "topaz.font",8,0,0 };
  99.                     struct IntuiText Body3 =
  100.                         { AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,
  101.                           8,24,&TopazFont8,
  102.                           "Unable to run this application.",NULL };
  103.                     struct IntuiText Body2 =
  104.                         { AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,
  105.                           8,16,&TopazFont8,bodytext2,&Body3 };
  106.                     struct IntuiText Body =
  107.                         { AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,
  108.                           8,8,&TopazFont8,bodytext1,&Body2 };
  109.                     struct IntuiText OK =
  110.                         { AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,
  111.                           AUTOLEFTEDGE,AUTOTOPEDGE,NULL," OK ",NULL };
  112.                     sprintf(bodytext1,"\"%s\" version %ld expected.",name,version);
  113.                     sprintf(bodytext2,"Found only version %ld.",actual);
  114.                     ULONG len = strlen(bodytext1);
  115.                     if (len < strlen(bodytext2))
  116.                         len = strlen(bodytext2);
  117.                     if (len < 32)
  118.                         len = 32;
  119.                     AutoRequest(NULL,&Body,NULL,&OK,0,0,len*8+48,70);
  120.                 }
  121.                 else {
  122.                     char bodytext[80];
  123.                     struct TextAttr TopazFont8 =
  124.                         { "topaz.font",8,0,0 };
  125.                     struct IntuiText Body2 =
  126.                         { AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,
  127.                           8,16,&TopazFont8,
  128.                           "Unable to run this application.",NULL };
  129.                     struct IntuiText Body =
  130.                         { AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,
  131.                           8,8,&TopazFont8,bodytext,&Body2 };
  132.                     struct IntuiText OK =
  133.                         { AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,
  134.                           AUTOLEFTEDGE,AUTOTOPEDGE,NULL," OK ",NULL };
  135.                     sprintf(bodytext,"Cannot open \"%s\".",name);
  136.                     ULONG len = strlen(bodytext);
  137.                     if (len < 32)
  138.                         len = 32;
  139.                     AutoRequest(NULL,&Body,NULL,&OK,0,0,len*8+48,62);
  140.                 };
  141.             };
  142.         };
  143.         if (close_intuition && IntuitionBase)
  144.         {
  145.             CloseLibrary(IntuitionBase);
  146.             IntuitionBase = NULL;
  147.         };
  148.     };
  149. };
  150.