home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
workbench
/
forceicon
/
source.lha
/
source
/
LoadPrefs.h
< prev
next >
Wrap
Text File
|
1995-01-05
|
4KB
|
141 lines
/**********************************************************************/
/* Load in settings */
/**********************************************************************/
static BOOL DoLoadPrefs(struct FIconSema *FIconSema, char *PrefsName);
static void LoadPrefs(struct FIconSema *FIconSema)
{
// Try env: first, then envarc:
if(!DoLoadPrefs(FIconSema, "ENV:ForceIcon_prefs.iff"))
DoLoadPrefs(FIconSema, "ENVARC:ForceIcon_prefs.iff");
}
static BOOL DoLoadPrefs(struct FIconSema *FIconSema, char *PrefsName)
{
struct IFFHandle *PrefsHandle;
struct StoredProperty *SP;
UWORD *VersCheck;
LONG Error;
BOOL GoOn = FALSE;
// Initialize Lists first
NewList(&FIconSema->VolumeList);
FIconSema->VolumeList.lh_Type = 0;
// Get Prefs Handle
if((PrefsHandle = AllocIFF()))
{
// Open file
if((PrefsHandle->iff_Stream = Open(PrefsName, MODE_OLDFILE)))
{
// Init handle
InitIFFasDOS(PrefsHandle);
// Open Handle
if(!(Error = OpenIFF(PrefsHandle, IFFF_READ)))
{
// Search for version chunk
if(!(Error = PropChunk(PrefsHandle, 'FOIC', 'VERS')))
{
// Stop at prefs
if(!(Error = StopChunk(PrefsHandle, 'FOIC', 'PREF')))
{
// Start parsing
if(!(Error = ParseIFF(PrefsHandle, IFFPARSE_SCAN)))
{
// Try to find version chunk
if((SP = FindProp(PrefsHandle, 'FOIC', 'VERS')))
{
VersCheck = (UWORD *)SP->sp_Data;
// Check Version number
if(((*VersCheck) <= VERNUM) && ((*(VersCheck+1)) <= REVNUM))
{
struct VolEntry *ThisEntry;
UWORD NumEntries,
EntryType,
MultiPlyer = 4;
BOOL NoErr = TRUE;
// For versions >= 1.4 use larger arrays
if(((*VersCheck) >= 1) && ((*(VersCheck + 1)) >= 4))
MultiPlyer = 36;
// Read in prefs
if((Error = ReadChunkBytes(PrefsHandle, &NumEntries, sizeof(UWORD))) == sizeof(UWORD))
{
FIconSema->VolumeList.lh_Type = NumEntries;
while(NumEntries-- && NoErr)
{
if((ThisEntry = AllocVecPool(FIconSema, sizeof(struct VolEntry))))
{
AddTail(&FIconSema->VolumeList, (struct Node *)ThisEntry);
ThisEntry->Link.ln_Name = ThisEntry->VolName;
if((Error = ReadChunkBytes(PrefsHandle, &EntryType, sizeof(UWORD))) == sizeof(UWORD))
{
ThisEntry->Link.ln_Type = EntryType;
if((Error = ReadChunkBytes(PrefsHandle, &ThisEntry->VolName, 130)) == 130)
{
if((Error = ReadChunkBytes(PrefsHandle, &ThisEntry->IconName, 256)) == 256)
{
if((Error = ReadChunkBytes(PrefsHandle, &ThisEntry->Left, (sizeof(UWORD) * MultiPlyer))) != (sizeof(UWORD) * MultiPlyer))
NoErr = FALSE;
else
{
if(!ThisEntry->WinWidth)
ThisEntry->WinWidth = 50;
if(!ThisEntry->WinHeight)
ThisEntry->WinHeight = 50;
}
}
}
}
}
else
NoErr = FALSE;
}
GoOn = NoErr;
}
if(!NoErr)
Error = IoErr();
}
}
}
}
}
CloseIFF(PrefsHandle);
}
Close(PrefsHandle->iff_Stream);
}
else
Error = 0;
FreeIFF(PrefsHandle);
}
else
Error = ERR_NOMEM;
if(!GoOn && Error != 0 && Error != ERROR_OBJECT_NOT_FOUND)
DisplayError(Error, (ULONG)PrefsName);
return(GoOn);
}