home *** CD-ROM | disk | FTP | other *** search
/ World of A1200 / World_Of_A1200.iso / programs / workbench / forceicon / source.lha / source / LoadPrefs.h < prev    next >
Text File  |  1995-01-05  |  4KB  |  141 lines

  1.  
  2. /**********************************************************************/
  3. /*                          Load in settings                          */
  4. /**********************************************************************/
  5. static BOOL DoLoadPrefs(struct FIconSema *FIconSema, char *PrefsName);
  6. static void LoadPrefs(struct FIconSema *FIconSema)
  7. {
  8.         // Try env: first, then envarc:
  9.     if(!DoLoadPrefs(FIconSema, "ENV:ForceIcon_prefs.iff"))
  10.         DoLoadPrefs(FIconSema, "ENVARC:ForceIcon_prefs.iff");
  11. }
  12. static BOOL DoLoadPrefs(struct FIconSema *FIconSema, char *PrefsName)
  13. {
  14.     struct    IFFHandle    *PrefsHandle;
  15.     struct    StoredProperty    *SP;
  16.     UWORD    *VersCheck;
  17.     LONG    Error;
  18.     BOOL    GoOn = FALSE;
  19.  
  20.         // Initialize Lists first
  21.  
  22.     NewList(&FIconSema->VolumeList);
  23.     FIconSema->VolumeList.lh_Type = 0;
  24.  
  25.         // Get Prefs Handle
  26.  
  27.     if((PrefsHandle = AllocIFF()))
  28.     {
  29.             // Open file
  30.  
  31.         if((PrefsHandle->iff_Stream = Open(PrefsName, MODE_OLDFILE)))
  32.         {
  33.                 // Init handle
  34.  
  35.             InitIFFasDOS(PrefsHandle);
  36.  
  37.                 // Open Handle
  38.  
  39.             if(!(Error = OpenIFF(PrefsHandle, IFFF_READ)))
  40.             {
  41.                     // Search for version chunk
  42.  
  43.                 if(!(Error = PropChunk(PrefsHandle, 'FOIC', 'VERS')))
  44.                 {
  45.                         // Stop at prefs
  46.  
  47.                     if(!(Error = StopChunk(PrefsHandle, 'FOIC', 'PREF')))
  48.                     {
  49.                             // Start parsing
  50.  
  51.                         if(!(Error = ParseIFF(PrefsHandle, IFFPARSE_SCAN)))
  52.                         {
  53.                                 // Try to find version chunk
  54.  
  55.                             if((SP = FindProp(PrefsHandle, 'FOIC', 'VERS')))
  56.                             {
  57.                                 VersCheck = (UWORD *)SP->sp_Data;
  58.  
  59.                                     // Check Version number
  60.  
  61.                                 if(((*VersCheck) <= VERNUM) && ((*(VersCheck+1)) <= REVNUM))
  62.                                 {
  63.                                     struct    VolEntry    *ThisEntry;
  64.                                     UWORD            NumEntries,
  65.                                                 EntryType,
  66.                                                 MultiPlyer    = 4;
  67.                                     BOOL            NoErr        = TRUE;
  68.  
  69.                                         // For versions >= 1.4 use larger arrays
  70.  
  71.                                     if(((*VersCheck) >= 1) && ((*(VersCheck + 1)) >= 4))
  72.                                         MultiPlyer    = 36;
  73.  
  74.                                         // Read in prefs
  75.  
  76.                                     if((Error = ReadChunkBytes(PrefsHandle, &NumEntries, sizeof(UWORD))) == sizeof(UWORD))
  77.                                     {
  78.                                         FIconSema->VolumeList.lh_Type = NumEntries;
  79.  
  80.                                         while(NumEntries-- && NoErr)
  81.                                         {
  82.                                             if((ThisEntry = AllocVecPool(FIconSema, sizeof(struct VolEntry))))
  83.                                             {
  84.                                                 AddTail(&FIconSema->VolumeList, (struct Node *)ThisEntry);
  85.                                                 ThisEntry->Link.ln_Name = ThisEntry->VolName;
  86.  
  87.                                                 if((Error = ReadChunkBytes(PrefsHandle, &EntryType, sizeof(UWORD))) == sizeof(UWORD))
  88.                                                 {
  89.                                                     ThisEntry->Link.ln_Type = EntryType;
  90.  
  91.                                                     if((Error = ReadChunkBytes(PrefsHandle, &ThisEntry->VolName, 130)) == 130)
  92.                                                     {
  93.                                                         if((Error = ReadChunkBytes(PrefsHandle, &ThisEntry->IconName, 256)) == 256)
  94.                                                         {
  95.                                                             if((Error = ReadChunkBytes(PrefsHandle, &ThisEntry->Left, (sizeof(UWORD) * MultiPlyer))) != (sizeof(UWORD) * MultiPlyer))
  96.                                                                 NoErr = FALSE;
  97.                                                             else
  98.                                                             {
  99.                                                                 if(!ThisEntry->WinWidth)
  100.                                                                     ThisEntry->WinWidth    = 50;
  101.                                                                     
  102.                                                                 if(!ThisEntry->WinHeight)
  103.                                                                     ThisEntry->WinHeight    = 50;
  104.                                                             }
  105.                                                         }
  106.                                                     }
  107.                                                 }
  108.                                             }
  109.                                             else
  110.                                                 NoErr = FALSE;
  111.                                         }
  112.                                         GoOn = NoErr;
  113.                                     }
  114.  
  115.                                     if(!NoErr)
  116.                                         Error = IoErr();
  117.                                 }
  118.                             }
  119.                         }
  120.                     }
  121.                 }
  122.                 CloseIFF(PrefsHandle);
  123.             }
  124.  
  125.             Close(PrefsHandle->iff_Stream);
  126.         }
  127.         else
  128.             Error = 0;
  129.  
  130.         FreeIFF(PrefsHandle);
  131.     }
  132.     else
  133.         Error = ERR_NOMEM;
  134.  
  135.     if(!GoOn && Error != 0 && Error != ERROR_OBJECT_NOT_FOUND)
  136.         DisplayError(Error, (ULONG)PrefsName);
  137.  
  138.  
  139.     return(GoOn);
  140. }
  141.