home *** CD-ROM | disk | FTP | other *** search
- #include <exec/memory.h>
- #include <libraries/iffparse.h>
- #include <prefs/prefhdr.h>
-
- #include <proto/exec.h>
- #include <proto/dos.h>
- #include <proto/iffparse.h>
-
- #ifdef __MIXED_BINARY__
- #include <proto/powerpc.h>
- #endif
-
- #include <clib/alib_stdio_protos.h>
-
- #include "glmatrix_prefs.h"
-
- struct GLMatrixPrefs *glmatrix_prefs = NULL;
-
- struct GLMatrixPrefs* read_prefs(void)
- {
- struct IFFHandle *iff_handle = NULL;
- struct ContextNode *cn = NULL;
- struct StoredProperty *sp = NULL;
-
- #ifdef __MIXED_BINARY__
- struct GLMatrixPrefs *prefs = AllocVec32(sizeof(struct GLMatrixPrefs), MEMF_CLEAR | MEMF_ANY);
- #else
- struct GLMatrixPrefs *prefs = AllocVec(sizeof(struct GLMatrixPrefs), MEMF_CLEAR | MEMF_ANY);
- #endif
-
- if (prefs != NULL)
- {
- /* Loading default values into prefs */
- prefs->glm_Timeout = 300;
- prefs->glm_Density = 20;
- prefs->glm_Speed = 100;
- prefs->glm_Encoding = 0;
- prefs->glm_Fog = TRUE;
- prefs->glm_Wave = TRUE;
- prefs->glm_Rotate = TRUE;
- prefs->glm_Invert = FALSE;
- prefs->glm_ScreenSize = 0;
-
- iff_handle = AllocIFF();
- if (iff_handle != NULL)
- {
- iff_handle->iff_Stream = (ULONG)Open(ENVPREFSFILE, MODE_OLDFILE);
- if (iff_handle->iff_Stream != 0)
- {
- InitIFFasDOS(iff_handle);
- if (OpenIFF(iff_handle, IFFF_READ) == 0)
- {
- LONG error = 0;
- BOOL version1 = FALSE;
-
- /*PropChunk(iff_handle, ID_PREF, ID_PRHD);*/
- /*PropChunk(iff_handle, ID_PREF, ID_GLMP);*/
- PropChunk(iff_handle, ID_PREF, ID_PRHD);
- StopChunk(iff_handle, ID_PREF, ID_GLMP);
-
- error = ParseIFF(iff_handle, IFFPARSE_SCAN);
-
- sp = FindProp(iff_handle, ID_PREF, ID_PRHD);
- if (sp != NULL)
- {
- struct PrefHeader *head = sp->sp_Data;
- version1 = head->ph_Version == 0 ? FALSE : TRUE;
- } /* if sp */
-
- cn = CurrentChunk(iff_handle);
- if (cn != NULL && cn->cn_ID == ID_GLMP)
- {
- LONG read_length = version1 ? cn->cn_Size : cn->cn_Size - (sizeof(BOOL) + sizeof(ULONG));
- ReadChunkBytes(iff_handle, (APTR)prefs, read_length);
- } /* if cn */
-
- CloseIFF(iff_handle);
- } /* if OpenIFF */
-
- Close((BPTR)iff_handle->iff_Stream);
- } /* if iff_stream */
-
- FreeIFF(iff_handle);
- }/* if iff_handle */
- } /* if prefs */
-
- return prefs;
- }
-
- void write_prefs(struct GLMatrixPrefs *prefs, char *filename)
- {
- struct IFFHandle *iff_handle = NULL;
-
- struct PrefHeader header = {1,0,0};
-
- if(prefs != NULL)
- {
- iff_handle = AllocIFF();
- if (iff_handle != NULL)
- {
- iff_handle->iff_Stream = (ULONG)Open(filename, MODE_NEWFILE);
- if (iff_handle->iff_Stream != NULL)
- {
- InitIFFasDOS(iff_handle);
- if (OpenIFF(iff_handle, IFFF_RWBITS) == 0)
- {
- PushChunk(iff_handle, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN);
-
- /* Write Prefs header */
- PushChunk(iff_handle, ID_PREF, ID_PRHD, sizeof(struct PrefHeader));
- WriteChunkBytes(iff_handle, &header, sizeof(header));
- PopChunk(iff_handle);
-
- /* Write GLMatrix prefs */
- PushChunk(iff_handle, ID_PREF, ID_GLMP, sizeof(struct GLMatrixPrefs));
- WriteChunkBytes(iff_handle, prefs, sizeof(*prefs));
- PopChunk(iff_handle);
-
- PopChunk(iff_handle);
-
- CloseIFF(iff_handle);
- }
-
- Close((BPTR)iff_handle->iff_Stream);
- }
- FreeIFF(iff_handle);
- }
- }
- }
-
- void use_prefs(void)
- {
- write_prefs(glmatrix_prefs, ENVPREFSFILE);
- }
-
- void save_prefs(void)
- {
- write_prefs(glmatrix_prefs, ENVARCPREFSFILE);
- write_prefs(glmatrix_prefs, ENVPREFSFILE);
- }
-